rubocop-rspec 1.2.2 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 33cc3eb121d9cb56164a721c6856c1b640f7bed6
4
- data.tar.gz: 668538c6096e0beee8e9acbffc0b7639c3a50c22
3
+ metadata.gz: 885b88b3cfe9f4d470eed5daccc1071135e59e11
4
+ data.tar.gz: 0d91a813ca891c4b7b90227188a87d24250088cf
5
5
  SHA512:
6
- metadata.gz: 80ae0ce41af162ecbf52082e626a9921daf66b1f2e2b3b907105a6d247b611c548ba60228055e777a6fc06ac22e0702ce57b5a2afdc1c5eaac10ef7d8979cb8e
7
- data.tar.gz: c10dc7627d94f250ffb294a62db891c8a9854208cfe4f40856653759858f0c6079bc38e3e6b3b573b904eefaf0d17f48fbacd9e1d3dc87f30e2bcea5e571da51
6
+ metadata.gz: 8f100ef7123bf5a9df50d45dae99592e1704cab30aa12e24f4d1d8d58e851b88c0db6f9efc46b531743fdcf487f295a75fd1033b0a05e8c2de2d4cf25c9499bd
7
+ data.tar.gz: d9ec52c5ac1aebb71bd8e16303ecc479f4fdde51d1ff9fa27dc1f1bf95d4b9f80d8e7389aa472f400d91a532e4aff8d6168c9b4b7761aa32fab560845591b5d6
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Change log
2
2
 
3
+ # 1.3.0
4
+
5
+ * Ignore non string arguments for FilePathCop - thanks to @deivid-rodriguez. ([@geniou][])
6
+ * Skip DescribeMethod cop for tagged specs. ([@deivid-rodriguez][])
7
+ * Skip DescribeClass cop for feature/request specs. ([@deivid-rodriguez][])
8
+
3
9
  # 1.2.2
4
10
 
5
11
  * Make `RSpec::ExampleWording` case insensitive. ([@geniou][])
@@ -48,6 +54,7 @@
48
54
  <!-- Contributors -->
49
55
 
50
56
  [@andyw8]: https://github.com/andyw8
57
+ [@deivid-rodriguez]: https://github.com/deivid-rodriguez
51
58
  [@geniou]: https://github.com/geniou
52
59
  [@nevir]: https://github.com/nevir
53
60
  [@pstengel]: https://github.com/pstengel
@@ -14,15 +14,29 @@ module RuboCop
14
14
  # # good
15
15
  # describe TestedClass do
16
16
  # end
17
+ #
18
+ # describe "A feature example", type: :feature do
19
+ # end
17
20
  class DescribeClass < Cop
18
21
  include RuboCop::RSpec::TopLevelDescribe
19
22
 
23
+ REQUEST_PAIR = s(:pair, s(:sym, :type), s(:sym, :request))
24
+ FEATURE_PAIR = s(:pair, s(:sym, :type), s(:sym, :feature))
25
+
20
26
  MESSAGE = 'The first argument to describe should be the class or ' \
21
27
  'module being tested.'
22
28
 
23
29
  def on_top_level_describe(_node, args)
24
- return if args.first && args.first.type == :const
25
- add_offense(args.first, :expression, MESSAGE)
30
+ return if args[0] && args[0].type == :const
31
+
32
+ return if args[1..-1].any? do |arg|
33
+ next unless arg.hash_type?
34
+ arg.children.any? do |n|
35
+ [REQUEST_PAIR, FEATURE_PAIR].include?(n)
36
+ end
37
+ end
38
+
39
+ add_offense(args[0], :expression, MESSAGE)
26
40
  end
27
41
  end
28
42
  end
@@ -26,7 +26,7 @@ module RuboCop
26
26
 
27
27
  def on_top_level_describe(_node, args)
28
28
  second_arg = args[1]
29
- return unless second_arg
29
+ return unless second_arg && second_arg.type == :str
30
30
  return if METHOD_STRING_MATCHER =~ second_arg.children.first
31
31
 
32
32
  add_offense(second_arg, :expression, MESSAGE)
@@ -35,7 +35,9 @@ module RuboCop
35
35
 
36
36
  def matcher(object, method)
37
37
  path = File.join(parts(object))
38
- path += '*' + method.children.first.gsub(/\W+/, '') if method
38
+ if method && method.type == :str
39
+ path += '*' + method.children.first.gsub(/\W+/, '')
40
+ end
39
41
 
40
42
  "#{path}*_spec.rb"
41
43
  end
@@ -9,8 +9,6 @@ module RuboCop
9
9
  return unless top_level_describe?(node)
10
10
 
11
11
  _receiver, _method_name, *args = *node
12
- # Ignore non-string args (RSpec metadata)
13
- args = [args.first] + args[1..-1].select { |a| a.type == :str }
14
12
 
15
13
  on_top_level_describe(node, args)
16
14
  end
@@ -4,7 +4,7 @@ module RuboCop
4
4
  module RSpec
5
5
  # Version information for the RSpec RuboCop plugin.
6
6
  module Version
7
- STRING = '1.2.2'
7
+ STRING = '1.3.0'
8
8
  end
9
9
  end
10
10
  end
@@ -27,6 +27,23 @@ describe RuboCop::Cop::RSpec::DescribeClass do
27
27
  expect(cop.offenses).to be_empty
28
28
  end
29
29
 
30
+ it 'ignores request specs' do
31
+ inspect_source(cop, "describe 'my new feature', type: :request do; end")
32
+ expect(cop.offenses).to be_empty
33
+ end
34
+
35
+ it 'ignores feature specs' do
36
+ inspect_source(cop, "describe 'my new feature', type: :feature do; end")
37
+ expect(cop.offenses).to be_empty
38
+ end
39
+
40
+ it 'ignores feature specs - also with complex options' do
41
+ inspect_source(cop, ["describe 'my new feature',",
42
+ ' :test, :type => :feature, :foo => :bar do;',
43
+ 'end'])
44
+ expect(cop.offenses).to be_empty
45
+ end
46
+
30
47
  it "doesn't blow up on single-line describes" do
31
48
  inspect_source(cop, 'describe Some::Class')
32
49
  expect(cop.offenses).to be_empty
@@ -17,4 +17,10 @@ describe RuboCop::Cop::RSpec::DescribeMethod do
17
17
  "describe Some::Class, '#fdsa' do; end"])
18
18
  expect(cop.offenses).to be_empty
19
19
  end
20
+
21
+ it 'skips specs not having a string second argument' do
22
+ inspect_source(cop, 'describe Some::Class, :config do; end')
23
+
24
+ expect(cop.offenses).to be_empty
25
+ end
20
26
  end
@@ -49,6 +49,16 @@ describe RuboCop::Cop::RSpec::FilePath, :config do
49
49
  expect(cop.offenses).to be_empty
50
50
  end
51
51
 
52
+ it 'ignores second argument if is not a string' do
53
+ inspect_source(cop,
54
+ 'describe MyClass, :foo do; end',
55
+ 'wrong_class_spec.rb')
56
+ expect(cop.offenses.size).to eq(1)
57
+ expect(cop.offenses.map(&:line).sort).to eq([1])
58
+ expect(cop.messages)
59
+ .to eq(['Spec path should end with `my_class*_spec.rb`'])
60
+ end
61
+
52
62
  it 'checks class specs' do
53
63
  inspect_source(cop,
54
64
  'describe Some::Class do; end',
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-rspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ian MacLeod
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-02-26 00:00:00.000000000 Z
12
+ date: 2015-04-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rubocop