0

我正在构建一个基于社交流 gem 的应用程序,它是一个 Rails 引擎。我有一个 Rakefile。我已经在我的 Gemfile 中包含了 factory-girl gem,但由于某种原因,该类的 rake 任务失败了。

gem中有很多测试,我想执行。Rails 应用程序位于:/Users/sean/dropbox/fluent/sstest

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)>'

耙文件

#!/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
4

1 回答 1

2

我认为工厂是为旧版本的 factory-girl 创建的,因为班级名称在某些时候发生了更改。尝试在 Gemfile 中指定版本 1.3.3。

如果要使用最新版本,则需要更新语法。首先替换FactoryFactoryGirl. 查看文档以获取更多信息https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md

于 2013-02-28T21:10:10.867 回答