【发布时间】:2012-01-05 14:53:08
【问题描述】:
我有一个这样的块:
begin
response = Facebook.make_profile_request(params[:token])
rescue => e
Airbrake.notify(
:error_class => "Facebook Processing",
:error_message => "Error: #{e.message}"
)
flash[:notice] = "Uh oh...something went wrong. Please try again."
redirect_to root_path
end
这是我目前所拥有的:
it "should notify Airbrake if call to FB fails" do
Facebook.stub(:make_profile_request).with(fb_token).and_raise(Exception)
Airbrake.should_receive(:notify)
get :facebook_process, token: fb_token
end
我得到错误:
1) UsersController GET facebook_process should notify Airbrake if call to FB fails
Failure/Error: get :facebook_process, token: fb_token
Exception:
Exception
# ./app/controllers/users_controller.rb:9:in `facebook_process'
# ./spec/controllers/users_controller_spec.rb:41:in `block (3 levels) in <top (required)>'
我应该如何正确测试救援?
【问题讨论】:
-
将您在测试存根中引发的异常更改为
RuntimeError之类的内容,因为 `rescue' 没有捕捉到它。
标签: ruby-on-rails-3 rspec2 rspec-rails