diff options
author | Douwe Maan <douwe@gitlab.com> | 2017-06-14 18:21:13 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2017-06-14 18:21:13 +0000 |
commit | 43e1481c8191651880fe20ff2b07a5501a5f7112 (patch) | |
tree | 5913098b01d3931c61eb935e4c2587dbdab20716 /spec/rubocop | |
parent | 557cbba7df35e2f3a27995f1caf77d40a3c223fa (diff) | |
parent | 4daf9c00b7d38164f9a50dd3f27edc88235cecb8 (diff) | |
download | gitlab-ce-43e1481c8191651880fe20ff2b07a5501a5f7112.tar.gz |
Merge branch 'rs-single-line-rspec-hook-cop' into 'master'
Add a custom RSpec/SingleLineHook cop
Closes #24891
See merge request !11911
Diffstat (limited to 'spec/rubocop')
-rw-r--r-- | spec/rubocop/cop/rspec/single_line_hook_spec.rb | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/spec/rubocop/cop/rspec/single_line_hook_spec.rb b/spec/rubocop/cop/rspec/single_line_hook_spec.rb new file mode 100644 index 00000000000..f3eb8de63ac --- /dev/null +++ b/spec/rubocop/cop/rspec/single_line_hook_spec.rb @@ -0,0 +1,67 @@ +require 'spec_helper' + +require 'rubocop' +require 'rubocop/rspec/support' +require 'rubocop-rspec' + +require_relative '../../../../rubocop/cop/rspec/single_line_hook' + +describe RuboCop::Cop::RSpec::SingleLineHook do + include CopHelper + + subject(:cop) { described_class.new } + + # Override `CopHelper#inspect_source` to always appear to be in a spec file, + # so that our RSpec-only cop actually runs + def inspect_source(*args) + super(*args, 'foo_spec.rb') + end + + it 'registers an offense for a single-line `before` block' do + inspect_source(cop, 'before { do_something }') + + expect(cop.offenses.size).to eq(1) + expect(cop.offenses.map(&:line)).to eq([1]) + expect(cop.highlights).to eq(['before { do_something }']) + end + + it 'registers an offense for a single-line `after` block' do + inspect_source(cop, 'after(:each) { undo_something }') + + expect(cop.offenses.size).to eq(1) + expect(cop.offenses.map(&:line)).to eq([1]) + expect(cop.highlights).to eq(['after(:each) { undo_something }']) + end + + it 'registers an offense for a single-line `around` block' do + inspect_source(cop, 'around { |ex| do_something_else }') + + expect(cop.offenses.size).to eq(1) + expect(cop.offenses.map(&:line)).to eq([1]) + expect(cop.highlights).to eq(['around { |ex| do_something_else }']) + end + + it 'ignores a multi-line `before` block' do + inspect_source(cop, ['before do', + ' do_something', + 'end']) + + expect(cop.offenses.size).to eq(0) + end + + it 'ignores a multi-line `after` block' do + inspect_source(cop, ['after(:each) do', + ' undo_something', + 'end']) + + expect(cop.offenses.size).to eq(0) + end + + it 'ignores a multi-line `around` block' do + inspect_source(cop, ['around do |ex|', + ' do_something_else', + 'end']) + + expect(cop.offenses.size).to eq(0) + end +end |