class RSpec::LogMatcher::Matcher

Constants

LOG_PATH

Attributes

expected_logs[R]
initial_log_file_position[R]

Public Class Methods

new(expected_logs, initial_log_file_position) click to toggle source
# File lib/rspec/log_matcher/matcher.rb, line 10
def initialize(expected_logs, initial_log_file_position)
  @expected_logs = expected_logs
  @initial_log_file_position = initial_log_file_position || 0
end

Public Instance Methods

failure_message() click to toggle source
# File lib/rspec/log_matcher/matcher.rb, line 28
def failure_message
  "Expected subject to have logged `#{expected_logs}' in:\n\t#{logs}"
end
failure_message_when_negated() click to toggle source
# File lib/rspec/log_matcher/matcher.rb, line 32
def failure_message_when_negated
  "Expected subject not to have logged `#{expected_logs}' in:\n\t#{logs}"
end
matches?(subject) click to toggle source
# File lib/rspec/log_matcher/matcher.rb, line 15
def matches?(subject)
  prepare_matcher(subject)

  case expected_logs
  when Regexp
    logs.match?(expected_logs)
  when Proc
    logs.include?(expected_logs.call)
  when String
    logs.include?(expected_logs)
  end
end
supports_block_expectations?() click to toggle source
# File lib/rspec/log_matcher/matcher.rb, line 36
def supports_block_expectations?
  true
end

Private Instance Methods

log_file() click to toggle source
# File lib/rspec/log_matcher/matcher.rb, line 42
def log_file
  @log_file ||= File.new(LOG_PATH)
end
logs() click to toggle source
# File lib/rspec/log_matcher/matcher.rb, line 46
def logs
  @logs ||= log_file.read
end
prepare_matcher(subject) click to toggle source
# File lib/rspec/log_matcher/matcher.rb, line 50
def prepare_matcher(subject)
  if subject.is_a?(Proc)
    log_file.seek(0, IO::SEEK_END)
    subject.call
  elsif defined?(Capybara::Session) && subject.is_a?(Capybara::Session)
    log_file.seek(initial_log_file_position)
  end
end