rubocop-rspec 1.12.0 → 1.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +11 -0
  3. data/config/default.yml +15 -1
  4. data/lib/rubocop-rspec.rb +2 -0
  5. data/lib/rubocop/cop/rspec/any_instance.rb +7 -10
  6. data/lib/rubocop/cop/rspec/around_block.rb +19 -30
  7. data/lib/rubocop/cop/rspec/be_eql.rb +3 -7
  8. data/lib/rubocop/cop/rspec/before_after_all.rb +10 -16
  9. data/lib/rubocop/cop/rspec/cop.rb +5 -1
  10. data/lib/rubocop/cop/rspec/describe_class.rb +8 -8
  11. data/lib/rubocop/cop/rspec/describe_method.rb +6 -5
  12. data/lib/rubocop/cop/rspec/described_class.rb +2 -2
  13. data/lib/rubocop/cop/rspec/example_length.rb +5 -8
  14. data/lib/rubocop/cop/rspec/example_wording.rb +57 -23
  15. data/lib/rubocop/cop/rspec/expect_actual.rb +3 -9
  16. data/lib/rubocop/cop/rspec/expect_output.rb +2 -2
  17. data/lib/rubocop/cop/rspec/file_path.rb +30 -29
  18. data/lib/rubocop/cop/rspec/hook_argument.rb +1 -1
  19. data/lib/rubocop/cop/rspec/instance_spy.rb +12 -12
  20. data/lib/rubocop/cop/rspec/instance_variable.rb +2 -2
  21. data/lib/rubocop/cop/rspec/it_behaves_like.rb +47 -0
  22. data/lib/rubocop/cop/rspec/leading_subject.rb +1 -1
  23. data/lib/rubocop/cop/rspec/message_chain.rb +7 -4
  24. data/lib/rubocop/cop/rspec/message_spies.rb +6 -5
  25. data/lib/rubocop/cop/rspec/multiple_describes.rb +1 -1
  26. data/lib/rubocop/cop/rspec/multiple_expectations.rb +38 -6
  27. data/lib/rubocop/cop/rspec/named_subject.rb +2 -2
  28. data/lib/rubocop/cop/rspec/nested_groups.rb +10 -6
  29. data/lib/rubocop/cop/rspec/not_to_not.rb +12 -23
  30. data/lib/rubocop/cop/rspec/shared_context.rb +107 -0
  31. data/lib/rubocop/cop/rspec/single_argument_message_chain.rb +16 -23
  32. data/lib/rubocop/cop/rspec/subject_stub.rb +4 -4
  33. data/lib/rubocop/cop/rspec/verified_doubles.rb +4 -3
  34. data/lib/rubocop/rspec/example_group.rb +1 -1
  35. data/lib/rubocop/rspec/language.rb +25 -7
  36. data/lib/rubocop/rspec/version.rb +1 -1
  37. data/spec/expect_violation/expectation_spec.rb +16 -16
  38. data/spec/project/changelog_spec.rb +1 -1
  39. data/spec/project/default_config_spec.rb +1 -1
  40. data/spec/project/project_requires_spec.rb +1 -1
  41. data/spec/rubocop/cop/rspec/any_instance_spec.rb +4 -4
  42. data/spec/rubocop/cop/rspec/around_block_spec.rb +115 -26
  43. data/spec/rubocop/cop/rspec/be_eql_spec.rb +9 -9
  44. data/spec/rubocop/cop/rspec/before_after_all_spec.rb +38 -80
  45. data/spec/rubocop/cop/rspec/describe_class_spec.rb +1 -1
  46. data/spec/rubocop/cop/rspec/describe_method_spec.rb +2 -2
  47. data/spec/rubocop/cop/rspec/described_class_spec.rb +13 -13
  48. data/spec/rubocop/cop/rspec/empty_example_group_spec.rb +1 -1
  49. data/spec/rubocop/cop/rspec/example_length_spec.rb +3 -32
  50. data/spec/rubocop/cop/rspec/example_wording_spec.rb +21 -2
  51. data/spec/rubocop/cop/rspec/expect_actual_spec.rb +33 -18
  52. data/spec/rubocop/cop/rspec/expect_output_spec.rb +3 -3
  53. data/spec/rubocop/cop/rspec/file_path_spec.rb +119 -170
  54. data/spec/rubocop/cop/rspec/focus_spec.rb +1 -1
  55. data/spec/rubocop/cop/rspec/hook_argument_spec.rb +1 -3
  56. data/spec/rubocop/cop/rspec/implicit_expect_spec.rb +1 -1
  57. data/spec/rubocop/cop/rspec/instance_spy_spec.rb +11 -11
  58. data/spec/rubocop/cop/rspec/instance_variable_spec.rb +4 -4
  59. data/spec/rubocop/cop/rspec/it_behaves_like_spec.rb +51 -0
  60. data/spec/rubocop/cop/rspec/leading_subject_spec.rb +1 -1
  61. data/spec/rubocop/cop/rspec/let_setup_spec.rb +1 -1
  62. data/spec/rubocop/cop/rspec/message_chain_spec.rb +3 -3
  63. data/spec/rubocop/cop/rspec/message_expectation_spec.rb +5 -23
  64. data/spec/rubocop/cop/rspec/message_spies_spec.rb +9 -23
  65. data/spec/rubocop/cop/rspec/multiple_describes_spec.rb +1 -1
  66. data/spec/rubocop/cop/rspec/multiple_expectations_spec.rb +66 -3
  67. data/spec/rubocop/cop/rspec/nested_groups_spec.rb +4 -4
  68. data/spec/rubocop/cop/rspec/not_to_not_spec.rb +3 -3
  69. data/spec/rubocop/cop/rspec/repeated_description_spec.rb +1 -1
  70. data/spec/rubocop/cop/rspec/repeated_example_spec.rb +1 -1
  71. data/spec/rubocop/cop/rspec/scattered_setup_spec.rb +1 -1
  72. data/spec/rubocop/cop/rspec/shared_context_spec.rb +142 -0
  73. data/spec/rubocop/cop/rspec/single_argument_message_chain_spec.rb +5 -5
  74. data/spec/rubocop/cop/rspec/subject_stub_spec.rb +1 -1
  75. data/spec/rubocop/cop/rspec/verified_doubles_spec.rb +2 -2
  76. data/spec/rubocop/rspec/config_formatter_spec.rb +12 -12
  77. data/spec/rubocop/rspec/description_extractor_spec.rb +23 -23
  78. data/spec/rubocop/rspec/example_group_spec.rb +11 -11
  79. data/spec/rubocop/rspec/example_spec.rb +1 -1
  80. data/spec/rubocop/rspec/language/selector_set_spec.rb +1 -1
  81. data/spec/rubocop/rspec/util/one_spec.rb +1 -1
  82. data/spec/rubocop/rspec/wording_spec.rb +1 -1
  83. data/spec/shared/detects_style_behavior.rb +3 -4
  84. data/spec/spec_helper.rb +10 -0
  85. metadata +8 -2
