Rspec and named routes

╄→尐↘猪︶ㄣ 提交于 2019-11-27 04:22:44
Tom L

Named routes should work if you put the following in rspec_helper.rb:

RSpec.configure do |config|
  config.include Rails.application.routes.url_helpers
  ...
end

Is that how you set it up?

in rspec_helper.rb:

RSpec.configure do |config|
  config.include Rails.application.routes.url_helpers
  ...
end

Google brought me here, even my error message doesn't fit 100%.

In my case Capybara command visitis unknown...

Error:

NoMethodError:
       undefined method `visit' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0xa49a73c>

Since Capybara 2.0 one has to use folder spec/features capybara commands don't work in folder spec/requests anymore.

That helped me: http://alindeman.github.com/2012/11/11/rspec-rails-and-capybara-2.0-what-you-need-to-know.html

Hope you find this usefull.

I don't think you have access to named routes inside of your rspec controller specs. You could however just do visit('/'), which is the equivalent of root_path.

I had the same problem, with the same Tutorial. It turns out that I needed to just restart the Spork service, and all worked fine.

The solution posted by Tom L worked for me, but when I removed that line and restarted Spork, that also fixed the problem.

Hope that helps out any other people who are wary about deviating from the tutorial's code!

Benoît Legat

You should have used

rails generate rspec:install

instead of

rspec --init

and you wouldn't have had to modify the config file.

Don't do it now though or your application will break and you'll have to waste some more time figuring out why it broke.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!