Sha256: d10d19ed3d766525c3355f1b26def85f4a0b9fcae9f54fd6c5386c1679ae5897

Contents?: true

Size: 1.94 KB

Versions: 2

Compression:

Stored size: 1.94 KB

Contents

module RequestLogAnalyzer::RSpec::Mocks
  def mock_source
    source = double('RequestLogAnalyzer::Source::Base')
    source.stub(:file_format).and_return(testing_format)
    source.stub(:parsed_requests).and_return(2)
    source.stub(:skipped_requests).and_return(1)
    source.stub(:parse_lines).and_return(10)

    source.stub(:warning=)
    source.stub(:progress=)
    source.stub(:source_changes=)

    source.stub(:prepare)
    source.stub(:finalize)

    source.stub(:each_request).
      and_yield(testing_format.request(field: 'value1')).
      and_yield(testing_format.request(field: 'value2'))

    source
  end

  def mock_io
    mio = double('IO')
    mio.stub(:print)
    mio.stub(:puts)
    mio.stub(:write)
    mio
  end

  def mock_output
    output = double('RequestLogAnalyzer::Output::Base')
    output.stub(:report_tracker)
    output.stub(:header)
    output.stub(:footer)
    output.stub(:puts)
    output.stub(:<<)
    output.stub(:colorize).and_return('Fancy text')
    output.stub(:link)
    output.stub(:title)
    output.stub(:line)
    output.stub(:with_style)
    output.stub(:table).and_yield([])
    output.stub(:io).and_return(mock_io)
    output.stub(:options).and_return({})
    output.stub(:slice_results) { |a| a }
    output
  end

  def mock_database(*stubs)
    database = double('RequestLogAnalyzer::Database')
    database.stub(:connect)
    database.stub(:disconnect)
    database.stub(:connection).and_return(mock_connection)
    stubs.each { |s| database.stub(s) }
    database
  end

  def mock_connection
    table_creator = double('ActiveRecord table creator')
    table_creator.stub(:column)

    connection = double('ActiveRecord::Base.connection')
    connection.stub(:add_index)
    connection.stub(:remove_index)
    connection.stub(:table_exists?).and_return(false)
    connection.stub(:create_table).and_yield(table_creator).and_return(true)
    connection.stub(:table_creator).and_return(table_creator)
    connection
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
request-log-analyzer-1.13.4 spec/lib/mocks.rb
request-log-analyzer-1.13.3 spec/lib/mocks.rb