我正在构建一个Web应用程序自动化框架,旨在允许:
我正在使用Capybara与浏览器进行通信,我有一个包含许多辅助函数的组件库(login_to_the_back_office,create_customer等).
现在我希望我的组件可以单独使用,也可以在RSpec测试中使用.这意味着我的组件(包含在库中)describe... it...默认情况下不会被块包围,但是当测试使用它们时它们会在某个时刻出现,因此它们应该尽可能多地使用expect和朋友.
我跟着rspec的.should在Ruby 2中失败了(在describe/it block之外)?启用should和它的工作(实际上只是要求rspec-expectations在我的情况下足够),但我无法弄清楚如何使期望工作.
我认为expect在这里定义了https://github.com/rspec/rspec-expectations/blob/master/lib/rspec/expectations/syntax.rb但我对Ruby的元魔法的了解太过限制,无法弄清楚如何让人期待我班上有空.
我已经尝试过RSpec::Expectations::Syntax在课堂上学习,但undefined method 'expect'每当我尝试使用它时我仍然会得到它.
我怎么能expect在外面使用describe... it...?
包括 ::RSpec::Matchers
class A
include ::RSpec::Matchers
def test
expect('1'.to_i).to eq 1
end
def failed_test
expect('1'.to_i).to eq 2
end
end
A.new.test
# => true
A.new.failed_test
# RSpec::Expectations::ExpectationNotMetError:
# expected: 2
# got: 1
Run Code Online (Sandbox Code Playgroud)