Skip to content

Commit 773e26d

Browse files
committed
(CONT-801) Correct RSpec/ImplicitSubject
1 parent 0298868 commit 773e26d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+257
-264
lines changed

.rubocop_todo.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,6 @@ RSpec/FilePath:
153153
- 'spec/unit/puppet/provider/file_line/ruby_spec_alter.rb'
154154
- 'spec/unit/puppet/provider/file_line/ruby_spec_use_cases.rb'
155155

156-
# Offense count: 198
157-
# This cop supports safe autocorrection (--autocorrect).
158-
# Configuration parameters: EnforcedStyle.
159-
# SupportedStyles: single_line_only, single_statement_only, disallow, require_implicit
160-
RSpec/ImplicitSubject:
161-
Enabled: false
162-
163156
# Offense count: 2
164157
RSpec/LeakyConstantDeclaration:
165158
Exclude:

spec/functions/assert_private_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
expect(scope).to receive(:lookupvar).with('module_name').and_return('foo')
99
expect(scope).to receive(:lookupvar).with('caller_module_name').and_return('foo')
1010

11-
is_expected.to run.with_params
11+
expect(subject).to run.with_params
1212
end
1313
end
1414

@@ -19,11 +19,11 @@
1919
expect(scope.source).to receive(:name).and_return('foo::baz')
2020
expect(scope.source).to receive(:type).and_return('hostclass')
2121

22-
is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{Class foo::baz is private})
22+
expect(subject).to run.with_params.and_raise_error(Puppet::ParseError, %r{Class foo::baz is private})
2323
end
2424

2525
it 'fails with an explicit failure message' do
26-
is_expected.to run.with_params('failure message!').and_raise_error(Puppet::ParseError, %r{failure message!})
26+
expect(subject).to run.with_params('failure message!').and_raise_error(Puppet::ParseError, %r{failure message!})
2727
end
2828
end
2929

@@ -34,7 +34,7 @@
3434
expect(scope.source).to receive(:name).and_return('foo::baz')
3535
expect(scope.source).to receive(:type).and_return('definition')
3636

37-
is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{Definition foo::baz is private})
37+
expect(subject).to run.with_params.and_raise_error(Puppet::ParseError, %r{Definition foo::baz is private})
3838
end
3939
end
4040
end

spec/functions/base64_spec.rb

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,47 +24,47 @@
2424
it { is_expected.to run.with_params('decode', 'dGhlc3RyaW5n', 'strict').and_return('thestring') }
2525

2626
it {
27-
is_expected.to run.with_params('encode', 'a very long string that will cause the base64 encoder to produce output with multiple lines')
28-
.and_return("YSB2ZXJ5IGxvbmcgc3RyaW5nIHRoYXQgd2lsbCBjYXVzZSB0aGUgYmFzZTY0\nIGVuY29kZXIgdG8gcHJvZHVjZSBvdXRwdXQgd2l0aCBtdWx0aXBsZSBsaW5l\ncw==\n")
27+
expect(subject).to run.with_params('encode', 'a very long string that will cause the base64 encoder to produce output with multiple lines')
28+
.and_return("YSB2ZXJ5IGxvbmcgc3RyaW5nIHRoYXQgd2lsbCBjYXVzZSB0aGUgYmFzZTY0\nIGVuY29kZXIgdG8gcHJvZHVjZSBvdXRwdXQgd2l0aCBtdWx0aXBsZSBsaW5l\ncw==\n")
2929
}
3030

3131
it {
32-
is_expected.to run.with_params('decode', "YSB2ZXJ5IGxvbmcgc3RyaW5nIHRoYXQgd2lsbCBjYXVzZSB0aGUgYmFzZTY0\nIGVuY29kZXIgdG8gcHJvZHVjZSBvdXRwdXQgd2l0aCBtdWx0aXBsZSBsaW5l\ncw==\n")
33-
.and_return('a very long string that will cause the base64 encoder to produce output with multiple lines')
32+
expect(subject).to run.with_params('decode', "YSB2ZXJ5IGxvbmcgc3RyaW5nIHRoYXQgd2lsbCBjYXVzZSB0aGUgYmFzZTY0\nIGVuY29kZXIgdG8gcHJvZHVjZSBvdXRwdXQgd2l0aCBtdWx0aXBsZSBsaW5l\ncw==\n")
33+
.and_return('a very long string that will cause the base64 encoder to produce output with multiple lines')
3434
}
3535

