Rspec / Capybara:如何“期望看到路由错误”?

时间:2014-03-04 17:42:32

标签: ruby-on-rails rspec capybara

如何告诉RSpec / Capybara期待路由错误?原因是我希望用户点击链接“通过PUT索取牌照”,而不是通过GET /访问路径。

基本上我想要expect ActionController::RoutingError: No route matches [GET] "/plates/claim/1"

  scenario 'they have to click the claim link' do
    create_plates
    sign_in_as_doctor
    visit claim_plate_path(@plates.first.id)
    ?????
  end

1 个答案:

答案 0 :(得分:11)

试试这个

 scenario 'they have to click the claim link' do
    create_plates
    sign_in_as_doctor
    expect{visit claim_plate_path(@plates.first.id)}.to raise_error( ActionController::RoutingError)
  end