我想在irb中使用[1,2,3].should include(1)。我试过了:
~$ 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>'如何使用[1,2,3].should include(1)
发布于 2013-02-07 21:43:55
您已经接近了,但是在顶层调用include时,您将调用Module#include。要解决这个问题,您需要删除原始的include方法,以便调用RSpec的include。
首先让我们弄清楚系统include是从哪里来的:
> method :include
=> #<Method: main.include>好的。它看起来像是在main中定义的。这是Ruby顶级对象。因此,让我们重命名并删除原始的include:
> class << self; alias_method :inc, :include; remove_method :include; end现在我们可以开始工作了:
> require 'rspec'
> inc RSpec::Matchers
> [1,2,3].should include(1)
=> truehttps://stackoverflow.com/questions/14749047
复制相似问题