当我 运行 测试“ rspec item_container_spec.rb ”时,我会在控制台中收到警告

When I run the test “ rspec item_container_spec.rb ”In the console, I'll get a warning

  it 'add items into the container' do
    item1 = Item.new('kettle', price: 200)
    item2 = Item.new('kettle', price: 300)
    @box.add_item(item1)
    @box.add_item(item2)
    @box.items.should have(2).items
  end

这支球队可能会失误? “@box.items.should 有 (2).items”。 在控制台中,我会收到警告

**E:\work\storeapp\spec>rspec item_container_spec.rb
F

Failures:

  1) ItemContainer add items into the container
     Failure/Error: @box.items.should have(2).items
     NoMethodError:
       undefined method `have' for #<RSpec::ExampleGroups::ItemContainer:0x2419908>
     # ./item_container_spec.rb:27:in `block (2 levels) in <top (required)>'

Finished in 0 seconds (files took 0.23234 seconds to load)
1 example, 1 failure

Failed examples:

rspec ./item_container_spec.rb:22 # ItemContainer add items into the container**

我哪里错了?

我打赌你已经安装了rspec 3.0.

have 匹配器系列在 RSpec 2.99 中被弃用,并已从 RSpec 3.0 移至单独的 rspec-collection_matchers gem。

看看here.