我正在使用watir-cucumber进行自动化测试。我在一个单独的.rb中写了下面的方法,这个方法不在步骤定义中。
def has_logged_in?
$browser.text.should include("t788")
end当我从步骤定义调用这个方法时,这个错误出现了,
wrong argument type String (expected Module) (TypeError)相同的代码在步骤定义中工作得很好。我到处搜索,发现include方法是用来包含模块的,但那就是ruby-include方法,而should include属于rspec\expectations。那么,如何在上述步骤定义之外调用should include方法呢?我在linux上使用watir-cucumber
发布于 2012-10-23 21:23:28
您需要的include方法在RSpec::Matchers模块中。
如果你的has_logged_in?方法在一个类中(不是main的一部分),你可以在你的类中包含RSpec::Matcher模块。这将使您能够访问include方法。
因此,您的类将如下所示:
class YourClass
include RSpec::Matchers
def has_logged_in?
$browser.text.should include("t788")
end
end注意:我以前没有这样做过,但是快速检查一下,只要RSpec::Matcher包含在一个类中,而不是main中,它就可以工作。在main中包含它似乎不会做任何事情(即include继续调用标准的include module方法)。我并没有探究这样做是否有任何负面的副作用。
发布于 2012-10-23 05:42:11
在gem文件中:
gem 'rspec', "1.3.2", :require => "spec/expectations"或者在RSpec 1.X.X的env.rb中:
require 'spec/expectations'或者在RSpec 2.x的env.rb中:
require 'rspec/expectations'https://stackoverflow.com/questions/13012412
复制相似问题