@@ -1,11 +1,11 @@
1
- describe RuboCop::Cop::RSpec::ExampleWording, :config do
1
+ RSpec.describe RuboCop::Cop::RSpec::ExampleWording, :config do
2
2
  subject(:cop) { described_class.new(config) }
3
3
 
4
4
  context 'with configuration' do
5
5
  let(:cop_config) do
6
6
  {
7
7
  'CustomTransform' => { 'have' => 'has', 'not' => 'does not' },
8
- 'IgnoredWords' => %w(only really)
8
+ 'IgnoredWords' => %w(only really)
9
9
  }
10
10
  end
11
11
 
@@ -37,6 +37,21 @@ describe RuboCop::Cop::RSpec::ExampleWording, :config do
37
37
  RUBY
38
38
  end
39
39
 
40
+ it 'finds leading its' do
41
+ expect_violation(<<-RUBY)
42
+ it "it does something" do
43
+ ^^^^^^^^^^^^^^^^^ Do not repeat 'it' when describing your tests.
44
+ end
45
+ RUBY
46
+ end
47
+
48
+ it "skips words beginning with 'it'" do
49
+ expect_no_violations(<<-RUBY)
50
+ it 'itemizes items' do
51
+ end
52
+ RUBY
53
+ end
54
+
40
55
  it 'skips descriptions without `should` at the beginning' do
