Search code examples
ruby-on-railstestingshoulda

Adding custom shoulda matchers to TestCase


After using shoulda it is very clear that shoulda no longer uses macros (They are all deprecated for the preferred matchers) For example:

should_allow_custom_test

is deprecated for the following:

should allow_custom_test

However all the documentation I can find is for the former macro setup by placing them in the shoulda_macros directory. I thought the same could be accomplished with a custom matcher but shoulda can not find it them.

My matcher I'm using is at http://gist.github.com/613522

How do I include custom matchers into my TestCase's?


Solution

  • Delving into active_record.rb, looks like the matchers are directly required into Test::Unit::TestCase I think your gist pulls it into ActiveSupport::TestCase - not sure if that'd help... but might be worth a try.

    From active_record.rb:

    module Test # :nodoc: all
      module Unit
        class TestCase
          include Shoulda::ActiveRecord::Helpers
          include Shoulda::ActiveRecord::Matchers
          include Shoulda::ActiveRecord::Assertions
          extend Shoulda::ActiveRecord::Macros
        end
      end
    end