0

I've changed the name of a column in my database and have changed spec/factories.rb accordingly, however when I run my rspec tests, it's still trying to make use of the old column names. I've restarted the Ruby on Rails server, yet that doesn't fix it.

# Changed :height to :height_feet
# Added :height_inches


FactoryGirl.define do
  factory :user do
    ...
    height 180
  end
end

# Changed to:

FactoryGirl.define do
  factory :user do
    ...
    height_feet 5
    height_inches 11
  end
end

Yet when I run rspec spec/models the following line:

let(:user) { FactoryGirl.create(:user) }

produces the following error:

Failure/Error: let(:user) { FactoryGirl.create(:user) }
NoMethodError:
   undefined method `height' for #<User:0x0000000532fc08>

Any thoughts on how I can fix this?

Nick
  • 9,493
  • 8
  • 43
  • 66

2 Answers2

1

It's your spork server you'll need to restart. I don't use guard so I'm not totally sure how, but have a look at this question, there is some other useful info on refreshing:

Spork: how to refresh validations and other code?

Community
  • 1
  • 1
psugar
  • 1,897
  • 2
  • 18
  • 27
  • As far as I can tell, Guard is supposed to reload Spork automatically. I already have it running and when I start/restart Guard, it seems to start the Spork server. One thing I'm noticing is that it's loading up the prefork block, which tracks my `spec/factories.rb` file. As per the troubleshooting link (https://github.com/sporkrb/spork/wiki/Spork.trap_method-Jujitsu), I've added the line `FactoryGirl.reload` to my `Spork.each_run do` block, but it doesn't seem to be reloading the cache. – Nick Mar 27 '12 at 03:01
  • So you've tried reloading it with 'guard r' (just looked it up), and you still have that error? – psugar Mar 27 '12 at 03:02
  • Yup. Regarding my previous comment, the `FactoryGirl.reload` line I added is actually for FactoryGirl 2, but I'm running FactoryGirl 1.4.0. I've tried applying the appropriate solution (`require 'factory_girl_rails'`) and it still doesn't work. – Nick Mar 27 '12 at 03:14
1

I fixed this problem by upgrading to FactoryGirl 2.0.0 from FactoryGirl 1.4.0. From the troubleshooting link:

https://github.com/sporkrb/spork/wiki/Spork.trap_method-Jujitsu

Factory Girl 2 does not have the auto-loading issues of previous versions, so you do not need to do anything to get Spork to work.

Nick
  • 9,493
  • 8
  • 43
  • 66