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



139
140
141
# File 'lib/carrierwave/test/matchers.rb', line 139

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

Instance Method Details

#descriptionObject



160
161
162
# File 'lib/carrierwave/test/matchers.rb', line 160

def description
  "have an exact size of #{@width} by #{@height}"
end

#failure_messageObject



152
153
154
# File 'lib/carrierwave/test/matchers.rb', line 152

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

#failure_message_when_negatedObject Also known as: negative_failure_message



156
157
158
# File 'lib/carrierwave/test/matchers.rb', line 156

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

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


143
144
145
146
147
148
149
150
# File 'lib/carrierwave/test/matchers.rb', line 143

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