Advertisement
Guest User

Untitled

a guest
Jul 28th, 2012
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.81 KB | None | 0 0
  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.yield
  17.         end
  18.       end
  19.     end
  20.   end
  21. end
  22.  
  23. RSpec.configure do |c|
  24.   c.extend BenchmarkHelpers
  25. end
  26.  
  27. describe "scopes" do
  28.   benchmark "how do they work" do
  29.     true.should == true # success
  30.     true.should be      # exception
  31.   end
  32. end
  33.  
  34.  
  35. rake spec SPEC=spec/benchmark_spec.rb
  36. /home/aaron/.rvm/rubies/ruby-1.9.2-p290/bin/ruby -S bundle exec rspec spec/benchmark_spec.rb
  37.  
  38. scopes
  39.                       user     system      total        real
  40. how do they work  how do they work (FAILED - 1)
  41.  
  42. Failures:
  43.  
  44.   1) scopes how do they work
  45.      Failure/Error: true.should be
  46.      NameError:
  47.        undefined local variable or method `be' for RSpec::Core::ExampleGroup::Nested_1:Class
  48.     # ./spec/benchmark_spec.rb:25:in `block (2 levels) in <top (required)>'
  49.     # ./spec/benchmark_spec.rb:12:in `yield'
  50.      # ./spec/benchmark_spec.rb:12:in `block (3 levels) in benchmark'
  51.      # /home/aaron/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/benchmark.rb:295:in `measure'
  52.      # /home/aaron/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/benchmark.rb:382:in `item'
  53.      # ./spec/benchmark_spec.rb:11:in `block (2 levels) in benchmark'
  54.      # /home/aaron/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/benchmark.rb:178:in `benchmark'
  55.      # /home/aaron/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/benchmark.rb:208:in `bm'
  56.      # ./spec/benchmark_spec.rb:10:in `block in benchmark'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement