Module: RspecRailsMatchers::Associations::HaveMany

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

Instance Method Summary collapse

Instance Method Details

#have_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_many.rb', line 4

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

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

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