Class: CarrierWave::Test::Matchers::HaveDimensions

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

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(width, height) ⇒ HaveDimensions

Returns a new instance of HaveDimensions.



85
86
87
# File 'lib/carrierwave/test/matchers.rb', line 85

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

Instance Method Details

#failure_messageObject



98
99
100
# File 'lib/carrierwave/test/matchers.rb', line 98

def failure_message
  "expected #{@actual.current_path.inspect} to have an exact size of #{@width} by #{@height}, but it was #{@actual_width} by #{@actual_height}."
end

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


89
90
91
92
93
94
95
96
# File 'lib/carrierwave/test/matchers.rb', line 89

def matches?(actual)
  @actual = actual
  # Satisfy expectation here. Return false or raise an error if it's not met.
  image = ImageLoader.load_image(@actual.current_path)
  @actual_width = image.width
  @actual_height = image.height
  @actual_width == @width && @actual_height == @height
end

#negative_failure_messageObject



102
103
104
# File 'lib/carrierwave/test/matchers.rb', line 102

def negative_failure_message
  "expected #{@actual.current_path.inspect} not to have an exact size of #{@width} by #{@height}, but it did."
end