6

For example, I want to say b = double("book") in irb and play with the result.

In irb if I say

require 'rspec'
b = double("book")

I get an error. Ideas?

ThinkingStiff
  • 64,767
  • 30
  • 146
  • 239
pitosalas
  • 10,286
  • 12
  • 72
  • 120

1 Answers1

7

You can play around with RSpec test doubles in irb by requiring "rspec/mocks/standalone":

$ irb
> require 'rspec/mocks/standalone'
> b = double("book")
  =>  #<RSpec::Mocks::Mock:0x3fd88d0157e8 @name="book">
Paul Fioravanti
  • 16,423
  • 7
  • 71
  • 122
  • Great tip! What other .../standalone options are there? Any? – pitosalas Feb 19 '13 at 23:37
  • As far as I know, it's only mocks, but you can stub methods and set message expectations on your mock objects, which is pretty handy. If you find anything interesting out, please update this thread! – Paul Fioravanti Feb 19 '13 at 23:43
  • 1
    The other idea I got which is quite nice is to call irb or pry from inside the test that you are trying fix. That will allow you to have a 100% correct state in which to experiment. – pitosalas Feb 23 '13 at 17:18