3636
it {
37-
is_expected.to run.with_params('decode', 'YSB2ZXJ5IGxvbmcgc3RyaW5nIHRoYXQgd2lsbCBjYXVzZSB0aGUgYmFzZTY0IGVuY29kZXIgdG8gcHJvZHVjZSBvdXRwdXQgd2l0aCBtdWx0aXBsZSBsaW5lcw==')
38-
.and_return('a very long string that will cause the base64 encoder to produce output with multiple lines')
37+
expect(subject).to run.with_params('decode', 'YSB2ZXJ5IGxvbmcgc3RyaW5nIHRoYXQgd2lsbCBjYXVzZSB0aGUgYmFzZTY0IGVuY29kZXIgdG8gcHJvZHVjZSBvdXRwdXQgd2l0aCBtdWx0aXBsZSBsaW5lcw==')
38+
.and_return('a very long string that will cause the base64 encoder to produce output with multiple lines')
3939
}
4040

4141
it {
42-
is_expected.to run.with_params('encode', 'a very long string that will cause the base64 encoder to produce output with multiple lines', 'strict')
43-
.and_return('YSB2ZXJ5IGxvbmcgc3RyaW5nIHRoYXQgd2lsbCBjYXVzZSB0aGUgYmFzZTY0IGVuY29kZXIgdG8gcHJvZHVjZSBvdXRwdXQgd2l0aCBtdWx0aXBsZSBsaW5lcw==')
42+
expect(subject).to run.with_params('encode', 'a very long string that will cause the base64 encoder to produce output with multiple lines', 'strict')
43+
.and_return('YSB2ZXJ5IGxvbmcgc3RyaW5nIHRoYXQgd2lsbCBjYXVzZSB0aGUgYmFzZTY0IGVuY29kZXIgdG8gcHJvZHVjZSBvdXRwdXQgd2l0aCBtdWx0aXBsZSBsaW5lcw==')
4444
}
4545

4646
it {
47-
is_expected.to run.with_params('decode', 'YSB2ZXJ5IGxvbmcgc3RyaW5nIHRoYXQgd2lsbCBjYXVzZSB0aGUgYmFzZTY0IGVuY29kZXIgdG8gcHJvZHVjZSBvdXRwdXQgd2l0aCBtdWx0aXBsZSBsaW5lcw==', 'strict')
48-
.and_return('a very long string that will cause the base64 encoder to produce output with multiple lines')
47+
expect(subject).to run.with_params('decode', 'YSB2ZXJ5IGxvbmcgc3RyaW5nIHRoYXQgd2lsbCBjYXVzZSB0aGUgYmFzZTY0IGVuY29kZXIgdG8gcHJvZHVjZSBvdXRwdXQgd2l0aCBtdWx0aXBsZSBsaW5lcw==', 'strict')
48+
.and_return('a very long string that will cause the base64 encoder to produce output with multiple lines')
4949
}
5050

5151
it {
52-
is_expected.to run.with_params('encode', 'https://www.google.com.tw/?gws_rd=ssl#q=hello+world', 'urlsafe')
53-
.and_return('aHR0cHM6Ly93d3cuZ29vZ2xlLmNvbS50dy8_Z3dzX3JkPXNzbCNxPWhlbGxvK3dvcmxk')
52+
expect(subject).to run.with_params('encode', 'https://www.google.com.tw/?gws_rd=ssl#q=hello+world', 'urlsafe')
53+
.and_return('aHR0cHM6Ly93d3cuZ29vZ2xlLmNvbS50dy8_Z3dzX3JkPXNzbCNxPWhlbGxvK3dvcmxk')
5454
}
5555

