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
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With