我想寫一些rspec集成測試來測試我的條件路由路由是否正確,但我遇到了一堆問題。Rspec測試條件路由約束
在routes.rb中:
root :to => "error#ie6", :constraints => {:user_agent => /MSIE 6/}
root :to => "protocol_sets#index", :constraints => UserRoleConstraint.new(/doctor/i)
root :to => "refill_requests#create", :constraints => UserRoleConstraint.new(/member/i)
root :to => "refill_requests#create", :constraints => {:subdomain => "demo"}
root :to => "site#index"
在規格/請求/ homepage_routing_spec.rb
require 'spec_helper'
describe "User Visits Homepage" do
describe "Routings to homepage" do
it "routes/to site#index when no session information exists" do
visit root_path
end
end
end
我收到以下錯誤,當我嘗試運行測試。
Failures: 1) User Visits Homepage Routings to homepage routes/to site#index when no session information exists Failure/Error: visit root_path NoMethodError: undefined method `match' for nil:NilClass # :10:in `synchronize' # ./spec/requests/homepage_routings_spec.rb:6:in `block (3 levels) in ' Finished in 0.08088 seconds 1 example, 1 failure Failed examples: rspec ./spec/requests/homepage_routings_spec.rb:5 # User Visits Homepage Routings to homepage routes/to site#index when no session information exists
從谷歌搜索我猜可能有一個問題,如何rspec/capybara處理條件路由。
有無論如何測試rspec和水豚的路線限制?
謝謝你。現在你有沒有找到更好的解決方案? – Hendrik
不幸的是,沒有。 – Florian