Class: RSpec::ActiveRecord::Expectations::Matchers::LoadMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/activerecord/expectations/matchers/load_matcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(klass) ⇒ LoadMatcher

Returns a new instance of LoadMatcher.



4
5
6
7
# File 'lib/rspec/activerecord/expectations/matchers/load_matcher.rb', line 4

def initialize(klass)
  @collector = Collector.new
  @klass = klass.to_s
end

Instance Method Details

#failure_messageObject



20
21
22
# File 'lib/rspec/activerecord/expectations/matchers/load_matcher.rb', line 20

def failure_message
  "expected block to repeatedly load #{@klass}, but it was loaded #{@count} times"
end

#failure_message_when_negatedObject



24
25
26
# File 'lib/rspec/activerecord/expectations/matchers/load_matcher.rb', line 24

def failure_message_when_negated
  "expected block not to repeatedly load #{@klass}, but it was loaded #{@count} times"
end

#matches?(block) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
16
17
18
# File 'lib/rspec/activerecord/expectations/matchers/load_matcher.rb', line 13

def matches?(block)
  block.call

  @count = @collector.calls_by_name("#{@klass} Load")
  @count > 1
end

#supports_block_expectations?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/rspec/activerecord/expectations/matchers/load_matcher.rb', line 9

def supports_block_expectations?
  true
end