我正在构建一个基于社交流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)>'
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
我认为工厂是为旧版本的factory-girl创建的,因为类名在某些时候发生了变化。尝试在Gemfile中指定1.3.3版本。
如果你想使用最新的版本,你需要更新语法。首先用FactoryGirl
代替Factory
。查看文档获取更多信息https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md