5656
it {
57-
is_expected.to run.with_params('decode', 'aHR0cHM6Ly93d3cuZ29vZ2xlLmNvbS50dy8_Z3dzX3JkPXNzbCNxPWhlbGxvK3dvcmxk', 'urlsafe')
58-
.and_return('https://www.google.com.tw/?gws_rd=ssl#q=hello+world')
57+
expect(subject).to run.with_params('decode', 'aHR0cHM6Ly93d3cuZ29vZ2xlLmNvbS50dy8_Z3dzX3JkPXNzbCNxPWhlbGxvK3dvcmxk', 'urlsafe')
58+
.and_return('https://www.google.com.tw/?gws_rd=ssl#q=hello+world')
5959
}
6060

6161
it {
62-
is_expected.to run.with_params('encode', 'https://github.com/puppetlabs/puppetlabs-stdlib/pulls?utf8=%E2%9C%93&q=is%3Apr+is%3Aopen+Add', 'urlsafe')
63-
.and_return('aHR0cHM6Ly9naXRodWIuY29tL3B1cHBldGxhYnMvcHVwcGV0bGFicy1zdGRsaWIvcHVsbHM_dXRmOD0lRTIlOUMlOTMmcT1pcyUzQXByK2lzJTNBb3BlbitBZGQ=')
62+
expect(subject).to run.with_params('encode', 'https://github.com/puppetlabs/puppetlabs-stdlib/pulls?utf8=%E2%9C%93&q=is%3Apr+is%3Aopen+Add', 'urlsafe')
63+
.and_return('aHR0cHM6Ly9naXRodWIuY29tL3B1cHBldGxhYnMvcHVwcGV0bGFicy1zdGRsaWIvcHVsbHM_dXRmOD0lRTIlOUMlOTMmcT1pcyUzQXByK2lzJTNBb3BlbitBZGQ=')
6464
}
6565

6666
it {
67-
is_expected.to run.with_params('decode', 'aHR0cHM6Ly9naXRodWIuY29tL3B1cHBldGxhYnMvcHVwcGV0bGFicy1zdGRsaWIvcHVsbHM_dXRmOD0lRTIlOUMlOTMmcT1pcyUzQXByK2lzJTNBb3BlbitBZGQ=', 'urlsafe')
68-
.and_return('https://github.com/puppetlabs/puppetlabs-stdlib/pulls?utf8=%E2%9C%93&q=is%3Apr+is%3Aopen+Add')
67+
expect(subject).to run.with_params('decode', 'aHR0cHM6Ly9naXRodWIuY29tL3B1cHBldGxhYnMvcHVwcGV0bGFicy1zdGRsaWIvcHVsbHM_dXRmOD0lRTIlOUMlOTMmcT1pcyUzQXByK2lzJTNBb3BlbitBZGQ=', 'urlsafe')
68+
.and_return('https://github.com/puppetlabs/puppetlabs-stdlib/pulls?utf8=%E2%9C%93&q=is%3Apr+is%3Aopen+Add')
6969
}
7070
end

spec/functions/batch_escape_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
it { is_expected.to run.with_params('foo bar').and_return('"foo bar"') }
2121

2222
it {
23-
is_expected.to run.with_params('~`!@#$%^&*()_-=[]\{}|;\':",./<>?')
24-
.and_return('"~`!@#\\$%^&*()_-=[]\\\{}|;\':"",./<>?"')
23+
expect(subject).to run.with_params('~`!@#$%^&*()_-=[]\{}|;\':",./<>?')
24+
.and_return('"~`!@#\\$%^&*()_-=[]\\\{}|;\':"",./<>?"')
2525
}
2626
end
2727
end

spec/functions/convert_base_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
it { is_expected.to run.with_params('1', 37).and_raise_error(Puppet::ParseError, %r{base must be at least 2 and must not be greater than 36}) }
1414

1515
it 'raises a ParseError if argument 1 is a string that does not correspond to an integer in base 10' do
16-
is_expected.to run.with_params('ten', 6).and_raise_error(Puppet::ParseError, %r{argument must be an integer or a string corresponding to an integer in base 10})
16+
expect(subject).to run.with_params('ten', 6).and_raise_error(Puppet::ParseError, %r{argument must be an integer or a string corresponding to an integer in base 10})
1717
end
1818

1919
it 'raises a ParseError if argument 2 is a string and does not correspond to an integer in base 10' do
20-
is_expected.to run.with_params(100, 'hex').and_raise_error(Puppet::ParseError, %r{argument must be an integer or a string corresponding to an integer in base 10})
20+
expect(subject).to run.with_params(100, 'hex').and_raise_error(Puppet::ParseError, %r{argument must be an integer or a string corresponding to an integer in base 10})
2121
end
2222

