我想我的黄瓜匹配器移动到一个模块我可以在模块定义函数中使用Rspec Expect吗?
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。我试过使用
include ::RSpec::Matchers
按照Use RSpec's "expect" etc. outside a describe ... it block但没有成功。
我得到的错误是
undefined method `expect' for AccessFunc:Module (NoMethodError)
有人能提供一些线索我怎么会这样(例如,使用一个模块内期望解决办法
P/S:我可以解决通过去除问题模块,并定义功能posted_http_response_check全球。
这是一个测试吗?如果不是,你为什么需要一个模块的期望。 – AshwinKumarS 2015-03-25 07:03:11
是的,这是测试的一部分。我将这个期望转化为一个模块,这是因为我打算使用它是各种不同的测试场景,因此不希望在Cucumber Matcher上重复使用它。 – Elye 2015-03-25 10:05:38