我想[1,2,3].should include(1)在irb中使用.我试过了:
~$ irb
1.9.3p362 :001 > require 'rspec/expectations'
=> true
1.9.3p362 :002 > include RSpec::Matchers
=> Object
1.9.3p362 :003 > [1,2,3].should include(1)
TypeError: wrong argument type Fixnum (expected Module)
from (irb):3:in `include'
from (irb):3
from /home/andrey/.rvm/rubies/ruby-1.9.3-p362/bin/irb:16:in `<main>'
Run Code Online (Sandbox Code Playgroud)
但它不起作用虽然它是一个有效的案例.我该怎么用[1,2,3].should include(1)?
我正在构建一个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...?