开发者

Rspec: Can't understand "and_raise" method

开发者 https://www.devze.com 2023-01-11 09:43 出处:网络
Here is my code: account_double.should_receive(:withdraw).and_raise I get the output: 1) Statement uses the customer\'s name in the header

Here is my code:

account_double.should_receive(:withdraw).and_raise

I get the output:

1) Statement uses the customer's name in the header
Failure/Error: Unable to find matching line from backtrace
Exception
# ./spec/codebreaker/test.rb:8:in `generate'
# ./spec/codebreaker/test.rb:20
# /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:3开发者_Python百科1:in `inject'

It cannot find Exception. How could I get this test to pass?

I dont understand the picture


Try adding an argument to and_raise - either an Exception class or a string to pass to RuntimeError

From the docs:

Tells the mock to raise an exception instead of returning a value. may be any Exception class, an instance of any Exception class, or a String (in which case a RuntimeError will be raised with that String as its message).

account_double.should_receive(:withdraw).and_raise(Exception)
0

精彩评论

暂无评论...
验证码 换一张
取 消