Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

undefined method `get?' for 302:Integer

I like to upgrade the ruby version from 2.4.2 to 2.5.0 in my rails application.

All specs/tests fail where I use turbolinks. Is there a known issue with turbolinks and ruby 2.5.0?

Here is the output on the terminal.

Failure/Error: expect(request).to redirect_to company_salesmen_path(salesman.company)

NoMethodError:
    undefined method `get?' for 302:Integer
  # /Users/dennish/.rvm/gems/ruby-2.5.0/gems/turbolinks-5.1.0/lib/turbolinks/assertions.rb:37:in `turbolinks_request?'
  # /Users/dennish/.rvm/gems/ruby-2.5.0/gems/turbolinks-5.1.0/lib/turbolinks/assertions.rb:6:in `assert_redirected_to'
  # ./spec/requests/salesmen_spec.rb:206:in `block (3 levels) in <top (required)>'

This is the spec:

describe 'DELETE /salesman/:id' do
  subject(:request) do
    delete salesman_path(salesman), headers: auth_headers
  end

  let!(:salesman) { create :salesman }

  it 'destroys salesman' do
    expect { request }.to change { Salesman.count }.by(-1)
  end

  it 'redirects to index' do
    expect(request).to redirect_to company_salesmen_path(salesman.company)
  end
end
like image 518
DenicioCode Avatar asked Mar 15 '18 07:03

DenicioCode


2 Answers

The root cause of this error is:

subject(:request)

By assigning :request we are overwriting rails internals - hence it breaks and the tests fail wierdly.

The Solution

Just go with the default (no name)

subject { delete salesman_path(salesman) }

Or you can rename the subject:

subject(:http_request) { delete salesman_path(salesman) }

Both solutions will make the tests succeed.

like image 113
davegson Avatar answered Nov 15 '22 14:11

davegson


I had this same issue it seems to be a compatibility issue with Turbolinks 5.1 and Rails 5.0.x. Downgrading to Turbolinks 5.0.1 solved it for me.

like image 3
Jared Avatar answered Nov 15 '22 13:11

Jared