Ruby on rails Rails 3-渲染布局会破坏测试
我在wsp_控制器上定义了一个名为location的函数:Ruby on rails Rails 3-渲染布局会破坏测试,ruby-on-rails,ruby-on-rails-3,Ruby On Rails,Ruby On Rails 3,我在wsp_控制器上定义了一个名为location的函数: def location @title ="Edit account" @page_name = "edit" end 而且效果很好。但当我尝试渲染这样的布局时: def location @title ="Edit account" @page_name = "edit" render :layout => 'signup_login' end RSpec测试开始失败
def location
@title ="Edit account"
@page_name = "edit"
end
而且效果很好。但当我尝试渲染这样的布局时:
def location
@title ="Edit account"
@page_name = "edit"
render :layout => 'signup_login'
end
RSpec测试开始失败。然而,应用程序做了应该做的,但是测试失败了。
我在布局中有javascript代码,当我转到/location时需要运行这些代码,如果我将Java脚本放在应用程序布局中,它会工作(测试和应用程序),但是不需要放在那里,所以我需要一个新的布局并呈现它
我该怎么做
编辑:下面是我在routes.rb中看到的内容
match '/wsps/:id/location', :to =>'wsps#location'
谢谢
编辑:
一些RSpec错误:
Failures:
1) WspsController GET 'index' for non-signed-in wsps should deny access to 'index'
Failure/Error: get :index
You have a nil object when you didn't expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.errors
当我渲染布局时,它没有通过测试。但是,这只是一种方法。您可能需要提供更多关于所遇到故障的信息。您提到在呈现页面时需要运行javascript吗?不要忘记,在功能测试中,页面呈现为html,但没有使用真正的浏览器,因此没有运行javascript。对于涉及javascript的测试,您应该查看Cucumber之类的东西来定义一些验收测试,再结合Watir或Selenium之类的东西来驱动浏览器。Rspec测试中的失败消息是什么?我添加了更多信息。谢谢