diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 7b2dab1..33293f3 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -44,6 +44,8 @@ jobs: rails-version: '7.0' - ruby-version: 3.2 rails-version: '7.0' + - ruby-version: 3.2 + rails-version: '8.1' steps: - uses: actions/checkout@v3 - name: Set up Ruby ${{ matrix.ruby-version }} diff --git a/Gemfile b/Gemfile index 90eaba4..b49d9c0 100644 --- a/Gemfile +++ b/Gemfile @@ -13,7 +13,7 @@ end group :test do gem 'byebug' - gem 'rails', "~> #{ENV['RAILS_VERSION'] || '6.1.0'}" + gem 'rails', "~> #{ENV['RAILS_VERSION'] || '8.0'}" gem 'rb-fsevent', '~> 0.9' gem 'redis', require: false gem 'simplecov', require: false diff --git a/spec/lib/logstasher/device/redis_spec.rb b/spec/lib/logstasher/device/redis_spec.rb index 8752402..c16732f 100644 --- a/spec/lib/logstasher/device/redis_spec.rb +++ b/spec/lib/logstasher/device/redis_spec.rb @@ -62,19 +62,19 @@ describe '#write' do it 'rpushes logs onto a list' do device = LogStasher::Device::Redis.new(data_type: 'list') - expect(device.redis).to receive(:rpush).with('logstash', 'the log') + expect(device.redis).to receive(:rpush).with('logstash', 'the log').and_return(1) device.write('the log') end it 'rpushes logs onto a custom key' do device = LogStasher::Device::Redis.new(data_type: 'list', key: 'custom') - expect(device.redis).to receive(:rpush).with('custom', 'the log') + expect(device.redis).to receive(:rpush).with('custom', 'the log').and_return(1) device.write('the log') end it 'publishes logs onto a channel' do device = LogStasher::Device::Redis.new(data_type: 'channel', key: 'custom') - expect(device.redis).to receive(:publish).with('custom', 'the log') + expect(device.redis).to receive(:publish).with('custom', 'the log').and_return(1) device.write('the log') end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d37f50d..aa94423 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,7 +1,10 @@ # frozen_string_literal: true # Notice there is a .rspec file in the root folder. It defines rspec arguments -if ENV['COVERAGE'] + +def setup_code_coverage + return unless ENV['COVERAGE'] + require 'simplecov' SimpleCov.start do # Remove the spec folder from coverage. By default all code files are included. For more config options see @@ -10,23 +13,36 @@ end end -# Set rails env as test -ENV['RAILS_ENV'] = 'test' +def configure_test_environment + # Set rails env as test + ENV['RAILS_ENV'] = 'test' + + # This will require me all the gems automatically for the groups. If I do only .setup then I will have to require gems + # manually. Note that you have still have to require some gems if they are part of bigger gem like ActiveRecord which is + # part of Rails. You can say :require => false in gemfile to always use explicit requiring + require 'bundler' + Bundler.require(:default, :test) + require 'active_record' + require 'minitest' + require 'active_support/testing/assertions' +end -# This will require me all the gems automatically for the groups. If I do only .setup then I will have to require gems -# manually. Note that you have still have to require some gems if they are part of bigger gem like ActiveRecord which is -# part of Rails. You can say :require => false in gemfile to always use explicit requiring -Bundler.require(:default, :test) -require 'active_support/testing/assertions' -Dir[File.join('./spec/support/**/*.rb')].sort.each { |f| require f } +def load_support_files + Dir[File.join('./spec/support/**/*.rb')].sort.each { |file| require file } +end -# Set Rails environment as test +# Set test timestamp for consistent test assertions $test_timestamp = '1970-01-01T00:00:00.000Z' +# Initialize test environment +setup_code_coverage +configure_test_environment +load_support_files + +# Configure RSpec RSpec.configure do |config| config.include(ActiveSupport::Testing::Assertions) config.run_all_when_everything_filtered = true config.filter_run :focus - ActiveJob::Base.queue_adapter = :test -end +end \ No newline at end of file