【问题标题】:rspec w/IronRuby missing be_* methodsrspec w/IronRuby 缺少 be_* 方法
【发布时间】:2012-07-23 15:14:24
【问题描述】:

我安装的 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)

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

【问题讨论】:

    标签: ruby rspec ironruby


    【解决方案1】:

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

    【讨论】:

    • 嗯。你是对的 - 将代码放入 describe...if... 块可以解决这个问题。但如果是这样的话,当我希望它们在 it 块之外时如何引入这些匹配器 - 就像在黄瓜里面时 /^ etc $/ do 块?还是我认为这个功能来自 rspec 是错误的?
    【解决方案2】:

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

    require 'rspec/expectations'
    World(RSpec::Matchers)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-18
      • 1970-01-01
      • 1970-01-01
      • 2021-11-04
      • 1970-01-01
      相关资源
      最近更新 更多