Sha256: 8942c7b05351b36c2f956cd86d9b6917ccf8c3135ac8994f6b5c00c17520ce61

Contents?: true

Size: 1.26 KB

Versions: 9

Compression:

Stored size: 1.26 KB

Contents

# frozen_string_literal: true

require_relative 'helper'

class TestImage < Test::Unit::TestCase
  include DeterministicHelper

  PLACEHOLDER = 'https://dummyimage.com/'

  assert_methods_are_deterministic(FFakerTW::Image, :url)

  def setup
    @tester = FFakerTW::Image
  end

  def test_url
    assert_match(%r(#{Regexp.quote(PLACEHOLDER)}300x300/[0-9a-f]{6}/[0-9a-f]{6}\.png\?text=),
                 @tester.url)
  end

  def test_image_url_with_param
    assert_equal("#{PLACEHOLDER}300x300//.png?text=",
                 @tester.url('300x300', 'png', nil, nil))
  end

  def test_image_url_with_correct_size
    assert_match(%r(#{Regexp.quote(PLACEHOLDER)}150x320/[0-9a-f]{6}/[0-9a-f]{6}\.png\?text=),
                 @tester.url('150x320'))
  end

  def test_image_url_with_incorrect_size
    assert_raise ArgumentError do
      @tester.url('150x320z')
    end
  end

  def test_image_url_with_supported_format
    assert_match(%r(#{Regexp.quote(PLACEHOLDER)}300x300/[0-9a-f]{6}/[0-9a-f]{6}\.jpg\?text=),
                 @tester.url('300x300', 'jpg'))
  end

  def test_image_url_with_incorrect_format
    assert_raise ArgumentError do
      @tester.url('300x300', 'wrong_format')
    end
  end

  def test_image_file
    assert_equal(@tester.file.class.name, 'File')
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
ffakerTW-1.8.0 test/test_image.rb
ffakerTW-1.7.0 test/test_image.rb
ffakerTW-1.6.0 test/test_image.rb
ffakerTW-1.5.0 test/test_image.rb
ffakerTW-1.4.0 test/test_image.rb
ffakerTW-1.3.0 test/test_image.rb
ffakerTW-1.2.0 test/test_image.rb
ffakerTW-1.1.0 test/test_image.rb
ffakerTW-0.1.0 test/test_image.rb