Minitest::MockRaiseError
A simple Minitest mock extension to raise error.
Installation
Add this line to your application's Gemfile:
gem 'minitest-mock_raise_error'
And then execute:
$ bundle
Or install it yourself as:
$ gem install minitest-mock_raise_error
Usage
Require minitest/mock_raise_error
in your test_helper.rb before require 'minitest/autorun'
.
require 'minitest/mock_raise_error'
require 'minitest/autorun'
Next, call Minitest::Mock#expect
with a exception or a subclass of Exception as ret_val.
Then, the mock raises error with a specified exception or a instance of subclass of Exception.
class MyTestError < StandardError; end
# With a exception
mock = Minitest::Mock.new
error = MyTestError.new('error message')
mock.expect(:my_test, error)
mock.my_test # specified error is raised
mock.verify # => true
# With a subclass of Exception
mock = Minitest::Mock.new
mock.expect(:my_test2, MyTestError)
mock.my_test2 # specified class instance error is raised
mock.verify # => true
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/ryu39/minitest-mock_raise_error.
This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
If you want to send pull requests, please follow these steps.
- Fork this repository.
- Clone the forked repository.
- Execute
bin/setup
. - Execute
bundle exec rake
and check there are no failed test or offences. - Create and check out your feature branch.
- Commit your changes.
- Execute
bundle exec rake
and confirm again. - Push your branch.
- Create pull requests to master branch!!
License
The gem is available as open source under the terms of the MIT License.