41
56
  expect_no_violations(<<-RUBY)
42
57
  it 'finds no should here' do
@@ -47,6 +62,10 @@ describe RuboCop::Cop::RSpec::ExampleWording, :config do
47
62
  include_examples 'autocorrect',
48
63
  'it "should only have trait" do end',
49
64
  'it "only has trait" do end'
65
+
66
+ include_examples 'autocorrect',
67
+ 'it "it does something" do end',
68
+ 'it "does something" do end'
50
69
  end
51
70
 
52
71
  context 'when configuration is empty' do
@@ -1,20 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe RuboCop::Cop::RSpec::ExpectActual do
4
- subject(:cop) { described_class.new }
3
+ RSpec.describe RuboCop::Cop::RSpec::ExpectActual, :config do
4
+ subject(:cop) { described_class.new(config) }
5
5
 
6
6
  it 'flags numeric literal values within expect(...)' do
7
7
  expect_violation(<<-RUBY)
8
8
  describe Foo do
9
9
  it 'uses expect incorrectly' do
10
10
  expect(123).to eq(bar)
11
- ^^^ Provide the actual you are testing to `expect(...)`
11
+ ^^^ Provide the actual you are testing to `expect(...)`.
12
12
  expect(12.3).to eq(bar)
13
- ^^^^ Provide the actual you are testing to `expect(...)`
13
+ ^^^^ Provide the actual you are testing to `expect(...)`.
14
14
  expect(1i).to eq(bar)
15
- ^^ Provide the actual you are testing to `expect(...)`
15
+ ^^ Provide the actual you are testing to `expect(...)`.
16
16
  expect(1r).to eq(bar)
17
- ^^ Provide the actual you are testing to `expect(...)`
17
+ ^^ Provide the actual you are testing to `expect(...)`.
18
18
  end
19
19
  end
20
20
  RUBY
@@ -25,9 +25,9 @@ describe RuboCop::Cop::RSpec::ExpectActual do
25
25
  describe Foo do
26
26
  it 'uses expect incorrectly' do
27
27
  expect(true).to eq(bar)
28
- ^^^^ Provide the actual you are testing to `expect(...)`
28
+ ^^^^ Provide the actual you are testing to `expect(...)`.
29
29
  expect(false).to eq(bar)
30
- ^^^^^ Provide the actual you are testing to `expect(...)`
30
+ ^^^^^ Provide the actual you are testing to `expect(...)`.
31
31
  end
32
32
  end
33
33
  RUBY
@@ -38,9 +38,9 @@ describe RuboCop::Cop::RSpec::ExpectActual do
38
38
  describe Foo do
39
39
  it 'uses expect incorrectly' do
40
40
  expect("foo").to eq(bar)
41
- ^^^^^ Provide the actual you are testing to `expect(...)`
41
+ ^^^^^ Provide the actual you are testing to `expect(...)`.
42
42
  expect(:foo).to eq(bar)
43
- ^^^^ Provide the actual you are testing to `expect(...)`
43
+ ^^^^ Provide the actual you are testing to `expect(...)`.
44
44
  end
45
45
  end
46
46
  RUBY
@@ -51,7 +51,7 @@ describe RuboCop::Cop::RSpec::ExpectActual do
51
51
  describe Foo do
52
52
  it 'uses expect incorrectly' do
53
53
  expect(nil).to eq(bar)
54
- ^^^ Provide the actual you are testing to `expect(...)`
54
+ ^^^ Provide the actual you are testing to `expect(...)`.
55
55
  end
56
56
  end
57
57
  RUBY
@@ -74,9 +74,9 @@ describe RuboCop::Cop::RSpec::ExpectActual do
74
74
  describe Foo do
75
75
  it 'uses expect incorrectly' do
76
76
  expect([123]).to eq(bar)
