Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate FillMurray service #2657

Merged
merged 3 commits into from
Jan 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
stefannibrasil marked this conversation as resolved.
Show resolved Hide resolved
_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