File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments