我正在使用Rails 3,牛排和 capybara 。我的资源很安静,是否可以使用 View 和 Controller 可用的路由助手?
最佳答案
您只需将其放在您的spec_helper.rb
config.include Rails.application.routes.url_helpers
在配置定义块中,即由以下内容包装的块:
RSpec.configure do |config|
# All your config.include calls go here.
end
然后,您可以在功能规范上使用它:
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
不使用:
include ActionController::UrlWrite
由于它已在 rails 3中弃用
关于ruby-on-rails - 如何使 capybara 使用路由助手,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4411930/