Rspec-rails: be_succes(not be_success) passes in my tests.

Created on 27 Jul 2016  路  13Comments  路  Source: rspec/rspec-rails

I noticed in one of my tests that I had a typo for the response check, expect(response).to be_succes instead of expect(response).to be_success. The test passed. I have tested this in other test files for to and not_to and I still get a pass. Why did the test still pass?

Most helpful comment

It's a behaviour that I've often noted isn't to my personal preference, but it is intentional.

Nor mine. I don't think I've ever seen it used and I never really understood why we support that. I think we should remove support in RSpec 4. See rspec/rspec-expectations#935.

All 13 comments

be_success leverages the fact that response exposes a success? method, if be_succes also works then it's likely that response responds to succes? as well, although I can't find a citation for that at the moment.

Closing because unless I'm mistaken this is just a query and not a bug report :)

response.succes? returns:

Failure/Error: response.succes?
     NoMethodError:
       undefined method `succes?' for #<ActionController::TestResponse:0x007fe6e22a2530>

It was kind of a "is this a bug" query :). I couldn't find an documentation either.

succes should probably be success right?

Hi @samphippen, it should have been but I made a typo in my code. When I ran the tests, they still passed with the typo. Any instances that you see in this thread of succes were intentional.

Can you copy and paste you exact spec? If response doesn't respond to succes? then be_succes should raise an error about response not responding to that method name.

I can't post the exact code, here is a sample:

 it "creates this thing" do
    get :create_this_thing, study_id: study.friendly_id, user_id: user.id
    expect(response).to be_succes
    expect(flash[:success]).to eq("Successfully created this thing.")
  end

Again, expect(response).to be_succes does not cause an error. If I try something like expect(response).to be_succ or expect(response).to be_successssss then I do get an error such as:

Failure/Error: expect(response).to be_succ
       expected #<ActionController::TestResponse:0x007ffa67272400> to respond to `succ?`

and:

Failure/Error: expect(response).to be_successsss
       expected #<ActionController::TestResponse:0x007ffa67272400> to respond to `successsss?`

Again response.success? is fine but response.succes? returns:

Failure/Error: response.succes?
     NoMethodError:
       undefined method `succes?' for #<ActionController::TestResponse:0x007fe6e22a2530>

What does response.respond_to? :succes? return? Or for that matter response.methods.grep /succes/ (sorry to be a pain but I don't have a working rspec-rails project at the moment, all mine use plain RSpec)

the problem here is that we also allow present tense predicates e.g. be_friends? for a method called friend?

https://github.com/rspec/rspec-expectations/blob/master/lib/rspec/matchers/built_in/be.rb#L248

this is an intentional behaviour of RSpec and not a bug.

I'm actually surprised by that.

It's a behaviour that I've often noted isn't to my personal preference, but it is intentional.

Yeah I guess I've never needed: be_friend for friends? many other grammatial things but never that.

:thumbsup: Thanks guys.

It's a behaviour that I've often noted isn't to my personal preference, but it is intentional.

Nor mine. I don't think I've ever seen it used and I never really understood why we support that. I think we should remove support in RSpec 4. See rspec/rspec-expectations#935.

Was this page helpful?
0 / 5 - 0 ratings