Pseudo is very simple test double library that supports only the features which support good mocking practices:
- Stubbing
- Spy-style mocking
Stub a method.
double = Pseudo.new
double.stub(:stubbed_method)
double.stubbed_method # => nil
Stub a method with a return value.
double = Pseudo.new
double.stub(:stub_with_return).return(123)
double.stub_with_return # => 123
Stub a method to yield a value.
double = Pseudo.new
double.stub(:stub_with_yield).yield(456)
double.stub_with_yield do |value|
value # => 456
end
Stub a method to raise an exception.
double = Pseudo.new
double.stub(:stub_with_raise).raise(ArgumentError, 'bad argument')
double.stub_with_raise
# ArgumentError: bad argument
# from ...
Spies are a form of mock that doesn't break up the four-phase test structure.
def test_setup_exercise_verify_teardown
double = Pseudo.new
double.stub(:record_it)
double.stub(:never_called)
double.record_it
assert_equal true, double.received?(:record_it)
assert_equal false, double.received?(:never_called)
end
- Ruby 2.0.0+
- Nothing else. No gem dependencies, nothing.
The best way to install Pseudo is with RubyGems:
$ [sudo] gem install pseudo
If you'd like to make some changes to Pseudo, start by forking the repo on GitHub:
http://github.com/nwjsmith/pseudo
The best way to get contributions merged into Pseudo:
- Clone down your fork.
- Create a well-named topic branch for your change
- Make your change.
- Add tests and make sure everything passes (see the section on running the tests below).
- If you are adding new functionality, document it in the README.
- Do not change the version number.
- If necessary, rebase your commits into logical chunks, with no failing commits.
- Push the branch to GitHub.
- Send a pull request to the nwjsmith/pseudo project.
$ bundle install
$ bundle exec rake test
Pseudo is released under the MIT License.