我使用的是Rails 3.2,我的set文件设置如下:
# Testing Gems
gem "factory_girl_rails", :group => :test
group :development, :test do
gem "capybara"
gem "rspec-rails"
gem "guard-rspec"
gem "ruby_gntp", :require => false
gem "addressable"
gem "launchy"
end然而,工厂女孩坚持将测试记录保存到我的开发数据库而不是测试数据库。注意:我正在使用通过shell运行测试。
下面是我的database.yml中的内容:
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000我知道我的问题和这个问题很相似:工厂女孩在我的开发数据库中保存记录,但是我做了他做的每一件事,但它仍然对我不起作用。
我还运行了bundle update、bundle install、bundle install --without test,然后又运行了bundle install。我最初认为这是一个Gemfile.lock问题,但我所做的一切更新都没有效果。
有人有什么想法吗?
更新
我所有的工厂都在使用development.sqlite3数据库,但是这里有一个例子:
FactoryGirl.define do
factory :saddle, :class => Saddle do
name "Carlton"
saddle_category_id 2
description "This is a saddle description"
details "Saddle details will go here!"
best_uses "List of best uses should go here."
price 3025.00
end
end保存到我的数据库的测试代码仅仅是saddle = Factory(:saddle)。
发布于 2012-01-27 19:11:08
你也有同样的问题。看看你的个人档案:
group :development, :test do它也在为:test加载所有这些宝石。把那部分去掉,你就可以走了。
发布于 2012-01-27 19:10:30
您是否尝试过在命令行中定义RAILS_ENV:
rake test RAILS_ENV=test发布于 2014-06-25 12:29:31
正如我所见,你已经得到了答案,这里。问题是使用==而不是=。
我只是面对类似的问题(Rspec 3)。如您所知,其中包含文件spec/rails_helper.rb和字符串ENV["RAILS_ENV"] ||= 'test'。首先,我认为它已经设置了错误的值,并试图用ENV["RAILS_ENV"] = 'test'替换它,但它并没有帮助我。
然后,我将该字符串移动到spec/spec_helper.rb,它正常工作。我还不能解释这种行为,但它起作用了。
https://stackoverflow.com/questions/9038682
复制相似问题