I'm having a little trouble getting spec to run with Factory Girl on my
new Rails 3 app.
/spec/spec_helper.rb:
# 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 'factory_girl'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
Dir[Rails.root.join("spec/factories/*.rb")].each {|f| require f}
I just tried the console and same error occurs:
ruby-1.9.2-p136 :016 > Factory.define :blah do |f| f.name "dasd";
f.email "blsdfkj@fdk.de" end
=> #<Factory:0x82d2ac8 @factory_name=:blah, @options={},
@attributes=[#<Factory::Attribute::Static:0x82ccb00 @name=:name,
@value="dasd">, #<Factory::Attribute::Static:0x82cc7cc @name=:email,
@value="blsdfkj@fdk.de">]>
ruby-1.9.2-p136 :017 > Factory(:blah)
NameError: uninitialized constant Blah
from
/usr/local/rvm/gems/ruby-1.9.2-p136/gems/rspec-core-2.4.0/lib/rspec/core/backward_compatibility.rb:20:in
`const_missing'
from
/usr/local/rvm/gems/ruby-1.9.2-p136/gems/factory_girl-1.3.3/lib/factory_girl/factory.rb:355:in
`const_get'
from
/usr/local/rvm/gems/ruby-1.9.2-p136/gems/factory_girl-1.3.3/lib/factory_girl/factory.rb:355:in
`block in class_for'
from
/usr/local/rvm/gems/ruby-1.9.2-p136/gems/factory_girl-1.3.3/lib/factory_girl/factory.rb:354:in
`each'
from
/usr/local/rvm/gems/ruby-1.9.2-p136/gems/factory_girl-1.3.3/lib/factory_girl/factory.rb:354:in
`inject'
from
/usr/local/rvm/gems/ruby-1.9.2-p136/gems/factory_girl-1.3.3/lib/factory_girl/factory.rb:354:in
`class_for'
from
/usr/local/rvm/gems/ruby-1.9.2-p136/gems/factory_girl-1.3.3/lib/factory_girl/factory.rb:71:in
`build_class'
from
/usr/local/rvm/gems/ruby-1.9.2-p136/gems/factory_girl-1.3.3/lib/factory_girl/factory.rb:321:in
`run'
from
/usr/local/rvm/gems/ruby-1.9.2-p136/gems/factory_girl-1.3.3/lib/factory_girl/factory.rb:273:in
`create'
from
/usr/local/rvm/gems/ruby-1.9.2-p136/gems/factory_girl-1.3.3/lib/factory_girl/factory.rb:304:in
`default_strategy'
from
/usr/local/rvm/gems/ruby-1.9.2-p136/gems/factory_girl-1.3.3/lib/factory_girl.rb:20:in
`Factory'
from (irb):17
from
/usr/local/rvm/gems/ruby-1.9.2-p136/gems/railties-3.0.0/lib/rails/commands/console.rb:44:in
`start'
from
/usr/local/rvm/gems/ruby-1.9.2-p136/gems/railties-3.0.0/lib/rails/commands/console.rb:8:in
`start'
from
/usr/local/rvm/gems/ruby-1.9.2-p136/gems/railties-3.0.0/lib/rails/commands.rb:23:in
`<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'ruby-1.9.2-p136 :018 >