keisei_1092 keisei_1092 - 1 year ago 51
Ruby Question

Can RSpec ignore checking port number?

I wrote a simple spec:

visit root_url
click_button 'Sign in'

expect(current_url).to eq user_sign_in_url

and run this spec, it fails because of following:

expected: ""
got: ""

Why in this case RSpec checked port number?

Can RSpec ignore checking this? Any helps would be appreciated.

Answer Source

First at all you should use current_path method instead of current_url, because the second one returns the whole url. Another thing is that you are asserting strings (expect current_url to equal some string). This is totally okay in most of the cases, but more safe method is to use have_current_path like this:

expect(page).to have_current_path(...)

It will ensure to complete all preceding actions like click_button.