Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 升级到rspec 3在使用时导致错误应具有(1)。错误\u on_Ruby On Rails_Rspec_Rspec3 - Fatal编程技术网

Ruby on rails 升级到rspec 3在使用时导致错误应具有(1)。错误\u on

Ruby on rails 升级到rspec 3在使用时导致错误应具有(1)。错误\u on,ruby-on-rails,rspec,rspec3,Ruby On Rails,Rspec,Rspec3,由于我更新了我的GEM文件并移动到rspec 3,在许多测试中,我得到一个错误:way: it "should reject attribute that are too short" do short = "a" * 3 hash = @attr.merge(:details => short) Deal.new(hash).should have(1).error_on(:details) end 我得到了这个错误: Failure/Err

由于我更新了我的GEM文件并移动到rspec 3,在许多测试中,我得到一个错误:way:

it "should reject attribute that are too short" do
      short = "a" * 3
      hash = @attr.merge(:details => short)
      Deal.new(hash).should have(1).error_on(:details)
    end
我得到了这个错误:

Failure/Error: Deal.new(hash).should have(1).error_on(:details)
     NoMethodError:
       undefined method `have' for #<RSpec::ExampleGroups::Deal_2::TestsOnDealsModelsValidations>

已经
和其他类似的匹配器已经从rspec核心转移到另一个gem中

我建议按照rspec文档中详述的rspec 2->3的升级路径进行升级:

  • 升级至rspec 2.99
  • 运行您的测试套件
  • 修复弃用警告
  • 升级到rspec3

如果您这样做了,您的代码将收到一个弃用错误,该错误还将告诉您如何修复它。

我已替换了

Deal.new(hash).should have(1).error_on(:details)


valid?
的第一个期望值是必要的,因为它初始化了
错误列表。

要添加到
GEM文件的行应该是:

gem 'rspec-collection_matchers'

只需添加gem文件:gem“rspec集合匹配器”。
deal = Deal.new(hash)
expect(deal.valid?).to be_falsey
expect(deal.errors[:details].size).to eq(1)
gem 'rspec-collection_matchers'