Topic: Issue with factories data using shoulda

Hi i was getting error when running test file
I have data like this :

factories.rb:
Factory.define :Procedure do |p|
  p.sequence(:name) {|n| "foo#{n}"}
  p.procedure_group_id "1"
  end

procedure_test.rb:
require 'test/test_helper'
class ProcedureTest < ActiveSupport::TestCase
end

Gemfile:
group :test do
  gem 'shoulda'
  gem "factory_girl_rails", "~> 1.0.1"
end

test_helper.rb:
require 'test/factories'
class ActiveSupport::TestCase
end

But when executed test file it was showing error like :

/usr/lib/ruby/gems/1.8/gems/factory_girl-1.3.3/lib/factory_girl/factory.rb:61:in `define': Factory already defined: Procedure (Factory::DuplicateDefinitionError)
    from ./test/factories.rb:2
    from /usr/lib/ruby/gems/1.8/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:239:in `require'
    from /usr/lib/ruby/gems/1.8/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:239:in `require'
    from /usr/lib/ruby/gems/1.8/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:227:in `load_dependency'
    from /usr/lib/ruby/gems/1.8/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:239:in `require'
    from ./test/test_helper.rb:4
    from test/unit/procedure_test.rb:7:in `require'
    from test/unit/procedure_test.rb:7

Can any one tell me why this was coming ?

thanks in advance

Last edited by srinathbtech (2011-06-15 10:13:54)

Re: Issue with factories data using shoulda

I'm not sure if this will work the same with Test::Unit, but with RSpec, the factories are automatically loaded if they're in a file called 'factories.rb' in the spec directory.  So, you might not need to require it in test_helper.rb.

Last edited by bdondo (2011-06-15 12:50:44)