Change rake spec setup (#19012)

This commit is contained in:
Mac Siri 2023-01-30 10:51:38 -05:00 committed by GitHub
parent 2da1b45c32
commit b77c1ea2e6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 40 additions and 31 deletions

View file

@ -3,7 +3,9 @@ require "knapsack_pro"
require "simplecov"
require "simplecov_json_formatter"
SimpleCov.formatter = SimpleCov::Formatter::JSONFormatter
if ENV["CI"]
SimpleCov.formatter = SimpleCov::Formatter::JSONFormatter
end
KnapsackPro::Adapters::RSpecAdapter.bind
KnapsackPro::Hooks::Queue.before_queue do |_queue_id|
SimpleCov.command_name("rspec_ci_node_#{KnapsackPro::Config::Env.ci_node_index}")
@ -24,6 +26,9 @@ require File.expand_path("../config/environment", __dir__)
require "rspec/rails"
abort("The Rails environment is running in production mode!") if Rails.env.production?
Rake.application = Rake::Application.new
Rails.application.load_tasks
# Add additional requires below this line. Rails is not loaded until this point!
require "fakeredis/rspec"
@ -83,7 +88,7 @@ Browser::Bot.matchers.delete(Browser::Bot::EmptyUserAgentMatcher)
RSpec.configure do |config|
config.use_transactional_fixtures = true
config.fixture_path = "#{::Rails.root}/spec/fixtures"
config.fixture_path = Rails.root.join("spec/fixtures")
config.include ActionMailer::TestHelper
config.include ApplicationHelper

View file

@ -2,28 +2,20 @@ require "rails_helper"
RSpec.describe "Navigation Links tasks", type: :task do
before do
Rake::Task.clear
PracticalDeveloper::Application.load_tasks
Rake.application["navigation_links:create"].reenable
%w[home readinglist contact code_of_conduct privacy terms].each do |page|
Rake.application["navigation_links:find_or_create:#{page}"].reenable
end
end
describe "#create" do
it "creates navigation links for new forem if nonexistent" do
expect { Rake::Task["navigation_links:create"].invoke }.to change(NavigationLink, :count).by(6)
end
it "creates navigation links for new forem if nonexistent" do
expect { Rake::Task["navigation_links:create"].invoke }.to change(NavigationLink, :count).by(6)
end
context "when navigation links exist" do
before do
NavigationLink.destroy_all
create(:navigation_link,
name: "Reading List",
url: URL.url("readinglist"),
display_to: :logged_in,
position: 0)
end
it "does not create nav links if they already exist" do
create(:navigation_link, name: "Reading List", url: URL.url("readinglist"), display_to: :logged_in, position: 0)
it "does not create nav links if they already exist" do
expect { Rake::Task["navigation_links:create"].invoke }.to change(NavigationLink, :count).from(1).to(6)
end
end
expect { Rake::Task["navigation_links:create"].invoke }.to change(NavigationLink, :count).from(1).to(6)
end
end

View file

@ -2,20 +2,35 @@ require "rails_helper"
RSpec.describe "Fastly tasks", type: :task do
before do
Rake::Task.clear
PracticalDeveloper::Application.load_tasks
Rake.application["fastly:update_configs"].reenable
allow(FastlyConfig::Update).to receive(:call)
end
describe "#update_configs" do
it "doesn't run if Fastly isn't configured" do
%w[FASTLY_API_KEY FASTLY_SERVICE_ID].each do |var|
allow(ApplicationConfig).to receive(:[]).with(var).and_return(nil)
end
allow(FastlyConfig::Update).to receive(:call)
allow(ApplicationConfig).to receive(:[]).with("FASTLY_API_KEY").and_return(nil)
allow(ApplicationConfig).to receive(:[]).with("FASTLY_SERVICE_ID").and_return(nil)
Rake::Task["fastly:update_configs"].invoke
expect(FastlyConfig::Update).not_to have_received(:call)
end
it "doesn't run if SKIP_FASTLY_CONFIG_UPDATE is set" do
allow(ENV).to receive(:[]).with("SKIP_FASTLY_CONFIG_UPDATE").and_return("true")
Rake::Task["fastly:update_configs"].invoke
expect(FastlyConfig::Update).not_to have_received(:call)
end
it "does run if Fastly is configured" do
allow(ApplicationConfig).to receive(:[]).with("FASTLY_API_KEY").and_return("123")
allow(ApplicationConfig).to receive(:[]).with("FASTLY_SERVICE_ID").and_return("123")
Rake::Task["fastly:update_configs"].invoke
expect(FastlyConfig::Update).to have_received(:call)
end
end
end

View file

@ -1,10 +1,7 @@
require "rails_helper"
RSpec.describe "Metrics Overview task", type: :task do
before do
Rake::Task.clear
PracticalDeveloper::Application.load_tasks
end
before { Rake.application["fastly:update_configs"].reenable }
describe "#overview" do
let(:event_name) { "Admin Overview Link Clicked" }