-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #673
- Loading branch information
Showing
4 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
|
||
|
||
module Faker | ||
class Fillmurray < Base | ||
class << self | ||
|
||
def image(grayscale = false, width = 200, height = 200) | ||
raise ArgumentError, "Width should be a number in string format" unless width.match(/^[0-9]+$/) | ||
raise ArgumentError, "Height should be a number in string format" unless height.match(/^[0-9]+$/) | ||
raise ArgumentError, "Grayscale should be a boolean" unless [true, false].include?(grayscale) | ||
|
||
fillmurray_url = grayscale == true ? "https://fillmurray.com/g/#{width}/#{height}" : "https://fillmurray.com/#{width}/#{height}" | ||
|
||
fillmurray_url | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
require File.expand_path(File.dirname(__FILE__) + '/test_helper.rb') | ||
|
||
class TestFakerFillmurray < Test::Unit::TestCase | ||
def setup | ||
@tester = Faker::Fillmurray | ||
end | ||
|
||
def test_fillmurray | ||
assert @tester.image(false, '300', '300').match(/https:\/\/fillmurray\.com\/(\d+)\/(\d+)/) != nil | ||
end | ||
|
||
def test_fillmurray_with_grayscale | ||
assert @tester.image(true, '300', '300').match(/https:\/\/fillmurray\.com\/(g?\/?)(\d+)\/(\d+)/)[1] == 'g/' | ||
end | ||
|
||
def test_fillmurray_with_incorrect_height_format | ||
assert_raise ArgumentError do | ||
@tester.image(false, '300', 'nine-thousand') | ||
end | ||
|
||
end | ||
|
||
def test_fillmurray_with_incorrect_width_format | ||
assert_raise ArgumentError do | ||
@tester.image(false, 'three-hundred') | ||
end | ||
end | ||
|
||
def test_fillmurray_with_incorrect_grayscale | ||
assert_raise ArgumentError do | ||
@tester.image('gray', '300', '400') | ||
end | ||
end | ||
end |