From 7c611a4c24abd77117823e2bd4e75f0a3ffd4d5c Mon Sep 17 00:00:00 2001 From: Clinton Wolfe Date: Wed, 7 Nov 2018 13:59:48 -0500 Subject: [PATCH] Silence RSpec 'should' Warning (#3560) * Failing functional test for RSpec should deprecation * Configure RSpec to allow .should calls * Remove cruft from test files where we needed to filter deprecation warning Signed-off-by: Clinton Wolfe --- lib/inspec/rspec_extensions.rb | 8 ++++++++ test/functional/filter_table_test.rb | 16 ++++------------ test/functional/inspec_exec_test.rb | 10 ++++++++++ .../controls/explicit_should.rb | 5 +++++ .../profiles/rspec-should-deprecation/inspec.yml | 8 ++++++++ 5 files changed, 35 insertions(+), 12 deletions(-) create mode 100644 test/unit/mock/profiles/rspec-should-deprecation/controls/explicit_should.rb create mode 100644 test/unit/mock/profiles/rspec-should-deprecation/inspec.yml diff --git a/lib/inspec/rspec_extensions.rb b/lib/inspec/rspec_extensions.rb index 5199dfdc21..888c8b1f0e 100644 --- a/lib/inspec/rspec_extensions.rb +++ b/lib/inspec/rspec_extensions.rb @@ -1,6 +1,14 @@ require 'inspec/attribute_registry' +require 'rspec/core' require 'rspec/core/example_group' +# Setup RSpec to allow use of `should` syntax without warnings +RSpec.configure do |config| + config.expect_with(:rspec) do |rspec_expectations_config| + rspec_expectations_config.syntax = :should + end +end + # This file allows you to add ExampleGroups to be used in rspec tests # class RSpec::Core::ExampleGroup diff --git a/test/functional/filter_table_test.rb b/test/functional/filter_table_test.rb index 7e1b7ce41d..3d365d9857 100644 --- a/test/functional/filter_table_test.rb +++ b/test/functional/filter_table_test.rb @@ -18,9 +18,7 @@ cmd += ' --controls ' + controls.join(' ') cmd = inspec(cmd) - # RSpec keeps issuing a deprecation count to stdout; I can't seem to disable it. - output = cmd.stdout.split("\n").reject {|line| line =~ /deprecation/}.join("\n") - data = JSON.parse(output) + data = JSON.parse(cmd.stdout) failed_controls = data['profiles'][0]['controls'].select { |ctl| ctl['results'][0]['status'] == 'failed' } control_hash = {} failed_controls.each do |ctl| @@ -69,9 +67,7 @@ cmd += ' --controls ' + controls.join(' ') cmd = inspec(cmd) - # RSpec keeps issuing a deprecation count to stdout; I can't seem to disable it. - output = cmd.stdout.split("\n").reject {|line| line =~ /deprecation/}.join("\n") - data = JSON.parse(output) + data = JSON.parse(cmd.stdout) failed_controls = data['profiles'][0]['controls'].select { |ctl| ctl['results'][0]['status'] == 'failed' } control_hash = {} failed_controls.each do |ctl| @@ -105,9 +101,7 @@ cmd += ' --controls ' + controls.join(' ') cmd = inspec(cmd) - # RSpec keeps issuing a deprecation count to stdout; I can't seem to disable it. - output = cmd.stdout.split("\n").reject {|line| line =~ /deprecation/}.join("\n") - data = JSON.parse(output) + data = JSON.parse(cmd.stdout) failed_controls = data['profiles'][0]['controls'].select { |ctl| ctl['results'][0]['status'] == 'failed' } control_hash = {} failed_controls.each do |ctl| @@ -175,9 +169,7 @@ cmd += ' --controls ' + controls.join(' ') cmd = inspec(cmd) - # RSpec keeps issuing a deprecation count to stdout; I can't seem to disable it. - output = cmd.stdout.split("\n").reject {|line| line =~ /deprecation/}.join("\n") - data = JSON.parse(output) + data = JSON.parse(cmd.stdout) failed_controls = data['profiles'][0]['controls'].select { |ctl| ctl['results'][0]['status'] == 'failed' } control_hash = {} failed_controls.each do |ctl| diff --git a/test/functional/inspec_exec_test.rb b/test/functional/inspec_exec_test.rb index 0a6a937329..8818397213 100644 --- a/test/functional/inspec_exec_test.rb +++ b/test/functional/inspec_exec_test.rb @@ -514,4 +514,14 @@ out.exit_status.must_equal 0 end end + + describe 'when using a profile that calls .should explicitly' do + let(:run_result) { inspec('exec ' + File.join(profile_path, 'rspec-should-deprecation')) } + it 'should suppress the RSpec deprecation warning' do + # Refs inspec github issue 952 + run_result.exit_status.must_equal 0 + run_result.stderr.must_be_empty + run_result.stdout.wont_include('1 deprecation warning total') + end + end end diff --git a/test/unit/mock/profiles/rspec-should-deprecation/controls/explicit_should.rb b/test/unit/mock/profiles/rspec-should-deprecation/controls/explicit_should.rb new file mode 100644 index 0000000000..e2e19de3fc --- /dev/null +++ b/test/unit/mock/profiles/rspec-should-deprecation/controls/explicit_should.rb @@ -0,0 +1,5 @@ +control 'call-should-as-an-explicit-method' do + describe 'It should work without issuing a deprecation warning' do + it { 'a string'.should include 'ing' } + end +end diff --git a/test/unit/mock/profiles/rspec-should-deprecation/inspec.yml b/test/unit/mock/profiles/rspec-should-deprecation/inspec.yml new file mode 100644 index 0000000000..7379e6cfaf --- /dev/null +++ b/test/unit/mock/profiles/rspec-should-deprecation/inspec.yml @@ -0,0 +1,8 @@ +name: rspec-should-deprecation +title: A profile to trigger an RSpec deprecation warning, refs github 952 +maintainer: The Authors +copyright: The Authors +copyright_email: you@example.com +license: Apache-2.0 +summary: An InSpec Compliance Profile +version: 0.1.0