Sha256: 5eba63ce860605c3409a063c2ca4dbde874331b8fe3050df35d2d5d9408a4da7

Contents?: true

Size: 1.28 KB

Versions: 2

Compression:

Stored size: 1.28 KB

Contents

module RequestLogAnalyzer::Spec::Helper
  
  include RequestLogAnalyzer::Spec::Mocks

  # Create or return a new TestingFormat
  def testing_format
    @testing_format ||= TestingFormat.new
  end
  
  # Load a log file from the fixture folder
  def log_fixture(name, extention = "log")
    File.dirname(__FILE__) + "/../fixtures/#{name}.#{extention}"
  end

  # Request loopback
  def request(fields, format = testing_format)
    if fields.kind_of?(Array)
      format.request(*fields)
    else
      format.request(fields)      
    end
  end

  # Run a specific command
  # Used to call request-log-analyzer through binary
  def run(arguments)
    binary = "#{File.dirname(__FILE__)}/../../bin/request-log-analyzer"
    arguments = arguments.join(' ') if arguments.kind_of?(Array)
    
    output = []
    IO.popen("#{binary} #{arguments}") do |pipe|
      output = pipe.readlines
    end
    $?.exitstatus.should == 0
    output
  end
  
  # Cleanup all temporary files generated by specs
  def cleanup_temp_files!
    Dir["#{File.dirname(__FILE__)}/../../tmp/spec.*tmp"].each do |file|
      File.unlink(file)
    end
  end
  
  # Return a filename that can be used as temporary file in specs
  def temp_output_file(file_type)
    "#{File.dirname(__FILE__)}/../../tmp/spec.#{file_type}.tmp"    
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
wvanbergen-request-log-analyzer-1.2.1 spec/lib/helper.rb
request-log-analyzer-1.2.1 spec/lib/helper.rb