views:

57

answers:

2

Hi all,

when I run rspec spec/models result is OK.

But when I use spork, every test where shoulda macros (like it { should validate_presence_of(:title) } is used FAILS with error like: undefined method 'validate_presence_of' for ...

I use:

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

spec/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'
...
A: 

Try moving the

require "shoulda"

line into the Spork.each_run block. Apparently, shoulda does some magic to include the matchers into the appropriate example groups.

Jacob
Thank's for help, but it is not working ;-(
boblin
A: 

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)

artemave
It works! :) Thank you, artemave.
boblin