Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVitali Tatarintev <vtatarintev@gitlab.com>2019-08-22 12:42:16 +0300
committerVitali Tatarintev <vtatarintev@gitlab.com>2019-08-28 09:43:47 +0300
commit4f2ac51644754f9a4d4df697ac8984180b0bfdca (patch)
tree9d23512fd38c993e44ca91354727613e85a52eda /spec/rubocop
parentbe3ec70556b5c514d479e443b4141005ea0365d3 (diff)
Add Rubocop check to avoid using `be_success`
Prevent using `be_success` call in controller specs to avoid getting following deprecation warning: ``` DEPRECATION WARNING: The success? predicate is deprecated and will be removed in Rails 6.0. Please use successful? as provided by Rack::Response::Helpers. ```
Diffstat (limited to 'spec/rubocop')
-rw-r--r--spec/rubocop/cop/rspec/be_success_matcher_spec.rb77
1 files changed, 77 insertions, 0 deletions
diff --git a/spec/rubocop/cop/rspec/be_success_matcher_spec.rb b/spec/rubocop/cop/rspec/be_success_matcher_spec.rb
new file mode 100644
index 00000000000..fcb5791ef57
--- /dev/null
+++ b/spec/rubocop/cop/rspec/be_success_matcher_spec.rb
@@ -0,0 +1,77 @@
+require 'spec_helper'
+
+require 'rubocop'
+require 'rubocop/rspec/support'
+
+require_relative '../../../../rubocop/cop/rspec/be_success_matcher'
+
+describe RuboCop::Cop::RSpec::BeSuccessMatcher do
+ include CopHelper
+
+ OFFENSE_CALL_EXPECT_TO_BE_SUCCESS = %(expect(response).to be_success).freeze
+ OFFENSE_CALL_IS_EXPECTED_TO_BE_SUCCESS = %(is_expected.to be_success).freeze
+ CALL_EXPECT_TO_BE_SUCCESSFUL = %(expect(response).to be_successful).freeze
+ CALL_IS_EXPECTED_TO_BE_SUCCESSFUL = %(is_expected.to be_successful).freeze
+
+ let(:source_file) { 'spec/foo_spec.rb' }
+
+ subject(:cop) { described_class.new }
+
+ shared_examples 'an offensive be_success call' do |content|
+ it "registers an offense for `#{content}`" do
+ inspect_source(content, source_file)
+
+ expect(cop.offenses.size).to eq(1)
+ expect(cop.offenses.map(&:line)).to eq([1])
+ expect(cop.highlights).to eq([content])
+ end
+ end
+
+ context 'in a controller spec file' do
+ before do
+ allow(cop).to receive(:in_controller_spec?).and_return(true)
+ end
+
+ context "using expect(response).to be_success call" do
+ it_behaves_like 'an offensive be_success call', OFFENSE_CALL_EXPECT_TO_BE_SUCCESS
+ end
+
+ context "using is_expected.to be_success call" do
+ it_behaves_like 'an offensive be_success call', OFFENSE_CALL_IS_EXPECTED_TO_BE_SUCCESS
+ end
+
+ context "using expect(response).to be_successful" do
+ it "does not register an offense" do
+ inspect_source(CALL_EXPECT_TO_BE_SUCCESSFUL)
+
+ expect(cop.offenses.size).to eq(0)
+ end
+ end
+
+ context "using is_expected.to be_successful" do
+ it "does not register an offense" do
+ inspect_source(CALL_IS_EXPECTED_TO_BE_SUCCESSFUL)
+
+ expect(cop.offenses.size).to eq(0)
+ end
+ end
+ end
+
+ context 'outside of a controller spec file' do
+ context "using expect(response).to be_success call" do
+ it "does not register an offense" do
+ inspect_source(OFFENSE_CALL_EXPECT_TO_BE_SUCCESS)
+
+ expect(cop.offenses.size).to eq(0)
+ end
+ end
+
+ context "using is_expected.to be_success call" do
+ it "does not register an offense" do
+ inspect_source(OFFENSE_CALL_IS_EXPECTED_TO_BE_SUCCESS)
+
+ expect(cop.offenses.size).to eq(0)
+ end
+ end
+ end
+end