【问题标题】:Rspec/Capybara: How to "expect to see Routing Error"?Rspec/Capybara:如何“期待看到路由错误”?
【发布时间】:2014-04-06 09:53:52
【问题描述】:

如何告诉 RSpec/Capybara 期待 RoutingError?原因是我希望用户通过 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

【问题讨论】:

    标签: ruby-on-rails rspec capybara


    【解决方案1】:

    试试这个

     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
    

    【讨论】:

    • 值得注意的是,当您期望引发错误时,您必须传递 expect 一个 proc(带大括号),而不是简单地用括号调用它。
    • 使用 Minitest:assert_raises(Exception) { visit claim_plate_path }
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多