[英]Why doesn't this Rails Rspec Test Work?
我手动创建程序的所有路由,当然也要对rspec测试进行创建。 通常,我的路线和测试工作正常,但我的角色控制器的测试有问题。 路线是:
scope :path => '/characters', :controller => :characters do
get '/' => :show, :as => 'user_character'
end
使用我的浏览器进行测试时,/字符可以正常工作。 一切似乎都很好。 但是,测试:
require 'spec_helper'
require 'devise/test_helpers'
describe CharactersController do
login_user
describe "when it GETS 'show'" do
it "should render the template and be successful" do
get :show
response.should render_template(:show)
response.should be_success
end
end
end
因错误而失败:
1) CharactersController when it GETS 'show' should render the template and be successful
Failure/Error: get :show
ActionController::RoutingError:
No route matches {:controller=>"characters", :action=>"show"}
# ./spec/controllers/characters_controller_spec.rb:9
我所有的控制器都有类似的测试,可以正常工作。 为什么这不起作用?
重要编辑:
刚刚看到,如果我关闭Spork,则测试通过! 为什么会这样呢? 每次添加新测试时,都需要重新启动Spork吗?
更改路线时必须重新启动spork。
或将其放在您的spec_helper.rb中:
Spork.each_run do
ApplicationName::Application.reload_routes!
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.