Module: Matchbox

Included in:
Test::Unit::TestCase
Defined in:
lib/matchbox.rb,
lib/matchbox/version.rb

Overview

Test::Unit assertions for RSpec and Shoulda matchers.

I created this since:

  • I like assertions, not the Shoulda "should" statements.
  • I want to use shoulda-matchers in my Rails project.
  • I'm in love with the simplicity of the contest gem.

These methods are based upon those found in shoulda-context.

With shoulda-matchers, it can be used like so:

class PostTest < Test::Unit::TestCase
  def test_active_record_relations
    post = Post.new
    assert_accepts belong_to(:topic), post
  end
end

Constant Summary

VERSION =
'1.0.0'

Instance Method Summary (collapse)

Instance Method Details

- assert_accepts(matcher, target)

Asserts that a matcher matches a given target.

Parameters:

  • matcher (#failure_message && #matches?)
  • target (Object)


25
26
27
28
# File 'lib/matchbox.rb', line 25

def assert_accepts(matcher, target)
  matched = matcher.matches?(target)
  assert_block(matcher.failure_message) { matched }
end

- assert_rejects(matcher, target)

Asserts that a matcher does not match a given target.

Parameters:

  • matcher (#negative_failure_message && #matches?)
  • target (Object)


35
36
37
38
# File 'lib/matchbox.rb', line 35

def assert_rejects(matcher, target)
  matched = matcher.matches?(target)
  assert_block(matcher.negative_failure_message) { !matched }
end