77
- ^^^^^ Provide the actual you are testing to `expect(...)`
77
+ ^^^^^ Provide the actual you are testing to `expect(...)`.
78
78
  expect([[123]]).to eq(bar)
79
- ^^^^^^^ Provide the actual you are testing to `expect(...)`
79
+ ^^^^^^^ Provide the actual you are testing to `expect(...)`.
80
80
  end
81
81
  end
82
82
  RUBY
@@ -87,9 +87,9 @@ describe RuboCop::Cop::RSpec::ExpectActual do
87
87
  describe Foo do
88
88
  it 'uses expect incorrectly' do
89
89
  expect(foo: 1, bar: 2).to eq(bar)
90
- ^^^^^^^^^^^^^^ Provide the actual you are testing to `expect(...)`
90
+ ^^^^^^^^^^^^^^ Provide the actual you are testing to `expect(...)`.
91
91
  expect(foo: 1, bar: [{}]).to eq(bar)
92
- ^^^^^^^^^^^^^^^^^ Provide the actual you are testing to `expect(...)`
92
+ ^^^^^^^^^^^^^^^^^ Provide the actual you are testing to `expect(...)`.
93
93
  end
94
94
  end
95
95
  RUBY
@@ -100,9 +100,9 @@ describe RuboCop::Cop::RSpec::ExpectActual do
100
100
  describe Foo do
101
101
  it 'uses expect incorrectly' do
102
102
  expect(1..2).to eq(bar)
103
- ^^^^ Provide the actual you are testing to `expect(...)`
103
+ ^^^^ Provide the actual you are testing to `expect(...)`.
104
104
  expect(1...2).to eq(bar)
105
- ^^^^^ Provide the actual you are testing to `expect(...)`
105
+ ^^^^^ Provide the actual you are testing to `expect(...)`.
106
106
  end
107
107
  end
108
108
  RUBY
@@ -113,7 +113,7 @@ describe RuboCop::Cop::RSpec::ExpectActual do
113
113
  describe Foo do
114
114
  it 'uses expect incorrectly' do
115
115
  expect(/foo|bar/).to eq(bar)
116
- ^^^^^^^^^ Provide the actual you are testing to `expect(...)`
116
+ ^^^^^^^^^ Provide the actual you are testing to `expect(...)`.
117
117
  end
118
118
  end
119
119
  RUBY
@@ -123,6 +123,7 @@ describe RuboCop::Cop::RSpec::ExpectActual do
123
123
  expect_no_violations(<<-'RUBY')
124
124
  describe Foo do
125
125
  it 'uses expect incorrectly' do
126
+ expect.to eq(bar)
126
127
  expect([foo]).to eq(bar)
127
128
  expect([[foo]]).to eq(bar)
128
129
  expect(foo: 1, bar: foo).to eq(bar)
@@ -133,4 +134,18 @@ describe RuboCop::Cop::RSpec::ExpectActual do
133
134
  end
134
135
  RUBY
135
136
  end
137
+
138
+ context 'when inspecting rspec-rails routing specs' do
139
+ let(:cop_config) { {} }
140
+
141
+ it 'ignores rspec-rails routing specs' do
142
+ inspect_source(
143
+ cop,
144
+ 'expect(get: "/foo").to be_routeable',
145
+ 'spec/routing/foo_spec.rb'
146
+ )
147
+
148
+ expect(cop.offenses).to be_empty
149
+ end
150
+ end
136
151
  end
@@ -2,14 +2,14 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe RuboCop::Cop::RSpec::ExpectOutput do
5
+ RSpec.describe RuboCop::Cop::RSpec::ExpectOutput do
6
6
  subject(:cop) { described_class.new }
7
7
 
8
8
  it 'registers an offense for overwriting $stdout within an example' do
9
9
  expect_violation(<<-RUBY)
10
10
  specify do
11
11
  $stdout = StringIO.new
12
- ^^^^^^^ Use `expect { ... }.to output(...).to_stdout` instead of mutating $stdout
12
+ ^^^^^^^ Use `expect { ... }.to output(...).to_stdout` instead of mutating $stdout.
13
13
  end
