Module: RspecRailsMatchers::Associations::HaveAndBelongToMany

Included in:
RspecRailsMatchers::Associations
Defined in:
lib/rspec_rails_matchers/associations/have_and_belong_to_many.rb

Instance Method Summary collapse

Instance Method Details

#have_and_belong_to_many(association) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/rspec_rails_matchers/associations/have_and_belong_to_many.rb', line 4

def have_and_belong_to_many(association)
  Rspec::Matchers::Matcher.new :have_and_belong_to_many, association do |_association_|
    extend RspecRailsMatchers::Associations::Helpers

    match do |model|
      associations(model, :has_and_belongs_to_many).any? { |a| a == _association_ }
    end

    failure_message_for_should do |model|
      RspecRailsMatchers::Message.error(
        :expected => [ "%s to have and belong to %s", model, _association_ ],
        :actual   => [ "%s has and belongs to %s", model, associations(model, :has_and_belongs_to_many) ]
      )
    end
  end
end