Rspec,shoulda和spork不能一起工作

bob*_*lin 16 rspec ruby-on-rails shoulda spork

当我运行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)
Run Code Online (Sandbox Code Playgroud)

投机/ spec_helper.rb:

require 'rubygems'
require 'spork'

Spork.prefork do
  # This file is copied to spec/ when you run 'rails generate rspec:install'
  ENV["RAILS_ENV"] ||= 'test'
  require File.expand_path("../../config/environment", __FILE__)
  require 'rspec/rails'
  require 'shoulda'
...

art*_*ave 16

我遇到过同样的问题.通过在prefork块中require 'shoulda/integrations/rspec2'要求后粘贴来修复它rspec/rails.

您可能还想将spork升级到最新版本(gem 'spork', >= 0.9.0.rc2),因为我没有在0.8.4上尝试此修复程序(虽然我很确定它也会起作用)

  • 对于当前的shoulda-matcher,请尝试`require' Shoulda/matchers/integrations/rspec'` (22认同)
  • 对我来说这很有效:需要'shoulda/matchers/integrations/rspec' (4认同)