I'm reading through Rails 4 in Action. I'm getting the aforementioned error while testing with Rspec and Capybara. My viewing_projects_spec.rb looks like this:
require 'spec_helper'
feature "Viewing projects" do
scenario "Listing all projectcs" do
project = FactoryGirl.create(:project, name: "TextMate 2")
visit '/'
click_link 'TextMate 2'
expect(page.current_url).to eql(project_url(project))
end
end
The rest of the error says Failure/Error: expect(page.current_url).to eql(project_url(project))
.
I did some googling and people say to place the following inside config/environments/development.rb:
Rails.application.routes.default_url_options[:host] = 'localhost:3000'
Unfortunately this doesn't do anything.
The host statement should be put into config/environments/test.rb instead of development.rb, because you are running tests.
The reason you see 'example.com' is Capybara set this as default host. To change that, just add the following line in spec_help
after require 'capybara'
Capybara.default_host = 'localhost:3000'
Ref: https://rspec.lighthouseapp.com/projects/16211-cucumber/tickets/206
Then you urls should match what you've set in test.rb.
Anyway, I would prefer not to have that trouble to use current_path
directly.
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