Rails 3, RSpec, Factory Girl results in NameError: uninitialized constant

Heinz Strunk
Sun, 16 Jan 2011 11:57:53 -0000

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?