mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-05 22:26:07 +00:00
Merge pull request #3088 from kristinalim/cleanup-test_scripts
Run RSpec tests in custom engines (and some fixes, cleanup)
This commit is contained in:
@@ -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"
|
||||
@@ -21,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:
|
||||
@@ -42,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:
|
||||
|
||||
@@ -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`.
|
||||
|
||||
@@ -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 }
|
||||
|
||||
47
lib/tasks/specs.rake
Normal file
47
lib/tasks/specs.rake
Normal file
@@ -0,0 +1,47 @@
|
||||
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} && DISABLE_KNAPSACK=true 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
|
||||
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
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
namespace :all do
|
||||
desc "Run RSpec tests for all engines"
|
||||
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
|
||||
|
||||
desc "Alias for openfoodnetwork:specs:engines:all:rspec"
|
||||
task rspec: "all:rspec"
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user