forgery 0.4.3 → 0.8.1
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 +12 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +35 -0
- data/LICENSE +1 -1
- data/README.markdown +196 -60
- data/Rakefile +10 -54
- data/forgery.gemspec +23 -0
- data/lib/forgery.rb +0 -1
- data/lib/forgery/dictionaries/bics +7 -0
- data/lib/forgery/dictionaries/company_names +0 -1
- data/lib/forgery/dictionaries/currency_descriptions +2 -2
- data/lib/forgery/dictionaries/ibans +61 -0
- data/lib/forgery/dictionaries/job_titles +1 -1
- data/lib/forgery/dictionaries/zones +1 -2
- data/lib/forgery/extend.rb +0 -2
- data/lib/forgery/extensions/range.rb +1 -1
- data/lib/forgery/file_reader.rb +2 -1
- data/lib/forgery/forgery/bank_account.rb +25 -0
- data/lib/forgery/forgery/basic.rb +1 -1
- data/lib/forgery/forgery/credit_card.rb +71 -0
- data/lib/forgery/forgery/geo.rb +54 -0
- data/lib/forgery/forgery/internet.rb +7 -0
- data/lib/forgery/forgery/lorem_ipsum.rb +4 -4
- data/lib/forgery/forgery/russian_tax.rb +57 -0
- data/lib/forgery/forgery_railtie.rb +0 -29
- data/lib/forgery/formats/phone +1 -1
- data/lib/forgery/version.rb +3 -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 +33 -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/bank_account_spec.rb +16 -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 +89 -38
- data/lib/forgery/file_writer.rb +0 -54
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Forgery::RussianTax do
|
4
|
+
|
5
|
+
it 'bik should be 9 symbols' do
|
6
|
+
expect(Forgery::RussianTax.bik.length).to eq 9
|
7
|
+
end
|
8
|
+
|
9
|
+
it "bik should start with 04" do
|
10
|
+
expect(Forgery::RussianTax.bik[0,2]).to eq '04'
|
11
|
+
end
|
12
|
+
|
13
|
+
it "bik should have valid last part" do
|
14
|
+
expect(Forgery::RussianTax.bik[6,8].to_i).to be > 50
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'bik should be 20 symbols' do
|
18
|
+
expect(Forgery::RussianTax.account_number.length).to eq 20
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'legal inn' do
|
22
|
+
let(:inn) { Forgery::RussianTax.inn({ :type =>:legal }) }
|
23
|
+
|
24
|
+
it 'legal inn should be 10 symbols' do
|
25
|
+
expect(inn.length).to eq 10
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'leagl inn crc' do
|
29
|
+
mask = [2, 4, 10, 3, 5, 9, 4, 6, 8]
|
30
|
+
expect((0..(inn.length-2)).inject(0) {|crc, i| crc + inn[i].to_i*mask[i].to_i} % 11 % 10).to eq inn[9].chr.to_i
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'person inn' do
|
36
|
+
let(:inn) { Forgery::RussianTax.inn({ :type => :person }) }
|
37
|
+
|
38
|
+
it 'person inn should be 12 symbols' do
|
39
|
+
expect(inn.length).to eq 12
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'person inn crc 10' do
|
43
|
+
mask = [7, 2, 4, 10, 3, 5, 9, 4, 6, 8]
|
44
|
+
expect((0..(inn.length-3)).inject(0) {|crc, i| crc + inn[i].to_i*mask[i].to_i} % 11 % 10).to eq inn[10].chr.to_i
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'person inn crc 11' do
|
48
|
+
mask = [3, 7, 2, 4, 10, 3, 5, 9, 4, 6, 8]
|
49
|
+
expect((0..(inn.length-2)).inject(0) {|crc, i| crc + inn[i].to_i*mask[i].to_i} % 11 % 10).to eq inn[11].chr.to_i
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
context 'legal ogrn' do
|
55
|
+
let(:ogrn) { Forgery::RussianTax.ogrn({ :type => :legal }) }
|
56
|
+
|
57
|
+
it 'legal ogrn should be 13 symbols' do
|
58
|
+
expect(ogrn.length).to eq 13
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'legal ogrn should have valid crc' do
|
62
|
+
expect(ogrn[0..-2].to_i%11%10).to eq ogrn[-1].chr.to_i
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context 'person ogrn' do
|
67
|
+
let(:ogrn) { Forgery::RussianTax.ogrn({ :type => :person }) }
|
68
|
+
|
69
|
+
it 'person ogrn should be 15 symbols' do
|
70
|
+
expect(ogrn.length).to eq 15
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'person ogrn should have valid crc' do
|
74
|
+
expect(ogrn[0..-2].to_i%13%10).to eq ogrn[-1].chr.to_i
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'pathname'
|
3
|
+
|
4
|
+
describe Forgery do
|
5
|
+
it 'should load a dictionary when it is requested' do
|
6
|
+
Forgery.dictionaries.reset!
|
7
|
+
|
8
|
+
expect(Forgery.dictionaries).not_to be_loaded(:colors)
|
9
|
+
|
10
|
+
Forgery.dictionaries[:colors]
|
11
|
+
|
12
|
+
expect(Forgery.dictionaries).to be_loaded(:colors)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should load formats when it is requested' do
|
16
|
+
Forgery.formats.reset!
|
17
|
+
|
18
|
+
expect(Forgery.formats).not_to be_loaded(:phone)
|
19
|
+
|
20
|
+
Forgery.formats[:phone]
|
21
|
+
|
22
|
+
expect(Forgery.formats).to be_loaded(:phone)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should accept a symbol and return the appropriate forgery class' do
|
26
|
+
expect(Forgery(:address)).to eq(Forgery::Address)
|
27
|
+
expect(Forgery(:basic)).to eq(Forgery::Basic)
|
28
|
+
expect(Forgery(:internet)).to eq(Forgery::Internet)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should accept two symbols, finding the right class and calling the appropriate method' do
|
32
|
+
expect(Forgery::Address).to receive(:street_name)
|
33
|
+
Forgery(:address, :street_name)
|
34
|
+
|
35
|
+
expect(Forgery::Name).to receive(:full_name)
|
36
|
+
Forgery(:name, :full_name)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should accept two symbols and arguments, passing them along to the appropriate method' do
|
40
|
+
expect(Forgery::LoremIpsum).to receive(:text).with(:sentences, 2)
|
41
|
+
Forgery(:lorem_ipsum, :text, :sentences, 2)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should return the rails root path as a string if Rails.root is defined' do
|
45
|
+
Rails = Object.new
|
46
|
+
allow(Rails).to receive(:root).and_return(Pathname.new('/path/from/rails/dot/root'))
|
47
|
+
expect(Forgery.rails_root).to eq('/path/from/rails/dot/root')
|
48
|
+
Object.instance_eval { remove_const(:Rails) }
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should return nil when Rails.root and Rails.root are not defined' do
|
52
|
+
expect(Forgery.rails_root).to be_nil
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should not be a rails environment when there is not a rails_root' do
|
56
|
+
expect(Forgery.rails?).to be false
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should be a rails environment when there is a rails_root' do
|
60
|
+
allow(Forgery).to receive(:rails?).and_return(true)
|
61
|
+
expect(Forgery.rails?).to be true
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Forgery::Formats do
|
4
|
+
it "should check if the dictionary is loaded" do
|
5
|
+
formats = Forgery::Formats.new
|
6
|
+
|
7
|
+
formats[:phone]
|
8
|
+
|
9
|
+
expect(formats).to be_loaded(:phone)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should load a dictionary when called by the key" do
|
13
|
+
formats = Forgery::Formats.new
|
14
|
+
|
15
|
+
formats.reset!
|
16
|
+
|
17
|
+
expect(formats).not_to be_loaded(:phone)
|
18
|
+
|
19
|
+
formats[:phone]
|
20
|
+
|
21
|
+
expect(formats).to be_loaded(:phone)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should clear the loaded formats when calling reset!" do
|
25
|
+
formats = Forgery::Formats.new
|
26
|
+
|
27
|
+
formats[:phone]
|
28
|
+
|
29
|
+
expect(formats).to be_loaded(:phone)
|
30
|
+
|
31
|
+
formats.reset!
|
32
|
+
|
33
|
+
expect(formats).not_to be_loaded(:phone)
|
34
|
+
end
|
35
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'bundler/setup'
|
6
|
+
require 'forgery'
|
7
|
+
require 'ipaddr'
|
8
|
+
|
9
|
+
ENV["TESTING_VIA_RSPEC"] = "true"
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
class OnlyContain
|
16
|
+
def initialize(*expected)
|
17
|
+
@expected = [expected].flatten
|
18
|
+
end
|
19
|
+
|
20
|
+
def matches?(target)
|
21
|
+
@target = target.dup
|
22
|
+
@expected.each do |e|
|
23
|
+
target.gsub!(e, '')
|
24
|
+
end
|
25
|
+
target.size == 0
|
26
|
+
end
|
27
|
+
|
28
|
+
def failure_message
|
29
|
+
"expected #{@target} to only contain #{@expected.join(', ')}"
|
30
|
+
end
|
31
|
+
|
32
|
+
def failure_message
|
33
|
+
"expected #{@target} to not only contain #{@expected.join(', ')}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def only_contain(*expected)
|
38
|
+
OnlyContain.new(expected)
|
39
|
+
end
|
metadata
CHANGED
@@ -1,50 +1,54 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: forgery
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.8.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Nathan Sutton
|
9
8
|
- Brandon Arbini
|
9
|
+
- Kamil Kieliszczyk
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2020-07-23 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
17
|
-
requirement:
|
18
|
-
none: false
|
16
|
+
name: bundler
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
19
18
|
requirements:
|
20
|
-
- - ~>
|
19
|
+
- - "~>"
|
21
20
|
- !ruby/object:Gem::Version
|
22
|
-
version:
|
23
|
-
type: :
|
21
|
+
version: 2.1.4
|
22
|
+
type: :development
|
24
23
|
prerelease: false
|
25
|
-
version_requirements:
|
26
|
-
- !ruby/object:Gem::Dependency
|
27
|
-
name: rspec
|
28
|
-
requirement: &70093145961760 !ruby/object:Gem::Requirement
|
29
|
-
none: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
25
|
requirements:
|
31
|
-
- -
|
26
|
+
- - "~>"
|
32
27
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: *70093145961760
|
28
|
+
version: 2.1.4
|
37
29
|
description: Easy and customizable generation of forged data. Can be used as a gem
|
38
30
|
or a rails plugin. Includes rails generators for creating your own forgeries.
|
39
31
|
email:
|
40
32
|
- nate@zencoder.com
|
41
|
-
-
|
33
|
+
- b@arbini.dev
|
34
|
+
- kamil@kieliszczyk.net
|
42
35
|
executables: []
|
43
36
|
extensions: []
|
44
37
|
extra_rdoc_files: []
|
45
38
|
files:
|
46
|
-
-
|
39
|
+
- ".gitignore"
|
40
|
+
- ".travis.yml"
|
41
|
+
- Gemfile
|
42
|
+
- Gemfile.lock
|
43
|
+
- LICENSE
|
44
|
+
- README.markdown
|
45
|
+
- Rakefile
|
46
|
+
- forgery.gemspec
|
47
47
|
- generators/forgery/USAGE
|
48
|
+
- generators/forgery/forgery_generator.rb
|
49
|
+
- lib/forgery.rb
|
50
|
+
- lib/forgery/dictionaries.rb
|
51
|
+
- lib/forgery/dictionaries/bics
|
48
52
|
- lib/forgery/dictionaries/cities
|
49
53
|
- lib/forgery/dictionaries/colors
|
50
54
|
- lib/forgery/dictionaries/company_names
|
@@ -56,6 +60,7 @@ files:
|
|
56
60
|
- lib/forgery/dictionaries/female_first_names
|
57
61
|
- lib/forgery/dictionaries/frequencies
|
58
62
|
- lib/forgery/dictionaries/genders
|
63
|
+
- lib/forgery/dictionaries/ibans
|
59
64
|
- lib/forgery/dictionaries/industries
|
60
65
|
- lib/forgery/dictionaries/job_title_suffixes
|
61
66
|
- lib/forgery/dictionaries/job_titles
|
@@ -76,59 +81,105 @@ files:
|
|
76
81
|
- lib/forgery/dictionaries/streets
|
77
82
|
- lib/forgery/dictionaries/top_level_domains
|
78
83
|
- lib/forgery/dictionaries/zones
|
79
|
-
- lib/forgery/dictionaries.rb
|
80
84
|
- lib/forgery/extend.rb
|
81
85
|
- lib/forgery/extensions/array.rb
|
82
86
|
- lib/forgery/extensions/range.rb
|
83
87
|
- lib/forgery/extensions/string.rb
|
84
88
|
- lib/forgery/file_reader.rb
|
85
|
-
- lib/forgery/
|
89
|
+
- lib/forgery/forgery.rb
|
86
90
|
- lib/forgery/forgery/address.rb
|
91
|
+
- lib/forgery/forgery/bank_account.rb
|
87
92
|
- lib/forgery/forgery/basic.rb
|
93
|
+
- lib/forgery/forgery/credit_card.rb
|
88
94
|
- lib/forgery/forgery/currency.rb
|
89
95
|
- lib/forgery/forgery/date.rb
|
90
96
|
- lib/forgery/forgery/email.rb
|
97
|
+
- lib/forgery/forgery/geo.rb
|
91
98
|
- lib/forgery/forgery/internet.rb
|
92
99
|
- lib/forgery/forgery/lorem_ipsum.rb
|
93
100
|
- lib/forgery/forgery/monetary.rb
|
94
101
|
- lib/forgery/forgery/name.rb
|
95
102
|
- lib/forgery/forgery/personal.rb
|
103
|
+
- lib/forgery/forgery/russian_tax.rb
|
96
104
|
- lib/forgery/forgery/time.rb
|
97
|
-
- lib/forgery/forgery.rb
|
98
105
|
- lib/forgery/forgery_api.rb
|
99
106
|
- lib/forgery/forgery_railtie.rb
|
107
|
+
- lib/forgery/formats.rb
|
100
108
|
- lib/forgery/formats/phone
|
101
109
|
- lib/forgery/formats/street_number
|
102
110
|
- lib/forgery/formats/zip
|
103
|
-
- lib/forgery/formats.rb
|
104
111
|
- lib/forgery/version.rb
|
105
|
-
- lib/forgery.rb
|
106
112
|
- lib/generators/forgery/forgery_generator.rb
|
107
|
-
-
|
108
|
-
-
|
109
|
-
-
|
113
|
+
- spec/data/dictionaries/code_names
|
114
|
+
- spec/data/dictionaries/female_first_names
|
115
|
+
- spec/data/documents/mock_web_page.html
|
116
|
+
- spec/data/documents/mock_xml_doc.xml
|
117
|
+
- spec/dictionaries_spec.rb
|
118
|
+
- spec/extensions/array_spec.rb
|
119
|
+
- spec/extensions/range_spec.rb
|
120
|
+
- spec/extensions/string_spec.rb
|
121
|
+
- spec/file_reader_spec.rb
|
122
|
+
- spec/forgery/address_spec.rb
|
123
|
+
- spec/forgery/bank_account_spec.rb
|
124
|
+
- spec/forgery/basic_spec.rb
|
125
|
+
- spec/forgery/credit_card_spec.rb
|
126
|
+
- spec/forgery/currency_spec.rb
|
127
|
+
- spec/forgery/date_spec.rb
|
128
|
+
- spec/forgery/internet_spec.rb
|
129
|
+
- spec/forgery/lorem_ipsum_spec.rb
|
130
|
+
- spec/forgery/monetary_spec.rb
|
131
|
+
- spec/forgery/name_spec.rb
|
132
|
+
- spec/forgery/personal_spec.rb
|
133
|
+
- spec/forgery/russian_tax_spec.rb
|
134
|
+
- spec/forgery/time_spec.rb
|
135
|
+
- spec/forgery_spec.rb
|
136
|
+
- spec/formats_spec.rb
|
137
|
+
- spec/spec_helper.rb
|
110
138
|
homepage: http://github.com/sevenwire/forgery
|
111
139
|
licenses: []
|
140
|
+
metadata: {}
|
112
141
|
post_install_message:
|
113
142
|
rdoc_options: []
|
114
143
|
require_paths:
|
115
144
|
- lib
|
116
145
|
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
-
none: false
|
118
146
|
requirements:
|
119
|
-
- -
|
147
|
+
- - ">="
|
120
148
|
- !ruby/object:Gem::Version
|
121
149
|
version: '0'
|
122
150
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
|
-
none: false
|
124
151
|
requirements:
|
125
|
-
- -
|
152
|
+
- - ">="
|
126
153
|
- !ruby/object:Gem::Version
|
127
|
-
version:
|
154
|
+
version: 1.3.6
|
128
155
|
requirements: []
|
129
|
-
|
130
|
-
rubygems_version: 1.8.10
|
156
|
+
rubygems_version: 3.1.2
|
131
157
|
signing_key:
|
132
|
-
specification_version:
|
158
|
+
specification_version: 4
|
133
159
|
summary: Easy and customizable generation of forged data.
|
134
|
-
test_files:
|
160
|
+
test_files:
|
161
|
+
- spec/data/dictionaries/code_names
|
162
|
+
- spec/data/dictionaries/female_first_names
|
163
|
+
- spec/data/documents/mock_web_page.html
|
164
|
+
- spec/data/documents/mock_xml_doc.xml
|
165
|
+
- spec/dictionaries_spec.rb
|
166
|
+
- spec/extensions/array_spec.rb
|
167
|
+
- spec/extensions/range_spec.rb
|
168
|
+
- spec/extensions/string_spec.rb
|
169
|
+
- spec/file_reader_spec.rb
|
170
|
+
- spec/forgery/address_spec.rb
|
171
|
+
- spec/forgery/bank_account_spec.rb
|
172
|
+
- spec/forgery/basic_spec.rb
|
173
|
+
- spec/forgery/credit_card_spec.rb
|
174
|
+
- spec/forgery/currency_spec.rb
|
175
|
+
- spec/forgery/date_spec.rb
|
176
|
+
- spec/forgery/internet_spec.rb
|
177
|
+
- spec/forgery/lorem_ipsum_spec.rb
|
178
|
+
- spec/forgery/monetary_spec.rb
|
179
|
+
- spec/forgery/name_spec.rb
|
180
|
+
- spec/forgery/personal_spec.rb
|
181
|
+
- spec/forgery/russian_tax_spec.rb
|
182
|
+
- spec/forgery/time_spec.rb
|
183
|
+
- spec/forgery_spec.rb
|
184
|
+
- spec/formats_spec.rb
|
185
|
+
- spec/spec_helper.rb
|
data/lib/forgery/file_writer.rb
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'nokogiri'
|
3
|
-
require 'open-uri'
|
4
|
-
class Forgery
|
5
|
-
|
6
|
-
class FileWriter
|
7
|
-
|
8
|
-
# Creates a dictionary file with data from a web page
|
9
|
-
def self.create_dictionary(dictionary_name, source_url, *css_or_xpath)
|
10
|
-
doc = open_page(source_url)
|
11
|
-
lines = []
|
12
|
-
doc.search(*css_or_xpath).each do |node|
|
13
|
-
lines << node.content
|
14
|
-
end
|
15
|
-
raise empty_msg if lines.empty?
|
16
|
-
create_file(dictionary_name, lines)
|
17
|
-
end
|
18
|
-
|
19
|
-
# Path to which new dictionaries will be written
|
20
|
-
# '${GEM_HOME}/lib/forgery/dictionaries' by default
|
21
|
-
def self.write_path
|
22
|
-
@@write_path
|
23
|
-
end
|
24
|
-
|
25
|
-
# Sets path to which new dictionaries will be written
|
26
|
-
def self.write_to!(path)
|
27
|
-
@@write_path = File.expand_path path
|
28
|
-
end
|
29
|
-
|
30
|
-
private
|
31
|
-
# Creates file with a line for each item in the supplied array
|
32
|
-
def self.create_file(name, lines)
|
33
|
-
file_path = File.join(write_path, name)
|
34
|
-
File.open(file_path, "w") do |f|
|
35
|
-
lines.each do |line|
|
36
|
-
stripped_line = line.strip
|
37
|
-
f.puts stripped_line unless stripped_line.empty?
|
38
|
-
end
|
39
|
-
end
|
40
|
-
puts "Created file #{name} in #{write_path}" unless ENV["TESTING_VIA_RSPEC"]
|
41
|
-
file_path
|
42
|
-
end
|
43
|
-
|
44
|
-
# opens url and parses document
|
45
|
-
def self.open_page(url)
|
46
|
-
Nokogiri.parse(open url)
|
47
|
-
end
|
48
|
-
|
49
|
-
def self.empty_msg
|
50
|
-
msg = %q{No items found. Please double check your css or xpath selectors
|
51
|
-
and ensure that the site you are trying to reach does not block scripts. }
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|