11# frozen_string_literal: true
22
33# Notice there is a .rspec file in the root folder. It defines rspec arguments
4- if ENV [ 'COVERAGE' ]
4+
5+ def setup_code_coverage
6+ return unless ENV [ 'COVERAGE' ]
7+
58 require 'simplecov'
69 SimpleCov . start do
710 # Remove the spec folder from coverage. By default all code files are included. For more config options see
1013 end
1114end
1215
13- # Set rails env as test
14- ENV [ 'RAILS_ENV' ] = 'test'
16+ def configure_test_environment
17+ # Set rails env as test
18+ ENV [ 'RAILS_ENV' ] = 'test'
19+
20+ # This will require me all the gems automatically for the groups. If I do only .setup then I will have to require gems
21+ # manually. Note that you have still have to require some gems if they are part of bigger gem like ActiveRecord which is
22+ # part of Rails. You can say :require => false in gemfile to always use explicit requiring
23+ require 'bundler'
24+ Bundler . require ( :default , :test )
25+ require 'active_record'
26+ require 'minitest'
27+ require 'active_support/testing/assertions'
28+ end
1529
16- # This will require me all the gems automatically for the groups. If I do only .setup then I will have to require gems
17- # manually. Note that you have still have to require some gems if they are part of bigger gem like ActiveRecord which is
18- # part of Rails. You can say :require => false in gemfile to always use explicit requiring
19- Bundler . require ( :default , :test )
20- require 'active_support/testing/assertions'
21- Dir [ File . join ( './spec/support/**/*.rb' ) ] . sort . each { |f | require f }
30+ def load_support_files
31+ Dir [ File . join ( './spec/support/**/*.rb' ) ] . sort . each { |file | require file }
32+ end
2233
23- # Set Rails environment as test
34+ # Set test timestamp for consistent test assertions
2435$test_timestamp = '1970-01-01T00:00:00.000Z'
2536
37+ # Initialize test environment
38+ setup_code_coverage
39+ configure_test_environment
40+ load_support_files
41+
42+ # Configure RSpec
2643RSpec . configure do |config |
2744 config . include ( ActiveSupport ::Testing ::Assertions )
2845 config . run_all_when_everything_filtered = true
2946 config . filter_run :focus
30-
3147 ActiveJob ::Base . queue_adapter = :test
32- end
48+ end
0 commit comments