How to experiment with rspec from within irb
Asked Answered
A

1

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?

Aubade answered 19/2, 2013 at 23:17 Comment(0)
M
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">
Maurene answered 19/2, 2013 at 23:35 Comment(3)
Great tip! What other .../standalone options are there? Any?Aubade
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!Maurene
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.Aubade

© 2022 - 2024 — McMap. All rights reserved.