Advertisement
Guest User

Untitled

a guest
Jul 28th, 2012
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. require 'benchmark'
  2.  
  3. module BenchmarkHelpers
  4.   def benchmark(description, &block)
  5.     # 1. Nope
  6.     #bm_proc = Proc.new do
  7.     #  db = Proc.new { |bm| bm.report(description, &block) }
  8.     #  Benchmark.bm(description.length, &db)
  9.     #end
  10.     it description do
  11.       Benchmark.bm(description.length) do |bm|
  12.         # 2. Nada
  13.         #bm.report description, &block
  14.         bm.report description do
  15.           # 3. Zilch.
  16.           #block.call
  17.           #block.yield
  18.           # eval in context of example_group_instance!
  19.           example.example_group_instance.instance_eval(&block)
  20.         end
  21.       end
  22.     end
  23.   end
  24. end
  25.  
  26. RSpec.configure do |c|
  27.   c.extend BenchmarkHelpers
  28. end
  29.  
  30. describe "scopes" do
  31.   it "succeeds" do
  32.     p self.class
  33.     p be
  34.     true.should == true # success
  35.     true.should be      # success
  36.   end
  37.   benchmark "throws exception on 'be'" do
  38.     p self.class
  39.     p be
  40.     true.should == true # success
  41.     true.should be      # exception
  42.   end
  43. end
  44.  
  45.  
  46. /home/aaron/.rvm/rubies/ruby-1.9.2-p290/bin/ruby -S bundle exec rspec spec/benchmark_spec.rb
  47.  
  48. scopes
  49. RSpec::Core::ExampleGroup::Nested_1
  50. #<RSpec::Matchers::Be:0x00000002822740 @args=[]>
  51.   succeeds
  52.                               user     system      total        real
  53. throws exception on 'be'RSpec::Core::ExampleGroup::Nested_1
  54. #<RSpec::Matchers::Be:0x0000000281f068 @args=[]>
  55.   0.000000   0.000000   0.000000 (  0.000091)
  56.   throws exception on 'be'
  57.  
  58. Finished in 0.0016 seconds
  59. 2 examples, 0 failures
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement