module RSpecCommand::Rake::ClassMethods
@!classmethods
Public Instance Methods
included(klass)
click to toggle source
Calls superclass method
# File lib/rspec_command/rake.rb, line 110 def included(klass) super # Pull this in as a dependency. klass.send(:include, RSpecCommand) klass.extend ClassMethods end
rake_task(name, *args)
click to toggle source
Run a Rake
task as the subject of this example group. The subject will be a string returned by {#capture_output}.
@param name [String] Name of the task to execute. @param args [Array<Object>] Arguments to pass to the task. @return [void] @example
describe 'mytask' do rakefile 'require "myapp/rake_tasks"' rake_task 'mytask' its(:stdout) { is_expected.to include 'Complete!' } end
# File lib/rspec_command/rake.rb, line 57 def rake_task(name, *args) metadata[: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)
click to toggle source
Write out a Rakefile to the temporary directory for this example group. Content can be passed as either a string or a block.
@param content [String] Rakefile content. @param block [Proc] Optional block to return the Rakefile content. @return [void] @example
describe 'mytask' do rakefile <<-EOH task 'mytask' do ... end EOH rake_task 'mytask' its(:stdout) { is_expected.to include 'Complete!' } end
# File lib/rspec_command/rake.rb, line 106 def rakefile(content=nil, &block) file('Rakefile', content, &block) end