Skip to content

Commit

Permalink
Fix test configuration to allow rake test coverage
Browse files Browse the repository at this point in the history
The test coverage was getting reset for the rake tests because rake was
being restarted constantly.  This moves the start into the spec_helper,
so it's only started once, based on reading:

simplecov-ruby/simplecov#369

Also required moving the last_comment fix into the spec_helper since
that's how production rake runs
  • Loading branch information
Frank Duncan committed May 30, 2020
1 parent 9c4d92c commit 9b81bb5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 23 deletions.
17 changes: 0 additions & 17 deletions spec/lib/tasks/incidents_periodic_spec.rb
Original file line number Diff line number Diff line change
@@ -1,26 +1,9 @@
require 'spec_helper'

describe "incidents_periodic:send_reminders" do
include_context "rake"

describe '#prerequisites' do
subject { super().prerequisites }
it { is_expected.to eq(['send_missing_incident_report'])}
end
end

describe "" do
include_context "rake"
let(:task_name) { self.class.description }

before(:each) do

end

after(:each) do
Delorean.back_to_1985
end

describe "incidents_periodic:send_no_incident_report" do

before(:each) do
Expand Down
11 changes: 11 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@
# If you are not using ActiveRecord, you can remove this line.
ActiveRecord::Migration.maintain_test_schema!

# Load rake tasks so they can be tested.
module TempFixForRakeLastComment
def last_comment
last_description
end
end
Rake::Application.send :include, TempFixForRakeLastComment

Rake.application = Rake::Application.new
Rails.application.load_tasks

RSpec.configure do |config|
# ## Mock Framework
#
Expand Down
8 changes: 2 additions & 6 deletions spec/support/shared_contexts/rake.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
require "rake"

shared_context "rake" do
let(:rake) { Rake::Application.new }
let(:task_name) { self.class.top_level_description }
let(:task_path) { "lib/tasks/#{task_name.split(":").first}" }
subject { rake[task_name] }
subject { Rake.application[task_name] }

def loaded_files_excluding_current_rake_file
$".reject {|file| file == Rails.root.join("#{task_path}.rake").to_s }
end

before do
Rake.application = rake
Rake.application.rake_require(task_path, [Rails.root.to_s], loaded_files_excluding_current_rake_file)

Rake::Task.define_task(:environment)
subject.reenable
end
end

0 comments on commit 9b81bb5

Please sign in to comment.