File: test_faker_lorem_flickr.rb

package info (click to toggle)
ruby-faker 3.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,596 kB
  • sloc: ruby: 20,656; sh: 6; makefile: 6
file content (126 lines) | stat: -rw-r--r-- 4,489 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# frozen_string_literal: true

require_relative '../../test_helper'

class TestFakerLoremFlickr < Test::Unit::TestCase
  def setup
    @tester = Faker::LoremFlickr
    @colorizations = %w[red green blue]
  end

  def test_image
    assert_equal('https://loremflickr.com/300/300', @tester.image)
  end

  def test_image_with_size
    assert_equal('https://loremflickr.com/50/60', @tester.image(size: '50x60'))
  end

  def test_image_with_incorrect_size
    assert_raise ArgumentError do
      @tester.image(size: '300x300s')
    end
  end

  def test_image_with_single_search_term
    assert_equal('https://loremflickr.com/50/60/faker', @tester.image(size: '50x60', search_terms: %w[faker]))
  end

  def test_image_with_multiple_search_terms
    assert_equal('https://loremflickr.com/50/60/dog,cat', @tester.image(size: '50x60', search_terms: %w[dog cat]))
  end

  def test_image_with_search_terms_and_match_all
    assert_equal('https://loremflickr.com/50/60/dog,cat/all', @tester.image(size: '50x60', search_terms: %w[dog cat], match_all: true))
  end

  def test_grayscale_image
    assert_equal('https://loremflickr.com/g/300/300/all', @tester.grayscale_image)
  end

  def test_grayscale_image_with_incorrect_size
    assert_raise ArgumentError do
      @tester.grayscale_image(size: '300x300s')
    end
  end

  def test_grayscale_image_without_search_terms
    assert_equal('https://loremflickr.com/g/50/60/all', @tester.grayscale_image(size: '50x60'))
  end

  def test_grayscale_image_with_single_search_term
    assert_equal('https://loremflickr.com/g/50/60/faker', @tester.grayscale_image(size: '50x60', search_terms: %w[faker]))
  end

  def test_grayscale_image_with_multiple_search_terms
    assert_equal('https://loremflickr.com/g/50/60/dog,cat', @tester.grayscale_image(size: '50x60', search_terms: %w[dog cat]))
  end

  def test_grayscale_image_with_search_terms_and_match_all
    assert_equal('https://loremflickr.com/g/50/60/dog,cat/all', @tester.grayscale_image(size: '50x60', search_terms: %w[dog cat], match_all: true))
  end

  def test_pixelated_image
    assert_equal('https://loremflickr.com/p/300/300/all', @tester.pixelated_image)
  end

  def test_pixelated_image_with_incorrect_size
    assert_raise ArgumentError do
      @tester.pixelated_image(size: '300x300s')
    end
  end

  def test_pixelated_image_without_search_terms
    assert_equal('https://loremflickr.com/p/50/60/all', @tester.pixelated_image(size: '50x60'))
  end

  def test_pixelated_image_with_single_search_term
    assert_equal('https://loremflickr.com/p/50/60/faker', @tester.pixelated_image(size: '50x60', search_terms: %w[faker]))
  end

  def test_pixelated_image_with_multiple_search_terms
    assert_equal('https://loremflickr.com/p/50/60/dog,cat', @tester.pixelated_image(size: '50x60', search_terms: %w[dog cat]))
  end

  def test_pixelated_image_with_search_terms_and_match_all
    assert_equal('https://loremflickr.com/p/50/60/dog,cat/all', @tester.pixelated_image(size: '50x60', search_terms: %w[dog cat], match_all: true))
  end

  def test_colorized_image
    assert_equal('https://loremflickr.com/red/300/300/all', @tester.colorized_image)
  end

  def test_colorized_image_with_incorrect_size
    assert_raise ArgumentError do
      @tester.colorized_image(size: '300x300s')
    end
  end

  def test_colorized_image_without_search_terms
    assert_equal('https://loremflickr.com/red/50/60/all', @tester.colorized_image(size: '50x60', color: 'red'))
  end

  def test_colorized_image_with_unsupported_colorization
    assert_raise ArgumentError do
      @tester.colorized_image(size: '50x60', color: 'yellow')
    end
  end

  def test_colorized_image_with_single_search_term
    @colorizations.each do |colorization|
      assert_equal @tester.colorized_image(size: '50x60', color: colorization, search_terms: %w[faker]), "https://loremflickr.com/#{colorization}/50/60/faker"
    end
  end

  def test_colorized_image_with_multiple_search_terms
    @colorizations.each do |colorization|
      assert_equal @tester.colorized_image(size: '50x60', color: colorization, search_terms: %w[dog cat]), "https://loremflickr.com/#{colorization}/50/60/dog,cat"
    end
  end

  def test_colorized_image_with_search_terms_and_match_all
    @colorizations.each do |colorization|
      assert_equal @tester.colorized_image(size: '50x60', color: colorization, search_terms: %w[dog cat], match_all: true), "https://loremflickr.com/#{colorization}/50/60/dog,cat/all"
    end
  end
end