diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 14:34:42 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 14:34:42 +0000 |
commit | 9f46488805e86b1bc341ea1620b866016c2ce5ed (patch) | |
tree | f9748c7e287041e37d6da49e0a29c9511dc34768 /spec/rubocop/cop/rspec | |
parent | dfc92d081ea0332d69c8aca2f0e745cb48ae5e6d (diff) | |
download | gitlab-ce-9f46488805e86b1bc341ea1620b866016c2ce5ed.tar.gz |
Add latest changes from gitlab-org/gitlab@13-0-stable-ee
Diffstat (limited to 'spec/rubocop/cop/rspec')
-rw-r--r-- | spec/rubocop/cop/rspec/empty_line_after_shared_example_spec.rb | 86 | ||||
-rw-r--r-- | spec/rubocop/cop/rspec/env_assignment_spec.rb | 12 |
2 files changed, 92 insertions, 6 deletions
diff --git a/spec/rubocop/cop/rspec/empty_line_after_shared_example_spec.rb b/spec/rubocop/cop/rspec/empty_line_after_shared_example_spec.rb new file mode 100644 index 00000000000..cee593fe535 --- /dev/null +++ b/spec/rubocop/cop/rspec/empty_line_after_shared_example_spec.rb @@ -0,0 +1,86 @@ +# frozen_string_literal: true + +require 'spec_helper' + +require_relative '../../../../rubocop/cop/rspec/empty_line_after_shared_example' + +describe RuboCop::Cop::RSpec::EmptyLineAfterSharedExample do + subject(:cop) { described_class.new } + + it 'flags a missing empty line after `it_behaves_like` block' do + expect_offense(<<-RUBY) + RSpec.describe Foo do + it_behaves_like 'does this' do + end + ^^^ Add an empty line after `it_behaves_like` block. + it_behaves_like 'does that' do + end + end + RUBY + + expect_correction(<<-RUBY) + RSpec.describe Foo do + it_behaves_like 'does this' do + end + + it_behaves_like 'does that' do + end + end + RUBY + end + + it 'ignores one-line shared examples before shared example blocks' do + expect_no_offenses(<<-RUBY) + RSpec.describe Foo do + it_behaves_like 'does this' + it_behaves_like 'does that' do + end + end + RUBY + end + + it 'flags a missing empty line after `shared_examples`' do + expect_offense(<<-RUBY) + RSpec.context 'foo' do + shared_examples do + end + ^^^ Add an empty line after `shared_examples` block. + shared_examples 'something gets done' do + end + end + RUBY + + expect_correction(<<-RUBY) + RSpec.context 'foo' do + shared_examples do + end + + shared_examples 'something gets done' do + end + end + RUBY + end + + it 'ignores consecutive one-liners' do + expect_no_offenses(<<-RUBY) + RSpec.describe Foo do + it_behaves_like 'do this' + it_behaves_like 'do that' + end + RUBY + end + + it 'flags mixed one-line and multi-line shared examples' do + expect_offense(<<-RUBY) + RSpec.context 'foo' do + it_behaves_like 'do this' + it_behaves_like 'do that' + it_behaves_like 'does this' do + end + ^^^ Add an empty line after `it_behaves_like` block. + it_behaves_like 'do this' + it_behaves_like 'do that' + end + RUBY + end +end diff --git a/spec/rubocop/cop/rspec/env_assignment_spec.rb b/spec/rubocop/cop/rspec/env_assignment_spec.rb index 2a2bd1434d6..1c7cfb5c827 100644 --- a/spec/rubocop/cop/rspec/env_assignment_spec.rb +++ b/spec/rubocop/cop/rspec/env_assignment_spec.rb @@ -10,8 +10,8 @@ require_relative '../../../../rubocop/cop/rspec/env_assignment' describe RuboCop::Cop::RSpec::EnvAssignment do include CopHelper - OFFENSE_CALL_SINGLE_QUOTES_KEY = %(ENV['FOO'] = 'bar').freeze - OFFENSE_CALL_DOUBLE_QUOTES_KEY = %(ENV["FOO"] = 'bar').freeze + offense_call_single_quotes_key = %(ENV['FOO'] = 'bar').freeze + offense_call_double_quotes_key = %(ENV["FOO"] = 'bar').freeze let(:source_file) { 'spec/foo_spec.rb' } @@ -36,12 +36,12 @@ describe RuboCop::Cop::RSpec::EnvAssignment do end context 'with a key using single quotes' do - it_behaves_like 'an offensive ENV#[]= call', OFFENSE_CALL_SINGLE_QUOTES_KEY - it_behaves_like 'an autocorrected ENV#[]= call', OFFENSE_CALL_SINGLE_QUOTES_KEY, %(stub_env('FOO', 'bar')) + it_behaves_like 'an offensive ENV#[]= call', offense_call_single_quotes_key + it_behaves_like 'an autocorrected ENV#[]= call', offense_call_single_quotes_key, %(stub_env('FOO', 'bar')) end context 'with a key using double quotes' do - it_behaves_like 'an offensive ENV#[]= call', OFFENSE_CALL_DOUBLE_QUOTES_KEY - it_behaves_like 'an autocorrected ENV#[]= call', OFFENSE_CALL_DOUBLE_QUOTES_KEY, %(stub_env("FOO", 'bar')) + it_behaves_like 'an offensive ENV#[]= call', offense_call_double_quotes_key + it_behaves_like 'an autocorrected ENV#[]= call', offense_call_double_quotes_key, %(stub_env("FOO", 'bar')) end end |