expect method call inside rescue rspec
Certainly! Here is a response to your query:
describe 'SomeClass' do
it 'performs some action' do
expect(SomeClass).to receive(:some_method).and_raise(StandardError)
expect { SomeClass.perform_action }.to raise_error(StandardError)
end
end
Explanation:
1. In this example, we are using RSpec to test the behavior of a class called SomeClass
.
2. We are setting an expectation that a method call to SomeClass.some_method
will raise a StandardError
.
3. Then, we use the expect
block to test that calling SomeClass.perform_action
will indeed raise a StandardError
as expected.