Created
March 5, 2010 02:25
-
-
Save radar/322391 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Bench | |
module Matchers | |
class RunsIn #:nodoc: | |
def initialize(receiver=nil, &block) | |
@receiver = receiver | |
# Placeholder | |
end | |
def matches?(event_proc) | |
raise_block_syntax_error if block_given? | |
before = Time.now | |
event_proc.call | |
after = Time.now | |
return (after - before) < @receiver | |
end | |
end | |
def run_in(receiver=nil, &block) | |
Matchers::RunsIn.new(receiver, &block) | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe "Bench" do | |
it "runs in under 2.5 seconds" do | |
lambda { sleep(1) }.should run_in(2.5.seconds) | |
end | |
it "fails to run in under 2.5 seconds" do | |
lambda { sleep(2.6) }.should_not run_in(2.5.seconds) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Spec::Runner.configure do |config| | |
config.include(Bench::Matchers) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment