Grumpy Old Man
Adding old school asserts to RSpec
GrumpyOldMan adds the following methods to RSpec without compromising any of RSpec's other features.
assert
assert_equal
assert_raise
refute
NOTE: If you're using rspec-rails, these methods are delegated to MiniTest and you don't need GrumpyOldMan.
Testing libraries exist to help you do the following.
- Execute some code
- Verify that it produced the expected outcome
Or more simply...
assert true
Unfortunately RSpec adds a lot of unnecessary complexity. Looking at you expectations and matchers.
Simplicity FTW
Consider the following example from the RSpec docs.
expect(order.total).to eq(Money.new(5.55, :USD))
Rewritten with GrumpyOldMan.
assert order.total == Money.new(5.55, :USD)
# or ...
assert_equal order.total, Money.new(5.55, :USD)
Simple asserts
encourage test code that resembles your application logic.
Usage
bundle add grumpy_old_man
Simply include GrumpyOldMan in your spec/test like so.
require "grumpy_old_man"
describe Thing do
include GrumpyOldMan
it "should be simple" do
assert true
assert_equal true, true
assert_raise(Exception) { raise }
refute false
end
end
You may not agree, but I'm sticking with my old fashioned assert. Now get off my lawn!
If you like GrupyOldMan, check out PryTest and discover just how serene testing can be.