rubocop-rspec 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d78e6378d0979625180390c70a6e37d889a67652
4
- data.tar.gz: 95a96f1a4def09e03681c8f76600a066556186a4
3
+ metadata.gz: 5e1993245da215069d2de0ca4a565ccd0ac9aaa6
4
+ data.tar.gz: ab550daf4e1f7ea5121d19fbea73e6626b6ae3a2
5
5
  SHA512:
6
- metadata.gz: 24074653cb0280bbafea8676c58f3fddca8dea629d79c72ce26655fb8fb7a3440e9665ce6d231701d22f7a8375c36681dd8522ce8f49def8d8d5cbe2ad914b47
7
- data.tar.gz: ae19016c5b9ae6385ecc7f56dbc9f5e97daba9c93eff6d0d3f061a35d5407f0c36b713f1adb81bba5db7b65b9bb5a7c3566614a20070fd9cae9c802005456479
6
+ metadata.gz: 01f3a531a9acaef8fd91e3f2af343eaecf80d7e74e224e386d2470911189c24a90e27a9e2b717e01250c2f76fc60269ea3bef26c413adac9eb4e71d4c44d4180
7
+ data.tar.gz: 34ec3b6aeaa188e97066a479ec6c33fbbdc714609afbaccf82dc4aa0e64f8277ab6c376c35be726f52794d3e84c367e7d3222a8afd8a586061e51a1cd968c606
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Change log
2
2
 
3
+ ## 1.2.0
4
+
5
+ * Drop support of ruby `1.9.2`. ([@geniou][])
6
+ * Update to RuboCop `~> 0.24`. ([@geniou][])
7
+ * Add `autocorrect` to `RSpec::ExampleWording`. This experimental - use with care and check the changes. ([@geniou][])
8
+ * Fix config loader debug output. ([@geniou][])
9
+ * Rename `FileName` cop to `FilePath` as a workaround - see [#19](https://github.com/nevir/rubocop-rspec/issues/19). ([@geniou][])
10
+
3
11
  ## 1.1.0
4
12
 
5
13
  * Add `autocorrect` to `RSpec::DescribedClass` cop. ([@geniou][])
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  gemspec
data/README.md CHANGED
@@ -66,7 +66,7 @@ In your `.rubocop.yml`, you may treat the RSpec cops just like any other
66
66
  cop. For example:
67
67
 
68
68
  ```yaml
69
- RSpec/FileName:
69
+ RSpec/FilePath:
70
70
  Exclude:
71
71
  - spec/my_poorly_named_spec_file.rb
72
72
  ```
data/config/default.yml CHANGED
@@ -13,6 +13,12 @@ RSpec/DescribeMethod:
13
13
  RSpec/ExampleWording:
14
14
  Description: 'Do not use should when describing your tests.'
15
15
  Enabled: true
16
+ CustomTransform:
17
+ be: is
18
+ have: has
19
+ not: does not
20
+ IgnoredWords: []
21
+
16
22
 
17
23
  RSpec/MultipleDescribes:
18
24
  Description: 'Checks for multiple top level describes.'
@@ -22,7 +28,7 @@ RSpec/InstanceVariable:
22
28
  Description: 'Checks for the usage of instance variables.'
23
29
  Enabled: true
24
30
 
25
- RSpec/FileName:
31
+ RSpec/FilePath:
26
32
  Description: 'Checks the file and folder naming of the spec file.'
27
33
  Enabled: true
28
34
  CustomTransform:
data/lib/rubocop-rspec.rb CHANGED
@@ -13,6 +13,6 @@ require 'rubocop/cop/rspec/describe_class'
13
13
  require 'rubocop/cop/rspec/describe_method'
14
14
  require 'rubocop/cop/rspec/described_class'
15
15
  require 'rubocop/cop/rspec/example_wording'
16
- require 'rubocop/cop/rspec/file_name'
16
+ require 'rubocop/cop/rspec/file_path'
17
17
  require 'rubocop/cop/rspec/instance_variable'
18
18
  require 'rubocop/cop/rspec/multiple_describes'
@@ -6,6 +6,9 @@ module RuboCop
6
6
  # Do not use should when describing your tests.
7
7
  # see: http://betterspecs.org/#should
8
8
  #
9
+ # The autocorrect is experimental - use with care! It can be configured
10
+ # with CustomTransform (e.g. have => has) and IgnoredWords (e.g. only).
11
+ #
9
12
  # @example
10
13
  # # bad
11
14
  # it 'should find nothing' do
@@ -27,7 +30,57 @@ module RuboCop
27
30
  message = arguments.first.to_s
28
31
  return unless message.start_with?('should')
29
32
 
30
- add_offense(method, :selector, MSG)
33
+ arg1 = args.first.loc.expression
34
+ message = Parser::Source::Range
35
+ .new(arg1.source_buffer, arg1.begin_pos + 1, arg1.end_pos - 1)
36
+
37
+ add_offense(message, message, MSG)
38
+ end
39
+
40
+ def autocorrect(range)
41
+ @corrections << lambda do |corrector|
42
+ corrector.replace(range, corrected_message(range))
43
+ end
44
+ end
45
+
46
+ private
47
+
48
+ def corrected_message(range)
49
+ range.source.split(' ').tap do |words|
50
+ first_word = words.shift
51
+ words.unshift('not') if first_word == "shouldn't"
52
+
53
+ words.each_with_index do |value, key|
54
+ next if ignored_words.include?(value)
55
+ words[key] = simple_present(words[key])
56
+ break
57
+ end
58
+ end.join(' ')
59
+ end
60
+
61
+ def simple_present(word)
62
+ return custom_transform[word] if custom_transform[word]
63
+
64
+ # ends with o s x ch sh or ss
65
+ if %w(o s x]).include?(word[-1]) ||
66
+ %w(ch sh ss]).include?(word[-2..-1])
67
+ return "#{word}es"
68
+ end
69
+
70
+ # ends with y
71
+ if word[-1] == 'y' && !%w(a u i o e).include?(word[-2])
72
+ return "#{word[0..-2]}ies"
73
+ end
74
+
75
+ "#{word}s"
76
+ end
77
+
78
+ def custom_transform
79
+ cop_config['CustomTransform'] || []
80
+ end
81
+
82
+ def ignored_words
83
+ cop_config['IgnoredWords'] || []
31
84
  end
