16

当我运行rspec spec/models结果是好的。

但是当我使用spork时,应该使用宏的每个测试(就像it { should validate_presence_of(:title) }使用 FAILS 一样,错误如下:undefined method 'validate_presence_of' for ...

我用:

rails (3.0.0)
shoulda (2.11.3)
spork (0.8.4)
rspec-rails (>= 2.0.0.beta.22)

规范/spec_helper.rb:

需要“红宝石”
需要'spork'

Spork.prefork 做
  # 当你运行 'rails generate rspec:install' 时,这个文件被复制到 spec/
  ENV["RAILS_ENV"] ||= '测试'
  需要 File.expand_path("../../config/environment", __FILE__)
  需要'rspec/rails'
  要求“应该”
...
4

2 回答 2

16

I had the same issue. Fixed it by sticking require 'shoulda/integrations/rspec2' after requiring rspec/rails in prefork block.

You might also want to upgrade your spork to the latest version (gem 'spork', >= 0.9.0.rc2), since I didn't try this fix on 0.8.4 (although I am pretty sure it'll work too)

于 2010-10-19T09:42:08.873 回答
2

尝试移动

require "shoulda"

线入Spork.each_run块。显然,应该做一些魔术来将匹配器包含到适当的示例组中。

于 2010-10-10T21:18:26.267 回答