debian-mirror-gitlab/spec/rubocop/cop/rspec/be_success_matcher_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

54 lines
1.4 KiB
Ruby
Raw Permalink Normal View History

2019-12-04 20:38:33 +05:30
# frozen_string_literal: true
2022-10-11 01:57:18 +05:30
require 'rubocop_spec_helper'
2019-12-04 20:38:33 +05:30
require_relative '../../../../rubocop/cop/rspec/be_success_matcher'
2021-03-08 18:12:59 +05:30
RSpec.describe RuboCop::Cop::RSpec::BeSuccessMatcher do
2019-12-04 20:38:33 +05:30
let(:source_file) { 'spec/foo_spec.rb' }
shared_examples 'cop' do |good:, bad:|
context "using #{bad} call" do
2021-03-11 19:13:27 +05:30
it 'registers an offense and corrects', :aggregate_failures do
expect_offense(<<~CODE, node: bad)
%{node}
^{node} Do not use deprecated `success?` method, use `successful?` instead.
CODE
expect_correction(<<~CODE)
#{good}
CODE
2019-12-04 20:38:33 +05:30
end
end
context "using #{good} call" do
it 'does not register an offense' do
2021-03-11 19:13:27 +05:30
expect_no_offenses(good)
2019-12-04 20:38:33 +05:30
end
end
end
include_examples 'cop',
bad: 'expect(response).to be_success',
good: 'expect(response).to be_successful'
include_examples 'cop',
bad: 'expect(response).to_not be_success',
good: 'expect(response).to_not be_successful'
include_examples 'cop',
bad: 'expect(response).not_to be_success',
good: 'expect(response).not_to be_successful'
include_examples 'cop',
bad: 'is_expected.to be_success',
good: 'is_expected.to be_successful'
include_examples 'cop',
bad: 'is_expected.to_not be_success',
good: 'is_expected.to_not be_successful'
include_examples 'cop',
bad: 'is_expected.not_to be_success',
good: 'is_expected.not_to be_successful'
end