Sha256: 4d8893744d2ab47f36bfa06da789f8032ff2176b4d7d363aa5f38e53fbaf0e9f

Contents?: true

Size: 1.2 KB

Versions: 13

Compression:

Stored size: 1.2 KB

Contents

require 'spec_helper'
require 'thread'
require 'stringio'

## Logger helpers

def mock_logger
  @stdout = StringIO.new

  @logger = Logger.new(@stdout).tap do |logger|
    logger.formatter = proc do |level, time, prog, msg|
      "#{time.strftime('%H:%M:%S.%N')} #{msg}\n"
    end
    logger.level = Logger::INFO
  end
end

def log_entries
  @stdout && @stdout.string.split(/\n/)
end

def should_log *patterns
  patterns.each do |pattern|
    log_entries.any? { |entry| entry =~ pattern }.should be_true
  end
end

def should_not_log *patterns
  patterns.each do |pattern|
    log_entries.any? { |entry| entry =~ pattern }.should be_false
  end
end

## Connection helpers

# Clear logs and message collector. Output may be silenced.
def clean_connection
  if OPTS[:verbose]
    #puts @received.map { |type, msg| [" #{type}:", msg.map(&:to_human)] } if @received
    puts @ib.received.map { |type, msg| [" #{type}:", msg.map(&:to_human)] }
    puts " Logs:", log_entries if @stdout
  end
  @stdout.string = '' if @stdout
  @ib.clear_received
  @received.clear if @received # In connection_spec
end

def close_connection
  @ib.cancel_order @local_id_placed if @ib && @local_id_placed
  @ib.close if @ib
  clean_connection
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
ib-ruby-0.9.2 spec/message_helper.rb
ib-ruby-0.9.1 spec/message_helper.rb
ib-ruby-0.9.0 spec/message_helper.rb
ib-ruby-0.8.5 spec/message_helper.rb
ib-ruby-0.8.4 spec/message_helper.rb
ib-ruby-0.8.3 spec/message_helper.rb
ib-ruby-0.8.1 spec/message_helper.rb
ib-ruby-0.8.0 spec/message_helper.rb
ib-ruby-0.7.12 spec/message_helper.rb
ib-ruby-0.7.11 spec/message_helper.rb
ib-ruby-0.7.10 spec/message_helper.rb
ib-ruby-0.7.9 spec/message_helper.rb
ib-ruby-0.7.8 spec/message_helper.rb