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 online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
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)