0

我的 rspec gem 的 IronRuby 安装似乎缺少自动化的 be_* 方法助手。例如,以下代码会生成未定义的方法错误:

require 'rubygems'
require 'rspec'

x = 7
x.should == 7 # works
x.nonzero?.should == 7 #works
x.should be_nonzero # undefined method `be_nonzero' for main:Object

我使用 igem 来安装 rspec gem。这是我安装的 gem 的列表:

bewildr (0.1.14)
builder (3.0.0)
cucumber (0.6.3)
diff-lcs (1.1.3)
iron-term-ansicolor (0.0.3)
json_pure (1.7.3)
polyglot (0.3.3)
rspec (2.11.0)
rspec-core (2.11.1)
rspec-expectations (2.11.1)
rspec-mocks (2.11.1)
term-ansicolor (1.0.7)
treetop (1.4.10)

知道我在这里缺少什么吗?

4

2 回答 2

2

RSpec 匹配器通常只在一个it块中可用,以避免污染全局命名空间。您是否尝试过在不同的 Ruby 实现上运行您的代码?你会得到同样的错误。

于 2012-07-23T16:52:59.817 回答
0

我有同样的问题,但你的帖子启发了我做一些研究。我在这里找到了解决方案: https ://github.com/cucumber/cucumber/wiki/RSpec-Expectations 总之在我的“features\support\env.rb”中我添加了这个:

require 'rspec/expectations'
World(RSpec::Matchers)
于 2012-08-15T11:45:05.530 回答