Class: Bench::Matchers::RunsIn

Inherits:
Object
  • Object
show all
Defined in:
lib/bench/runs_in.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(receiver = nil, &block) ⇒ RunsIn

Returns a new instance of RunsIn.



4
5
6
7
# File 'lib/bench/runs_in.rb', line 4

def initialize(receiver=nil, &block)
  @receiver = receiver
  # Placeholder
end

Instance Method Details

#failure_messageObject



20
21
22
23
# File 'lib/bench/runs_in.rb', line 20

def failure_message
  duration = ActiveSupport::Duration.new(1, [[:seconds, @distance]])
  "Expected call to run in #{@receiver.inspect}, actually ran in #{duration.inspect}."
end

#matches?(event_proc) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
12
13
14
15
16
17
18
# File 'lib/bench/runs_in.rb', line 9

def matches?(event_proc)
  raise_block_syntax_error if block_given?
  
  @before = Time.now
  event_proc.call
  @after = Time.now
  
  @distance = @after - @before
  return @distance < @receiver
end