我想知道如何簡單地允許所有異常在請求規範的中間向上冒泡到rspec。如何允許異常在rspec請求規範中冒泡
我希望一個例子能說清楚。比方說,我有以下要求規範和相應的應用程序代碼:
# user_browses_posts_spec.rb
feature 'User views a post' do
scenario 'this should fail with route missing' do
FactoryGirl.create(:post)
visit(root_path)
click_on('View Post')
end
end
# config/routes.rb
MyApp::Application.routes.draw do
root to: 'posts#index'
# notice I have not defined a :posts resource, so post_path should raise NoMethodError
end
# assume a totally standard app/controllers/posts_controller.rb
# app/views/posts/index.html.erb
<% @posts.each do |post| %>
<%= link_to 'View Post', post_path(post) %> # this line should fail
<% end %>
當我運行測試,我所看到的是:
Failure/Error: click_on('View Post')
Capybara::ElementNotFound:
no link or button 'View Post' found
這是因爲當NoMethodError從應用程序內提出,spec runner沒有察覺到問題,因爲它看到了正常的Rails開發錯誤頁面(帶有錯誤消息,回溯,params等)。
但我想在我的終端看到的是:
Failure/Error: visit(root_path)
NoMethodError:
undefined method `post_path' for #<PostsController:0x007fea60a779c8>
我的問題,那麼,是如何可以禁用軌誤差完全處理,所以NoMethodError氣泡一路攀升至rspec的?
謝謝!
這肯定是一個很好的可選功能,而不必跟蹤測試日誌並關聯外部功能通過測試。 – agmin