Skip to content
[UNSUPPORTED: consider minitest-should_syntax instead.] RSpec-like syntax for Test::Unit
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
lib Release v0.3.0
test New way of hooking onto Test::Unit should now not break setup blocks.
.gitignore Initial. Release v0.3.0 + Messages (blaming)
Rakefile Initial.
renvy.gemspec Release v0.3.0


Rspec-like matching for Test::Unit.

REnvy lets you use a syntax similar to RSpec on your Test::Unit tests. It monkey-patches Object to translate RSpec-like sugar into plain Test::Unit assert matchers.

$ gem install renvy

Then you may use it as so:

obj.should == 2                    # => assert_equal 2, obj
obj.should =~ /regex/              # => assert_match /regex/, obj
obj.should != 3                    # => assert_not_equal 3, obj
obj.should.nil                     # => assert_nil obj
obj.should.respond_to(:freeze)     # => assert_respond_to obj, :freeze 

# Note that .be, .a and .an are optional.
obj.should.nil                     # => assert_nil obj                  # => assert_nil obj                # => assert_nil obj

# You can also use should_not, or should.not:
obj.should_not == 3
obj.should.not == 3

# Anything else will pass through with a ?:         # => assert obj.good_looking?

should.raise(Error) { lol }
should_not.raise { puts "hi" }

# You may add messages to your asserts with #blaming or #messaging.
(2 + 2).should.blaming("weird math") == 4

Wrapped assertions

These are based from Test::Spec.

Test::Unit REnvy
assert_equal should.equal, should ==
assert_not_equal should.not.equal, should.not ==
assert_match should.match, should =~
assert_no_match should.not.match, should.not =~
assert_respond_to should.respond_to
assert_raise should.raise
assert_nothing_raised should.not.raise
assert_throws should.throw
assert_nothing_thrown should.not.throw
assert_block should.satisfy


Need to create your own matchers? Create your new matcher in a module, then use REnvy::Should.add.

module DanceMatcher
  def boogie_all_night!
    if positive?
      test.assert left.respond_to?(:dance)
      test.assert ! left.respond_to?(:dance)

REnvy::Should.add DanceMatcher

# Then in your tests, use:

REnvy vs. Test::Spec

Test-Spec accomplishes roughly the same thing as REnvy, but:

  • REnvy does it with lean <4kb code.

  • REnvy can play alongside with other Test::Unit wrappers. In fact, is made to be used with gems like Contest, Shoulda, and other similar tools.

  • REnvy does not provide contexts or 'should'-like syntax like Test::Spec does. For that, I suggest using REnvy alongside Contest.

Something went wrong with that request. Please try again.