On May 1, 2009, at 7:04 AM, David Chelimsky wrote:

On Sun, Mar 29, 2009 at 6:14 PM, Andrew Vit <and...@avit.ca> wrote:
It appears this is a bug, with an apparently simple fix in
spec_server.rb (rails 2.3 compatibility):

https://rspec.lighthouseapp.com/projects/5645/tickets/759

However, now that it's reloading my app, it's not reloading the setup
from my fixture/factory gems and throwing up a bunch of errors on re-
run. (I've tried it with both factory_girl and machinist now.) These
are required in my spec_helper.rb:

config.gem 'notahat-machinist', :lib => 'machinist', :source =>
'http://gems.github.com'
require File.dirname(__FILE__) + '/blueprints'

or:

config.gem 'thoughtbot-factory_girl', :lib => 'factory_girl', :source
=> 'http://gems.github.com'
# automatically loaded from spec/factories/*.rb

In spec_helper?


Hi David,

Sorry, that wasn't clear the way I wrote it. The config.gem directive was actually in the rails/environments/test.rb file. Then I required the blueprints.rb file in spec_helper (or in factory_girl's case it automatically loads the factory files from spec/factories). These steps showed that rails model reloading wasn't working in 1.2.2 with rails 2.3.2:

$ gem list rails
rails (2.3.2)
$ gem list rspec
rspec (1.2.2)
rspec-rails (1.2.2)
$ rails test_spec_server && cd test_spec_server
$ script/plugin install git://github.com/dchelimsky/rspec-rails.git
$ script/generate rspec
$ script/generate rspec_model car name:string
# edit config/environments/test.rb => config.cache_classes = false
# edit spec/spec.opts => --drb
$ rake spec:server:start
$ script/autospec
# 1 example, 0 failures
# edit app/models/car.rb => add invalid syntax!
# 1 example, 0 failures


I had given up on spec_server for the time being. The ticket is resolved now, and I just gave these steps another try with a new app using updated versions. Reloading the app classes for each run works fine out of the box now: I can get it to return a success or failure when I change the model on the fly.


However, the problem comes when adding Factory Girl:

# config/environments/test.rb
# add:
  config.gem "thoughtbot-factory_girl", :lib => 'factory_girl'

# spec/factories/car.rb
  Factory.define :car do |f|
    f.name "Jetta"
  end

# spec/models/car_spec.rb
  it "should create a new instance given valid attributes" do
    car = Factory :car
    car.name.should == 'Jetta'
  end


It runs fine the first time against drb, but on all subsequent runs I get the following error until I restart spec_server. None of the lines in the stacktrace say "rspec" but I was also getting the same error with Machinist too, so it's not unique to Factory Girl, and I'm guessing something to do with the reloading.


TypeError in 'Car should create a new instance given valid attributes'
can't dup NilClass
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.2/lib/active_record/ base.rb:2189:in `dup' /Library/Ruby/Gems/1.8/gems/activerecord-2.3.2/lib/active_record/ base.rb:2189:in `scoped_methods' /Library/Ruby/Gems/1.8/gems/activerecord-2.3.2/lib/active_record/ base.rb:2193:in `current_scoped_methods' /Library/Ruby/Gems/1.8/gems/activerecord-2.3.2/lib/active_record/ base.rb:2176:in `scoped?' /Library/Ruby/Gems/1.8/gems/activerecord-2.3.2/lib/active_record/ base.rb:2440:in `send' /Library/Ruby/Gems/1.8/gems/activerecord-2.3.2/lib/active_record/ base.rb:2440:in `initialize' /Library/Ruby/Gems/1.8/gems/thoughtbot-factory_girl-1.2.1/lib/ factory_girl/proxy/build.rb:5:in `new' /Library/Ruby/Gems/1.8/gems/thoughtbot-factory_girl-1.2.1/lib/ factory_girl/proxy/build.rb:5:in `initialize' /Library/Ruby/Gems/1.8/gems/thoughtbot-factory_girl-1.2.1/lib/ factory_girl/factory.rb:284:in `new' /Library/Ruby/Gems/1.8/gems/thoughtbot-factory_girl-1.2.1/lib/ factory_girl/factory.rb:284:in `run' /Library/Ruby/Gems/1.8/gems/thoughtbot-factory_girl-1.2.1/lib/ factory_girl/factory.rb:237:in `create' /Library/Ruby/Gems/1.8/gems/thoughtbot-factory_girl-1.2.1/lib/ factory_girl/factory.rb:268:in `send' /Library/Ruby/Gems/1.8/gems/thoughtbot-factory_girl-1.2.1/lib/ factory_girl/factory.rb:268:in `default_strategy' /Library/Ruby/Gems/1.8/gems/thoughtbot-factory_girl-1.2.1/lib/ factory_girl.rb:20:in `Factory'
./spec/models/car_spec.rb:11:
/Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
/Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.2/lib/active_support/ dependencies.rb:156:in `require' /Library/Ruby/Gems/1.8/gems/activesupport-2.3.2/lib/active_support/ dependencies.rb:521:in `new_constants_in' /Library/Ruby/Gems/1.8/gems/activesupport-2.3.2/lib/active_support/ dependencies.rb:156:in `require'

Andrew Vit

_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to