Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spec cleanup from rubocop-rspec #740

Merged
merged 1 commit into from
Sep 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions spec/rubocop/chef/cookbook_helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

RSpec.describe RuboCop::Chef::CookbookHelpers do
include RuboCop::AST::Sexp
include RuboCop::Chef::CookbookHelpers
include described_class

let (:running_false_ast) { s(:send, nil, :running, s(:false)) }

Expand All @@ -31,15 +31,15 @@
describe 'when the the resource name is a string' do
let(:resource_source) { "service 'foo' do; running true; end" }

it 'should return the resource name string' do
it 'returns the resource name string' do
expect(resource_block_name_if_string(parse_source(resource_source).ast)).to eq 'foo'
end
end

describe 'when the the resource name is a variable' do
let(:resource_source) { 'service foo_service do; running true; end' }

it 'should return nil' do
it 'returns nil' do
expect(resource_block_name_if_string(parse_source(resource_source).ast)).to be_nil
end
end
Expand All @@ -49,15 +49,15 @@
describe 'when the passed name matches the resource' do
let(:resource_source) { "service 'foo' do; running true; end" }

it 'should yield a the service block ast objects' do
it 'yields a the service block ast objects' do
expect { |b| match_resource_type?(:service, parse_source(resource_source).ast, &b) }.to yield_successive_args(s(:block, s(:send, nil, :service, s(:str, 'foo')), s(:args), s(:send, nil, :running, s(:true))))
end
end

describe "when the passed name doesn't match the resource" do
let(:resource_source) { "service 'foo' do; running true; end" }

it 'should not yield anything' do
it 'does not yield anything' do
expect { |b| match_resource_type?(:archive_file, parse_source(resource_source).ast, &b) }.not_to yield_control
end
end
Expand All @@ -67,19 +67,19 @@
describe 'single property in a resource' do
let(:resource_source) { "service 'single_property' do; running true; end" }

it "should yield a single 'running' property ast objects" do
it "yields a single 'running' property ast objects" do
expect { |b| match_property_in_resource?(:service, 'running', parse_source(resource_source).ast, &b) }.to yield_successive_args(running_true_ast)
end

it "should yield a single 'running' property ast objects when passed an array" do
it "yields a single 'running' property ast objects when passed an array" do
expect { |b| match_property_in_resource?(%i(service file), 'running', parse_source(resource_source).ast, &b) }.to yield_successive_args(running_true_ast)
end
end

describe 'multiple properties in a resource' do
let(:resource_source) { "service 'single_property' do; not_running true; running true; end" }

it "should yield a single 'running' property ast objects" do
it "yields a single 'running' property ast objects" do
expect { |b| match_property_in_resource?(:service, 'running', parse_source(resource_source).ast, &b) }.to yield_successive_args(running_true_ast)
end
end
Expand All @@ -95,7 +95,7 @@
RUBY
end

it "should yield a single 'running' property ast objects" do
it "yields a single 'running' property ast objects" do
expect { |b| match_property_in_resource?(:service, %w(running verify), parse_source(resource_source).ast, &b) }.to yield_successive_args(running_true_ast)
end
end
Expand All @@ -111,7 +111,7 @@
RUBY
end

it "should yield a single 'running' property ast objects" do
it "yields a single 'running' property ast objects" do
expect { |b| match_property_in_resource?(:service, 'running', parse_source(resource_source).ast, &b) }.to yield_successive_args(running_true_ast)
end
end
Expand All @@ -130,7 +130,7 @@
RUBY
end

it "should yield both 'running' property ast objects" do
it "yields both 'running' property ast objects" do
expect { |b| match_property_in_resource?(:service, 'running', parse_source(resource_source).ast, &b) }.to yield_successive_args(running_true_ast, running_false_ast)
end
end
Expand All @@ -153,7 +153,7 @@
RUBY
end

it "should yield three 'running' property ast objects" do
it "yields three 'running' property ast objects" do
expect { |b| match_property_in_resource?(:service, 'running', parse_source(resource_source).ast, &b) }.to yield_successive_args(running_true_ast, running_false_ast, running_true_ast)
end
end
Expand All @@ -172,7 +172,7 @@
RUBY
end

it "should yield a single 'running' property ast objects" do
it "yields a single 'running' property ast objects" do
expect { |b| match_property_in_resource?(:service, 'running', parse_source(resource_source).ast, &b) }.to yield_successive_args(running_false_ast)
end
end
Expand All @@ -188,7 +188,7 @@
RUBY
end

it "should yield a single 'running' property ast objects" do
it "yields a single 'running' property ast objects" do
expect { |b| match_property_in_resource?(:service, 'running', parse_source(resource_source).ast, &b) }.to yield_successive_args(running_false_ast)
end
end
Expand All @@ -204,7 +204,7 @@
RUBY
end

it "should yield a single 'running' property ast objects" do
it "yields a single 'running' property ast objects" do
expect { |b| match_property_in_resource?(:service, 'running', parse_source(resource_source).ast, &b) }.to yield_successive_args(running_false_ast)
end
end
Expand All @@ -218,7 +218,7 @@
RUBY
end

it 'should not yield anything' do
it 'does not yield anything' do
expect { |b| match_property_in_resource?(:service, 'running', parse_source(resource_source).ast, &b) }.not_to yield_control
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

# prior to Rubocop 0.87 the autocorrect was not with expect_offense
# in Rubocop 0.87 the autocorrect method is being executed and this attempts to write data
before(:each) do
before do
allow(IO).to receive(:read).with('/foo/bar/metadata.rb').and_return("supports 'ubuntu'")
allow(IO).to receive(:write).with('/foo/bar/metadata.rb', "name 'bar'\nsupports 'ubuntu'")
end
Expand Down
11 changes: 0 additions & 11 deletions spec/rubocop/cop/chef/modernize/node_init_package_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,6 @@
RUBY
end

it "registers an offense with File.exist?('/proc/1/comm') && File.open('/proc/1/comm').chomp == 'systemd'" do
expect_offense(<<~RUBY)
File.exist?('/proc/1/comm') && File.open('/proc/1/comm').chomp == 'systemd'
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use node['init_package'] to check for systemd instead of reading the contents of '/proc/1/comm'
RUBY

expect_correction(<<~RUBY)
node['init_package'] == 'systemd'
RUBY
end

it "registers an offense with IO.read('/proc/1/comm').chomp == 'systemd'" do
expect_offense(<<~RUBY)
IO.read('/proc/1/comm').chomp == 'systemd'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def initialize(name, run_context = nil)
RUBY
end

it 'registers an offense with a HWRP that uses respond_to? with resource_name' do
it 'does not register an offense with a HWRP does not use respond_to? with resource_name' do
expect_no_offenses(<<~RUBY)
class Chef
class Resource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
RUBY
end

it "doesn't register an offense when apt_repository sets a non-PPA uri" do
it "doesn't register an offense with a simplified PPA uri" do
expect_no_offenses(<<~RUBY)
apt_repository 'atom-ppa' do
uri 'ppa:webupd8team/atom'
Expand Down
9 changes: 0 additions & 9 deletions spec/rubocop/cop/chef/style/file_mode_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,6 @@
RUBY
end

it 'does not register an offense when setting a mode using a double quoted string' do
expect_no_offenses(<<~RUBY)
file '/foo' do
owner 'root'
mode '644'
end
RUBY
end

it 'registers an offense when setting a files_mode as well' do
expect_offense(<<~RUBY)
file '/foo' do
Expand Down