Class: CarrierWave::Test::Matchers::BeNoLargerThan

Inherits:
Object
  • Object
show all
Defined in:
lib/carrierwave/test/matchers.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(width, height) ⇒ BeNoLargerThan

Returns a new instance of BeNoLargerThan.



57
58
59
# File 'lib/carrierwave/test/matchers.rb', line 57

def initialize(width, height)
  @width, @height = width, height
end

Instance Method Details

#failure_messageObject



70
71
72
# File 'lib/carrierwave/test/matchers.rb', line 70

def failure_message
  "expected #{@actual.current_path.inspect} to be no larger than #{@width} by #{@height}, but it was #{@actual_width} by #{@actual_height}."
end

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


61
62
63
64
65
66
67
68
# File 'lib/carrierwave/test/matchers.rb', line 61

def matches?(actual)
  @actual = actual
  # Satisfy expectation here. Return false or raise an error if it's not met.
  img = ::Magick::Image.read(@actual.current_path).first
  @actual_width = img.columns
  @actual_height = img.rows
  @actual_width <= @width && @actual_height <= @height
end

#negative_failure_messageObject



74
75
76
# File 'lib/carrierwave/test/matchers.rb', line 74

def negative_failure_message
  "expected #{@actual.current_path.inspect} to be larger than #{@width} by #{@height}, but it wasn't."
end