14
14
  RUBY
15
15
  end
@@ -19,7 +19,7 @@ describe RuboCop::Cop::RSpec::ExpectOutput do
19
19
  expect_violation(<<-RUBY)
20
20
  before(:each) do
21
21
  $stderr = StringIO.new
22
- ^^^^^^^ Use `expect { ... }.to output(...).to_stderr` instead of mutating $stderr
22
+ ^^^^^^^ Use `expect { ... }.to output(...).to_stderr` instead of mutating $stderr.
23
23
  end
24
24
  RUBY
25
25
  end
@@ -1,236 +1,188 @@
1
- describe RuboCop::Cop::RSpec::FilePath, :config do
1
+ RSpec.describe RuboCop::Cop::RSpec::FilePath, :config do
2
2
  subject(:cop) { described_class.new(config) }
3
3
 
4
- shared_examples 'invalid spec path' do |source, expected:, actual:|
5
- context "when `#{source}` is defined in #{actual}" do
6
- before do
7
- inspect_source(cop, source, actual)
8
- end
9
-
10
- it 'flags an offense' do
11
- expect(cop.offenses.size).to eq(1)
12
- end
13
-
14
- it 'registers the offense on line 1' do
15
- expect(cop.offenses.map(&:line)).to eq([1])
16
- end
17
-
18
- it 'adds a message saying what the path should end with' do
19
- expect(cop.messages).to eql(["Spec path should end with `#{expected}`"])
20
- end
21
- end
4
+ it 'registers an offense for a bad path' do
5
+ expect_violation(<<-RUBY, filename: 'wrong_path_foo_spec.rb')
6
+ describe MyClass, 'foo' do; end
7
+ ^^^^^^^^^^^^^^^^^^^^^^^ Spec path should end with `my_class*foo*_spec.rb`.
8
+ RUBY
22
9
  end
23
10
 
24
- include_examples 'invalid spec path',
25
- "describe MyClass, 'foo' do; end",
26
- expected: 'my_class*foo*_spec.rb',
27
- actual: 'wrong_path_foo_spec.rb'
11
+ it 'registers an offense for a wrong class but a correct method' do
12
+ expect_violation(<<-RUBY, filename: 'wrong_class_foo_spec.rb')
13
+ describe MyClass, '#foo' do; end
14
+ ^^^^^^^^^^^^^^^^^^^^^^^^ Spec path should end with `my_class*foo*_spec.rb`.
15
+ RUBY
16
+ end
28
17
 
29
- include_examples 'invalid spec path',
30
- "describe MyClass, '#foo' do; end",
31
- expected: 'my_class*foo*_spec.rb',
32
- actual: 'wrong_class_foo_spec.rb'
18
+ it 'registers an offense for a repeated .rb' do
19
+ expect_violation(<<-RUBY, filename: 'my_class/foo_spec.rb.rb')
20
+ describe MyClass, '#foo' do; end
21
+ ^^^^^^^^^^^^^^^^^^^^^^^^ Spec path should end with `my_class*foo*_spec.rb`.
22
+ RUBY
23
+ end
33
24
 
34
- include_examples 'invalid spec path',
35
- "describe MyClass, '#foo' do; end",
36
- expected: 'my_class*foo*_spec.rb',
37
- actual: 'my_class/foo_spec.rb.rb'
25
+ it 'registers an offense for a file missing a .rb' do
26
+ expect_violation(<<-RUBY, filename: 'my_class/foo_specorb')
27
+ describe MyClass, '#foo' do; end
28
+ ^^^^^^^^^^^^^^^^^^^^^^^^ Spec path should end with `my_class*foo*_spec.rb`.
29
+ RUBY
30
+ end
38
31
 
39
- include_examples 'invalid spec path',
40
- "describe MyClass, '#foo' do; end",
41
- expected: 'my_class*foo*_spec.rb',
42
- actual: 'my_class/foo_specorb'
32
+ it 'registers an offense for a wrong class and highlights metadata' do
33
+ expect_violation(<<-RUBY, filename: 'wrong_class_foo_spec.rb')
34
+ describe MyClass, '#foo', blah: :blah do; end
35
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Spec path should end with `my_class*foo*_spec.rb`.
36
+ RUBY
37
+ end
43
38
 
