Where to put custom RSpec matchers

Updated . Posted . Visible to the public. Deprecated.

When you write a custom RSpec matcher a good place to store them is to create one file per matcher in spec/support/matchers:

spec/support/matchers/be_same_numbers_as.rb
spec/support/matchers/be_same_second_as.rb
spec/support/matchers/exist_in_database.rb
spec/support/matchers/include_hash.rb

You can include all matchers in the support directory by adding the following line to your spec_helper.rb:

Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f}

Cucumber

If you want to use your custom matchers in Cucumber scenarios, you need to require them in features/support/env.rb:

Dir[File.expand_path('spec/support/matchers/*.rb')].each {|f| require f}
Henning Koch
Last edit
Dominik Schöler
License
Source code in this card is licensed under the MIT License.
Posted by Henning Koch to makandra dev (2011-03-29 16:12)