summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVitali Tatarintev <vtatarintev@gitlab.com>2019-08-26 15:13:41 +0200
committerVitali Tatarintev <vtatarintev@gitlab.com>2019-08-28 08:43:47 +0200
commit17385f4dc42d86d7606e3359b9db82cb43d5e534 (patch)
treedfd8bc788c36d021ff3224f321299b0927ca4150
parent99b27e69510e83006d4dd2e5ecc5c555409aa4a0 (diff)
downloadgitlab-ce-17385f4dc42d86d7606e3359b9db82cb43d5e534.tar.gz
Refactor BeSuccessMatcher specs for readability
-rw-r--r--.rubocop.yml1
-rw-r--r--rubocop/cop/rspec/be_success_matcher.rb2
-rw-r--r--spec/rubocop/cop/rspec/be_success_matcher_spec.rb65
3 files changed, 34 insertions, 34 deletions
diff --git a/.rubocop.yml b/.rubocop.yml
index 1319752fc9c..573f2fbb6c6 100644
--- a/.rubocop.yml
+++ b/.rubocop.yml
@@ -273,3 +273,4 @@ RSpec/BeSuccessMatcher:
- 'spec/support/shared_examples/controllers/**/*'
- 'ee/spec/support/shared_examples/controllers/**/*'
- 'spec/support/controllers/**/*'
+ - 'ee/spec/support/controllers/**/*'
diff --git a/rubocop/cop/rspec/be_success_matcher.rb b/rubocop/cop/rspec/be_success_matcher.rb
index 0b7d737f4e2..07dad061613 100644
--- a/rubocop/cop/rspec/be_success_matcher.rb
+++ b/rubocop/cop/rspec/be_success_matcher.rb
@@ -26,7 +26,7 @@ module RuboCop
class BeSuccessMatcher < RuboCop::Cop::Cop
include SpecHelpers
- MESSAGE = 'Do not use deprecated `success?` method, use `successful?` instead.'.freeze
+ MESSAGE = 'Do not use deprecated `success?` method, use `successful?` instead.'
def_node_search :expect_to_be_success?, <<~PATTERN
(send (send nil? :expect (send nil? ...)) {:to :not_to :to_not} (send nil? :be_success))
diff --git a/spec/rubocop/cop/rspec/be_success_matcher_spec.rb b/spec/rubocop/cop/rspec/be_success_matcher_spec.rb
index 77aff7c9dcc..0b4e9853dae 100644
--- a/spec/rubocop/cop/rspec/be_success_matcher_spec.rb
+++ b/spec/rubocop/cop/rspec/be_success_matcher_spec.rb
@@ -10,33 +10,6 @@ require_relative '../../../../rubocop/cop/rspec/be_success_matcher'
describe RuboCop::Cop::RSpec::BeSuccessMatcher do
include CopHelper
- CODE_EXAMPLES = [
- {
- bad: %(expect(response).to be_success).freeze,
- good: %(expect(response).to be_successful).freeze
- },
- {
- bad: %(expect(response).to_not be_success).freeze,
- good: %(expect(response).to_not be_successful).freeze
- },
- {
- bad: %(expect(response).not_to be_success).freeze,
- good: %(expect(response).not_to be_successful).freeze
- },
- {
- bad: %(is_expected.to be_success).freeze,
- good: %(is_expected.to be_successful).freeze
- },
- {
- bad: %(is_expected.to_not be_success).freeze,
- good: %(is_expected.to_not be_successful).freeze
- },
- {
- bad: %(is_expected.not_to be_success).freeze,
- good: %(is_expected.not_to be_successful).freeze
- }
- ].freeze
-
let(:source_file) { 'spec/foo_spec.rb' }
subject(:cop) { described_class.new }
@@ -59,18 +32,44 @@ describe RuboCop::Cop::RSpec::BeSuccessMatcher do
end
end
- CODE_EXAMPLES.each do |code_example|
- context "using #{code_example[:bad]} call" do
- it_behaves_like 'an offensive be_success call', code_example[:bad]
- it_behaves_like 'an autocorrected be_success call', code_example[:bad], code_example[:good]
+ shared_examples 'cop' do |good:, bad:|
+ context "using #{bad} call" do
+ it_behaves_like 'an offensive be_success call', bad
+ it_behaves_like 'an autocorrected be_success call', bad, good
end
- context "using #{code_example[:good]} call" do
+ context "using #{good} call" do
it 'does not register an offense' do
- inspect_source(code_example[:good])
+ inspect_source(good)
expect(cop.offenses.size).to eq(0)
end
end
end
+
+ describe 'using different code examples' do
+ it_behaves_like 'cop',
+ bad: 'expect(response).to be_success',
+ good: 'expect(response).to be_successful'
+
+ it_behaves_like 'cop',
+ bad: 'expect(response).to_not be_success',
+ good: 'expect(response).to_not be_successful'
+
+ it_behaves_like 'cop',
+ bad: 'expect(response).not_to be_success',
+ good: 'expect(response).not_to be_successful'
+
+ it_behaves_like 'cop',
+ bad: 'is_expected.to be_success',
+ good: 'is_expected.to be_successful'
+
+ it_behaves_like 'cop',
+ bad: 'is_expected.to_not be_success',
+ good: 'is_expected.to_not be_successful'
+
+ it_behaves_like 'cop',
+ bad: 'is_expected.not_to be_success',
+ good: 'is_expected.not_to be_successful'
+ end
end