开发者

How can I make Capybara use Routing helpers

开发者 https://www.devze.com 2023-01-29 18:16 出处:网络
I am using rails 3, Steak 开发者_如何学Go& Capybara. I have restful resources, is it possible to use routing helpers available to views and controllers?You just have to put this on your spec_helpe

I am using rails 3, Steak 开发者_如何学Go& Capybara. I have restful resources, is it possible to use routing helpers available to views and controllers?


You just have to put this on your spec_helper.rb

config.include Rails.application.routes.url_helpers

inside the configuration definition block, that is, the one that is wrapped by:

RSpec.configure do |config|
# All your config.include calls go here.
end

And then you can use it on your feature specs:

scenario "Show school" do
school = School.create!(:name => "Pablo de Olavide")
visit(school_path(school))
save_and_open_page
page.has_content?("Pablo de Olavide").should == true
end

Do not use:

include ActionController::UrlWrite

As it is deprecated in rails 3


I changed it to this to get it working with Rails 4.1.6:

config.include Rails.application.routes.url_helpers if defined? Rails
0

精彩评论

暂无评论...
验证码 换一张
取 消