gpt4 book ai didi

ruby-on-rails - 不知道如何构建任务 - cucumber

转载 作者:行者123 更新时间:2023-12-05 04:17:14 25 4
gpt4 key购买 nike

在 Cucumber 中,我的种子数据是通过几个 rake 任务加载的。这些都不起作用:

Spree::Core::Engine.load_seed if defined?(Spree::Core)
Spree::Auth::Engine.load_seed if defined?(Spree::Auth)
Rake::Task['alchemy:db:seed'].invoke

当我运行 spree 的一项抽佣任务时,我得到:

Don't know how to build task 'db:load_dir' (RuntimeError)

当我运行炼金术的一项抽成任务时,我得到:

Don't know how to build task 'alchemy:db:seed' (RuntimeError)

测试数据库存在。我已经运行了 rake db:test:prepare,它似乎是根据我的检查设置的。让我们转到钩子(Hook)上:

# features/support/hooks.rb
Before do
load File.join(Rails.root, 'db', 'seeds.rb')
end

这会转到根目录并为我提供种子数据。我决定试试这个:

# features/support/hooks.rb
before do
# load File.join(Rails.root, 'db', 'seeds.rb')
Rake::Task['alchemy:db:seed'].invoke
end

错误是:

Don't know how to build task 'alchemy:db:seed' (RuntimeError)

我无法弄清楚为什么 rake 任务在 cucumber 中不起作用。

我的 Gemfile 如下:

source 'https://rubygems.org'
ruby '2.1.2'

gem 'rails', '4.0.6'

gem 'pg'
gem 'redis-rails'
gem 'redis-rack-cache'

gem 'sass-rails', '~> 4.0.3'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'

gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'

gem 'thin'
gem 'durable_decorator_rails', github: 'jumph4x/durable_decorator_rails'
gem 'newrelic_rpm'
gem 'rake'

gem 'spree', '2.2.2'
gem 'spree_gateway', github: 'spree/spree_gateway', branch: '2-2-stable'
gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: '2-2-stable'
gem 'spree_bootstrap_frontend', github: '200Creative/spree_bootstrap_frontend', branch: '2-2-stable'

gem 'alchemy_cms', github: 'magiclabs/alchemy_cms'
gem 'spree_alchemy', github: 'tesserakt/spree_alchemy'

group :doc do
gem 'sdoc', '~> 0.4.0'
end

group :development do
gem 'better_errors'
gem 'binding_of_caller'
gem 'meta_request'
end

group :test do
gem 'simplecov', require: false
gem 'cucumber-rails', require: false
gem "cucumber-websteps"
gem 'database_cleaner'
gem "selenium-webdriver"
gem "capybara-webkit"
end

group :development, :test do
gem "factory_girl_rails", "~> 4.0"
gem "rspec-rails"
gem 'rspec-its'
gem 'shoulda-matchers', require: false
end

这是我的环境支持文件:

# features/support/env.rb
require 'cucumber/rails'

ActionController::Base.allow_rescue = false

begin
DatabaseCleaner.strategy = :transaction
rescue NameError
raise 'You need to add database_cleaner to your' \
'Gemfile (in the :test group) if you wish to use it.'
end

Cucumber::Rails::Database.javascript_strategy = :truncation

Capybara.register_driver :chrome do |app|
Capybara::Selenium::Driver.new(app, browser: :chrome)
end

Capybara.javascript_driver = :chrome

最佳答案

Rake 默认不加载任务,你可以自己检查一下:

irb(main):002:0> require 'rake'
=> true
irb(main):003:0> Rake::Task.tasks
=> []

因此它不“知道”如何运行您的任务。您需要告诉 Rails 加载它们:

Rails.application.load_tasks

Spree::Core::Engine.load_seed if defined?(Spree::Core)
Spree::Auth::Engine.load_seed if defined?(Spree::Auth)

关于ruby-on-rails - 不知道如何构建任务 - cucumber ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24461492/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com