Search code examples
ruby-on-railstddcucumberrake

Don't know how to build task - Cucumber


In cucumber, my seed data is loaded up via several rake tasks. None of which are working:

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

When I run one of spree's rake tasks I get:

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

When I run one of alchemy's rake tasks I get:

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

The testing database exists. I have ran rake db:test:prepare and it appears to be setup from my inspections. Lets move onto the hooks:

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

This goes to the root and gets me the seed data. I decided to try this:

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

The error was:

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

I'm unable to figure out why the rake tasks are not working in cucumber.

My Gemfile is as follows:

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

And this is my env support file:

# 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

Solution

  • It seems that the test database is missing. So as already written in the comment above, the solution is to create the database and run the migrations with

    RAILS_ENV=test rake db:setup
    

    Happy to help :)