forked from faker-ruby/faker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
144 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
repo_token: YysDKPzbssfETbQG7t2zEQOxPraO4Or1b | ||
repo_token: VJWNNdqvbmV4izRaFRKmXsqNawiDClygs |
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 |
---|---|---|
|
@@ -53,7 +53,7 @@ PLATFORMS | |
ruby | ||
|
||
DEPENDENCIES | ||
coveralls | ||
coveralls (>= 0.8.21) | ||
faker! | ||
minitest | ||
rake | ||
|
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,25 @@ | ||
# Faker::Source | ||
Need to generate a code sample for something? Just give me the language (defaults to `ruby`, obviously). | ||
|
||
```ruby | ||
# Optional argument: lang=:ruby | ||
Faker::Source.hello_world #=> "print 'Hello World!'" | ||
Faker::Source.hello_world(:javascript) #=> "alert('Hello World!');" | ||
|
||
# Optional arguments: str='some string', lang=:ruby | ||
Faker::Source.print #=> "print 'some string'" | ||
Faker::Source.print('cake') #=> "print 'cake'" | ||
Faker::Source.print(str: 'cake', lang: :javascript) #=> "console.log('cake');" | ||
|
||
# Optional argument: lang=:ruby | ||
Faker::Source.print_1_to_10 <<-DOC=> " | ||
10.times do |i| | ||
print i | ||
end" | ||
DOC | ||
Faker::Source.print_1_to_10(:javascript) <<-DOC=> " | ||
for (let i=0; i<10; i++) { | ||
console.log(i); | ||
}" | ||
DOC | ||
``` |
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 Source < Base | ||
class << self | ||
def hello_world(lang = :ruby) | ||
fetch("source.hello_world.#{lang}") | ||
end | ||
|
||
def print(str: 'some string', lang: :ruby) | ||
code = fetch("source.print.#{lang}") | ||
code.gsub('faker_string_to_print', str) | ||
end | ||
|
||
def print_1_to_10(lang = :ruby) | ||
fetch("source.print_1_to_10.#{lang}") | ||
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,18 @@ | ||
en: | ||
faker: | ||
source: | ||
hello_world: | ||
ruby: "print 'Hello World!'" | ||
javascript: "alert('Hello World!');" | ||
print: | ||
ruby: "print 'faker_string_to_print'" | ||
javascript: "console.log('faker_string_to_print');" | ||
print_1_to_10: | ||
ruby: " | ||
10.times do |i| | ||
print i | ||
end" | ||
javascript: " | ||
for (let i=0; i<10; i++) { | ||
console.log(i); | ||
}" |
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,39 @@ | ||
require File.expand_path(File.dirname(__FILE__) + '/test_helper.rb') | ||
|
||
class TestFakerSource < Test::Unit::TestCase | ||
def setup | ||
@tester = Faker::Source | ||
end | ||
|
||
def test_hello_world | ||
assert_instance_of String, @tester.hello_world | ||
end | ||
|
||
def test_print | ||
assert_instance_of String, @tester.print | ||
end | ||
|
||
def test_print_javascript | ||
assert_equal "console.log('some string');", @tester.print(lang: :javascript) | ||
end | ||
|
||
def test_print_another_string | ||
assert_equal "print 'another string'", @tester.print(str: 'another string') | ||
end | ||
|
||
def test_print_invalid_lang | ||
assert_raise(I18n::MissingTranslationData) { @tester.print(lang: :js) } | ||
end | ||
|
||
def test_print_1_to_10 | ||
assert_instance_of String, @tester.print_1_to_10 | ||
end | ||
|
||
def test_print_1_to_10_javascript | ||
assert_match 'console.log(i);', @tester.print_1_to_10(:javascript) | ||
end | ||
|
||
def test_print_1_to_10_matches | ||
assert_match 'print i', @tester.print_1_to_10 | ||
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