Heinz Strunk
2011-Jan-16 11:57 UTC
Rails 3, RSpec, Factory Girl results in NameError: uninitialized constant
Hi people,
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}
RSpec.configure do |config|
# == Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the
appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
config.mock_with :rspec
# Remove this line if you''re not using ActiveRecord or ActiveRecord
fixtures
# config.fixture_path = "#{::Rails.root}/spec/fixtures"
# If you''re not using ActiveRecord, or you''d prefer not to
run each of
your
# examples within a transaction, remove the following line or assign
false
# instead of true.
config.use_transactional_fixtures = true
end
/spec/factories/videos.rb:
Factory.define :video_one do |f|
f.title "MyString"
f.teaser "MyText"
f.link "MyString"
end
and /spec/controllers/video_controller_spec.rb:
require File.dirname(__FILE__) + ''/../spec_helper''
describe VideosController do
render_views
it "destroy action should destroy model and redirect to index
action"
do
video = Factory(:video_one)
delete :destroy, :id => video
response.should redirect_to(videos_url)
Video.exists?(video.id).should be_false
end
end
results in:
VideosController destroy action should destroy model and redirect to
index action
Failure/Error: video = Factory(:video_one)
NameError:
uninitialized constant VideoOne
# ./spec/controllers/videos_controller_spec.rb:51:in `block (2
levels) in <top (required)>''
I''ve been googling etc. but not successful yet. Anyone know
what''s wrong
there?
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Heinz Strunk
2011-Jan-16 13:45 UTC
Re: Rails 3, RSpec, Factory Girl results in NameError: uninitialized constant
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-m9b4e1/XOJA@public.gmane.org" end
=> #<Factory:0x82d2ac8 @factory_name=:blah, @options={},
@attributes=[#<Factory::Attribute::Static:0x82ccb00 @name=:name,
@value="dasd">, #<Factory::Attribute::Static:0x82cc7cc
@name=:email,
@value="blsdfkj-m9b4e1/XOJA@public.gmane.org">]>
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 >
...what''s wrong with this girl?
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Arailsdemo A.
2011-Jan-16 14:56 UTC
Re: Rails 3, RSpec, Factory Girl results in NameError: uninitialized constant
Did you create your VideoOne model yet? FactoryGirl requires that this be present. Here''s some general background on FactoryGirl http://www.arailsdemo.com/posts/39. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Heinz Strunk
2011-Jan-16 15:26 UTC
Re: Rails 3, RSpec, Factory Girl results in NameError: uninitialized constant
Yeah, just figured that out. Didn''t know FactoryGirl was so strict about it. That one worked: Factory.define :video do |f| f.title "MyString" f.teaser "MyText" f.link "MyString" end Thanks! -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.