32
85
  end
33
86
  end
@@ -14,7 +14,7 @@ module RuboCop
14
14
  # my_class/method_spec.rb # describe MyClass, '#method'
15
15
  # my_class_method_spec.rb # describe MyClass, '#method'
16
16
  # my_class_spec.rb # describe MyClass
17
- class FileName < Cop
17
+ class FilePath < Cop
18
18
  include RuboCop::RSpec::TopLevelDescribe
19
19
 
20
20
  MESSAGE = 'Spec path should end with `%s`'
@@ -13,7 +13,7 @@ module RuboCop
13
13
 
14
14
  def self.defaults!
15
15
  hash = YAML.load_file(DEFAULT_FILE)
16
- puts "configuration from #{path}" if ConfigLoader.debug?
16
+ puts "configuration from #{DEFAULT_FILE}" if ConfigLoader.debug?
17
17
  config = ConfigLoader.merge_with_default(hash, DEFAULT_FILE)
18
18
 
19
19
  ConfigLoader.instance_variable_set(:@default_configuration, config)
@@ -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.1.0'
7
+ STRING = '1.2.0'
8
8
  end
9
9
  end
10
10
  end
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
17
17
 
18
18
  spec.version = RuboCop::RSpec::Version::STRING
19
19
  spec.platform = Gem::Platform::RUBY
20
- spec.required_ruby_version = '>= 1.9.2'
20
+ spec.required_ruby_version = '>= 1.9.3'
21
21
 
