Sha256: ced92de00c65038bbd15b544b986074201be72ed7a6f56b79f13b4f662e2a2b9

Contents?: true

Size: 903 Bytes

Versions: 129

Compression:

Stored size: 903 Bytes

Contents

require 'rake'

module RakeHelper
  def load_rake_environment(files)
    @rake = Rake::Application.new
    Rake.application = @rake
    Rake::Task.define_task(:environment)
    files.each { |file| load file }
  end

  def run_task(task, arg = nil)
    capture_stdout_stderr do
      @rake[task].invoke(arg)
    end
  end

  # saves original $stdout in variable
  # set $stdout as local instance of StringIO
  # yields to code execution
  # returns the local instance of StringIO
  # resets $stdout to original value
  def capture_stdout_stderr
    out = StringIO.new
    err = StringIO.new
    $stdout = out
    $stderr = err
    begin
      yield
    rescue SystemExit => e
      puts "error = #{e.inspect}"
    end
    return "Output: #{out.string}\n Errors:#{err.string}"
  ensure
    $stdout = STDOUT
    $stdout = STDERR
  end

  RSpec.configure do |config|
    config.include RakeHelper
  end
end

Version data entries

129 entries across 129 versions & 4 rubygems

Version Path
hyrax-2.6.0 spec/support/rake.rb
hyrax-3.0.0.pre.rc1 spec/support/rake.rb
hyrax-3.0.0.pre.beta3 spec/support/rake.rb
hyrax-2.5.1 spec/support/rake.rb
hyrax-2.5.0 spec/support/rake.rb
hyrax-3.0.0.pre.beta2 spec/support/rake.rb
hyrax-2.4.1 spec/support/rake.rb
hyrax-3.0.0.pre.beta1 spec/support/rake.rb
hyrax-2.4.0 spec/support/rake.rb
hyrax-2.3.3 spec/support/rake.rb
hyrax-2.3.2 spec/support/rake.rb
hyrax-2.3.1 spec/support/rake.rb
hyrax-1.1.1 spec/support/rake.rb
hyrax-2.3.0 spec/support/rake.rb
hyrax-2.0.3 spec/support/rake.rb
hyrax-2.2.4 spec/support/rake.rb
hyrax-2.2.3 spec/support/rake.rb
hyrax-2.2.2 spec/support/rake.rb
hyrax-2.2.1 spec/support/rake.rb
hyrax-2.2.0 spec/support/rake.rb