Skip to content

Commit

Permalink
Fix conflicts with master
Browse files Browse the repository at this point in the history
  • Loading branch information
vbrazo committed May 17, 2018
2 parents 239f4a8 + be985c1 commit 67267c3
Show file tree
Hide file tree
Showing 11 changed files with 144 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .coveralls.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
repo_token: YysDKPzbssfETbQG7t2zEQOxPraO4Or1b
repo_token: VJWNNdqvbmV4izRaFRKmXsqNawiDClygs
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
pkg/*

# Ignore Bundle folder
.bundle/*

# Ignore Coveralls files
.coveralls/*
coverage/*

# Ignore Vim backup files.
*~
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ PLATFORMS
ruby

DEPENDENCIES
coveralls
coveralls (>= 0.8.21)
faker!
minitest
rake
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Faker [![Build Status](https://travis-ci.org/stympy/faker.svg?branch=master)](https://travis-ci.org/stympy/faker) [![Gem Version](https://badge.fury.io/rb/faker.svg)](https://badge.fury.io/rb/faker) [![Coverage Status](https://coveralls.io/repos/github/stympy/faker/badge.svg?branch=master)](https://coveralls.io/github/stympy/faker?branch=master)
# Faker [![Build Status](https://travis-ci.org/stympy/faker.svg?branch=master)](https://travis-ci.org/stympy/faker) [![Gem Version](https://badge.fury.io/rb/faker.svg)](https://badge.fury.io/rb/faker) [![Coverage Status](https://coveralls.io/repos/github/stympy/faker/badge.svg)](https://coveralls.io/github/stympy/faker)


This gem is a port of Perl's Data::Faker library that generates fake data.
Expand Down Expand Up @@ -108,6 +108,7 @@ Contents
- [Faker::SiliconValley](doc/silicon_valley.md)
- [Faker::Simpsons](doc/simpsons.md)
- [Faker::SlackEmoji](doc/slack_emoji.md)
- [Faker::Source](doc/source.md)
- [Faker::Space](doc/space.md)
- [Faker::StarTrek](doc/star_trek.md)
- [Faker::StarWars](doc/star_wars.md)
Expand Down
25 changes: 25 additions & 0 deletions doc/source.md
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
```
2 changes: 1 addition & 1 deletion faker.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Gem::Specification.new do |s|
s.license = 'MIT'

s.add_runtime_dependency('i18n', '>= 0.7')
s.add_development_dependency('coveralls')
s.add_development_dependency('coveralls', '>= 0.8.21')
s.add_development_dependency('minitest')
s.add_development_dependency('rake')
s.add_development_dependency('rubocop')
Expand Down
18 changes: 18 additions & 0 deletions lib/faker/source.rb
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
18 changes: 18 additions & 0 deletions lib/locales/en/source.yml
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);
}"
27 changes: 18 additions & 9 deletions test/test_faker_omniauth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@ def test_omniauth_google
assert_instance_of String, info[:image]
assert_instance_of String, credentials[:token]
assert_instance_of String, credentials[:refresh_token]

if RUBY_VERSION < '2.4.0'
assert_instance_of Fixnum, credentials[:expires_at]
else
assert_instance_of Integer, credentials[:expires_at]
end

assert_equal true, credentials[:expires]
assert_equal 9, extra_raw_info[:sub].length
assert_equal info[:email], extra_raw_info[:email]
Expand All @@ -51,9 +44,25 @@ def test_omniauth_google
assert_equal 'APP_ID', id_info['azp']
assert_equal info[:email], id_info['email']
assert_equal 'APP_ID', id_info['aud']
assert_instance_of Fixnum, id_info['iat']
assert_instance_of Fixnum, id_info['exp']
assert_equal openid_id, id_info['openid_id']

if RUBY_VERSION < '2.4.0'
assert_instance_of Fixnum, credentials[:expires_at]
else
assert_instance_of Integer, credentials[:expires_at]
end

if RUBY_VERSION < '2.4.0'
assert_instance_of Fixnum, id_info['iat']
else
assert_instance_of Integer, id_info['iat']
end

if RUBY_VERSION < '2.4.0'
assert_instance_of Fixnum, id_info['exp']
else
assert_instance_of Integer, id_info['exp']
end
end

def test_omniauth_google_with_name
Expand Down
39 changes: 39 additions & 0 deletions test/test_faker_source.rb
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
21 changes: 17 additions & 4 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
# add Coveralls and SimpleCov support
begin
require 'simplecov'
require 'coveralls'

SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
SimpleCov::Formatter::HTMLFormatter,
Coveralls::SimpleCov::Formatter
]
SimpleCov.start do
add_filter ['/test/', 'lib/helpers', 'lib/extensions']
end
rescue LoadError
puts 'Coverage disabled, enable by installing simplecov'
end

require 'test/unit'
require 'rubygems'
require 'timecop'
require 'yaml'

YAML::ENGINE.yamler = 'psych' if defined? YAML::ENGINE
require File.expand_path(File.dirname(__FILE__) + '/../lib/faker')

# add Coveralls support
require 'coveralls'
Coveralls.wear!

# configure I18n
locales_path = File.expand_path(File.dirname(__FILE__) + '../lib/locales')
I18n.available_locales = Dir[locales_path + '/*'].map do |file|
Expand Down

0 comments on commit 67267c3

Please sign in to comment.