Đây là cấu hình Gemfile tôi:Không thể có được factory_girl chạy dưới đường ray 3.0.5, bất ngờ tCONSTANT
group :development, :test do
gem 'rspec-rails'
gem 'factory_girl', '~>2.0.0.beta1'
gem 'factory_girl_rails', :git => 'https://github.com/thoughtbot/factory_girl_rails.git', :tag => 'v1.1.beta1'
end
Đây là tôi 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}
tôi đã thêm vào thư mục factories
đến LOAD_PATH, bởi vì Tôi muốn giữ chúng trong một thư mục riêng biệt.
Đây là factories.rb
tập tin của tôi:
đòi hỏi File.expand_path (File.dirname (FILE) + '../../spec_helper')
Factory.define(:user) do |f|
f.country("China")
... other attributes here
end
Khi tôi chạy thử nghiệm , sử dụng rake spec:models
, tôi có được điều này:
spec/factories/factories.rb:1: syntax error, unexpected tCONSTANT, expecting $end
tôi thấy rằng đây có nguồn gốc từ factory_girl
's 01.234.349 Phương thức. Tôi đã cố tự gọi nó, từ spec_helper, nhưng nó không thay đổi gì cả. Đây là một phần của dấu vết ngăn xếp:
** Invoke spec:models (first_time)
** Invoke db:test:prepare (first_time)
** Invoke db:abort_if_pending_migrations (first_time)
** Invoke environment (first_time)
** Execute environment
rake aborted!
C:/rails/rcproj/spec/factories/factories.rb:1: syntax error, unexpected tCONSTANT, expecting
$end
f.count...er) do |f|
^
C:/Ruby187/lib/ruby/gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:239:in `req
uire'
C:/Ruby187/lib/ruby/gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:239:in `req
uire'
C:/Ruby187/lib/ruby/gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:225:in `loa
d_dependency'
C:/Ruby187/lib/ruby/gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:596:in `new
_constants_in'
C:/Ruby187/lib/ruby/gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:225:in `loa
d_dependency'
C:/Ruby187/lib/ruby/gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:239:in `req
uire'
C:/Ruby187/lib/ruby/gems/1.8/gems/factory_girl-2.0.0.beta2/lib/factory_girl/find_definitions.rb:20:i
n `find_definitions'
C:/Ruby187/lib/ruby/gems/1.8/gems/factory_girl-2.0.0.beta2/lib/factory_girl/find_definitions.rb:19:i
n `each'
C:/Ruby187/lib/ruby/gems/1.8/gems/factory_girl-2.0.0.beta2/lib/factory_girl/find_definitions.rb:19:i
Nhận xét dòng đầu tiên (yêu cầu 'spec_helper') và dùng thử. – Ashish
Có một số tiến bộ, thử nghiệm bắt đầu chạy, nhưng tại dòng nói rằng: 'u = Nhà máy (: người dùng) .tạo' nó ném một ArgumentError,' Chưa đăng ký: user', ngoại lệ. – Geo
u = Dòng nhà máy (: người dùng) chỉ tạo người dùng cho bạn – Ashish