Rspec: I can not understand the method and_raise

Here is my code:

account_double.should_receive(:withdraw).and_raise

I get the output:

1) Statement uses the customer 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:31:in `inject'

It cannot find an exception. How can I pass this test?

I do not understand the image

+3
source share
1 answer

Try adding an argument and_raise- either to the class Exceptionor to the string to go toRuntimeError

From the docs:

Tells the layout to raise an exception instead of returning a value. can be any Exception class, an instance of any Exception or String class (in this case, a RuntimeError will be raised with this string as its message).

account_double.should_receive(:withdraw).and_raise(Exception)
+6
source

Source: https://habr.com/ru/post/1759255/


All Articles