Thursday, April 7, 2011

How to set Custom Rspec Matchers

rspec version is 1.3.x.
create custom_matchers.rb in application's spec directory, railsapp/spec.
custom_matchers.rb
module CustomMatcher
  def matcher_something
    #define custom matcher
  end
end

edit railsapp/spec/spec_helper.rb
.
.
.
require 'spec/rails'
require File.dirname(__FILE__) + "/custom_matchers"
・
・
Spec::Runner.configure do |config|
  .
  .
  config.fixture_path = RAILS_ROOT + '/spec/fixtures/'
  config.include(CustomMatcher)
And matcher_someting is enabled.