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

时间:2015-04-02 17:29:25

标签: ruby-on-rails rspec

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

    require 'rspec'
    require_relative '../app/item'
    require_relative '../app/virtual_item'
    require_relative '../app/antique_item'
    require_relative '../app/item_container'
    require_relative '../app/cart'

    describe Cart do

      it 'add items into the cart' do
        cart = Cart.new('')
        item1 = Item.new('kettle', price: 200)
        item2 = Item.new('car', price: 200)
        cart.add_items(item1, item2)
        cart.items.should include(item1, item2)
      end

    end

在控制台中,我会收到警告

E:\work\storeapp\spec>rspec spec/cart_spec.rb
c:/tools/rubies/ruby-2.1.5-p273/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.2/lib/rspec/core/configuration.rb:1226:in `load': cannot load such file -- E:/work/storeapp/spec/spec/cart_s
pec.rb (LoadError)
        from c:/tools/rubies/ruby-2.1.5-p273/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.2/lib/rspec/core/configuration.rb:1226:in `block in load_spec_files'
        from c:/tools/rubies/ruby-2.1.5-p273/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.2/lib/rspec/core/configuration.rb:1224:in `each'
        from c:/tools/rubies/ruby-2.1.5-p273/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.2/lib/rspec/core/configuration.rb:1224:in `load_spec_files'
        from c:/tools/rubies/ruby-2.1.5-p273/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.2/lib/rspec/core/runner.rb:97:in `setup'
        from c:/tools/rubies/ruby-2.1.5-p273/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.2/lib/rspec/core/runner.rb:85:in `run'
        from c:/tools/rubies/ruby-2.1.5-p273/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.2/lib/rspec/core/runner.rb:70:in `run'
        from c:/tools/rubies/ruby-2.1.5-p273/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.2/lib/rspec/core/runner.rb:38:in `invoke'
        from c:/tools/rubies/ruby-2.1.5-p273/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.2/exe/rspec:4:in `<top (required)>'
        from c:/tools/rubies/ruby-2.1.5-p273/bin/rspec:23:in `load'
        from c:/tools/rubies/ruby-2.1.5-p273/bin/rspec:23:in `<main>'

![在此处输入图片说明] [1]

我的错误在哪里?

1 个答案:

答案 0 :(得分:1)

错误说它无法找到spec文件,实际上你指的是

spec/cart_spec.rb

...在spec目录中。要从中找到它,您需要删除spec/

rspec cart_spec.rb

我通常的做法是从应用根目录运行规范。从那里,你的原始命令应该工作。或者你可以使用绝对路径而不是相对路径。