Skip to content

Commit aea3a3a

Browse files
committed
Add spec for errors rake task
This will prevent re-occurence of today's error where the site didn't have custom error pages for a few minutes.
1 parent 7026c59 commit aea3a3a

3 files changed

Lines changed: 78 additions & 0 deletions

File tree

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
require 'rake'
2+
3+
module RakeTaskExampleGroup
4+
extend ActiveSupport::Concern
5+
6+
included do
7+
let(:rake) { Rake.application }
8+
let(:task) { self.class.top_level_description }
9+
let(:prerequisites) { subject.prerequisites }
10+
11+
subject { rake[task] }
12+
13+
around do |example|
14+
with_rake_env { example.run }
15+
end
16+
end
17+
18+
private
19+
20+
def application_tasks
21+
Rails.application.paths['lib/tasks'].to_a
22+
end
23+
24+
def with_rake_env
25+
new_rake = Rake::Application.new
26+
old_rake, Rake.application = Rake.application, new_rake
27+
28+
# The Rails enviroment is already loaded so we define an
29+
# empty environment task to fufill the prerequisites.
30+
Rake::Task.define_task(:environment)
31+
32+
# Load just the application tasks defined in `lib/tasks`
33+
application_tasks.each { |task| load(task) }
34+
35+
yield
36+
37+
ensure
38+
Rake.application = old_rake
39+
end
40+
end
41+
42+
RSpec.configure do |config|
43+
config.include RakeTaskExampleGroup, type: :rake, file_path: %r[spec/tasks]
44+
end

spec/tasks/assets_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require 'rails_helper'
2+
3+
RSpec.describe "assets:precompile", type: :task do
4+
it "includes 'errors:precompile' in its prerequisites" do
5+
expect(prerequisites).to include('errors:precompile')
6+
end
7+
end

spec/tasks/errors_spec.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
require 'rails_helper'
2+
3+
RSpec.describe "errors:precompile", type: :task do
4+
let(:public_path) { Pathname.new(Dir.mktmpdir) }
5+
let(:public_files) { public_path.entries.map(&:to_s) }
6+
7+
before do
8+
allow(Rails).to receive(:public_path).and_return(public_path)
9+
10+
subject.invoke
11+
end
12+
13+
after do
14+
FileUtils.remove_entry(public_path)
15+
end
16+
17+
it "renders the error pages" do
18+
expect(public_files).to include('400.html')
19+
expect(public_files).to include('403.html')
20+
expect(public_files).to include('404.html')
21+
expect(public_files).to include('406.html')
22+
expect(public_files).to include('422.html')
23+
expect(public_files).to include('500.html')
24+
expect(public_files).to include('503.html')
25+
expect(public_files).to include('error.css')
26+
end
27+
end

0 commit comments

Comments
 (0)