相关疑难解决方法(0)

使用rake从db/seeds.rb自动加载种子数据

我正在使用rails-rspecgem,我有几个规格(模型,控制器等).当我跑:

bundle exec rake
Run Code Online (Sandbox Code Playgroud)

一切都经过测试 但是,我想通过在创建数据库之后(在测试环境中)播种一些数据(来自db/seeds.rb)来改进我的规范.

我的spec/spec_helper.rb文件如下所示:

ENV["RAILS_ENV"] ||= 'test'

require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'capybara/rspec'
require 'ruby-debug'

# 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}

RSpec.configure do |config|
  config.mock_with :rspec

  # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
  config.fixture_path = "#{::Rails.root}/spec/fixtures"

  # If you're not using ActiveRecord, or you'd prefer not to run each of your
  # examples within …
Run Code Online (Sandbox Code Playgroud)

testing rake rspec ruby-on-rails-3

20
推荐指数
5
解决办法
2万
查看次数

如何使用rake db:seed将种子数据添加到测试数据库?

我正在使用Factory Girl填充种子数据并将其添加到seed.rb中的数据库中.

我正在使用Cucumber运行我的测试.

我有一个价格表,其中包含我想要在所有环境中使用的种子数据.

我想rake db:seed将它添加到我的dev 测试db和黄瓜能够使用该测试种子.然后我也会在prod中添加种子数据.

如何确保将种子数据添加到dev和test db?

rake db:seed #only adds it only to my dev database
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails cucumber factory-bot

14
推荐指数
2
解决办法
2万
查看次数