44
- include_examples 'invalid spec path',
45
- "describe MyClass, '#foo', blah: :blah do; end",
46
- expected: 'my_class*foo*_spec.rb',
47
- actual: 'wrong_class_foo_spec.rb'
39
+ it 'registers an offense for a wrong class name' do
40
+ expect_violation(<<-RUBY, filename: 'wrong_class_spec.rb')
41
+ describe MyClass do; end
42
+ ^^^^^^^^^^^^^^^^ Spec path should end with `my_class*_spec.rb`.
43
+ RUBY
44
+ end
48
45
 
49
- include_examples 'invalid spec path',
50
- 'describe MyClass do; end',
51
- expected: 'my_class*_spec.rb',
52
- actual: 'wrong_class_spec.rb'
46
+ it 'registers an offense for a wrong class name with a symbol argument' do
47
+ expect_violation(<<-RUBY, filename: 'wrong_class_spec.rb')
48
+ describe MyClass, :foo do; end
49
+ ^^^^^^^^^^^^^^^^^^^^^^ Spec path should end with `my_class*_spec.rb`.
50
+ RUBY
51
+ end
53
52
 
54
- include_examples 'invalid spec path',
55
- 'describe MyClass, :foo do; end',
56
- expected: 'my_class*_spec.rb',
57
- actual: 'wrong_class_spec.rb'
53
+ it 'registers an offense for a file missing _spec' do
54
+ expect_violation(<<-RUBY, filename: 'user.rb')
55
+ describe User do; end
56
+ ^^^^^^^^^^^^^ Spec path should end with `user*_spec.rb`.
57
+ RUBY
58
+ end
58
59
 
59
60
  it 'skips specs that do not describe a class / method' do
60
- inspect_source(
61
- cop,
62
- "describe 'Test something' do; end",
63
- 'some/class/spec.rb'
64
- )
65
- expect(cop.offenses).to be_empty
61
+ expect_no_violations(<<-RUBY, filename: 'some/class/spec.rb')
62
+ describe 'Test something' do; end
63
+ RUBY
66
64
  end
67
65
 
68
66
  it 'skips specs that do have multiple top level describes' do
69
- inspect_source(
70
- cop,
71
- [
72
- "describe MyClass, 'do_this' do; end",
73
- "describe MyClass, 'do_that' do; end"
74
- ],
75
- 'some/class/spec.rb'
76
- )
77
- expect(cop.offenses).to be_empty
67
+ expect_no_violations(<<-RUBY, filename: 'some/class/spec.rb')
68
+ describe MyClass, 'do_this' do; end
69
+ describe MyClass, 'do_that' do; end
70
+ RUBY
78
71
  end
79
72
 
80
73
  it 'checks class specs' do
81
- inspect_source(
82
- cop,
83
- 'describe Some::Class do; end',
84
- 'some/class_spec.rb'
85
- )
86
- expect(cop.offenses).to be_empty
74
+ expect_no_violations(<<-RUBY, filename: 'some/class_spec.rb')
75
+ describe Some::Class do; end
76
+ RUBY
77
+ end
78
+
79
+ it 'allows different parent directories' do
80
+ expect_no_violations(<<-RUBY, filename: 'parent_dir/some/class_spec.rb')
81
+ describe Some::Class do; end
82
+ RUBY
87
83
  end
88
84
 
89
85
  it 'handles CamelCaps class names' do
90
- inspect_source(
91
- cop,
92
- 'describe MyClass do; end',
93
- 'my_class_spec.rb'
94
- )
95
- expect(cop.offenses).to be_empty
86
+ expect_no_violations(<<-RUBY, filename: 'my_class_spec.rb')
87
+ describe MyClass do; end
88
+ RUBY
96
89
  end
97
90
 
98
91
  it 'handles ACRONYMClassNames' do
