factory-helper 1.7.5 → 1.7.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/lib/factory-helper/version.rb +1 -1
- data/spec/config_spec.rb +18 -0
- data/spec/factory_helper/my_sql_spec.rb +123 -0
- data/spec/factory_helper/string_spec.rb +55 -0
- data/spec/rspec_locale_hooks_spec.rb +28 -0
- data/spec/spec_helper.rb +92 -0
- data/test/legacy/test_array_sample_method_compat.rb +56 -0
- data/test/legacy/test_avatar.rb +36 -0
- data/test/legacy/test_en_au_ocker_locale.rb +23 -0
- data/test/legacy/test_en_ca_locale.rb +18 -0
- data/test/legacy/test_en_locale.rb +25 -0
- data/test/legacy/test_en_us_locale.rb +79 -0
- data/test/legacy/test_es_locale.rb +34 -0
- data/test/legacy/test_faker.rb +29 -0
- data/test/legacy/test_faker_app.rb +12 -0
- data/test/legacy/test_faker_bitcoin.rb +14 -0
- data/test/legacy/test_faker_business.rb +33 -0
- data/test/legacy/test_faker_city.rb +46 -0
- data/test/legacy/test_faker_code.rb +27 -0
- data/test/legacy/test_faker_commerce.rb +74 -0
- data/test/legacy/test_faker_company.rb +19 -0
- data/test/legacy/test_faker_date.rb +77 -0
- data/test/legacy/test_faker_hacker_talk.rb +37 -0
- data/test/legacy/test_faker_internet.rb +146 -0
- data/test/legacy/test_faker_lorem.rb +87 -0
- data/test/legacy/test_faker_name.rb +20 -0
- data/test/legacy/test_faker_number.rb +77 -0
- data/test/legacy/test_faker_street.rb +53 -0
- data/test/legacy/test_faker_team.rb +13 -0
- data/test/legacy/test_faker_time.rb +74 -0
- data/test/legacy/test_flexible.rb +57 -0
- data/test/legacy/test_locale.rb +45 -0
- data/test/legacy/test_pl_locale.rb +27 -0
- data/test/test_avatar.rb +36 -0
- data/test/test_determinism.rb +57 -0
- data/test/test_en_au_ocker_locale.rb +23 -0
- data/test/test_en_ca_locale.rb +18 -0
- data/test/test_en_locale.rb +25 -0
- data/test/test_en_us_locale.rb +79 -0
- data/test/test_es_locale.rb +34 -0
- data/test/test_factory_helper.rb +28 -0
- data/test/test_factory_helper_app.rb +12 -0
- data/test/test_factory_helper_bitcoin.rb +14 -0
- data/test/test_factory_helper_business.rb +33 -0
- data/test/test_factory_helper_city.rb +46 -0
- data/test/test_factory_helper_code.rb +27 -0
- data/test/test_factory_helper_commerce.rb +70 -0
- data/test/test_factory_helper_company.rb +23 -0
- data/test/test_factory_helper_date.rb +78 -0
- data/test/test_factory_helper_hacker_talk.rb +37 -0
- data/test/test_factory_helper_internet.rb +155 -0
- data/test/test_factory_helper_lorem.rb +87 -0
- data/test/test_factory_helper_name.rb +54 -0
- data/test/test_factory_helper_number.rb +77 -0
- data/test/test_factory_helper_slack_emoji.rb +45 -0
- data/test/test_factory_helper_street.rb +53 -0
- data/test/test_factory_helper_team.rb +13 -0
- data/test/test_factory_helper_time.rb +74 -0
- data/test/test_flexible.rb +57 -0
- data/test/test_fr_locale.rb +34 -0
- data/test/test_helper.rb +15 -0
- data/test/test_locale.rb +45 -0
- data/test/test_pl_locale.rb +27 -0
- metadata +144 -20
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
NTU2YzI1YzI4MjBkMmIyZTNjM2ZiZDE1ZmU0MTcwN2ViMTU1YzBkOQ==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2e1bbf8193f66356eb0c96f78e36c12cf8f0dec4
|
4
|
+
data.tar.gz: 483c42c0cd325d125d76cfa4edc26c176e016979
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
YWMwMGY1ZjNmM2VlMTMwOTY3ZWQ1NjA0ZDQzOWFiOWE1ZjI0Yjk2MmFkYTA0
|
11
|
-
YmJlOTdhYjc2NjYzMmRhNmVhMzQ1OTRmY2MzYjQ3YTRjZTdjNmM=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
Zjg5YjFmMDkyMTg2ODFiY2M0NmU1MWE2MGJkZGY2ZmIxMzJiNjRiYWE0MTE1
|
14
|
-
YTVlOGQ2N2ZiMGNmYzFiZjEzOTNmYzdhMTNjZDQxZTQwODg3NjFhMmEzOWUw
|
15
|
-
ZDMzOWMzZDE0Y2RlOGNmYzhkZmRmMzg5ZjY1MzM5NjI4NzM5OWU=
|
6
|
+
metadata.gz: 0378402ec5a16def1b1d9de50b67175814f30d549a04e85ac901b6ad9f0a0b8fc037f7eaca1b4109e2b363c1f5d89faeb3030666d71d1bafd99a727094a5793f
|
7
|
+
data.tar.gz: 00fecf659a4e149748da6dcd59550f4bc1b82f7d53d035677a4dc08ac3ab6587794fd4b915bc299fcbbb592a3025fc9b39cdb982f0f80653076b9f8ee6a69c28
|
data/spec/config_spec.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
RSpec.describe FactoryHelper::Config do
|
2
|
+
describe 'PRNG' do
|
3
|
+
specify '.random.seed' do
|
4
|
+
expect(FactoryHelper::Config.random.seed).to eq FactoryHelper::Config.seed
|
5
|
+
end
|
6
|
+
|
7
|
+
specify 'use Random for entropy' do
|
8
|
+
expect(Random).to receive(:new_seed)
|
9
|
+
FactoryHelper::Config.seed= nil
|
10
|
+
end
|
11
|
+
|
12
|
+
#use two entropy sources because "Starting with Unicorn 3.6.1, we have builtin workarounds for Kernel#rand and OpenSSL::Random users, but applications may use other PRNGs."
|
13
|
+
specify 'use Kernel.rand for entropy' do
|
14
|
+
expect(Kernel).to receive(:rand)
|
15
|
+
FactoryHelper::Config.seed= nil
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
RSpec.describe FactoryHelper::MySQL do
|
2
|
+
describe 'integers' do
|
3
|
+
specify 'tinyint is in-bounds' do
|
4
|
+
expect(-128.. 127).to include FactoryHelper::MySQL.tinyint
|
5
|
+
end
|
6
|
+
specify 'tinyint (unsigned) is in-bounds' do
|
7
|
+
expect(0.. 255).to include FactoryHelper::MySQL.tinyint(:unsigned => true)
|
8
|
+
end
|
9
|
+
|
10
|
+
specify 'smallint is in-bounds' do
|
11
|
+
expect(-32768.. 32767).to include FactoryHelper::MySQL.smallint
|
12
|
+
end
|
13
|
+
specify 'smallint (unsigned) is in-bounds' do
|
14
|
+
expect(0.. 65535).to include FactoryHelper::MySQL.smallint(:unsigned => true)
|
15
|
+
end
|
16
|
+
|
17
|
+
specify 'mediumint is in-bounds' do
|
18
|
+
expect(-8388608.. 8388607).to include FactoryHelper::MySQL.mediumint
|
19
|
+
end
|
20
|
+
specify 'mediumint (unsigned) is in-bounds' do
|
21
|
+
expect(0.. 16777215).to include FactoryHelper::MySQL.mediumint(:unsigned => true)
|
22
|
+
end
|
23
|
+
|
24
|
+
specify 'integer is in-bounds' do
|
25
|
+
expect(-2147483648.. 2147483647).to include FactoryHelper::MySQL.integer
|
26
|
+
end
|
27
|
+
specify 'integer (unsigned) is in-bounds' do
|
28
|
+
expect(0.. 4294967295).to include FactoryHelper::MySQL.integer(:unsigned => true)
|
29
|
+
end
|
30
|
+
|
31
|
+
specify 'bigint is in-bounds' do
|
32
|
+
expect(-9223372036854775808.. 9223372036854775807).to include FactoryHelper::MySQL.bigint
|
33
|
+
end
|
34
|
+
specify 'bigint (unsigned) is in-bounds' do
|
35
|
+
expect(0.. 18446744073709551615).to include FactoryHelper::MySQL.bigint(:unsigned => true)
|
36
|
+
end
|
37
|
+
|
38
|
+
specify 'int is in-bounds' do #MySQL aliases INT as INTEGER
|
39
|
+
expect(-2147483648.. 2147483647).to include FactoryHelper::MySQL.int
|
40
|
+
end
|
41
|
+
specify 'int (unsigned) is in-bounds' do #MySQL aliases INT as INTEGER
|
42
|
+
expect(0.. 4294967295).to include FactoryHelper::MySQL.int(:unsigned => true)
|
43
|
+
end
|
44
|
+
|
45
|
+
%w[tinyint smallint mediumint integer bigint int].each do |int_name|
|
46
|
+
['', ':unsigned => true'].each do |unsigned|
|
47
|
+
eval %Q[
|
48
|
+
describe '.#{int_name}' do
|
49
|
+
context '#{unsigned.empty? ? 'signed' : 'unsigned'}' do
|
50
|
+
it 'is an integer' do
|
51
|
+
expect(FactoryHelper::MySQL.#{int_name}(#{unsigned})
|
52
|
+
).to be_a_kind_of Integer
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'accepts minimum and maximum' do
|
56
|
+
expect(100.. 125).to include(
|
57
|
+
FactoryHelper::MySQL.#{int_name}(:min => 100, :max => 125, #{unsigned})
|
58
|
+
)
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'rejects only a minimum' do
|
62
|
+
expect{
|
63
|
+
FactoryHelper::MySQL.#{int_name}(:min => 100, #{unsigned})
|
64
|
+
}.to raise_error FactoryHelper::MySQL::ArgumentError
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'rejects only a maximum' do
|
68
|
+
expect{
|
69
|
+
FactoryHelper::MySQL.#{int_name}(:max => 100, #{unsigned})
|
70
|
+
}.to raise_error FactoryHelper::MySQL::ArgumentError
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'accepts no min/max' do
|
74
|
+
expect{FactoryHelper::MySQL.#{int_name}(#{unsigned})
|
75
|
+
}.to_not raise_error
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'rejects non-integer minimum' do
|
79
|
+
expect{
|
80
|
+
FactoryHelper::MySQL.#{int_name}(:min => 1.25, :max => 125, #{unsigned})
|
81
|
+
}.to raise_error FactoryHelper::MySQL::ArgumentError
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'rejects non-integer maximum' do
|
85
|
+
expect{
|
86
|
+
FactoryHelper::MySQL.#{int_name}(:min => 125, :max => 1.25, #{unsigned})
|
87
|
+
}.to raise_error FactoryHelper::MySQL::ArgumentError
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'rejects min/max mismatch' do
|
91
|
+
expect{
|
92
|
+
FactoryHelper::MySQL.#{int_name}(:min => 125, :max => 100, #{unsigned})
|
93
|
+
}.to raise_error FactoryHelper::MySQL::ArgumentError
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
]
|
98
|
+
end
|
99
|
+
|
100
|
+
eval %Q[
|
101
|
+
describe ".#{int_name} conflicting arguments" do
|
102
|
+
specify 'bounds negative when unsigned' do
|
103
|
+
expect{
|
104
|
+
FactoryHelper::MySQL.#{int_name}(min: -100, max: -3, unsigned: true)
|
105
|
+
}.to raise_error FactoryHelper::MySQL::ArgumentError
|
106
|
+
end
|
107
|
+
|
108
|
+
specify 'negative maximum when unsigned' do
|
109
|
+
expect{
|
110
|
+
FactoryHelper::MySQL.#{int_name}(min: 100, max: -3, unsigned: true)
|
111
|
+
}.to raise_error FactoryHelper::MySQL::ArgumentError
|
112
|
+
end
|
113
|
+
|
114
|
+
specify 'unsigned minimum below zero' do
|
115
|
+
expect{
|
116
|
+
FactoryHelper::MySQL.#{int_name}(min: -100, max: 3, unsigned: true)
|
117
|
+
}.to raise_error FactoryHelper::MySQL::ArgumentError
|
118
|
+
end
|
119
|
+
end
|
120
|
+
]
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
RSpec.describe FactoryHelper::String do
|
2
|
+
describe '.random' do
|
3
|
+
specify 'is String' do
|
4
|
+
expect(FactoryHelper::String.random).to be_a_kind_of String
|
5
|
+
end
|
6
|
+
|
7
|
+
specify 'is valid' do
|
8
|
+
expect(FactoryHelper::String.random.valid_encoding?).to be_truthy
|
9
|
+
end
|
10
|
+
|
11
|
+
specify 'default encoding' do
|
12
|
+
expect(FactoryHelper::String.random.encoding.to_s).to eq 'UTF-8'
|
13
|
+
end
|
14
|
+
|
15
|
+
specify 'default length' do
|
16
|
+
expect(FactoryHelper::String.random.length).to eq 32
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'length' do
|
20
|
+
specify 'nil' do
|
21
|
+
expect(FactoryHelper::String.random(nil).length).to eq 0
|
22
|
+
end
|
23
|
+
|
24
|
+
specify 'integer' do
|
25
|
+
len= [0, -1, 1, rand(500), rand(4096)- 2048].sample
|
26
|
+
expect(FactoryHelper::String.random(len).length).to eq [0, len].max
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'range' do
|
30
|
+
specify 'is accepted' do
|
31
|
+
range= (-5..30)
|
32
|
+
expect(range).to include FactoryHelper::String.random(range).length
|
33
|
+
end
|
34
|
+
|
35
|
+
specify 'is used' do
|
36
|
+
range= (42..42)
|
37
|
+
expect(FactoryHelper::String.random(range).length).to eq 42
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'array' do
|
42
|
+
specify 'is accepted' do
|
43
|
+
array= [0, -1, 1, 1024, rand(2048)]
|
44
|
+
expect(array).to include (FactoryHelper::String.random(array).length)
|
45
|
+
end
|
46
|
+
|
47
|
+
specify 'is used' do
|
48
|
+
num= rand(4096)- 2048
|
49
|
+
array= [num, num, num]
|
50
|
+
expect(FactoryHelper::String.random(array).length).to eq [0, num].max
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
RSpec.describe 'RSpec locale hooks', :order => :defined do
|
2
|
+
|
3
|
+
before(:all) do
|
4
|
+
I18n.reload!
|
5
|
+
@original_locale = I18n.locale
|
6
|
+
I18n.backend.store_translations(:ankh, :factory_helper => {})
|
7
|
+
I18n.locale = :ankh
|
8
|
+
end
|
9
|
+
|
10
|
+
after(:all) do
|
11
|
+
I18n.reload!
|
12
|
+
I18n.locale = @original_locale
|
13
|
+
end
|
14
|
+
|
15
|
+
specify 'locale defaults to I18n if not declared explicitly' do
|
16
|
+
expect(FactoryHelper::Config.locale).to eq :ankh
|
17
|
+
end
|
18
|
+
|
19
|
+
specify 'locale can be set within an example' do
|
20
|
+
FactoryHelper::Config.locale = :morpork
|
21
|
+
|
22
|
+
expect(FactoryHelper::Config.locale).to eq :morpork
|
23
|
+
end
|
24
|
+
|
25
|
+
specify 'locale reverts to I18n after each example' do
|
26
|
+
expect(FactoryHelper::Config.locale).to eq :ankh
|
27
|
+
end
|
28
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'coveralls'
|
2
|
+
Coveralls.wear_merged!
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'yaml'
|
6
|
+
require File.expand_path(File.dirname(__FILE__) + '/../lib/factory-helper')
|
7
|
+
|
8
|
+
YAML::ENGINE.yamler = 'psych' if defined? YAML::ENGINE
|
9
|
+
|
10
|
+
locales_path = File.expand_path(File.dirname(__FILE__) + '../lib/locales')
|
11
|
+
I18n.available_locales = Dir[locales_path + '/*'].map do |file|
|
12
|
+
file.split('.').first
|
13
|
+
end
|
14
|
+
I18n.enforce_available_locales = true
|
15
|
+
|
16
|
+
RSpec.configure do |config|
|
17
|
+
config.before(:suite) do
|
18
|
+
FactoryHelper::Config.locale = nil
|
19
|
+
end
|
20
|
+
|
21
|
+
config.after(:each) do
|
22
|
+
FactoryHelper::Config.locale = nil
|
23
|
+
end
|
24
|
+
|
25
|
+
# rspec-expectations config goes here. You can use an alternate
|
26
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
27
|
+
# assertions if you prefer.
|
28
|
+
config.expect_with :rspec do |expectations|
|
29
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
30
|
+
# and `failure_message` of custom matchers include text for helper methods
|
31
|
+
# defined using `chain`, e.g.:
|
32
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
33
|
+
# # => "be bigger than 2 and smaller than 4"
|
34
|
+
# ...rather than:
|
35
|
+
# # => "be bigger than 2"
|
36
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
37
|
+
end
|
38
|
+
|
39
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
40
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
41
|
+
config.mock_with :rspec do |mocks|
|
42
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
43
|
+
# a real object. This is generally recommended, and will default to
|
44
|
+
# `true` in RSpec 4.
|
45
|
+
mocks.verify_partial_doubles = true
|
46
|
+
end
|
47
|
+
|
48
|
+
# These two settings work together to allow you to limit a spec run
|
49
|
+
# to individual examples or groups you care about by tagging them with
|
50
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
51
|
+
# get run.
|
52
|
+
config.filter_run :focus
|
53
|
+
config.run_all_when_everything_filtered = true
|
54
|
+
|
55
|
+
# Limits the available syntax to the non-monkey patched syntax that is
|
56
|
+
# recommended. For more details, see:
|
57
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
58
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
59
|
+
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
|
60
|
+
config.disable_monkey_patching!
|
61
|
+
|
62
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
63
|
+
# be too noisy due to issues in dependencies.
|
64
|
+
config.warnings = true
|
65
|
+
|
66
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
67
|
+
# file, and it's useful to allow more verbose output when running an
|
68
|
+
# individual spec file.
|
69
|
+
if config.files_to_run.one?
|
70
|
+
# Use the documentation formatter for detailed output,
|
71
|
+
# unless a formatter has already been configured
|
72
|
+
# (e.g. via a command-line flag).
|
73
|
+
config.default_formatter = 'doc'
|
74
|
+
end
|
75
|
+
|
76
|
+
# Print the 10 slowest examples and example groups at the
|
77
|
+
# end of the spec run, to help surface which specs are running
|
78
|
+
# particularly slow.
|
79
|
+
# config.profile_examples = 10
|
80
|
+
|
81
|
+
# Run specs in random order to surface order dependencies. If you find an
|
82
|
+
# order dependency and want to debug it, you can fix the order by providing
|
83
|
+
# the seed, which is printed after each run.
|
84
|
+
# --seed 1234
|
85
|
+
config.order = :random
|
86
|
+
|
87
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
88
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
89
|
+
# test failures related to randomization by passing the same `--seed` value
|
90
|
+
# as the one that triggered the failure.
|
91
|
+
Kernel.srand config.seed
|
92
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper.rb'
|
2
|
+
|
3
|
+
# when these tests are run under Ruby 1.8.7, they will use the
|
4
|
+
# self-defined Array#sample method in lib/extensions/array and will test whether it
|
5
|
+
# behaves as the built-in Array#sample method from Ruby 1.9 or greater.
|
6
|
+
# Under Ruby 1.9, they simply use the built-in Array#sample method
|
7
|
+
class TestFakerArraySampleMethodCompatibility < Test::Unit::TestCase
|
8
|
+
|
9
|
+
def test_returns_nil_or_empty_array_with_empty_source
|
10
|
+
source = []
|
11
|
+
|
12
|
+
result = source.sample
|
13
|
+
assert result.nil?
|
14
|
+
|
15
|
+
result = source.sample(1)
|
16
|
+
assert_equal result, []
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_returns_one_array_elem_without_param
|
20
|
+
source = ['foo', 'bar']
|
21
|
+
result = source.sample
|
22
|
+
assert source.include? result
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_returns_empty_array_with_param_zero
|
26
|
+
source = ['foo', 'bar']
|
27
|
+
result = source.sample(0)
|
28
|
+
assert_equal result, []
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_returns_an_array_with_integer_param
|
32
|
+
source = ['foo', 'bar', 'baz']
|
33
|
+
result = source.sample(2)
|
34
|
+
assert result.is_a? Array
|
35
|
+
assert result.length == 2
|
36
|
+
assert((result - source).empty?)
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_returns_source_array_with_integer_param_equal_or_bigger_than_source_length
|
40
|
+
source = ['foo','bar']
|
41
|
+
result = source.sample(2)
|
42
|
+
assert result.is_a? Array
|
43
|
+
assert((source.sort <=> result.sort) == 0)
|
44
|
+
|
45
|
+
result = source.sample(3)
|
46
|
+
assert result.is_a? Array
|
47
|
+
assert((source.sort <=> result.sort) == 0)
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_raises_Argument_Error_with_negative_param
|
51
|
+
source = ['foo','bar']
|
52
|
+
assert_raise ArgumentError do
|
53
|
+
source.sample(-1)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper.rb')
|
2
|
+
|
3
|
+
class TestFakerAvatar < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@tester = Faker::Avatar
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_avatar
|
9
|
+
assert @tester.image.match(/http:\/\/robohash\.org\/(.+)\.png/)[1] != nil
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_avatar_with_param
|
13
|
+
assert @tester.image('factory_helper').match(/http:\/\/robohash\.org\/(.+)\.png/)[1] == 'factory_helper'
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_avatar_with_correct_size
|
17
|
+
assert @tester.image('factory_helper', '150x320').match(/http:\/\/robohash\.org\/factory_helper\.png\?size=(.+)/)[1] == '150x320'
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_avatar_with_incorrect_size
|
21
|
+
assert_raise ArgumentError do
|
22
|
+
@tester.image(nil, '150x320z')
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_avatar_with_supported_format
|
27
|
+
assert @tester.image('factory_helper', '300x300', 'jpg').match(/http:\/\/robohash\.org\/factory_helper\.jpg/)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_avatar_with_incorrect_format
|
31
|
+
assert_raise ArgumentError do
|
32
|
+
@tester.image(nil, '300x300', 'wrong_format')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper.rb')
|
2
|
+
|
3
|
+
class TesetFakerEnAuLocale < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
Faker::Config.locale = nil
|
6
|
+
end
|
7
|
+
|
8
|
+
def teardown
|
9
|
+
Faker::Config.locale = nil
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_au_ocker_methods_with_en_au_ocker_locale
|
13
|
+
Faker::Config.locale = 'en-au-ocker'
|
14
|
+
|
15
|
+
assert Faker::Name.first_name.is_a? String
|
16
|
+
assert Faker::Name.last_name.is_a? String
|
17
|
+
assert Faker::Name.ocker_first_name.is_a? String
|
18
|
+
assert Faker::Address.street_name.is_a? String
|
19
|
+
assert Faker::Address.city.is_a? String
|
20
|
+
assert Faker::Address.region.is_a? String
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|