2323
it { is_expected.to run.with_params('11', '16').and_return('b') }

spec/functions/count_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
it {
1212
pending('should actually be like this, and not like above')
13-
is_expected.to run.with_params('one', 'two').and_raise_error(ArgumentError)
13+
expect(subject).to run.with_params('one', 'two').and_raise_error(ArgumentError)
1414
}
1515

1616
it { is_expected.to run.with_params('one', 'two', 'three').and_raise_error(ArgumentError) }

spec/functions/deep_merge_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,33 @@
1616

1717
describe 'when arguments have key collisions' do
1818
it 'prefers values from the last hash' do
19-
is_expected.to run \
19+
expect(subject).to run \
2020
.with_params({ 'key1' => 'value1', 'key2' => 'value2' }, 'key2' => 'replacement_value', 'key3' => 'value3') \
2121
.and_return('key1' => 'value1', 'key2' => 'replacement_value', 'key3' => 'value3')
2222
end
2323

2424
it {
25-
is_expected.to run \
25+
expect(subject).to run \
2626
.with_params({ 'key1' => 'value1' }, { 'key1' => 'value2' }, 'key1' => 'value3') \
2727
.and_return('key1' => 'value3')
2828
}
2929
end
3030

3131
describe 'when arguments have subhashes' do
3232
it {
33-
is_expected.to run \
33+
expect(subject).to run \
3434
.with_params({ 'key1' => 'value1' }, 'key2' => 'value2', 'key3' => { 'subkey1' => 'value4' }) \
3535
.and_return('key1' => 'value1', 'key2' => 'value2', 'key3' => { 'subkey1' => 'value4' })
3636
}
3737

3838
it {
39-
is_expected.to run \
39+
expect(subject).to run \
4040
.with_params({ 'key1' => { 'subkey1' => 'value1' } }, 'key1' => { 'subkey2' => 'value2' }) \
4141
.and_return('key1' => { 'subkey1' => 'value1', 'subkey2' => 'value2' })
4242
}
4343

4444
it {
45-
is_expected.to run \
45+
expect(subject).to run \
4646
.with_params({ 'key1' => { 'subkey1' => { 'subsubkey1' => 'value1' } } }, 'key1' => { 'subkey1' => { 'subsubkey1' => 'value2' } }) \
4747
.and_return('key1' => { 'subkey1' => { 'subsubkey1' => 'value2' } })
4848
}

spec/functions/defined_with_params_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
it { is_expected.to run.with_params(Puppet::Resource.new('Test::Deftype[foo]'), {}).and_return(true) }
9393

9494
it {
95-
is_expected.to run.with_params(Puppet::Resource.new('Test::Deftype[bar]'), {}).and_return(false)
95+
expect(subject).to run.with_params(Puppet::Resource.new('Test::Deftype[bar]'), {}).and_return(false)
9696

9797
expect(catalogue.resource('Notify[Duplicate found somewhere]')).not_to be_nil
9898
expect(catalogue.resource('Notify[Should not find me]')).to be_nil

spec/functions/delete_at_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
it {
1313
pending('Current implementation ignores parameters after the first two.')
14-
is_expected.to run.with_params(['one'], 0, 1).and_raise_error(Puppet::ParseError)
14+
expect(subject).to run.with_params(['one'], 0, 1).and_raise_error(Puppet::ParseError)
1515
}
1616

1717
describe 'argument validation' do

spec/functions/delete_regex_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@
3232
it { is_expected.to run.with_params({ 'key' => 'value' }, 'key').and_return({}) }
3333

3434
it {
35-
is_expected.to run \
35+
expect(subject).to run \
3636
.with_params({ 'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3' }, 'key2') \
3737
.and_return('key1' => 'value1', 'key3' => 'value3')
3838
}
3939

4040
it {
41-
is_expected.to run \
41+
expect(subject).to run \
4242
.with_params({ 'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3' }, ['key1', 'key2']) \
4343
.and_return('key3' => 'value3')
4444
}

0 commit comments

Comments
 (0)