Today I Learned

hashrocket A Hashrocket project

Custom RSpec negation matchers

You can create negated versions of existing rspec matchers, mostly useful with composition.

# spec/rails_helper.rb
RSpec::Matchers.define_negated_matcher :an_array_excluding, :include
# spec.rb
list = (1..5).to_a
expect {
  list.delete(5)
}.to change { 
  list
}.to an_array_excluding(5)
See More #rails TILs
Looking for help? Hashrocket has been an industry leader in Ruby on Rails since 2008. Rails is a core skill for each developer at Hashrocket, and we'd love to take a look at your project. Contact us and find out how we can help you.