forgery 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +6 -0
- data/.travis.yml +13 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +27 -0
- data/LICENSE +1 -1
- data/README.markdown +9 -5
- data/Rakefile +9 -1
- data/forgery.gemspec +23 -0
- data/lib/forgery/dictionaries/company_names +0 -1
- data/lib/forgery/dictionaries/currency_descriptions +2 -2
- data/lib/forgery/file_reader.rb +1 -0
- data/lib/forgery/forgery/geo.rb +54 -0
- data/lib/forgery/forgery/internet.rb +7 -0
- data/lib/forgery/forgery/russian_tax.rb +57 -0
- data/lib/forgery/version.rb +1 -1
- data/spec/data/dictionaries/code_names +6 -0
- data/spec/data/dictionaries/female_first_names +1 -0
- data/spec/data/documents/mock_web_page.html +17 -0
- data/spec/data/documents/mock_xml_doc.xml +5 -0
- data/spec/dictionaries_spec.rb +35 -0
- data/spec/extensions/array_spec.rb +25 -0
- data/spec/extensions/range_spec.rb +31 -0
- data/spec/extensions/string_spec.rb +29 -0
- data/spec/file_reader_spec.rb +32 -0
- data/spec/forgery/address_spec.rb +84 -0
- data/spec/forgery/basic_spec.rb +179 -0
- data/spec/forgery/credit_card_spec.rb +68 -0
- data/spec/forgery/currency_spec.rb +15 -0
- data/spec/forgery/date_spec.rb +134 -0
- data/spec/forgery/internet_spec.rb +62 -0
- data/spec/forgery/lorem_ipsum_spec.rb +132 -0
- data/spec/forgery/monetary_spec.rb +14 -0
- data/spec/forgery/name_spec.rb +11 -0
- data/spec/forgery/personal_spec.rb +15 -0
- data/spec/forgery/russian_tax_spec.rb +81 -0
- data/spec/forgery/time_spec.rb +7 -0
- data/spec/forgery_spec.rb +63 -0
- data/spec/formats_spec.rb +35 -0
- data/spec/spec_helper.rb +39 -0
- metadata +101 -64
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe String do
|
4
|
+
it "should change a single # to a number 0-9" do
|
5
|
+
(0..9).should include(Integer(Forgery::Extend("#").to_numbers))
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should change two #'s to two numbers 0-9" do
|
9
|
+
Forgery::Extend("##").to_numbers.split("").each do |s|
|
10
|
+
(0..9).should include(Integer(s))
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should only replace #'s in the string with numbers 0-9" do
|
15
|
+
s = Forgery::Extend('###-###-####')
|
16
|
+
n = s.to_numbers
|
17
|
+
0.upto(s.size - 1) do |i|
|
18
|
+
if s[i, 1] == "#"
|
19
|
+
('0'..'9').should include(n[i, 1])
|
20
|
+
else
|
21
|
+
('0'..'9').should_not include(n[i, 1])
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should allow the replacing of a different character" do
|
27
|
+
(0..9).should include(Integer(Forgery::Extend("-").to_numbers("-")))
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Forgery::FileReader do
|
4
|
+
it "should return an array when calling read_dictionary" do
|
5
|
+
Forgery::FileReader.read_dictionary(:colors).should be_is_a(Array)
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should return an array when calling read_format" do
|
9
|
+
Forgery::FileReader.read_format(:phone).should be_is_a(Array)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should override default dictionaries if Forgery#load_from! was called" do
|
13
|
+
Forgery.load_from! "spec/data"
|
14
|
+
Forgery::FileReader.read_dictionary(:female_first_names).should == %w(Amber)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should read dictionaries from custom places if Forgery#load_from! was called" do
|
18
|
+
Forgery.load_from! "spec/data"
|
19
|
+
Forgery::FileReader.read_dictionary(:code_names).should include('Shiretoko')
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should raise an exception if file wasn't found in load paths" do
|
23
|
+
lambda {
|
24
|
+
Forgery::FileReader.read_dictionary(:non_existing_dictionary)
|
25
|
+
}.should raise_error(ArgumentError)
|
26
|
+
end
|
27
|
+
after do
|
28
|
+
# reset load_paths
|
29
|
+
Forgery.load_paths.clear
|
30
|
+
Forgery.load_paths << File.expand_path("lib/forgery")
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Forgery::Address do
|
4
|
+
it "should return a random street" do
|
5
|
+
Forgery.dictionaries[:streets].should include(Forgery::Address.street_name)
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should return a random street number" do
|
9
|
+
original_format = Forgery::Address.street_number.gsub(/\d/, '#')
|
10
|
+
Forgery.formats[:street_number].should include(original_format)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should return a random street suffix" do
|
14
|
+
Forgery.dictionaries[:street_suffixes].should include(Forgery::Address.street_suffix)
|
15
|
+
end
|
16
|
+
|
17
|
+
describe ".street_address" do
|
18
|
+
before do
|
19
|
+
@split_address = Forgery::Address.street_address.split
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should return a random street suffix" do
|
23
|
+
street_suffix = @split_address.pop
|
24
|
+
Forgery.dictionaries[:street_suffixes].should include(street_suffix)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should return a random street number" do
|
28
|
+
street_number_format = @split_address.shift.gsub(/\d/, '#')
|
29
|
+
Forgery.formats[:street_number].should include(street_number_format)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should return a random street" do
|
33
|
+
@split_address.pop
|
34
|
+
@split_address.shift
|
35
|
+
street = @split_address.join(" ")
|
36
|
+
Forgery.dictionaries[:streets].should include(street)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should return a random city" do
|
41
|
+
city = Forgery::Address.city
|
42
|
+
Forgery.dictionaries[:cities].should include(city)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should return a random state" do
|
46
|
+
state = Forgery::Address.state
|
47
|
+
Forgery.dictionaries[:states].should include(state)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should return a random state abbreviation" do
|
51
|
+
state_abbrev = Forgery::Address.state_abbrev
|
52
|
+
Forgery.dictionaries[:state_abbrevs].should include(state_abbrev)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should return a random Canadian province or territory" do
|
56
|
+
province = Forgery::Address.province
|
57
|
+
Forgery.dictionaries[:provinces].should include(province)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should return a random Canadian province or territory abbreviation" do
|
61
|
+
province_abbrev = Forgery::Address.province_abbrev
|
62
|
+
Forgery.dictionaries[:province_abbrevs].should include(province_abbrev)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should return a random country" do
|
66
|
+
country = Forgery::Address.country
|
67
|
+
Forgery.dictionaries[:countries].should include(country)
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should return a random continent" do
|
71
|
+
continent = Forgery::Address.continent
|
72
|
+
Forgery.dictionaries[:continents].should include(continent)
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should return a random zip code" do
|
76
|
+
zip_format = Forgery::Address.zip.gsub(/\d/, '#')
|
77
|
+
Forgery.formats[:zip].should include(zip_format)
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should return a random phone number" do
|
81
|
+
phone_format = Forgery::Address.phone.gsub(/\d/, '#')
|
82
|
+
Forgery.formats[:phone].should include(phone_format)
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,179 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Forgery::Basic do
|
4
|
+
describe ".password" do
|
5
|
+
it "should only uppercase characters" do
|
6
|
+
Forgery::Basic.password(:allow_lower => false,
|
7
|
+
:allow_upper => true,
|
8
|
+
:allow_numeric => false,
|
9
|
+
:allow_special => false).should only_contain(Forgery::Basic::UPPER_ALPHA)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should only contain lowercase characters" do
|
13
|
+
Forgery::Basic.password(:allow_lower => true,
|
14
|
+
:allow_upper => false,
|
15
|
+
:allow_numeric => false,
|
16
|
+
:allow_special => false).should only_contain(Forgery::Basic::LOWER_ALPHA)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should only contain numeric characters" do
|
20
|
+
Forgery::Basic.password(:allow_lower => false,
|
21
|
+
:allow_upper => false,
|
22
|
+
:allow_numeric => true,
|
23
|
+
:allow_special => false).should only_contain(Forgery::Basic::NUMERIC)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should only contain special characters" do
|
27
|
+
Forgery::Basic.password(:allow_lower => false,
|
28
|
+
:allow_upper => false,
|
29
|
+
:allow_numeric => false,
|
30
|
+
:allow_special => true).should only_contain(Forgery::Basic::SPECIAL_CHARACTERS)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should only contain lower and uppercase characters" do
|
34
|
+
Forgery::Basic.password(:allow_lower => true,
|
35
|
+
:allow_upper => true,
|
36
|
+
:allow_numeric => false,
|
37
|
+
:allow_special => false).should only_contain(Forgery::Basic::LOWER_ALPHA,
|
38
|
+
Forgery::Basic::UPPER_ALPHA)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should only contain numeric and special characters" do
|
42
|
+
Forgery::Basic.password(:allow_lower => false,
|
43
|
+
:allow_upper => false,
|
44
|
+
:allow_numeric => true,
|
45
|
+
:allow_special => true).should only_contain(Forgery::Basic::NUMERIC,
|
46
|
+
Forgery::Basic::SPECIAL_CHARACTERS)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should contain any of the defined characters" do
|
50
|
+
Forgery::Basic.password(:allow_lower => true,
|
51
|
+
:allow_upper => true,
|
52
|
+
:allow_numeric => true,
|
53
|
+
:allow_special => true).should only_contain(Forgery::Basic::NUMERIC,
|
54
|
+
Forgery::Basic::SPECIAL_CHARACTERS,
|
55
|
+
Forgery::Basic::LOWER_ALPHA,
|
56
|
+
Forgery::Basic::UPPER_ALPHA)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe ".encrypt" do
|
61
|
+
it "should encrypt to hex digits" do
|
62
|
+
Forgery::Basic.encrypt("something").should only_contain(Forgery::Basic::HEX_DIGITS)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should encrypt different words to different output" do
|
66
|
+
Forgery::Basic.encrypt("foo").should_not == Forgery::Basic.encrypt("bar")
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should allow a salt that changes the output" do
|
70
|
+
Forgery::Basic.encrypt("foo", "baz").should_not == Forgery::Basic.encrypt("foo", "bar")
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should have the same output when encrypting twice" do
|
74
|
+
Forgery::Basic.encrypt("foo", "bar").should == Forgery::Basic.encrypt("foo", "bar")
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe ".boolean" do
|
79
|
+
it "should return true or false" do
|
80
|
+
[true, false].should include(Forgery::Basic.boolean)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe ".color" do
|
85
|
+
it "should return a random color" do
|
86
|
+
Forgery.dictionaries[:colors].should include(Forgery::Basic.color)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe ".hex_color" do
|
91
|
+
it "should return a 6-character hex color" do
|
92
|
+
Forgery::Basic.hex_color.should match(/#(#{Forgery::Basic::HEX_DIGITS.join('|')}){6}/)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe ".short_hex_color" do
|
97
|
+
it "should return a 3-character hex color" do
|
98
|
+
Forgery::Basic.short_hex_color.should match(/#(#{Forgery::Basic::HEX_DIGITS.join('|')}){3}/)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe ".number" do
|
103
|
+
it "should return a number >= the at_least option" do
|
104
|
+
Forgery::Basic.number(:at_least => 2).should >= 2
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should return a number <= the at_most option" do
|
108
|
+
Forgery::Basic.number(:at_most => 12).should <= 12
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe ".text" do
|
113
|
+
it "should return text whose length is >= the at_least option" do
|
114
|
+
Forgery::Basic.text(:at_least => 5).size.should >= 5
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should return text whose length is <= the at_most option" do
|
118
|
+
Forgery::Basic.text(:at_most => 15).size.should <= 15
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should return text whose length is == the exactly option" do
|
122
|
+
Forgery::Basic.text(:exactly => 20).size.should == 20
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should only uppercase characters" do
|
126
|
+
Forgery::Basic.text(:allow_lower => false,
|
127
|
+
:allow_upper => true,
|
128
|
+
:allow_numeric => false,
|
129
|
+
:allow_special => false).should only_contain(Forgery::Basic::UPPER_ALPHA)
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should only contain lowercase characters" do
|
133
|
+
Forgery::Basic.text(:allow_lower => true,
|
134
|
+
:allow_upper => false,
|
135
|
+
:allow_numeric => false,
|
136
|
+
:allow_special => false).should only_contain(Forgery::Basic::LOWER_ALPHA)
|
137
|
+
end
|
138
|
+
|
139
|
+
it "should only contain numeric characters" do
|
140
|
+
Forgery::Basic.text(:allow_lower => false,
|
141
|
+
:allow_upper => false,
|
142
|
+
:allow_numeric => true,
|
143
|
+
:allow_special => false).should only_contain(Forgery::Basic::NUMERIC)
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should only contain special characters" do
|
147
|
+
Forgery::Basic.text(:allow_lower => false,
|
148
|
+
:allow_upper => false,
|
149
|
+
:allow_numeric => false,
|
150
|
+
:allow_special => true).should only_contain(Forgery::Basic::SPECIAL_CHARACTERS)
|
151
|
+
end
|
152
|
+
|
153
|
+
it "should only contain lower and uppercase characters" do
|
154
|
+
Forgery::Basic.text(:allow_lower => true,
|
155
|
+
:allow_upper => true,
|
156
|
+
:allow_numeric => false,
|
157
|
+
:allow_special => false).should only_contain(Forgery::Basic::LOWER_ALPHA,
|
158
|
+
Forgery::Basic::UPPER_ALPHA)
|
159
|
+
end
|
160
|
+
|
161
|
+
it "should only contain numeric and special characters" do
|
162
|
+
Forgery::Basic.text(:allow_lower => false,
|
163
|
+
:allow_upper => false,
|
164
|
+
:allow_numeric => true,
|
165
|
+
:allow_special => true).should only_contain(Forgery::Basic::NUMERIC,
|
166
|
+
Forgery::Basic::SPECIAL_CHARACTERS)
|
167
|
+
end
|
168
|
+
|
169
|
+
it "should contain any of the defined characters" do
|
170
|
+
Forgery::Basic.text(:allow_lower => true,
|
171
|
+
:allow_upper => true,
|
172
|
+
:allow_numeric => true,
|
173
|
+
:allow_special => true).should only_contain(Forgery::Basic::NUMERIC,
|
174
|
+
Forgery::Basic::SPECIAL_CHARACTERS,
|
175
|
+
Forgery::Basic::LOWER_ALPHA,
|
176
|
+
Forgery::Basic::UPPER_ALPHA)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Forgery::CreditCard do
|
4
|
+
describe ".number" do
|
5
|
+
# basics
|
6
|
+
it "should be valid (pass a Luhn test)" do
|
7
|
+
valid_number?(Forgery::CreditCard.number).should eql(true)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should start with a valid prefix" do
|
11
|
+
which_type?(Forgery::CreditCard.number).should_not eql(false)
|
12
|
+
end
|
13
|
+
|
14
|
+
# type specified
|
15
|
+
it "should be valid if type specified" do
|
16
|
+
valid_number?(Forgery::CreditCard.number :type => 'Discover').should eql(true)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should start with a valid prefix for type specified" do
|
20
|
+
which_type?(Forgery::CreditCard.number :type => 'MasterCard').should eql(:master)
|
21
|
+
end
|
22
|
+
|
23
|
+
# type and length specified
|
24
|
+
it "should be valid if type and length specified" do
|
25
|
+
valid_number?(Forgery::CreditCard.number :type => 'Visa', :length => 13).should eql(true)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should be the length specified" do
|
29
|
+
(Forgery::CreditCard.number :type => 'Visa', :length => 13).length.should eql(13)
|
30
|
+
end
|
31
|
+
|
32
|
+
# length and prefixes specified
|
33
|
+
it "should be valid if length and prefixes specified" do
|
34
|
+
valid_number?(Forgery::CreditCard.number :length => 14, :prefixes => %w"300 301 302 303 36 38").should eql(true)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should be a valid Diners Club card, since its length and prefixes are specified" do
|
38
|
+
which_type?(Forgery::CreditCard.number :length => 14, :prefixes => %w"300 301 302 303 36 38").should eql(:diners)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe ".type" do
|
43
|
+
it "should return a valid type" do
|
44
|
+
which_type?(Forgery::CreditCard.number :type => Forgery::CreditCard.type).should_not eql(false)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# helper functions below originally from: https://gist.github.com/1182499
|
49
|
+
def valid_number?(number)
|
50
|
+
number.reverse!
|
51
|
+
relative_number = {'0' => 0, '1' => 2, '2' => 4, '3' => 6, '4' => 8, '5' => 1, '6' => 3, '7' => 5, '8' => 7, '9' => 9}
|
52
|
+
sum = 0
|
53
|
+
number.split("").each_with_index do |n, i|
|
54
|
+
sum += (i % 2 == 0) ? n.to_i : relative_number[n]
|
55
|
+
end
|
56
|
+
sum % 10 == 0
|
57
|
+
end
|
58
|
+
|
59
|
+
def which_type?(number)
|
60
|
+
return :diners if number.length == 14 && number =~ /^3(0[0-5]|[68])/ # 300xxx-305xxx, 36xxxx, 38xxxx
|
61
|
+
return :amex if number.length == 15 && number =~ /^3[47]/ # 34xxxx, 37xxxx
|
62
|
+
return :visa if [13,16].include?(number.length) && number =~ /^4/ # 4xxxxx
|
63
|
+
return :master if number.length == 16 && number =~ /^5[1-5]/ # 51xxxx-55xxxx
|
64
|
+
return :discover if number.length == 16 && number =~ /^6011/ # 6011xx
|
65
|
+
return false
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Forgery::Currency do
|
4
|
+
describe ".currency_descriptions" do
|
5
|
+
it "should be able to generate a currency description" do
|
6
|
+
Forgery::Currency.description.should_not eql(nil)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe ".currency_codes" do
|
11
|
+
it "should have the same output when encrypting twice" do
|
12
|
+
Forgery::Currency.code.should_not eql(nil)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,134 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'date'
|
3
|
+
|
4
|
+
describe Forgery::Date do
|
5
|
+
describe '.day_of_week' do
|
6
|
+
it 'should return a day of the week' do
|
7
|
+
Date::DAYNAMES.should include(Forgery::Date.day_of_week)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '.day_of_week(:abbr => true)' do
|
12
|
+
it 'should return a day of the week in abbreviated form' do
|
13
|
+
Date::ABBR_DAYNAMES.should include(Forgery::Date.day_of_week(:abbr => true))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '.month' do
|
18
|
+
it 'should return a valid month' do
|
19
|
+
Date::MONTHNAMES.should include(Forgery::Date.month)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '.month(:abbr => true)' do
|
24
|
+
it 'should return a valid month in abbreviated form' do
|
25
|
+
Date::ABBR_MONTHNAMES.should include(Forgery::Date.month(:abbr => true))
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '.month(:numerical => true)' do
|
30
|
+
it 'should return a valid month in numeric form' do
|
31
|
+
[1,2,3,4,5,6,7,8,9,10,11,12].should include(Forgery::Date.month(:numerical => true))
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe '.year' do
|
36
|
+
it 'should return a valid year within 20 years of the current year' do
|
37
|
+
year = Forgery::Date.year
|
38
|
+
year.should > Date.today.year - 21
|
39
|
+
year.should < Date.today.year + 21
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe '.year(:future => true)' do
|
44
|
+
it 'should return a year greater than the current one' do
|
45
|
+
year = Forgery::Date.year(:future => true)
|
46
|
+
year.should >= Date.today.year
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe '.year(:min_delta => 5, :max_delta => 5, :future => true)' do
|
51
|
+
it 'should return a year 5 years from the current one' do
|
52
|
+
year = Forgery::Date.year(:min_delta => 5, :max_delta => 5, :future => true)
|
53
|
+
year.should == Date.today.year + 5
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe '.year(:min_delta => 5, :max_delta => 10, :future => true)' do
|
58
|
+
it 'should return a year that is between 5 and 10 years greater than the current one' do
|
59
|
+
year = Forgery::Date.year(:min_delta => 5, :max_delta => 10, :future => true)
|
60
|
+
(0..5).map { |i| Date.today.year + i + 5 }.should include(year)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe '.year(:past => true)' do
|
65
|
+
it 'should return a year less than the current one' do
|
66
|
+
year = Forgery::Date.year(:past => true)
|
67
|
+
year.should <= Date.today.year
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe '.year(:min_delta => 5, :max_delta => 5, :past => true)' do
|
72
|
+
it 'should return a year 5 years until the current one' do
|
73
|
+
year = Forgery::Date.year(:min_delta => 5, :max_delta => 5, :past => true)
|
74
|
+
year.should == Date.today.year - 5
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe '.year(:min_delta => 5, :max_delta => 10, :past => true)' do
|
79
|
+
it 'should return a year that is between 5 and 10 years less than the current one' do
|
80
|
+
year = Forgery::Date.year(:min_delta => 5, :max_delta => 10, :past => true)
|
81
|
+
(0..5).map { |i| Date.today.year - i - 5 }.should include(year)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe '.date' do
|
86
|
+
it 'should return a valid date within 7300 days of the current date' do
|
87
|
+
date = Forgery::Date.date
|
88
|
+
date.should > Date.today - 7300
|
89
|
+
date.should < Date.today + 7300
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe '.date(:future => true)' do
|
94
|
+
it 'should return a date greater than the current one' do
|
95
|
+
date = Forgery::Date.date(:future => true)
|
96
|
+
date.should >= Date.today
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe '.date(:min_delta => 5, :max_delta => 5, :future => true)' do
|
101
|
+
it 'should return a date 5 days from the current one' do
|
102
|
+
date = Forgery::Date.date(:min_delta => 5, :max_delta => 5, :future => true)
|
103
|
+
date.should == Date.today + 5
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
describe '.date(:min_delta => 5, :max_delta => 10, :future => true)' do
|
108
|
+
it 'should return a date that is between 5 and 10 days greater than the current one' do
|
109
|
+
date = Forgery::Date.date(:min_delta => 5, :max_delta => 10, :future => true)
|
110
|
+
(0..5).map { |i| Date.today + i + 5 }.should include(date)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe '.date(:past => true)' do
|
115
|
+
it 'should return a date less than the current one' do
|
116
|
+
date = Forgery::Date.date(:past => true)
|
117
|
+
date.should <= Date.today
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
describe '.date(:min_delta => 5, :max_delta => 5, :past => true)' do
|
122
|
+
it 'should return a date 5 days until the current one' do
|
123
|
+
date = Forgery::Date.date(:min_delta => 5, :max_delta => 5, :past => true)
|
124
|
+
date.should == Date.today - 5
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
describe '.date(:min_delta => 5, :max_delta => 10, :past => true)' do
|
129
|
+
it 'should return a date that is between 5 and 10 days less than the current one' do
|
130
|
+
date = Forgery::Date.date(:min_delta => 5, :max_delta => 10, :past => true)
|
131
|
+
(0..5).map { |i| Date.today - i - 5 }.should include(date)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|