Skip to content

Commit 4b07bee

Browse files
committed
Update gemfile and spec helpers
1 parent 4bb1ab9 commit 4b07bee

File tree

3 files changed

+32
-16
lines changed

3 files changed

+32
-16
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ end
1313

1414
group :test do
1515
gem 'byebug'
16-
gem 'rails', "~> #{ENV['RAILS_VERSION'] || '6.1.0'}"
16+
gem 'rails', "~> #{ENV['RAILS_VERSION'] || '8.0'}"
1717
gem 'rb-fsevent', '~> 0.9'
1818
gem 'redis', require: false
1919
gem 'simplecov', require: false

spec/lib/logstasher/device/redis_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,19 @@
6262
describe '#write' do
6363
it 'rpushes logs onto a list' do
6464
device = LogStasher::Device::Redis.new(data_type: 'list')
65-
expect(device.redis).to receive(:rpush).with('logstash', 'the log')
65+
expect(device.redis).to receive(:rpush).with('logstash', 'the log').and_return(1)
6666
device.write('the log')
6767
end
6868

6969
it 'rpushes logs onto a custom key' do
7070
device = LogStasher::Device::Redis.new(data_type: 'list', key: 'custom')
71-
expect(device.redis).to receive(:rpush).with('custom', 'the log')
71+
expect(device.redis).to receive(:rpush).with('custom', 'the log').and_return(1)
7272
device.write('the log')
7373
end
7474

7575
it 'publishes logs onto a channel' do
7676
device = LogStasher::Device::Redis.new(data_type: 'channel', key: 'custom')
77-
expect(device.redis).to receive(:publish).with('custom', 'the log')
77+
expect(device.redis).to receive(:publish).with('custom', 'the log').and_return(1)
7878
device.write('the log')
7979
end
8080
end

spec/spec_helper.rb

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
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
@@ -10,23 +13,36 @@
1013
end
1114
end
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
2643
RSpec.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

Comments
 (0)