【发布时间】:2012-12-15 13:46:06
【问题描述】:
我在黄瓜框架中使用 rspec 期望,在步骤定义级别使用时它们看起来很好。
我已经配置了我的 env.rb 文件:
require 'rspec/expectations'
World(RSpec::Matchers)
我现在注意到的问题是,如果我尝试在某个步骤中使用的对象的方法中使用 rspec,那么我会失败。
E.g.
Steps_definition.rb
service.use_rspec
class Service
def use_rspec
header = page.find("div#services h2").text
header.should (be 'TV')
end
end
Error after execution:
undefined method `be' for #<Service:0x2592570> (NoMethodError)
知道问题出在哪里吗?
我已经尝试在该类中使用 Capybara.page.find(...).should have_content('...') 进行类似的断言,并且也无法识别 'have_content',所以不确定发生了什么:S
非常感谢任何提示!
【问题讨论】:
-
也许你需要 World(RSpec::Expectations) ?
标签: rspec cucumber capybara rspec-expectations