22
22
  spec.require_paths = ['lib']
23
23
  spec.files = Dir[
@@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
30
30
  spec.test_files = spec.files.grep(/^spec\//)
31
31
  spec.extra_rdoc_files = ['MIT-LICENSE.md', 'README.md']
32
32
 
33
- spec.add_runtime_dependency('rubocop', '~> 0.23')
33
+ spec.add_development_dependency('rubocop', '~> 0.24')
34
34
  spec.add_development_dependency('rake', '~> 10.1')
35
35
  spec.add_development_dependency('rspec', '~> 3.0')
36
36
  spec.add_development_dependency('simplecov', '~> 0.8')
data/spec/project_spec.rb CHANGED
@@ -77,7 +77,7 @@ describe 'RuboCop Project' do # rubocop:disable RSpec/DescribeClass
77
77
  it 'has a valid URL' do
78
78
  issues.each do |issue|
79
79
  number = issue[:number].gsub(/\D/, '')
80
- pattern = %r{^https://github\.com/[/]+/[/]+/(?:issues|pull)/#{number}$} # rubocop:disable LineLength
80
+ pattern = %r{^https://github\.com/.+/.+/(?:issues|pull)/#{number}$} # rubocop:disable LineLength
81
81
  expect(issue[:url]).to match(pattern)
82
82
  end
83
83
  end
@@ -2,8 +2,14 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe RuboCop::Cop::RSpec::ExampleWording do
6
- subject(:cop) { described_class.new }
5
+ describe RuboCop::Cop::RSpec::ExampleWording, :config do
6
+ subject(:cop) { described_class.new(config) }
7
+ let(:cop_config) do
8
+ {
9
+ 'CustomTransform' => { 'have' => 'has', 'not' => 'does not' },
10
+ 'IgnoredWords' => %w(only realy)
11
+ }
12
+ end
7
13
 
8
14
  it 'finds description with `should` at the beginning' do
9
15
  inspect_source(cop, ["it 'should do something' do", 'end'])
@@ -11,7 +17,16 @@ describe RuboCop::Cop::RSpec::ExampleWording do
11
17
  expect(cop.offenses.map(&:line).sort).to eq([1])
12
18
  expect(cop.messages)
13
19
  .to eq(['Do not use should when describing your tests.'])
14
- expect(cop.highlights).to eq(['it'])
20
+ expect(cop.highlights).to eq(['should do something'])
21
+ end
22
+
23
+ it 'finds description with `shouldn\'t` at the beginning' do
24
+ inspect_source(cop, ['it "shouldn\'t do something" do', 'end'])
25
+ expect(cop.offenses.size).to eq(1)
26
+ expect(cop.offenses.map(&:line).sort).to eq([1])
27
+ expect(cop.messages)
28
+ .to eq(['Do not use should when describing your tests.'])
29
+ expect(cop.highlights).to eq(['shouldn\'t do something'])
15
30
  end
16
31
 
17
32
  it 'skips descriptions without `should` at the beginning' do
@@ -20,4 +35,26 @@ describe RuboCop::Cop::RSpec::ExampleWording do
20
35
  'end'])
21
36
  expect(cop.offenses).to be_empty
22
37
  end
38
+
39
+ {
40
+ 'should return something' => 'returns something',
41
+ 'should not return something' => 'does not return something',
42
+ 'should do nothing' => 'does nothing',
43
+ 'should have sweets' => 'has sweets',
44
+ 'should worry about the future' => 'worries about the future',
45
+ 'should pay for pizza' => 'pays for pizza',
46
+ 'should miss me' => 'misses me',
47
+ 'should realy only return one item' => 'realy only returns one item'
48
+ }.each do |old, new|
49
+ it 'autocorrects an offenses' do
50
+ new_source = autocorrect_source(cop, ["it '#{old}' do", 'end'])
51
+ expect(new_source).to eq("it '#{new}' do\nend")
52
+ end
53
+ end
54
+
55
+ it "autocorrects shouldn't" do
56
+ new_source =
57
+ autocorrect_source(cop, 'it "shouldn\'t return something" do; end')
58
+ expect(new_source).to eq('it "does not return something" do; end')
59
+ end
23
60
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe RuboCop::Cop::RSpec::FileName, :config do
5
+ describe RuboCop::Cop::RSpec::FilePath, :config do
6
6
  subject(:cop) { described_class.new(config) }
7
7
  let(:cop_config) { { 'CustomTransform' => { 'FooFoo' => 'foofoo' } } }
8
8
 
data/spec/spec_helper.rb CHANGED
@@ -8,19 +8,3 @@ require File.join(
8
8
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
9
9
  $LOAD_PATH.unshift(File.dirname(__FILE__))
10
10
  require 'rubocop-rspec'
11
-
12
- # Overwriting RuboCop's parse_source to add support for mocked file paths.
13
- #
14
- # Remove once rubocop > 0.17.0 releases.
15
- def parse_source(source, file = nil)
16
- source = source.join($RS) if source.is_a?(Array)
17
- if file.is_a? String
18
- RuboCop::SourceParser.parse(source, file)
19
- elsif file
20
- file.write(source)
21
- file.rewind
22
- RuboCop::SourceParser.parse(source, file.path)
23
- else
24
- RuboCop::SourceParser.parse(source)
25
- end
26
- 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.1.0
4
+ version: 1.2.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: 2014-06-25 00:00:00.000000000 Z
12
+ date: 2014-09-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rubocop
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: '0.23'
21
- type: :runtime
20
+ version: '0.24'
21
+ type: :development
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: '0.23'
27
+ version: '0.24'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: rake
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -90,7 +90,7 @@ files:
90
90
  - lib/rubocop/cop/rspec/describe_method.rb
91
91
  - lib/rubocop/cop/rspec/described_class.rb
92
92
  - lib/rubocop/cop/rspec/example_wording.rb
93
- - lib/rubocop/cop/rspec/file_name.rb
93
+ - lib/rubocop/cop/rspec/file_path.rb
94
94
  - lib/rubocop/cop/rspec/instance_variable.rb
95
95
  - lib/rubocop/cop/rspec/multiple_describes.rb
96
96
  - lib/rubocop/rspec/inject.rb
@@ -102,7 +102,7 @@ files:
102
102
  - spec/rubocop/cop/rspec/describe_method_spec.rb
103
103
  - spec/rubocop/cop/rspec/described_class_spec.rb
104
104
  - spec/rubocop/cop/rspec/example_wording_spec.rb
105
- - spec/rubocop/cop/rspec/file_name_spec.rb
105
+ - spec/rubocop/cop/rspec/file_path_spec.rb
106
106
  - spec/rubocop/cop/rspec/instance_variable_spec.rb
107
107
  - spec/rubocop/cop/rspec/multiple_describes_spec.rb
108
108
  - spec/spec_helper.rb
@@ -118,7 +118,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
118
118
  requirements:
119
119
  - - ">="
120
120
  - !ruby/object:Gem::Version
121
- version: 1.9.2
121
+ version: 1.9.3
122
122
  required_rubygems_version: !ruby/object:Gem::Requirement
123
123
  requirements:
124
124
  - - ">="
@@ -136,7 +136,7 @@ test_files:
136
136
  - spec/rubocop/cop/rspec/describe_method_spec.rb
137
137
  - spec/rubocop/cop/rspec/described_class_spec.rb
138
138
  - spec/rubocop/cop/rspec/example_wording_spec.rb
139
- - spec/rubocop/cop/rspec/file_name_spec.rb
139
+ - spec/rubocop/cop/rspec/file_path_spec.rb
140
140
  - spec/rubocop/cop/rspec/instance_variable_spec.rb
141
141
  - spec/rubocop/cop/rspec/multiple_describes_spec.rb
142
142
  - spec/spec_helper.rb