99
- inspect_source(
100
- cop,
101
- 'describe ABCOne::Two do; end',
102
- 'abc_one/two_spec.rb'
103
- )
104
- expect(cop.offenses).to be_empty
92
+ expect_no_violations(<<-RUBY, filename: 'abc_one/two_spec.rb')
93
+ describe ABCOne::Two do; end
94
+ RUBY
105
95
  end
106
96
 
107
97
  it 'handles ALLCAPS class names' do
108
- inspect_source(
109
- cop,
110
- 'describe ALLCAPS do; end',
111
- 'allcaps_spec.rb'
112
- )
113
- expect(cop.offenses).to be_empty
98
+ expect_no_violations(<<-RUBY, filename: 'allcaps_spec.rb')
99
+ describe ALLCAPS do; end
100
+ RUBY
114
101
  end
115
102
 
116
103
  it 'handles alphanumeric class names' do
117
- inspect_source(
118
- cop,
119
- 'describe IPV4AndIPV6 do; end',
120
- 'ipv4_and_ipv6_spec.rb'
121
- )
122
- expect(cop.offenses).to be_empty
104
+ expect_no_violations(<<-RUBY, filename: 'ipv4_and_ipv6_spec.rb')
105
+ describe IPV4AndIPV6 do; end
106
+ RUBY
123
107
  end
124
108
 
125
109
  it 'checks instance methods' do
126
- inspect_source(
127
- cop,
128
- "describe Some::Class, '#inst' do; end",
129
- 'some/class/inst_spec.rb'
130
- )
131
- expect(cop.offenses).to be_empty
110
+ expect_no_violations(<<-RUBY, filename: 'some/class/inst_spec.rb')
111
+ describe Some::Class, '#inst' do; end
112
+ RUBY
132
113
  end
133
114
 
134
115
  it 'checks class methods' do
135
- inspect_source(
136
- cop,
137
- "describe Some::Class, '.inst' do; end",
138
- 'some/class/inst_spec.rb'
139
- )
140
- expect(cop.offenses).to be_empty
116
+ expect_no_violations(<<-RUBY, filename: 'some/class/inst_spec.rb')
117
+ describe Some::Class, '.inst' do; end
118
+ RUBY
141
119
  end
142
120
 
143
121
  it 'allows flat hierarchies for instance methods' do
144
- inspect_source(
145
- cop,
146
- "describe Some::Class, '#inst' do; end",
147
- 'some/class_inst_spec.rb'
148
- )
149
- expect(cop.offenses).to be_empty
122
+ expect_no_violations(<<-RUBY, filename: 'some/class_inst_spec.rb')
123
+ describe Some::Class, '#inst' do; end
124
+ RUBY
150
125
  end
151
126
 
152
127
  it 'allows flat hierarchies for class methods' do
153
- inspect_source(
154
- cop,
155
- "describe Some::Class, '.inst' do; end",
156
- 'some/class_inst_spec.rb'
157
- )
158
- expect(cop.offenses).to be_empty
128
+ expect_no_violations(<<-RUBY, filename: 'some/class_inst_spec.rb')
129
+ describe Some::Class, '.inst' do; end
130
+ RUBY
159
131
  end
160
132
 
161
133
  it 'allows subdirs for instance methods' do
162
- inspect_source(
163
- cop,
164
- "describe Some::Class, '#inst' do; end",
165
- 'some/class/instance_methods/inst_spec.rb'
166
- )
167
- expect(cop.offenses).to be_empty
134
+ filename = 'some/class/instance_methods/inst_spec.rb'
135
+ expect_no_violations(<<-RUBY, filename: filename)
136
+ describe Some::Class, '#inst' do; end
137
+ RUBY
168
138
  end
169
139
 
170
140
  it 'allows subdirs for class methods' do
171
- inspect_source(
172
- cop,
173
- "describe Some::Class, '.inst' do; end",
174
- 'some/class/class_methods/inst_spec.rb'
175
- )
176
- expect(cop.offenses).to be_empty
141
+ filename = 'some/class/class_methods/inst_spec.rb'
142
+ expect_no_violations(<<-RUBY, filename: filename)
143
+ describe Some::Class, '.inst' do; end
144
+ RUBY
177
145
  end
