Module: RspecRailsMatchers::Associations::BelongTo

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

Instance Method Summary collapse

Instance Method Details

#belong_to(association) ⇒ Object



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

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

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

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