Skip to content

Commit

Permalink
Deprecate FillMurray service (#2657)
Browse files Browse the repository at this point in the history
* Deprecate Fillmurray service

* Update date

* Skip deprecation message
  • Loading branch information
ferblape authored Jan 14, 2023
1 parent f8b0837 commit 7cfabab
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 15 deletions.
2 changes: 2 additions & 0 deletions lib/faker/default/fillmurray.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ class << self
# #=> "https://fillmurray.com/200/400"
#
# @faker.version 1.7.1
extend Gem::Deprecate
def image(grayscale: false, width: 200, height: 200)
raise ArgumentError, 'Width should be a number' unless width.to_s =~ /^\d+$/
raise ArgumentError, 'Height should be a number' unless height.to_s =~ /^\d+$/
raise ArgumentError, 'Grayscale should be a boolean' unless [true, false].include?(grayscale)

"https://www.fillmurray.com#{'/g' if grayscale == true}/#{width}/#{height}"
end
deprecate :image, 'Faker::LoremFlickr.image', 2023, 2
end
end
end
34 changes: 26 additions & 8 deletions test/faker/default/test_faker_fillmurray.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,46 @@ def setup
end

def test_fillmurray
refute_nil @tester.image(grayscale: false, width: '300', height: '300').match(%r{https://www\.fillmurray\.com/(\d+)/(\d+)})
Gem::Deprecate.skip_during do
refute_nil @tester.image(grayscale: false, width: '300', height: '300').match(%r{https://www\.fillmurray\.com/(\d+)/(\d+)})
end
end

def test_image_deprecation_message
_out, err = capture_output do
@tester.image(grayscale: false, width: '300', height: '300')
end

assert_match(/Faker::Fillmurray.image is deprecated; use Faker::LoremFlickr.image instead\./, err)
end

def test_fillmurray_with_grayscale
assert_equal('g/', @tester.image(grayscale: true, width: '300', height: '300').match(%r{https://www\.fillmurray\.com/(g?/?)(\d+)/(\d+)})[1])
Gem::Deprecate.skip_during do
assert_equal('g/', @tester.image(grayscale: true, width: '300', height: '300').match(%r{https://www\.fillmurray\.com/(g?/?)(\d+)/(\d+)})[1])
end
end

def test_fillmurray_with_incorrect_height_format
assert_raise ArgumentError do
@tester.image(grayscale: false, width: '300', height: 'nine-thousand')
Gem::Deprecate.skip_during do
assert_raise ArgumentError do
@tester.image(grayscale: false, width: '300', height: 'nine-thousand')
end
end
end

def test_fillmurray_with_incorrect_width_format
assert_raise ArgumentError do
@tester.image(grayscale: false, width: 'three-hundred')
Gem::Deprecate.skip_during do
assert_raise ArgumentError do
@tester.image(grayscale: false, width: 'three-hundred')
end
end
end

def test_fillmurray_with_incorrect_grayscale
assert_raise ArgumentError do
@tester.image(grayscale: 'gray', width: '300', height: '400')
Gem::Deprecate.skip_during do
assert_raise ArgumentError do
@tester.image(grayscale: 'gray', width: '300', height: '400')
end
end
end
end
17 changes: 10 additions & 7 deletions test/test_determinism.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,19 @@ def setup

def test_determinism
Faker::Config.random = Random.new(42)
@all_methods.each_index do |index|
store_result @all_methods[index]
end

@first_run.freeze
Gem::Deprecate.skip_during do
@all_methods.each_index do |index|
store_result @all_methods[index]
end

Faker::Config.random = Random.new(42)
@first_run.freeze

@all_methods.each_index do |index|
assert deterministic_random? @first_run[index], @all_methods[index]
Faker::Config.random = Random.new(42)

@all_methods.each_index do |index|
assert deterministic_random? @first_run[index], @all_methods[index]
end
end
end

Expand Down

0 comments on commit 7cfabab

Please sign in to comment.