我可以在模块定义的函数中使用Rspec Expect吗?

时间:2015-03-25 05:15:42

标签: ruby rspec cucumber

我试图将我的Cucumber Matcher移动到模块的功能

Then (/^posted "(.*?)" http response should be returned$/) do |arg1|
  expect($post_result.lines.last.to_i).to eq(arg1.to_i)
end

模块功能如下

module AccessFunc
    #  :
    #  : Some require... global variable setting etc
    #  :
  def self.posted_http_response_check(arg1)
    expect($post_result.lines.last.to_i).to eq(arg1.to_i)
  end
end

用黄瓜匹配器进行黄瓜测试可以使用Expect。但我无法在我的模块中使用Expect。我尝试使用

include ::RSpec::Matchers

根据Use RSpec's "expect" etc. outside a describe ... it block但未成功。

我得到的错误是

undefined method `expect' for AccessFunc:Module (NoMethodError)

有人可以解释一下如何解决这个问题(例如在模块中使用Expect。

p / s:我可以通过删除模块来解决问题,并在全局范围内定义函数 published_http_response_check

1 个答案:

答案 0 :(得分:0)

您可能需要混合使用AccessFunc模块,方案步骤才能识别这一点 尝试将World AccessFunc添加到您的env.rb并查看它是如何运行的。不能确定这是否有效,绝对值得一试。