take056553 (10) [Avatar] Offline
#1
In Rails.root/factories/project_factory.rb

Factory.define :project do |project|
project.name 'Ticketee'
end

AND

Rails.root/features/step_definitions/project_steps.rb

Given /^there is a project called "([^"]*)"$/ do |name|
Factory(:project, :name => name)
end

These syntax are DEPRECIATED. PLEASE CHECK:

http://robots.thoughtbot.com/post/19412394597/factory-girl-hits-3-0

I only know the first one should change to

FactoryGirl.create(:project, :name => name)

Anyone knows how to change the second one to fit in 3.0?

Also a small question: what is diff between factory_girl and factory_girl_rails gem.

Thanks!
take056553 (10) [Avatar] Offline
#2
Re: 4.1.2 Factory_girl Syntax Depreciated
factory_girl_rails gem provides Rails integration for factory_girl.
So why not use factory_girl_rails gem (page 85) instead factory_girl gem.

Confused ... o_O
xkcd (2) [Avatar] Offline
#3
Re: 4.1.2 Factory_girl Syntax Depreciated
Also would be glad to see the answer to this problem. Otherwise everything is going very well with this great book.
xkcd (2) [Avatar] Offline
#4
Re: 4.1.2 Factory_girl Syntax Depreciated
Hi I got it working fine now.

I followed robmi advice in
http://www.manning-sandbox.com/thread.jspa?threadID=48173&tstart=0

And set just the factory girl gem to the correct version at the time the book was written. I did the next two steps in the book as well and all 4 tests pass.

So in short I did this.

vi Gemfile

insert
gem 'factory_girl', '1.3.3'
into your test do group.

Run Bundle install and it will revert to the version that works with the book. Then change your code back to what is in the book.

I think it's probably possible to get it working with the new factory girl but you'd have to read the cucumber book and the factory girl source because the man page on github is not designed for those of us starting out with Rails.

Hope that works for you.

I will change it when I get through this whole tutorial but by then I'll hopefully know what I am doing.
take056553 (10) [Avatar] Offline
#5
Re: 4.1.2 Factory_girl Syntax Depreciated
Thanks xkcd!!! Your name reminds me of python comic... smilie Fly......

Thank you for inform the gem version at the time of book written. I didn't revert to the old gem if I have to. Because we've to keep it somehow up-to-date. But being up-to-date is fairly difficult. In Rails there are so many conventions over configurations. Like this gem, factory_girl. I am the first time here, how am I supposed to know the vintage syntax they introduced maybe from version 1.0 or 2.0 o_O...

Thank you for pointing out.
tllucero (4) [Avatar] Offline
#6
Re: 4.1.2 Factory_girl Syntax Depreciated
I got it to work with the new syntax:
Gemfile
group :test do
# gem 'cucumber-rails' # does not make web-steps file
# Aslak Hellesoy wrote this under duress - lets Rails 3 in Action work
gem 'cucumber-rails-training-wheels'
gem 'capybara'
gem 'database_cleaner'
gem 'factory_girl_rails'
end

factories/project_factory.rb
FactoryGirl.define do
factory :project do
name 'Ticketee'
end
end

rm features/support/factories.rb

And all green.
ryanbigg (423) [Avatar] Offline
#7
Re: 4.1.2 Factory_girl Syntax Depreciated
Yup, that new syntax will indeed work. We'll be using that in the next version of Rails 3 in Action as well.
EvanMisshula (1) [Avatar] Offline
#8
Re: 4.1.2 Factory_girl Syntax Depreciated
FYI,

I could not get the prior listed syntax to work. When I made the modifications I got an undefined function error from features/project_steps.rb. Even after changing Factory -> FactoryGirl the undefined function error persisted both when I ran bin/cucumber features/viewing_projects.rb and in the rails console. I was able to make the code on page 86 by following the instructions (http://www.manning-sandbox.com/thread.jspa?threadID=51512&tstart=0) by specifying the version of 'factory_girl','1.3.3'. I also had to add 'cucumber-rails' to the test group. Without cucumber-rails I received a:

no such file to load -- cucumber/rails/active_record (LoadError)

The answer appeared to be to reinstall cucumber: (http://railsforum.com/viewtopic.php?id=43492)

rails g cucumber:install

I allowed it to overwrite the path.rb and then the code worked. I would prefer to use as much of the new syntax as possible so I consider this less desirable the suggestion above. Howeve, I think there may still be a few missing steps. Many thanks to authors and other contributors to this forum.