From 93940ced3a712f20c7a126f629e018bfced298c2 Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Fri, 16 Nov 2018 14:47:26 +0800 Subject: [PATCH 1/9] Remove outdated comment recommending knapsack We are already using this. --- .travis.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 952e999999..dcb097a3e0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,9 +9,6 @@ addons: # Set the timezone for phantomjs with TZ # Set the timezone for karma with TIMEZONE -# -# The test cases are roughly split according to their test times. -# It would be better to use https://github.com/ArturT/knapsack. env: global: - TZ="Australia/Melbourne" From fb5a9356dc61b339fc85980b418ee9166772c3fc Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Tue, 20 Nov 2018 17:24:02 +0800 Subject: [PATCH 2/9] Fix spec_helper.rb of web engine This fixes the tests of the web engine when running the following from its root: bundle exec rspec An engine is meant to have some independence from the main application, and its tests should be run independently. This should be using the engine's own dummy application, actually, or the dummy application of a dependency. --- engines/web/spec/spec_helper.rb | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/engines/web/spec/spec_helper.rb b/engines/web/spec/spec_helper.rb index 3306063166..9cfd0bc717 100644 --- a/engines/web/spec/spec_helper.rb +++ b/engines/web/spec/spec_helper.rb @@ -1,8 +1,3 @@ -ENV["RAILS_ENV"] = "test" - -require File.expand_path("dummy/config/environment.rb", __dir__) -require "rails/test_help" - -Rails.backtrace_cleaner.remove_silencers! +require "../../spec/spec_helper.rb" Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f } From f7e03ca60e86c466762f4d55e0ddc21579c8653b Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Mon, 17 Dec 2018 04:02:46 +0800 Subject: [PATCH 3/9] Add Rake tasks openfoodnetwork:specs:engines:NAME:rspec The task name follows the directory name under engines/. For example, for the Web engine in engines/web, run: bundle exec rake openfoodnetwork:specs:engines:web:rspec --- lib/tasks/specs.rake | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 lib/tasks/specs.rake diff --git a/lib/tasks/specs.rake b/lib/tasks/specs.rake new file mode 100644 index 0000000000..544c011ce6 --- /dev/null +++ b/lib/tasks/specs.rake @@ -0,0 +1,30 @@ +namespace :openfoodnetwork do + namespace :specs do + namespace :engines do + def detect_engine_paths + Pathname("engines/").children.select(&:directory?) + end + + def engine_name_for_engine(engine_path) + engine_path.basename.to_path + end + + def execute_rspec_for_engine(engine_path) + system "cd #{engine_path.expand_path} && bundle exec rspec" + end + + engine_paths = detect_engine_paths + + engine_paths.each do |engine_path| + engine_name = engine_name_for_engine(engine_path) + + namespace engine_name do + task :rspec do + success = execute_rspec_for_engine(engine_path) + abort "Failure when running tests for engine \"#{engine_name}\"" unless success + end + end + end + end + end +end From 571ad37c3ef89b97c9761103339c7b04fe05f048 Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Mon, 17 Dec 2018 04:04:10 +0800 Subject: [PATCH 4/9] Add Rake task openfoodnetwork:specs:engines:rspec --- lib/tasks/specs.rake | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/tasks/specs.rake b/lib/tasks/specs.rake index 544c011ce6..ef092a0bd8 100644 --- a/lib/tasks/specs.rake +++ b/lib/tasks/specs.rake @@ -25,6 +25,20 @@ namespace :openfoodnetwork do end end end + + namespace :all do + task :rspec do + success = true + + engine_paths.each do |engine_path| + success = !!execute_rspec_for_engine(engine_path) && success + end + + abort "Failure encountered when running tests for engines" unless success + end + end + + task rspec: "all:rspec" end end end From 74ea1eee6b28716ec3de9a006bce7aa131ef1069 Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Mon, 17 Dec 2018 03:46:48 +0800 Subject: [PATCH 5/9] Add description for Rake tasks --- lib/tasks/specs.rake | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/tasks/specs.rake b/lib/tasks/specs.rake index ef092a0bd8..6f9b2068cf 100644 --- a/lib/tasks/specs.rake +++ b/lib/tasks/specs.rake @@ -19,6 +19,7 @@ namespace :openfoodnetwork do engine_name = engine_name_for_engine(engine_path) namespace engine_name do + desc "Run RSpec tests for engine \"#{engine_name}\"" task :rspec do success = execute_rspec_for_engine(engine_path) abort "Failure when running tests for engine \"#{engine_name}\"" unless success @@ -27,6 +28,7 @@ namespace :openfoodnetwork do end namespace :all do + desc "Run RSpec tests for all engines" task :rspec do success = true @@ -38,6 +40,7 @@ namespace :openfoodnetwork do end end + desc "Alias for openfoodnetwork:specs:engines:all:rspec" task rspec: "all:rspec" end end From 12780b722ed36363a7dc926111c58b817a77c2bf Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Tue, 20 Nov 2018 18:33:08 +0800 Subject: [PATCH 6/9] Make Travis CI run RSpec tests in app engines --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index dcb097a3e0..db818fad23 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,7 +18,7 @@ env: - CI_NODE_INDEX=0 - CI_NODE_INDEX=1 - CI_NODE_INDEX=2 - - CI_NODE_INDEX=3 + - CI_NODE_INDEX=3 RSPEC_ENGINES="true" - CI_NODE_INDEX=4 KARMA="true" GITHUB_DEPLOY="true" before_script: @@ -39,6 +39,7 @@ before_script: script: - 'if [ "$KARMA" = "true" ]; then bundle exec rake karma:run; else echo "Skipping karma run"; fi' + - 'if [ "$RSPEC_ENGINES" = "true" ]; then bundle exec rake openfoodnetwork:specs:engines:rspec; else echo "Skipping RSpec run in engines"; fi' - "bundle exec rake 'knapsack:rspec[--format progress --tag ~performance]'" after_success: From abcb71f8b37578cf8ede91d3de89968c329d75ee Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Tue, 20 Nov 2018 21:35:53 +1100 Subject: [PATCH 7/9] Document running app engine RSpec tests --- GETTING_STARTED.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/GETTING_STARTED.md b/GETTING_STARTED.md index 93cff8dad0..5a2e7eea54 100644 --- a/GETTING_STARTED.md +++ b/GETTING_STARTED.md @@ -69,10 +69,14 @@ Tests, both unit and integration, are based on RSpec. To run the test suite, fir bundle exec rake db:test:prepare -Then the tests can be run with: +Then the main application tests can be run with: bundle exec rspec spec +The tests of all custom engines can be run with: + + bundle exec rake openfoodnetwork:specs:engines:rspec + Note: If your OS is not explicitly supported in the setup guides then not all tests may pass. However, you may still be able to develop. Get in touch with the [#dev][slack-dev] channel on Slack to troubleshoot issues and determine if they will preclude you from contributing to OFN. Note: The time zone on your machine should match the one defined in `config/application.yml`. From a460e9d35fd1a19c286a3607761e379caecac51d Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Wed, 21 Nov 2018 15:41:32 +0800 Subject: [PATCH 8/9] Allow disabling Knapsack when running RSpec tests --- spec/spec_helper.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c198a68fbb..66924edea8 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -6,9 +6,13 @@ require 'rubygems' # Require pry when we're not inside Travis-CI require 'pry' unless ENV['CI'] -require 'knapsack' -Knapsack.tracker.config({enable_time_offset_warning: false}) unless ENV['CI'] -Knapsack::Adapters::RSpecAdapter.bind +# This spec_helper.rb is being used by the custom engines in engines/. The engines are not set up to +# use Knapsack, and this provides the option to disable it when running the tests in CI services. +unless ENV['DISABLE_KNAPSACK'] + require 'knapsack' + Knapsack.tracker.config({enable_time_offset_warning: false}) unless ENV['CI'] + Knapsack::Adapters::RSpecAdapter.bind +end ENV["RAILS_ENV"] ||= 'test' require_relative "../config/environment" From 4adae0a1e84d08eb5c21d02e5e3a3efbf0f67688 Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Wed, 19 Dec 2018 17:50:10 +0800 Subject: [PATCH 9/9] Disable Knapsack when running engine RSpec tests --- lib/tasks/specs.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/specs.rake b/lib/tasks/specs.rake index 6f9b2068cf..dddb5ffb54 100644 --- a/lib/tasks/specs.rake +++ b/lib/tasks/specs.rake @@ -10,7 +10,7 @@ namespace :openfoodnetwork do end def execute_rspec_for_engine(engine_path) - system "cd #{engine_path.expand_path} && bundle exec rspec" + system "cd #{engine_path.expand_path} && DISABLE_KNAPSACK=true bundle exec rspec" end engine_paths = detect_engine_paths