Sha256: 3c2d16cb8a910fdc594028438e9072d59adbc80457de2889ae7c27a40586f78d

Contents?: true

Size: 1.4 KB

Versions: 53

Compression:

Stored size: 1.4 KB

Contents

def image_properties(image)
  if image.is_a?(Tempfile)
    tempfile = image
  else
    tempfile = Tempfile.new('image')
    tempfile.binmode
    tempfile.write(image.is_a?(Dragonfly::TempObject) ? image.data : image)
    tempfile.close
  end
  details = `identify #{tempfile.path}`
  # example of details string:
  # myimage.png PNG 200x100 200x100+0+0 8-bit DirectClass 31.2kb
  filename, format, geometry, geometry_2, depth, image_class, size = details.split(' ')
  width, height = geometry.split('x')
  {
    :filename => filename,
    :format => format.downcase,
    :width => width,
    :height => height,
    :depth => depth,
    :image_class => image_class,
    :size => size
  }
end

RSpec::Matchers.define :have_width do |width|
  match do |given|
    width.should === image_properties(given)[:width].to_i
  end
end

RSpec::Matchers.define :have_height do |height|
  match do |given|
    height.should === image_properties(given)[:height].to_i
  end
end

RSpec::Matchers.define :have_format do |format|
  match do |given|
    image_properties(given)[:format].should == format
  end
end

RSpec::Matchers.define :have_size do |size|
  match do |given|
    image_properties(given)[:size].should == size
  end
end

RSpec::Matchers.define :equal_image do |other|
  match do |given|
    image_data = given.open.read
    other_image_data = other.open.read
    given.close
    other.close
    image_data == other_image_data
  end
end

Version data entries

53 entries across 53 versions & 2 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/dragonfly-0.9.12/spec/support/image_matchers.rb
classiccms-0.7.4 vendor/bundle/gems/dragonfly-0.9.12/spec/support/image_matchers.rb
classiccms-0.7.3 vendor/bundle/gems/dragonfly-0.9.12/spec/support/image_matchers.rb
classiccms-0.7.2 vendor/bundle/gems/dragonfly-0.9.12/spec/support/image_matchers.rb
classiccms-0.7.1 vendor/bundle/gems/dragonfly-0.9.12/spec/support/image_matchers.rb
classiccms-0.7.0 vendor/bundle/gems/dragonfly-0.9.12/spec/support/image_matchers.rb
dragonfly-0.9.15 spec/support/image_matchers.rb
dragonfly-0.9.14 spec/support/image_matchers.rb
dragonfly-0.9.13 spec/support/image_matchers.rb
classiccms-0.6.9 vendor/bundle/gems/dragonfly-0.9.12/spec/support/image_matchers.rb
classiccms-0.6.8 vendor/bundle/gems/dragonfly-0.9.12/spec/support/image_matchers.rb
classiccms-0.6.7 vendor/bundle/gems/dragonfly-0.9.12/spec/support/image_matchers.rb
classiccms-0.6.6 vendor/bundle/gems/dragonfly-0.9.12/spec/support/image_matchers.rb
classiccms-0.6.5 vendor/bundle/gems/dragonfly-0.9.12/spec/support/image_matchers.rb
classiccms-0.6.4 vendor/bundle/gems/dragonfly-0.9.12/spec/support/image_matchers.rb
classiccms-0.6.3 vendor/bundle/gems/dragonfly-0.9.12/spec/support/image_matchers.rb
classiccms-0.6.2 vendor/bundle/gems/dragonfly-0.9.12/spec/support/image_matchers.rb
classiccms-0.6.1 vendor/bundle/gems/dragonfly-0.9.12/spec/support/image_matchers.rb
classiccms-0.6.0 vendor/bundle/gems/dragonfly-0.9.12/spec/support/image_matchers.rb
classiccms-0.5.17 vendor/bundle/gems/dragonfly-0.9.12/spec/support/image_matchers.rb