Question

I'm building an application based on the social-stream gem, which is a Rails engine. I have a Rakefile. I've included the factory-girl gem in my Gemfile, but for some reason the rake tasks are failing on that class.

There are a lot of tests in the gem, which I'd like to execute. The Rails application lives at: /Users/sean/dropbox/fluent/sstest

The failing code from the gem:

# Helpers for building the post activity
#
class ActivityObjectSpecHelper < ActiveRecord::Base
  set_table_name "activity_objects"
end

class PostSpecHelper < ActiveRecord::Base
  set_table_name "posts"

  belongs_to :activity_object_spec_helper, :foreign_key => "activity_object_id"
end

Factory.define :activity_object_spec_helper do |a|
  a.object_type "Post"
  a.description "Post spec helper"
end

Factory.define :post_spec_helper do |p|
  p.association :activity_object_spec_helper
end




/Users/sean/.rvm/gems/ruby-1.9.3-p327/gems/social_stream-base- 1.1.4/spec/factories/activity.rb:13:in `<top (required)>': uninitialized constant Factory   (NameError)
from /Users/sean/Dropbox/fluent/sstest/spec/spec_helper.rb:22:in `block in <top  (required)>'

Rakefile

#!/usr/bin/env rake

require 'rspec/core'
require 'rspec/core/rake_task'
require 'resque/tasks'

require File.expand_path('../config/application', __FILE__)

Resque.after_fork = Proc.new { ActiveRecord::Base.establish_connection } if Resque.present?

# Include social_stream-base spec
def bsp(str)
  base_spec_path = File.join(Gem::Specification.find_by_name('social_stream- base').full_gem_path, 'spec/')
  File.join(base_spec_path, str)
end
RSpec::Core::RakeTask.new(:spec) do |s|
  s.pattern = ['./spec/**/*_spec.rb',
            bsp('./controllers/users_controller_spec.rb'),
            bsp('./controllers/notifications_controller_spec.rb'),
            bsp('./controllers/likes_controller_spec.rb'),
            bsp('./controllers/profiles_controller_spec.rb'),
            bsp('./controllers/comments_controller_spec.rb'),
            bsp('./controllers/frontpage_controller_spec.rb'),
            bsp('./controllers/posts_controller_spec.rb'),
            bsp('./controllers/representations_spec.rb'),
            bsp('./controllers/groups_controller_spec.rb'),
            bsp('./controllers/settings_controller_spec.rb'),
            bsp('./models/profile_spec.rb'),
            bsp('./models/user_spec.rb'),
            bsp('./models/tie_spec.rb'),
            bsp('./models/activity_spec.rb'),
            bsp('./models/actor_spec.rb'),
            bsp('./models/group_spec.rb'),
            bsp('./models/like_spec.rb'),
            bsp('./models/post_spec.rb')
      ]
end

task :default => [ :spec, 'assets:precompile' ]

Sstest::Application.load_tasks
Was it helpful?

Solution

I reckon the factories were created for an older version of factory-girl as the class name was changed at some point. Try specifying version 1.3.3 in your Gemfile.

If you want to use the latest version you need to update the syntax. Start by replacing Factory with FactoryGirl. Check the docs for more info https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top