Skip to content

Commit

Permalink
Silence RSpec 'should' Warning (#3560)
Browse files Browse the repository at this point in the history
* 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 <clintoncwolfe@gmail.com>
  • Loading branch information
clintoncwolfe authored and jquick committed Nov 7, 2018
1 parent 12d4b22 commit 7c611a4
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 12 deletions.
8 changes: 8 additions & 0 deletions 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
Expand Down
16 changes: 4 additions & 12 deletions test/functional/filter_table_test.rb
Expand Up @@ -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|
Expand Down Expand Up @@ -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|
Expand Down Expand Up @@ -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|
Expand Down Expand Up @@ -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|
Expand Down
10 changes: 10 additions & 0 deletions test/functional/inspec_exec_test.rb
Expand Up @@ -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
@@ -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
8 changes: 8 additions & 0 deletions 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

0 comments on commit 7c611a4

Please sign in to comment.