178
146
 
179
147
  it 'ignores non-alphanumeric characters' do
180
- inspect_source(
181
- cop,
182
- "describe Some::Class, '#pred?' do; end",
183
- 'some/class/pred_spec.rb'
184
- )
185
- expect(cop.offenses).to be_empty
148
+ expect_no_violations(<<-RUBY, filename: 'some/class/pred_spec.rb')
149
+ describe Some::Class, '#pred?' do; end
150
+ RUBY
186
151
  end
187
152
 
188
153
  it 'allows bang method' do
189
- inspect_source(
190
- cop,
191
- "describe Some::Class, '#bang!' do; end",
192
- 'some/class/bang_spec.rb'
193
- )
194
- expect(cop.offenses).to be_empty
154
+ expect_no_violations(<<-RUBY, filename: 'some/class/bang_spec.rb')
155
+ describe Some::Class, '#bang!' do; end
156
+ RUBY
195
157
  end
196
158
 
197
159
  it 'allows flexibility with predicates' do
198
- inspect_source(
199
- cop,
200
- "describe Some::Class, '#thing?' do; end",
201
- 'some/class/thing_predicate_spec.rb'
202
- )
203
- expect(cop.offenses).to be_empty
160
+ filename = 'some/class/thing_predicate_spec.rb'
161
+ expect_no_violations(<<-RUBY, filename: filename)
162
+ describe Some::Class, '#thing?' do; end
163
+ RUBY
204
164
  end
205
165
 
206
166
  it 'allows flexibility with operators' do
207
- inspect_source(
208
- cop,
209
- "describe MyLittleClass, '#<=>' do; end",
210
- 'my_little_class/spaceship_operator_spec.rb'
211
- )
212
- expect(cop.offenses).to be_empty
167
+ filename = 'my_little_class/spaceship_operator_spec.rb'
168
+ expect_no_violations(<<-RUBY, filename: filename)
169
+ describe MyLittleClass, '#<=>' do; end
170
+ RUBY
213
171
  end
214
172
 
215
173
  context 'when configured with CustomTransform' do
216
174
  let(:cop_config) { { 'CustomTransform' => { 'FooFoo' => 'foofoo' } } }
217
175
 
218
176
  it 'respects custom module name transformation' do
219
- inspect_source(
220
- cop,
221
- "describe FooFoo::Some::Class, '#bar' do; end",
222
- 'foofoo/some/class/bar_spec.rb'
223
- )
224
- expect(cop.offenses).to be_empty
177
+ expect_no_violations(<<-RUBY, filename: 'foofoo/some/class/bar_spec.rb')
178
+ describe FooFoo::Some::Class, '#bar' do; end
179
+ RUBY
225
180
  end
226
181
 
227
182
  it 'ignores routing specs' do
228
- inspect_source(
229
- cop,
230
- 'describe MyController, "#foo", type: :routing do; end',
231
- 'foofoo/some/class/bar_spec.rb'
232
- )
233
- expect(cop.offenses).to be_empty
183
+ expect_no_violations(<<-RUBY, filename: 'foofoo/some/class/bar_spec.rb')
184
+ describe MyController, "#foo", type: :routing do; end
185
+ RUBY
234
186
  end
235
187
  end
236
188
 
@@ -238,12 +190,9 @@ describe RuboCop::Cop::RSpec::FilePath, :config do
238
190
  let(:cop_config) { { 'IgnoreMethods' => true } }
239
191
 
240
192
  it 'does not care about the described method' do
241
- inspect_source(
242
- cop,
243
- "describe MyClass, '#look_here_a_method' do; end",
244
- 'my_class_spec.rb'
245
- )
246
- expect(cop.offenses).to be_empty
193
+ expect_no_violations(<<-RUBY, filename: 'my_class_spec.rb')
194
+ describe MyClass, '#look_here_a_method' do; end
195
+ RUBY
247
196
  end
248
197
  end
249
198
  end