Commit b61d26f4 authored by Vitali Tatarintev's avatar Vitali Tatarintev

Add support of not_to/to_not to BeSuccessMatcher

BeSuccessMatcher now supports following examples:

```
expect(response).to be_success
expect(response).to_not be_success
expect(response).not_to be_success

is_expected.to be_success
is_expected.to_not be_success
is_expected.not_to be_success
```
parent 23da356d
......@@ -29,11 +29,11 @@ module RuboCop
MESSAGE = 'Do not use deprecated `success?` method, use `successful?` instead.'.freeze
def_node_search :expect_to_be_success?, <<~PATTERN
(send (send nil? :expect (send nil? ...)) :to (send nil? :be_success))
(send (send nil? :expect (send nil? ...)) {:to :not_to :to_not} (send nil? :be_success))
PATTERN
def_node_search :is_expected_to_be_success?, <<~PATTERN
(send (send nil? :is_expected) :to (send nil? :be_success))
(send (send nil? :is_expected) {:to :not_to :to_not} (send nil? :be_success))
PATTERN
def be_success_usage?(node)
......
......@@ -15,11 +15,27 @@ describe RuboCop::Cop::RSpec::BeSuccessMatcher do
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' }
......@@ -55,7 +71,7 @@ describe RuboCop::Cop::RSpec::BeSuccessMatcher do
end
context "using #{code_example[:good]} call" do
it "does not register an offense" do
it 'does not register an offense' do
inspect_source(code_example[:good])
expect(cop.offenses.size).to eq(0)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment