Ruby on rails rails中helper方法的问题
我有以下助手方法(app/helpers/application\u helper.rb): 下面是erb(app/views/layouts/application.html.erb):Ruby on rails rails中helper方法的问题,ruby-on-rails,ruby,rspec,autotest,Ruby On Rails,Ruby,Rspec,Autotest,我有以下助手方法(app/helpers/application\u helper.rb): 下面是erb(app/views/layouts/application.html.erb): 但是,我仍然在您的视图中遇到相同的错误,默认情况下不包括帮助程序 你可以: 然后,您可以单独测试您的应用程序 或者,只需执行以下操作,即可将助手包括在视图规范中: include ApplicationHelper 编辑 describe PagesController do include Appli
但是,我仍然在您的视图中遇到相同的错误,默认情况下不包括帮助程序 你可以: 然后,您可以单独测试您的应用程序 或者,只需执行以下操作,即可将助手包括在视图规范中:
include ApplicationHelper
编辑
describe PagesController do
include ApplicationHelper
describe "GET 'home'" do
it "should be successful" do
controller.template.should_receive(:title).and_return("Title")
get 'home'
response.should be_success
end
end
end
我应该将include ApplicationHelper放在哪里?如果我没记错,它需要放在descripe块中。“编辑”刚找到这个链接很抱歉,当您提到帮助器方法时,我假设您正在测试一个视图。你试过stubing方法吗?我对rspec不太熟悉,所以我不知道该放在哪里,它说放在模板对象中,但它在哪里?请查看我的编辑,并告诉我这是否有效。我也建议退房
Failures:
1) PagesController GET 'home' should be successful
Failure/Error: get 'home'
ActionView::Template::Error:
undefined local variable or method `title' for #<#<Class:0x991ecb4>:0x991315c>
# ./app/views/layouts/application.html.erb:4:in `_app_views_layouts_application_html_erb__248109341_80250010__979063050'
# ./spec/controllers/pages_controller_spec.rb:8:in `block (3 levels) in <top (required)>'
2) PagesController GET 'home' should have the right title
Failure/Error: get 'home'
ActionView::Template::Error:
undefined local variable or method `title' for #<#<Class:0x991ecb4>:0x9d7d094>
# ./app/views/layouts/application.html.erb:4:in `_app_views_layouts_application_html_erb__248109341_82566280__979063050'
# ./spec/controllers/pages_controller_spec.rb:13:in `block (3 levels) in <top (required)>'
describe PagesController do
include ApplicationHelper
render_views
describe "GET 'home'" do
it "should be successful" do
get 'home'
response.should be_success
end
it "should have the right title" do
get 'home'
response.should have_selector("title",
:content => "Ruby on Rails Tutorial Sample App | Home")
end
end
//and some more
template.should_receive(:title).and_return("Title")
include ApplicationHelper
describe PagesController do
include ApplicationHelper
describe "GET 'home'" do
it "should be successful" do
controller.template.should_receive(:title).and_return("Title")
get 'home'
response.should be_success
end
end
end