Read more

Where to put custom RSpec matchers

Henning Koch
March 29, 2011Software engineer at makandra GmbH

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
Illustration UI/UX Design

UI/UX Design by makandra brand

We make sure that your target audience has the best possible experience with your digital product. You get:

  • Design tailored to your audience
  • Proven processes customized to your needs
  • An expert team of experienced designers
Read more Show archive.org snapshot

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}
Posted by Henning Koch to makandra dev (2011-03-29 18:12)