Module: RSpecCommand::Rake
- Defined in:
- lib/rspec_command/rake.rb
Overview
An RSpec helper module for testing Rake tasks without running them in a full subprocess. This improves test speed while still giving you most of the benefits of integration testing.
Class Method Summary collapse
-
.rake_task(name, *args)
Run a Rake task as the subject of this example group.
-
.rakefile(content = nil, &block)
Write out a Rakefile to the temporary directory for this example group.
Class Method Details
.rake_task(name, *args)
This method returns an undefined value.
Run a Rake task as the subject of this example group. The subject will be a string returned by RSpecCommand#capture_output.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/rspec_command/rake.rb', line 57 def rake_task(name, *args) [:rake] = true subject do exitstatus = [] capture_output do Process.waitpid fork { # This has to be nocov because simplecov doesn't track across fork. # :nocov: # Defang SimpleCov so it doesn't print its stuff. Can be removed # when https://github.com/colszowka/simplecov/pull/377 is in a # released version. if defined?(SimpleCov) SimpleCov.at_exit { SimpleCov.instance_variable_set(:@result, nil) } end # Because #init reads from ARGV and will try to parse rspec's flags. ARGV.replace([]) Dir.chdir(temp_path) ENV.update(_environment) rake = ::Rake::Application.new.tap do |rake| ::Rake.application = rake rake.init rake.load_rakefile end rake[name].invoke(*args) } exitstatus << $?.exitstatus # :nocov: end.tap do |output| output.define_singleton_method(:exitstatus) { exitstatus.first } end end end |
.rakefile(content = nil, &block)
This method returns an undefined value.
Write out a Rakefile to the temporary directory for this example group. Content can be passed as either a string or a block.
106 107 108 |
# File 'lib/rspec_command/rake.rb', line 106 def rakefile(content=nil, &block) file('Rakefile', content, &block) end |