public
Last active

  • Download Gist
runs_in.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
# In Rails 3 The require for the Numeric time helpers is simply:
# require 'active_support/core_ext/numeric/time'
# In Rails 2, it's all of this:
 
require 'active_support/core_ext/numeric/time'
require 'active_support/duration'
require 'i18n'
class Numeric #:nodoc:
include ActiveSupport::CoreExtensions::Numeric::Time
end
 
require 'active_support/core_ext/array/conversions'
 
class Array #:nodoc:
include ActiveSupport::CoreExtensions::Array::Conversions
end
 
 
# This is just a little taste of how many more things you're "not doing" in Rails 3.
 
# tl;dr Rails 2 sucks, Rails 3 will make the suck go away.
 
 
module Bench
module Matchers
class RunsIn #:nodoc:
def initialize(receiver=nil, &block)
@receiver = receiver
# Placeholder
end
def matches?(event_proc)
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
runs_in_spec.rb
Ruby
1 2 3 4 5 6 7 8 9
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
spec_helper
1 2 3
Spec::Runner.configure do |config|
config.include(Bench::Matchers)
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.