在RSpec中检查URL方向的规范方法是什么?

时间:2013-04-24 08:18:41

标签: ruby-on-rails rspec routing

我在Ruby on Rails开发中做TDD。我的代码看起来像这样:

require "spec_helper"

describe "Schedule routing" do

  it "by default should redirect /schedule to 'schedule/dateview'" do
    visit("/schedule")
    current_path.should == "/schedule/dateview"                                                                                      
  end

end

这是否有更简洁的方法来检查路由?

编辑:添加我的routes.rb以获取更多上下文:

 get "schedule/dateview", to: "events#dateview"
 get "schedule/courseview", to: "events#courseview"
 match "/schedule" => redirect("/schedule/dateview"), via: :get

1 个答案:

答案 0 :(得分:0)

如果你在控制器规范中这样的话应该可行

it "by default should redirect /schedule to schedule/dateview'" do
  visit schedule_path
  response.should redirect_to schedule_dateview_path
end