0

I'd like to do something like the following:

require 'rspec-expectations'
"bat".length.should eq(3)
# => NoMethodError: undefined method `eq' for main:Object

Is something like this possible? How would I need to change it? Would I need to require 'rspec-expectations'?

sawa
  • 165,429
  • 45
  • 277
  • 381
timpone
  • 19,235
  • 36
  • 121
  • 211

2 Answers2

2

Try interactive_rspec:

gem install interactive_rspec

then

irspec
001> "bat".length.should eq(3)
.

Finished in 0.00006 seconds
1 example, 0 failures
=> true
Patrick Oscity
  • 53,604
  • 17
  • 144
  • 168
1

In irb:

require 'rspec-expectations'
include RSpec::Matchers

"bat".length.should eq(3)
Shawn Balestracci
  • 7,380
  • 1
  • 34
  • 52
  • thx, this looks great. When it's not met, it's a little ugly but gets job done. – timpone Apr 28 '13 at 16:18
  • 1
    as a heads-up, you might run into issues with the above technique such as: http://stackoverflow.com/questions/14749047/how-to-use-rspec-expectations-in-irb?rq=1 – timpone Apr 28 '13 at 16:35