Class: RSpec::LogMatcher::Matcher

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/log_matcher/matcher.rb

Constant Summary collapse

LOG_PATH =
ENV.fetch('LOG_PATH', 'log/test.log')

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(expected_logs, initial_log_file_position) ⇒ Matcher

Returns a new instance of Matcher.



10
11
12
13
# 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

Instance Attribute Details

#expected_logsObject (readonly)

Returns the value of attribute expected_logs.



8
9
10
# File 'lib/rspec/log_matcher/matcher.rb', line 8

def expected_logs
  @expected_logs
end

#initial_log_file_positionObject (readonly)

Returns the value of attribute initial_log_file_position.



8
9
10
# File 'lib/rspec/log_matcher/matcher.rb', line 8

def initial_log_file_position
  @initial_log_file_position
end

Instance Method Details

#failure_messageObject



28
29
30
# 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_negatedObject



32
33
34
# 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) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
19
20
21
22
23
24
25
26
# 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?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/rspec/log_matcher/matcher.rb', line 36

def supports_block_expectations?
  true
end