Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions spec/lib/logstasher/device/redis_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 28 additions & 12 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Loading