data_magic 0.10 → 0.11
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +10 -1
- data/README.md +27 -0
- data/features/data_magic.feature +6 -1
- data/features/step_definitions/data_magic_steps.rb +4 -0
- data/features/yaml/example.yml +5 -0
- data/lib/data_magic/translation.rb +36 -5
- data/lib/data_magic/version.rb +1 -1
- metadata +4 -4
data/ChangeLog
CHANGED
@@ -1,4 +1,13 @@
|
|
1
|
-
|
1
|
+
=== Version 0.11 / 2012-12-22
|
2
|
+
* Enhancements
|
3
|
+
* Added title translator
|
4
|
+
* Added ability for street_address translator to also include secondary address
|
5
|
+
* Added ability for email_address to accept the name portion of the value
|
6
|
+
* Added url translator
|
7
|
+
* Added cell_phone translator
|
8
|
+
* Changed phone_number translator so it does not return an extension
|
9
|
+
|
10
|
+
=== Version 0.10 / 2012-12-8
|
2
11
|
* Enhancements
|
3
12
|
* Added randomize translator to return random selection from Array or Range
|
4
13
|
* Added mask translator which accepts a mask. Will replace # with number, A with upper case letter, and a with lower case letter
|
data/README.md
CHANGED
@@ -41,12 +41,39 @@ end
|
|
41
41
|
|
42
42
|
Notice that I am including the module on line 3. On lin 8 I am calling the _data_for_ method passing the key _:my_page_. The _populate_page_with_ method is a part of the page-object gem.
|
43
43
|
|
44
|
+
Your data might look something like this:
|
45
|
+
|
46
|
+
my_page:
|
47
|
+
name: Cheezy
|
48
|
+
address: 123 Main Street
|
49
|
+
email: cheezy@example.com
|
50
|
+
pay_type: 'Credit card'
|
51
|
+
|
44
52
|
In order to access the data directly you can just call the method on the module like this:
|
45
53
|
|
46
54
|
````ruby
|
47
55
|
my_data = DataMagic.data_for :my_test
|
48
56
|
````
|
49
57
|
|
58
|
+
## Data generators
|
59
|
+
|
60
|
+
You can call one of many built-in methods in your yaml file to randomize the data. Here is an example of how you would randomize the above yaml:
|
61
|
+
|
62
|
+
my_page:
|
63
|
+
name: ~full_name
|
64
|
+
address: ~street_address
|
65
|
+
email: ~email_address
|
66
|
+
pay_type: ~randomize ['Credit card', 'Purchase order', 'Check']
|
67
|
+
|
68
|
+
|
69
|
+
## Documentation
|
70
|
+
|
71
|
+
The rdocs for this project can be found at [rubydoc.info](http://rubydoc.info/github/cheezy/data_magic/master/frames).
|
72
|
+
|
73
|
+
To see the changes from release to release please look at the [ChangeLog](https://raw.github.com/cheezy/data_magic/master/ChangeLog)
|
74
|
+
|
75
|
+
|
76
|
+
|
50
77
|
## Known Issues
|
51
78
|
|
52
79
|
See [http://github.com/cheezy/data_magic/issues](http://github.com/cheezy/data_magic/issues)
|
data/features/data_magic.feature
CHANGED
@@ -14,9 +14,11 @@ Feature: Functionality of the data_magic gem
|
|
14
14
|
And the value for "last_name" should be 1 word long
|
15
15
|
And the value for "name_prefix" should be 1 word long
|
16
16
|
And the value for "name_suffix" should be 1 word long
|
17
|
+
And the value for "title" should have a minimum of 3 words
|
17
18
|
|
18
19
|
Scenario: Getting addresses from the yaml
|
19
20
|
Then the value for "street" should have a minimum of 2 words
|
21
|
+
And the value for "street_plus" should have a minimum of 4 words
|
20
22
|
And the value for "city" should have a minimum of 1 word
|
21
23
|
And the value for "state" should have a minimum of 1 word
|
22
24
|
And the value for "state_ab" should be 1 word long
|
@@ -29,11 +31,14 @@ Feature: Functionality of the data_magic gem
|
|
29
31
|
|
30
32
|
Scenario: Getting an email address from the yaml
|
31
33
|
Then the value for "email" should be 1 word long
|
34
|
+
And the value for "email_plus" should include "buddy"
|
32
35
|
And the value for "domain_name" should be 1 word long
|
33
36
|
And the value for "user_name" should be 1 word long
|
37
|
+
And the value for "url" should include "http://"
|
34
38
|
|
35
39
|
Scenario: Getting a phone number
|
36
|
-
Then the value for "phone" should
|
40
|
+
Then the value for "phone" should be 1 word long
|
41
|
+
And the value for "cell" should be 1 word long
|
37
42
|
|
38
43
|
Scenario: Random phrases
|
39
44
|
Then the value for "catch_phrase" should exist
|
@@ -69,3 +69,7 @@ Then /^the value for "(.*?)" should end with (\d+) lower case letters$/ do |key,
|
|
69
69
|
value = @data[key]
|
70
70
|
value[-1 * num.to_i,num.to_i].downcase.should == value[-3,3]
|
71
71
|
end
|
72
|
+
|
73
|
+
Then /^the value for "(.*?)" should include "(.*?)"$/ do |key, value|
|
74
|
+
@data[key].should include value
|
75
|
+
end
|
data/features/yaml/example.yml
CHANGED
@@ -7,6 +7,7 @@ dm:
|
|
7
7
|
name_prefix: ~name_prefix
|
8
8
|
name_suffix: ~name_suffix
|
9
9
|
street: ~street_address
|
10
|
+
street_plus: ~street_address(true)
|
10
11
|
city: ~city
|
11
12
|
state: ~state
|
12
13
|
state_ab: ~state_abbr
|
@@ -15,9 +16,12 @@ dm:
|
|
15
16
|
second_address: ~secondary_address
|
16
17
|
company: ~company_name
|
17
18
|
email: ~email_address
|
19
|
+
email_plus: ~email_address('buddy')
|
18
20
|
domain_name: ~domain_name
|
21
|
+
url: ~url
|
19
22
|
user_name: ~user_name
|
20
23
|
phone: ~phone_number
|
24
|
+
cell: ~cell_phone
|
21
25
|
catch_phrase: ~catch_phrase
|
22
26
|
words: ~words
|
23
27
|
sentence: ~sentence
|
@@ -29,6 +33,7 @@ dm:
|
|
29
33
|
random: ~randomize ['Tom', 'Dick', 'Harry']
|
30
34
|
range: ~randomize 1..5
|
31
35
|
mask: ~mask "###-AAA_aaa"
|
36
|
+
title: ~title
|
32
37
|
|
33
38
|
other:
|
34
39
|
name: Cheezy
|
@@ -35,11 +35,18 @@ module DataMagic
|
|
35
35
|
Faker::Name.suffix
|
36
36
|
end
|
37
37
|
|
38
|
+
#
|
39
|
+
# return a random title
|
40
|
+
#
|
41
|
+
def title
|
42
|
+
Faker::Name.title
|
43
|
+
end
|
44
|
+
|
38
45
|
#
|
39
46
|
# return a random street address
|
40
47
|
#
|
41
|
-
def street_address
|
42
|
-
Faker::Address.street_address
|
48
|
+
def street_address(include_secondary=false)
|
49
|
+
Faker::Address.street_address(include_secondary)
|
43
50
|
end
|
44
51
|
|
45
52
|
#
|
@@ -137,8 +144,8 @@ module DataMagic
|
|
137
144
|
#
|
138
145
|
# return a random email address
|
139
146
|
#
|
140
|
-
def email_address
|
141
|
-
Faker::Internet.email
|
147
|
+
def email_address(name=nil)
|
148
|
+
Faker::Internet.email(name)
|
142
149
|
end
|
143
150
|
|
144
151
|
#
|
@@ -148,6 +155,13 @@ module DataMagic
|
|
148
155
|
Faker::Internet.domain_name
|
149
156
|
end
|
150
157
|
|
158
|
+
#
|
159
|
+
# return a random url
|
160
|
+
#
|
161
|
+
def url
|
162
|
+
Faker::Internet.url
|
163
|
+
end
|
164
|
+
|
151
165
|
#
|
152
166
|
# return a random user name
|
153
167
|
#
|
@@ -159,7 +173,16 @@ module DataMagic
|
|
159
173
|
# return a random phone number
|
160
174
|
#
|
161
175
|
def phone_number
|
162
|
-
Faker::PhoneNumber.phone_number
|
176
|
+
value = Faker::PhoneNumber.phone_number
|
177
|
+
remove_extension(value)
|
178
|
+
end
|
179
|
+
|
180
|
+
#
|
181
|
+
# return a random cell number
|
182
|
+
#
|
183
|
+
def cell_phone
|
184
|
+
value = Faker::PhoneNumber.cell_phone
|
185
|
+
remove_extension(value)
|
163
186
|
end
|
164
187
|
|
165
188
|
#
|
@@ -191,5 +214,13 @@ module DataMagic
|
|
191
214
|
end
|
192
215
|
result
|
193
216
|
end
|
217
|
+
|
218
|
+
private
|
219
|
+
|
220
|
+
def remove_extension(phone)
|
221
|
+
index = phone.index('x')
|
222
|
+
phone = phone[0, (index-1)] if index
|
223
|
+
phone
|
224
|
+
end
|
194
225
|
end
|
195
226
|
end
|
data/lib/data_magic/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: data_magic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.11'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-12-
|
12
|
+
date: 2012-12-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faker
|
@@ -122,7 +122,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
122
122
|
version: '0'
|
123
123
|
segments:
|
124
124
|
- 0
|
125
|
-
hash:
|
125
|
+
hash: 4075926568841345413
|
126
126
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
127
|
none: false
|
128
128
|
requirements:
|
@@ -131,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
131
131
|
version: '0'
|
132
132
|
segments:
|
133
133
|
- 0
|
134
|
-
hash:
|
134
|
+
hash: 4075926568841345413
|
135
135
|
requirements: []
|
136
136
|
rubyforge_project:
|
137
137
|
rubygems_version: 1.8.24
|