Class: Barometer::Support::Matchers::HaveForecast

Inherits:
Object
  • Object
show all
Includes:
Formats
Defined in:
lib/barometer/support/matchers/have_forecast.rb

Instance Method Summary collapse

Methods included from Formats

#_find_regex, #is_of_format?

Constructor Details

#initialize(*paths) ⇒ HaveForecast

Returns a new instance of HaveForecast.



14
15
16
# File 'lib/barometer/support/matchers/have_forecast.rb', line 14

def initialize(*paths)
  @paths = paths
end

Instance Method Details

#as_format(format) ⇒ Object



41
42
43
44
# File 'lib/barometer/support/matchers/have_forecast.rb', line 41

def as_format(format)
  @format = format
  self
end

#as_value(value) ⇒ Object



36
37
38
39
# File 'lib/barometer/support/matchers/have_forecast.rb', line 36

def as_value(value)
  @value = value
  self
end

#descriptionObject



32
33
34
# File 'lib/barometer/support/matchers/have_forecast.rb', line 32

def description
  "have correct forecast value for #{@paths.join('.')}"
end

#failure_messageObject



28
29
30
# File 'lib/barometer/support/matchers/have_forecast.rb', line 28

def failure_message
  "expected that '#{@result}' matches '#{@value || @format}'"
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
21
22
23
24
25
26
# File 'lib/barometer/support/matchers/have_forecast.rb', line 18

def matches?(subject)
  @result = Walker.new(subject.forecast[0]).follow(@paths)

  if @format
    is_of_format?(@format, @result)
  else
    @result == @value || @result.to_f == @value
  end
end