Asserts for RSpec
Ruby
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
spec
.gitignore
.travis.yml
Gemfile
Gemfile.lock
README.md
Rakefile
grumpy_old_man.gemspec

README.md

Grumpy Old Man

Build Status Dependency Status Code Climate

Adding old school asserts to RSpec

GrumpyOldMan adds the following methods to RSpec without compromising any of RSpec's awesomeness.

  • assert
  • assert_equal
  • assert_raise

I love several things about RSpec.

  • Its beautiful output from the test runner
  • Its declarative approach to writing tests... well at least the outer wrapper i.e.
describe Thing do
  it 'should do stuff' do
    # ...
  end
end

Unfortunately parts of RSpec add unwanted complexity to a relatively simple problem:

assert true

Simple is better

I contend it's better to write tests in the same manner you write your app. Doing so reduces cognitive load by eliminating the context switching between app code and wonky DSLs in the test suite.

It simplifies your tests... and that's a good thing.

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)

Asserts encourage tests that more closely resemble the app logic itself. Making tests look familiar & more natural.

Usage

gem install grumpy_old_man

Simply include GrumpyOldMan in your spec/test like so.

require 'grumpy_old_man'

describe Thing
  include GrumpyOldMan

  it "should feel good" do
    assert true
  end

  it "should be balanced" do
    actual = true
    expected = true
    assert_equal actual, expected
  end

  it "should be exceptional" do
    assert_raise(Exception) do
      raise
    end
  end

end

You might not agree, but I'm sticking with my old fashioned assert.

Now get off my lawn!

If you like GrupyOldMan, check out MicroTest and discover just how serene testing can be.