Class: Bench::Matchers::RunsIn
- Inherits:
-
Object
- Object
- Bench::Matchers::RunsIn
- Defined in:
- lib/bench/runs_in.rb
Overview
:nodoc:
Instance Method Summary collapse
- #failure_message ⇒ Object
-
#initialize(receiver = nil, &block) ⇒ RunsIn
constructor
A new instance of RunsIn.
- #matches?(event_proc) ⇒ Boolean
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_message ⇒ Object
20 21 22 23 |
# File 'lib/bench/runs_in.rb', line 20 def duration = ActiveSupport::Duration.new(1, [[:seconds, @distance]]) "Expected call to run in #{@receiver.inspect}, actually ran in #{duration.inspect}." end |
#matches?(event_proc) ⇒ 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 |