From 47d3a7f03a50b4256abd240c93a21fc377f369dc Mon Sep 17 00:00:00 2001 From: Dmitry Rybakov Date: Thu, 15 Apr 2021 11:12:20 +0200 Subject: [PATCH 1/2] RUBY-2296: Fix app metadata spec This commit fixes an assumption that the spec is always executed on a Linux machine. --- spec/mongo/server/app_metadata_shared.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/spec/mongo/server/app_metadata_shared.rb b/spec/mongo/server/app_metadata_shared.rb index 47d852bf1f..d9d97dc3d5 100644 --- a/spec/mongo/server/app_metadata_shared.rb +++ b/spec/mongo/server/app_metadata_shared.rb @@ -12,13 +12,13 @@ end it 'includes operating system information' do - document[:client][:os][:type].should == 'linux' - if BSON::Environment.jruby? || RUBY_VERSION >= '3.0' - document[:client][:os][:name].should == 'linux' - else - document[:client][:os][:name].should == 'linux-gnu' + %w(linux darwin).each do |os| + if !!(RUBY_PLATFORM =~ /\#{os}/) + document[:client][:os][:type].should == os + end end - document[:client][:os][:architecture].should == 'x86_64' + document[:client][:os][:name].should == RbConfig::CONFIG['host_os'] + document[:client][:os][:architecture].should == RbConfig::CONFIG['target_cpu'] end context 'mri' do From 344e37dd992bf77b0f527b3bf0d35fc2ee4b463e Mon Sep 17 00:00:00 2001 From: Dmitry Rybakov Date: Thu, 15 Apr 2021 16:24:46 +0200 Subject: [PATCH 2/2] Separate tests for Linux and MacOS --- spec/mongo/server/app_metadata_shared.rb | 38 ++++++++++++++++++++---- spec/support/spec_config.rb | 8 +++++ 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/spec/mongo/server/app_metadata_shared.rb b/spec/mongo/server/app_metadata_shared.rb index d9d97dc3d5..b46aec6421 100644 --- a/spec/mongo/server/app_metadata_shared.rb +++ b/spec/mongo/server/app_metadata_shared.rb @@ -11,14 +11,40 @@ document[:client][:driver][:version].should == Mongo::VERSION end - it 'includes operating system information' do - %w(linux darwin).each do |os| - if !!(RUBY_PLATFORM =~ /\#{os}/) - document[:client][:os][:type].should == os + context 'linux' do + before(:all) do + unless SpecConfig.instance.linux? + skip "Linux required, we have #{RbConfig::CONFIG['host_os']}" end end - document[:client][:os][:name].should == RbConfig::CONFIG['host_os'] - document[:client][:os][:architecture].should == RbConfig::CONFIG['target_cpu'] + + it 'includes operating system information' do + document[:client][:os][:type].should == 'linux' + if BSON::Environment.jruby? || RUBY_VERSION >= '3.0' + document[:client][:os][:name].should == 'linux' + else + document[:client][:os][:name].should == 'linux-gnu' + end + document[:client][:os][:architecture].should == 'x86_64' + end + end + + context 'macos' do + before(:all) do + unless SpecConfig.instance.macos? + skip "MacOS required, we have #{RbConfig::CONFIG['host_os']}" + end + end + + it 'includes operating system information' do + document[:client][:os][:type].should == 'darwin' + if BSON::Environment.jruby? + document[:client][:os][:name].should == 'darwin' + else + document[:client][:os][:name].should =~ /darwin\d+/ + end + document[:client][:os][:architecture].should == 'x86_64' + end end context 'mri' do diff --git a/spec/support/spec_config.rb b/spec/support/spec_config.rb index 5ce8544323..27ba61d0cf 100644 --- a/spec/support/spec_config.rb +++ b/spec/support/spec_config.rb @@ -124,6 +124,14 @@ def jruby? !!(RUBY_PLATFORM =~ /\bjava\b/) end + def linux? + !!(RbConfig::CONFIG['host_os'].downcase =~ /\blinux/) + end + + def macos? + !!(RbConfig::CONFIG['host_os'].downcase =~ /\bdarwin/) + end + def platform RUBY_PLATFORM end