I'd want to use [1,2,3].should include(1)
in irb. I tried:
~$ irb
1.9.3p362 :001 > require 'rspec/expectations'
=> true
1.9.3p362 :002 > include RSpec::Matchers
=> Object
1.9.3p362 :003 > [1,2,3].should include(1)
TypeError: wrong argument type Fixnum (expected Module)
from (irb):3:in `include'
from (irb):3
from /home/andrey/.rvm/rubies/ruby-1.9.3-p362/bin/irb:16:in `<main>'
But it doesn't work though it's a valid case. How can I use [1,2,3].should include(1)
?
You are close, but calling
include
on top-level you will be callingModule#include
. To get around it you need to remove the original include method so that RSpec'sinclude
gets called instead.First let's figure out where the system
include
comes from:Ok. It looks like it's defined in
main
. This is the Ruby top-level object. So let's rename and remove the original include:Now we can get down to business: