From f0e56677578ebc75659a1dc716c636d23096755a Mon Sep 17 00:00:00 2001 From: Dmitry Rybakov Date: Mon, 19 Apr 2021 09:05:47 +0200 Subject: [PATCH] RUBY-2296: Fix app metadata spec (#2208) 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 | 40 +++++++++++++++++++----- spec/support/spec_config.rb | 8 +++++ 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/spec/mongo/server/app_metadata_shared.rb b/spec/mongo/server/app_metadata_shared.rb index c19898ab03..3c1d0fbe3d 100644 --- a/spec/mongo/server/app_metadata_shared.rb +++ b/spec/mongo/server/app_metadata_shared.rb @@ -8,14 +8,40 @@ document[:client][:driver][:version].should == Mongo::VERSION 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' + context 'linux' do + before(:all) do + unless SpecConfig.instance.linux? + skip "Linux required, we have #{RbConfig::CONFIG['host_os']}" + end + 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' + 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 - document[:client][:os][:architecture].should == 'x86_64' end context 'mri' do diff --git a/spec/support/spec_config.rb b/spec/support/spec_config.rb index 94d722c647..56d5a9294b 100644 --- a/spec/support/spec_config.rb +++ b/spec/support/spec_config.rb @@ -110,6 +110,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