2014-03-04 44 views
8

我如何告訴RSpec /水豚期待RoutingError?原因是我希望用戶通過PUT點擊一個鏈接到「索賠一盤」,而不是通過GET /訪問路徑。基本上我想expect ActionController::RoutingError: No route matches [GET] "/plates/claim/1"Rspec /水豚:如何「期望看到路由錯誤」?

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

回答

9

試試這個

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 
+6

值得一提的是,當你希望引發錯誤,你必須通過期望PROC(用大括號),而不是簡單地用括號調用它。 – benrugg

+2

使用Minitest:'assert_raises(Exception){visit claim_plate_path}' – mb21