From 1aee48e63702fc0e52a088788ada8299c4a005ea Mon Sep 17 00:00:00 2001 From: Sean Linsley Date: Sat, 26 Mar 2016 14:16:21 -0500 Subject: [PATCH] Don't create cucumber Rails environments This simplifies our test setup, making it easier to understand. The previous version created a cucumber and cucumber_with_reloading Rails environment, but I removed that in favor of setting a custom environment variable. --- cucumber.yml | 2 +- features/support/env.rb | 5 ++- spec/support/rails_template.rb | 45 ++----------------- spec/support/templates/cucumber.rb | 24 ---------- .../templates/cucumber_with_reloading.rb | 5 --- 5 files changed, 7 insertions(+), 74 deletions(-) delete mode 100644 spec/support/templates/cucumber.rb delete mode 100644 spec/support/templates/cucumber_with_reloading.rb diff --git a/cucumber.yml b/cucumber.yml index 2b8ee256bd4..4fdbfaac3ce 100644 --- a/cucumber.yml +++ b/cucumber.yml @@ -1,3 +1,3 @@ default: --format 'progress' --require features/support/env.rb --require features/step_definitions features --tags ~@requires-reloading --tags ~@wip wip: --format 'progress' --require features/support/env.rb --require features/step_definitions features --tags @wip:3 --wip features -class-reloading: RAILS_ENV=cucumber_with_reloading --format 'progress' --require features/support/env.rb --require features/step_definitions features --tags @requires-reloading +class-reloading: CLASS_RELOADING=true --format 'progress' --require features/support/env.rb --require features/step_definitions features --tags @requires-reloading diff --git a/features/support/env.rb b/features/support/env.rb index fefcd2691ed..8d490a059ad 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -4,7 +4,7 @@ # instead of editing this one. Cucumber will automatically load all features/**/*.rb # files. -ENV["RAILS_ENV"] ||= "cucumber" +ENV['RAILS_ENV'] = 'test' require File.expand_path('../../../spec/spec_helper', __FILE__) @@ -94,7 +94,8 @@ require 'database_cleaner' require 'database_cleaner/cucumber' DatabaseCleaner.strategy = :truncation - rescue LoadError => ignore_if_database_cleaner_not_present + rescue LoadError + # ignore if database_cleaner isn't present end end diff --git a/spec/support/rails_template.rb b/spec/support/rails_template.rb index bf7f3a55a9b..07a69738326 100644 --- a/spec/support/rails_template.rb +++ b/spec/support/rails_template.rb @@ -1,18 +1,5 @@ # Rails template to build the sample app for specs -# Create a cucumber database and environment -copy_file File.expand_path('../templates/cucumber.rb', __FILE__), 'config/environments/cucumber.rb' -copy_file File.expand_path('../templates/cucumber_with_reloading.rb', __FILE__), 'config/environments/cucumber_with_reloading.rb' - -gsub_file 'config/database.yml', /^test:.*\n/, "test: &test\n" -gsub_file 'config/database.yml', /\z/, "\ncucumber:\n <<: *test\n database: db/cucumber.sqlite3" -gsub_file 'config/database.yml', /\z/, "\ncucumber_with_reloading:\n <<: *test\n database: db/cucumber.sqlite3" - -if File.exists? 'config/secrets.yml' - gsub_file 'config/secrets.yml', /\z/, "\ncucumber:\n secret_key_base: #{'o' * 128}" - gsub_file 'config/secrets.yml', /\z/, "\ncucumber_with_reloading:\n secret_key_base: #{'o' * 128}" -end - generate :model, 'post title:string body:text published_at:datetime author_id:integer ' + 'position:integer custom_category_id:integer starred:boolean foo_id:integer' create_file 'app/models/post.rb', <<-RUBY.strip_heredoc, force: true @@ -118,8 +105,9 @@ class Tagging < ActiveRecord::Base end RUBY -inject_into_file 'config/environments/test.rb', <<-RUBY, after: 'config.cache_classes = true' +gsub_file 'config/environments/test.rb', / config.cache_classes = true/, <<-RUBY + config.cache_classes = !ENV['CLASS_RELOADING'] config.action_mailer.default_url_options = {host: 'example.com'} config.assets.digest = false @@ -163,35 +151,8 @@ class Tagging < ActiveRecord::Base # https://github.com/plataformatec/devise/issues/2554 gsub_file 'config/initializers/devise.rb', /# config.secret_key =/, 'config.secret_key =' -rake 'db:migrate db:test:prepare' -run '/usr/bin/env RAILS_ENV=cucumber rake db:migrate' +rake 'db:migrate' if ENV['INSTALL_PARALLEL'] inject_into_file 'config/database.yml', "<%= ENV['TEST_ENV_NUMBER'] %>", after: 'test.sqlite3' - inject_into_file 'config/database.yml', "<%= ENV['TEST_ENV_NUMBER'] %>", after: 'cucumber.sqlite3', force: true - - # Note: this is hack! - # Somehow, calling parallel_tests tasks from Rails generator using Thor does not work ... - # RAILS_ENV variable never makes it to parallel_tests tasks. - # We need to call these tasks in the after set up hook in order to create cucumber DBs + run migrations on test & cucumber DBs - create_file 'lib/tasks/parallel.rake', <<-RUBY.strip_heredoc - namespace :parallel do - def run_in_parallel(cmd, options) - count = "-n #{options[:count]}" if options[:count] - executable = 'parallel_test' - command = "#{executable} --exec '#{cmd}' #{count} #{'--non-parallel' if options[:non_parallel]}" - abort unless system(command) - end - - desc "create cucumber databases via db:create --> parallel:create_cucumber_db[num_cpus]" - task :create_cucumber_db, :count do |t, args| - run_in_parallel("rake db:create RAILS_ENV=cucumber", args) - end - - desc "load dumped schema for cucumber databases" - task :load_schema_cucumber_db, :count do |t,args| - run_in_parallel("rake db:schema:load RAILS_ENV=cucumber", args) - end - end - RUBY end diff --git a/spec/support/templates/cucumber.rb b/spec/support/templates/cucumber.rb deleted file mode 100644 index 183fa0f8cc9..00000000000 --- a/spec/support/templates/cucumber.rb +++ /dev/null @@ -1,24 +0,0 @@ -require File.expand_path('config/environments/test', Rails.root) - -# rails/railties/lib/rails/test_help.rb aborts if the environment is not 'test'. (Rails 3.0.0.beta3) -# We can't run Cucumber/RSpec/Test_Unit tests in different environments then. -# -# For now, I patch StringInquirer so that Rails.env.test? returns true when Rails.env is 'test' or 'cucumber' -# -# https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/4458-rails-should-allow-test-to-run-in-cucumber-environment -module ActiveSupport - class StringInquirer < String - def method_missing(method_name, *arguments) - if method_name.to_s[-1,1] == "?" - test_string = method_name.to_s[0..-2] - if test_string == 'test' - self == 'test' or self == 'cucumber' - else - self == test_string - end - else - super - end - end - end -end diff --git a/spec/support/templates/cucumber_with_reloading.rb b/spec/support/templates/cucumber_with_reloading.rb deleted file mode 100644 index e9b2592901a..00000000000 --- a/spec/support/templates/cucumber_with_reloading.rb +++ /dev/null @@ -1,5 +0,0 @@ -require File.expand_path('config/environments/cucumber', Rails.root) - -Rails.application.class.configure do - config.cache_classes = false -end