fig_magic 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +7 -0
  2. data/.DS_Store +0 -0
  3. data/.gitignore +17 -0
  4. data/.idea/.name +1 -0
  5. data/.idea/.rakeTasks +7 -0
  6. data/.idea/FigMagic.iml +33 -0
  7. data/.idea/atlassian-ide-plugin.xml +5 -0
  8. data/.idea/encodings.xml +6 -0
  9. data/.idea/misc.xml +14 -0
  10. data/.idea/modules.xml +8 -0
  11. data/.idea/workspace.xml +776 -0
  12. data/.rspec +2 -0
  13. data/.ruby-gemset +1 -0
  14. data/.ruby-version +1 -0
  15. data/ChangeLog +2 -0
  16. data/Gemfile +12 -0
  17. data/Guardfile +16 -0
  18. data/LICENSE +22 -0
  19. data/README.md +145 -0
  20. data/Rakefile +25 -0
  21. data/config/data/default.yml +3 -0
  22. data/config/data/user.yml +3 -0
  23. data/config/environments/default.yml +1 -0
  24. data/config/yaml/sample.yml +1 -0
  25. data/config/yaml/test_config.yml +14 -0
  26. data/cucumber.yml +2 -0
  27. data/features/data_magic.feature +124 -0
  28. data/features/defaults.feature +8 -0
  29. data/features/fig_newton.feature +85 -0
  30. data/features/step_definitions/data_magic_steps.rb +164 -0
  31. data/features/step_definitions/fig_newton_steps.rb +95 -0
  32. data/features/support/env.rb +9 -0
  33. data/features/yaml/another.yml +9 -0
  34. data/features/yaml/example.yml +56 -0
  35. data/fig_magic.gemspec +25 -0
  36. data/lib/fig_magic/core_ext/fixnum.rb +11 -0
  37. data/lib/fig_magic/core_ext/string.rb +5 -0
  38. data/lib/fig_magic/date_translation.rb +73 -0
  39. data/lib/fig_magic/missing.rb +35 -0
  40. data/lib/fig_magic/node.rb +15 -0
  41. data/lib/fig_magic/standard_translation.rb +316 -0
  42. data/lib/fig_magic/translation.rb +14 -0
  43. data/lib/fig_magic/version.rb +3 -0
  44. data/lib/fig_magic.rb +93 -0
  45. data/spec/lib/data_magic_spec.rb +60 -0
  46. data/spec/lib/translation_spec.rb +312 -0
  47. data/spec/spec_helper.rb +30 -0
  48. metadata +158 -0
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ fig_magic
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.1.7
data/ChangeLog ADDED
@@ -0,0 +1,2 @@
1
+ === Version 0.1 / 2012-1-21
2
+ Initial Release
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'rake'
4
+ gem 'rb-fsevent', :require => false if RUBY_PLATFORM =~ /darwin/i
5
+ gem 'growl'
6
+ gem 'guard-rspec'
7
+ gem 'guard-cucumber'
8
+ gem 'fuubar'
9
+ gem 'fuubar-cucumber'
10
+
11
+ # Specify your gem's dependencies in fig_magic.gemspec
12
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,16 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec', cmd: 'rspec --color --format Fuubar' do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { "spec" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+ end
9
+
10
+ guard 'cucumber', :notification => true, :cli => '--profile focus' do
11
+ watch(%r{^features/.+\.feature$})
12
+ watch(%r{^features/support/.+$}) { 'features' }
13
+ watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' }
14
+ watch(%r{^lib/.+\.rb$}) { 'features' }
15
+ watch(%r{^features/yaml/.+$}) { 'features' }
16
+ end
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Jeffrey S. Morgan
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,145 @@
1
+ # fig_magic
2
+
3
+ [![Build Status](http://travis-ci.org/cheezy/fig_magic.png)](http://travis-ci.org/cheezy/fig_magic)
4
+
5
+ An easy to use gem that provides datasets that can be used by your application
6
+ and tests. The data is stored in yaml files.
7
+
8
+ ## Using
9
+
10
+ In order to use _fig_magic_ you will have to inform the gem where it can find the yaml files. You can do this with the following code:
11
+
12
+ ````ruby
13
+ FigMagic.yml_directory = 'data/yml'
14
+ ````
15
+
16
+ If you do not specify a directory the gem will default to using a directory named _config/data_.
17
+
18
+ After setting the directory you must load a file. This can be accomplished by calling the _load_ method.
19
+
20
+ ````ruby
21
+ FigMagic.load 'filename.yml'
22
+ ````
23
+
24
+ If you do not specify a filename the gem will attempt to use a file named _default.yml_. If you are using this for testing you will more than likely want to call load before each test to load the proper data for the specific test, or use the namespaced keys method, detailed below.
25
+
26
+ Another option is to set an environment variable DATA_MAGIC_FILE. When this is set it will be used instead of the _default.yml_ file.
27
+
28
+ The final thing to do is use the data. The gem has a `data_for` method that will return the data for a specific key. The most common way to use this is to include the _FigMagic_ module in a [page-object](https://github.com/cheezy/page-object) and then populate a page with the data. Here's an example:
29
+
30
+ ````ruby
31
+ class MyPage
32
+ include PageObject
33
+ include FigMagic
34
+
35
+ ...
36
+
37
+ def populate_page
38
+ populate_page_with data_for :my_page
39
+ end
40
+ end
41
+ ````
42
+
43
+ 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.
44
+
45
+ To organize your data into namespaces, and load that data just in time for testing, use namespaced keys instead:
46
+
47
+ ````ruby
48
+ page.populate_page_with data_for "user_form/valid"
49
+ ````
50
+
51
+ This will load `user_form.yml`, and populate the page with the `valid:` record therein.
52
+
53
+ Your data might look something like this:
54
+
55
+ my_page:
56
+ name: Cheezy
57
+ address: 123 Main Street
58
+ email: cheezy@example.com
59
+ pay_type: 'Credit card'
60
+
61
+ In order to access the data directly you can just call the method on the module like this:
62
+
63
+ ````ruby
64
+ page = MyPage.new
65
+ my_data = page.data_for :my_test
66
+ ````
67
+
68
+ ## Data generators
69
+
70
+ 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:
71
+
72
+ my_page:
73
+ name: ~full_name
74
+ address: ~street_address
75
+ email: ~email_address
76
+ pay_type: ~randomize ['Credit card', 'Purchase order', 'Check']
77
+
78
+ Here is a list of the built-in methods:
79
+
80
+ | built-in methods | built-in methods |
81
+ | --- | --- |
82
+ | first_name last_name |
83
+ | last_name | full_name |
84
+ | name_prefix | name_suffix |
85
+ | title | street_address(include_secondary=false) |
86
+ | secondary_address | city |
87
+ | state | state_abbr |
88
+ | zip_code | country |
89
+ | company_name | catch_phrase |
90
+ | words(number = 3) | sentence(min_word_count = 4) |
91
+ | sentences(sentence_count = 3) | paragraphs(paragraph_count = 3) |
92
+ | characters(character_count = 255) | email_address(name = nil) |
93
+ | domain_name | url |
94
+ | user_name |
95
+ | phone_number | cell_phone |
96
+ | randomize([]) | randomize(1..4) |
97
+ | mask - #=num a=lower A=upper |
98
+ | today(format = '%D') | tomorrow(format = '%D') |
99
+ | yesterday(format = '%D') |
100
+ | 3.days_from_today(format = '%D') | 3.days_ago(format = '%D') |
101
+ | month | month_abbr |
102
+ | day_of_week | day_of_week_abbr |
103
+ | sequential([]) | sequential(1..4)|
104
+
105
+
106
+ If you wish to add your own built-in methods you can simply pass a module
107
+ to _FigMagic_ and all of the methods will be available.
108
+
109
+ ````ruby
110
+ module MyData
111
+ def abc
112
+ 'abc'
113
+ end
114
+ end
115
+
116
+ FigMagic.add_translator MyData # this line must go in the same file as the module
117
+
118
+ # can now use ~abc in my yml files
119
+ ````
120
+
121
+ ## Documentation
122
+
123
+ The rdocs for this project can be found at [rubydoc.info](http://rubydoc.info/github/cheezy/fig_magic/master/frames).
124
+
125
+ To see the changes from release to release please look at the [ChangeLog](https://raw.github.com/cheezy/fig_magic/master/ChangeLog)
126
+
127
+
128
+
129
+ ## Known Issues
130
+
131
+ See [http://github.com/cheezy/fig_magic/issues](http://github.com/cheezy/fig_magic/issues)
132
+
133
+ ## Contributing
134
+
135
+ Please ensure all contributions contain proper tests.
136
+
137
+ 1. Fork it
138
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
139
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
140
+ 4. Push to the branch (`git push origin my-new-feature`)
141
+ 5. Create new Pull Request
142
+
143
+ ## Copyright
144
+
145
+ Copyright (c) 2012-2013 Jeffrey S. Morgan. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env rake
2
+ require 'bundler/gem_tasks'
3
+
4
+ require 'rspec/core/rake_task'
5
+ require 'cucumber'
6
+ require 'cucumber/rake/task'
7
+
8
+ RSpec::Core::RakeTask.new(:spec) do |spec|
9
+ spec.ruby_opts = "-I lib:spec"
10
+ spec.pattern = 'spec/**/*_spec.rb'
11
+ end
12
+ task :spec
13
+
14
+ Cucumber::Rake::Task.new(:features, "Run features") do |t|
15
+ t.profile = "default"
16
+ end
17
+
18
+ desc 'Run all specs and cukes'
19
+ task :test => ['spec', 'features']
20
+
21
+ task :lib do
22
+ $LOAD_PATH.unshift(File.expand_path("lib", File.dirname(__FILE__)))
23
+ end
24
+
25
+ task :default => :test
@@ -0,0 +1,3 @@
1
+ dm:
2
+ value1: this is value 1
3
+ value2: this is value 2
@@ -0,0 +1,3 @@
1
+ valid:
2
+ name: Testy McTesterson
3
+ job: Tester
@@ -0,0 +1 @@
1
+ base_url: 'http://cheezyworld.com'
@@ -0,0 +1 @@
1
+ from_the_env_file: read from the env file
@@ -0,0 +1,14 @@
1
+ base_url: 'http://cheezyworld.com'
2
+
3
+ database:
4
+ username: steve
5
+ password: secret
6
+
7
+ first:
8
+ second:
9
+ third: foo
10
+ fourth: bar
11
+
12
+ port: 1234
13
+ set_flag: true
14
+ cleared_flag: false
data/cucumber.yml ADDED
@@ -0,0 +1,2 @@
1
+ default: --no-source --color --format pretty
2
+ focus: --no-source --color --format pretty --tags @focus
@@ -0,0 +1,124 @@
1
+ Feature: Functionality of the fig_magic gem
2
+
3
+ Background:
4
+ Given I have read the yaml file from features/yaml
5
+ When I ask for the data for "dm"
6
+
7
+ Scenario: Getting basic data from the yaml
8
+ Then the value for "value1" should be "this is value 1"
9
+ And the value for "value2" should be "this is value 2"
10
+
11
+ Scenario: Getting names from the yaml
12
+ Then the value for "full_name" should have a minimum of 2 words
13
+ And the value for "first_name" should be 1 word long
14
+ And the value for "last_name" should be 1 word long
15
+ And the value for "name_prefix" should be 1 word long
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
18
+
19
+ Scenario: Getting addresses from the yaml
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
22
+ And the value for "city" should have a minimum of 1 word
23
+ And the value for "state" should have a minimum of 1 word
24
+ And the value for "state_ab" should be 1 word long
25
+ And the value for "zip" should be 1 word long
26
+ And the value for "country" should have a minimum of 1 word
27
+ And the value for "second_address" should have a minimum of 1 words
28
+
29
+ Scenario: Getting a company name from the yaml
30
+ Then the value for "company" should have a minimum of 1 word
31
+
32
+ Scenario: Getting an email address from the yaml
33
+ Then the value for "email" should be 1 word long
34
+ And the value for "email_plus" should include "buddy"
35
+ And the value for "domain_name" should be 1 word long
36
+ And the value for "user_name" should be 1 word long
37
+ And the value for "url" should include "http://"
38
+
39
+ Scenario: Getting a phone number
40
+ Then the value for "phone" should be a phone number
41
+ And the value for "cell" should be a phone number
42
+
43
+ Scenario: Random phrases
44
+ Then the value for "catch_phrase" should exist
45
+ And the value for "words" should exist
46
+ And the value for "sentence" should exist
47
+ And the value for "sentences" should exist
48
+ And the value for "paragraphs" should exist
49
+ And the value for "characters" should be 255 characters long
50
+
51
+ Scenario: Boolean values
52
+ Then the value for "bool_true" should be true
53
+ And the value for "bool_false" should be false
54
+
55
+ Scenario: Reading multiple data segments
56
+ When I ask for the data for "other"
57
+ Then the value for "name" should be "Cheezy"
58
+ And the value for "address" should be "123 Main Street"
59
+ And the value for "email" should be "cheezy@example.com"
60
+
61
+ Scenario: Reading from multiple yml files
62
+ When I load the file "another.yml"
63
+ And I ask for the data for "other_file"
64
+ Then the value for "name" should be "Sneezy"
65
+ And the value for "address" should be "555 Easy Money Drive"
66
+ And the value for "email" should be "sneezy@example.com"
67
+
68
+ Scenario: Reading multiple entries from same file
69
+ When I load the file "another.yml"
70
+ And I ask for the data for "other_file"
71
+ Then the value for "name" should be "Sneezy"
72
+ When I ask for the data for "more_info"
73
+ Then the value for "name" should be "Wheezy"
74
+ And the value for "address" should be "999 Alergy Ave"
75
+ And the value for "email" should be "wheezy@example.com"
76
+
77
+ Scenario: Returning a randomly selected value from an array
78
+ Then the value for "random" should be either "Tom", "Dick", or "Harry"
79
+ And the value for "range" should be between 1 and 5
80
+
81
+ Scenario: Returning a sequential value from an array
82
+ Then the first value for the sequential data should be "first"
83
+ When I ask for the data again
84
+ Then the second value for the sequential data should be "second"
85
+ When I ask for the data again
86
+ Then the third value for the sequential data should be "third"
87
+
88
+ Scenario: Returning a value based on a mask
89
+ Then the value for "mask" should begin with 3 numbers
90
+ And the value for "mask" should have 3 upper case letters after a dash
91
+ And the value for "mask" should end with 3 lower case letters
92
+
93
+ Scenario: Returning dates
94
+ Then the value for "today" should be today's date
95
+ And the value for "tomorrow" should be tomorrow's date
96
+ And the value for "yesterday" should be yesterday's date
97
+
98
+ Scenario: Specifying number of days from today
99
+ Then the value for "5daysfromtoday" should be five days from today
100
+ And the value for "5daysago" should be five days ago
101
+
102
+ Scenario: Getting a random month name
103
+ Then the value for "some_month" should be a valid month
104
+
105
+ Scenario: Getting a random month abbreviation
106
+ Then the value for "month_abbr" should be a valid month abbreviation
107
+
108
+ Scenario: Getting a random day name
109
+ Then the value for "some_day" should be a valid day
110
+
111
+ Scenario: Getting a random day abbreviation
112
+ Then the value for "day_abbr" should be a valid day abbreviation
113
+
114
+ Scenario: It should allow one to add new translator methods
115
+ When I add the blah translator
116
+ Then the value for "blah" should be "foobar"
117
+
118
+ Scenario: Getting values from nested entries
119
+ Then the nested value for this is_nested should be "Nested Value"
120
+
121
+ Scenario: Should be able to call the translator methods on FigMagic module
122
+ Then I should be able to call the full_name translator
123
+ And I should be able to call the state translator
124
+ And I should be able to call the today translator
@@ -0,0 +1,8 @@
1
+ Feature: Default file and directory functionality of the fig_magic gem
2
+
3
+ Scenario: Using the default file and directory
4
+ Given I have read the default yaml file from the default location
5
+ When I ask for the data for "dm"
6
+ Then the value for "value1" should be "this is value 1"
7
+ And the value for "value2" should be "this is value 2"
8
+
@@ -0,0 +1,85 @@
1
+ Feature: Functionality of the fig_newton gem
2
+
3
+ Scenario: Getting basic configuration data from a yml config file
4
+ Given I have read the configuration file
5
+ When I ask for the value for "base_url"
6
+ Then I should see "http://cheezyworld.com"
7
+
8
+ Scenario: Requesting data that does not exist should result in error
9
+ Given I have read the configuration file
10
+ When I ask for a value that does not exist named "does_not_exist"
11
+ Then I should raise a NoMethodError exception
12
+
13
+ Scenario: Getting the default filename from an environment variable
14
+ Given I have an environment variable named "FIG_NEWTON_FILE" set to "sample.yml"
15
+ When I ask for the value for "from_the_env_file"
16
+ Then I should see "read from the env file"
17
+
18
+ Scenario: Using a file that has the same name as the hostname
19
+ Given I have a yml file that is named after the hostname
20
+ When I ask for the value for "from_the_hostname_file"
21
+ Then I should see "read from the hostname file"
22
+ And I should remove the file
23
+
24
+ Scenario: Requesting data that contains a node of additional data
25
+ Given I have read the configuration file
26
+ When I ask for the value for "database"
27
+ Then I should have a node
28
+ And the "username" value for the node should be "steve"
29
+ And the "password" value for the node should be "secret"
30
+
31
+ Scenario: Requesting data from multiple nested data
32
+ Given I have read the configuration file
33
+ When I ask for the value for "first"
34
+ And I ask for the node value for "second"
35
+ Then the "third" value for the node should be "foo"
36
+ And the "fourth" value for the node should be "bar"
37
+
38
+ Scenario: Using default directory and file
39
+ Given I have read the default file from the default directory
40
+ When I ask for the value for "base_url"
41
+ Then I should see "http://cheezyworld.com"
42
+
43
+ Scenario: Requesting a numerical value
44
+ Given I have read the configuration file
45
+ When I ask for the value for "port"
46
+ Then I should see 1234
47
+
48
+ Scenario: Requesting a true boolean value
49
+ Given I have read the configuration file
50
+ When I ask for the value for "set_flag"
51
+ Then I should see true
52
+
53
+ Scenario: Requesting a false boolean value
54
+ Given I have read the configuration file
55
+ When I ask for the value for "cleared_flag"
56
+ Then I should see false
57
+
58
+ Scenario: Requesting data from a node can be converted to a hash
59
+ Given I have read the configuration file
60
+ When I ask for the value for "database"
61
+ Then I should have a node
62
+ And the hash of values should look like:
63
+ | username | steve |
64
+ | password | secret |
65
+
66
+ Scenario: Requesting data that does not exist but has a default value should return the default value
67
+ Given I have read the configuration file
68
+ When I ask for a value that does not exist named "does_not_exist" that has a default value "the default value"
69
+ Then I should see "the default value"
70
+
71
+ Scenario: Requesting data that does not exist but has a default block should return the block result
72
+ Given I have read the configuration file
73
+ When I ask for a value that does not exist named "does_not_exist" that has a default block returning "the default value"
74
+ Then I should see "the default value"
75
+
76
+ Scenario: Requesting data that does not exist but has a default lambda should return the lambda result
77
+ Given I have read the configuration file
78
+ When I ask for a value that does not exist named "does_not_exist" that has a default lambda returning "the default value"
79
+ Then I should see "the default value"
80
+ And the lambda should be passed the property "does_not_exist"
81
+
82
+ Scenario: Requesting data that does not exist but has a default proc should return the proc result
83
+ Given I have read the configuration file
84
+ When I ask for a value that does not exist named "does_not_exist" that has a default proc returning "the default value"
85
+ Then I should see "the default value"
@@ -0,0 +1,164 @@
1
+ class TestClass
2
+ include FigMagic
3
+ end
4
+
5
+
6
+ Given /^I have read the yaml file from features\/yaml$/ do
7
+ FigMagic.yml_directory = 'features/yaml'
8
+ FigMagic.load "example.yml"
9
+ end
10
+
11
+ Given /^I have read the default yaml file from the default location$/ do
12
+
13
+ end
14
+
15
+ When /^I ask for the data for "(.+)"$/ do |key|
16
+ TestClass.instance_variable_set "@private_firstsecond_index", 0
17
+ @tc = TestClass.new
18
+ @data = @tc.data_for key
19
+ end
20
+
21
+
22
+ Then /^the value for "(.+)" should be "(.+)"$/ do |key, value|
23
+ expect(@data[key]).to eql value
24
+ end
25
+
26
+ Then /^the value for "(.+)" should be (true|false)$/ do |key, value|
27
+ expect(@data[key]).to eql eval(value)
28
+ end
29
+
30
+ Then /^the value for "(.+)" should be (\d+) word|words long$/ do |key, length|
31
+ expect(@data[key].split(' ').size).to eql length.to_i
32
+ end
33
+
34
+ Then /^the value for "(.+)" should have a minimum of (\d+) word|wordss$/ do |key, length|
35
+ expect(@data[key].split(' ').size).to be >= length.to_i
36
+ end
37
+
38
+ Then /^the value for "(.*?)" should be (\d+) characters long$/ do |key, length|
39
+ expect(@data[key].length).to eql length.to_i
40
+ end
41
+
42
+ Then /^the value for "(.+)" should exist$/ do |key|
43
+ expect(@data[key]).not_to be_nil
44
+ end
45
+
46
+ When /^I load the file "(.+)"$/ do |file_name|
47
+ FigMagic.yml_directory = 'config/data'
48
+ FigMagic.load file_name
49
+ end
50
+
51
+ Then /^the value for "(.*?)" should be either "(.*?)", "(.*?)", or "(.*?)"$/ do |key, vala, valb, valc|
52
+ expect([vala, valb, valc]).to include @data[key]
53
+ end
54
+
55
+ Then /^the value for "(.*?)" should be between (\d+) and (\d+)$/ do |key, low, high|
56
+ value = @data[key]
57
+ expect(value).to be >= low.to_i
58
+ expect(value).to be <= high.to_i
59
+ end
60
+
61
+ Then /^the value for "(.*?)" should begin with (\d+) numbers$/ do |key, num|
62
+ value = @data[key]
63
+ expect(value[0,num.to_i].is_integer).to be true
64
+ end
65
+
66
+ Then /^the value for "(.*?)" should have (\d+) upper case letters after a dash$/ do |key, num|
67
+ value = @data[key]
68
+ expect(value[4,num.to_i].upcase).to eql value[4,3]
69
+ end
70
+
71
+ Then /^the value for "(.*?)" should end with (\d+) lower case letters$/ do |key, num|
72
+ value = @data[key]
73
+ expect(value[-1 * num.to_i,num.to_i].downcase).to eql value[-3,3]
74
+ end
75
+
76
+ Then /^the value for "(.*?)" should include "(.*?)"$/ do |key, value|
77
+ expect(@data[key]).to include value
78
+ end
79
+
80
+ Then /^the value for "(.*?)" should be today\'s date$/ do |key|
81
+ expect(@data[key]).to eql Date.today.strftime('%D')
82
+ end
83
+
84
+ Then /^the value for "(.*?)" should be tomorrow\'s date$/ do |key|
85
+ tomorrow = Date.today + 1
86
+ expect(@data[key]).to eql tomorrow.strftime('%D')
87
+ end
88
+
89
+ Then /^the value for "(.*?)" should be yesterday\'s date$/ do |key|
90
+ yesterday = Date.today - 1
91
+ expect(@data[key]).to eql yesterday.strftime('%D')
92
+ end
93
+
94
+ Then /^the value for "(.*?)" should be five days from today$/ do |key|
95
+ the_day = Date.today + 5
96
+ expect(@data[key]).to eql the_day.strftime('%D')
97
+ end
98
+
99
+ Then /^the value for "(.*?)" should be five days ago$/ do |key|
100
+ the_day = Date.today - 5
101
+ expect(@data[key]).to eql the_day.strftime('%D')
102
+ end
103
+
104
+ Then /^the value for "(.*?)" should be a valid month$/ do |key|
105
+ months = %w[January February March April May June July August September October November December]
106
+ expect(months).to include @data[key]
107
+ end
108
+
109
+ Then /^the value for "(.*?)" should be a valid month abbreviation$/ do |key|
110
+ months = %w[Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec]
111
+ expect(months).to include @data[key]
112
+ end
113
+
114
+ Then /^the value for "(.*?)" should be a valid day$/ do |key|
115
+ days = %w[Sunday Monday Tuesday Wednesday Thursday Friday Saturday]
116
+ expect(days).to include @data[key]
117
+ end
118
+
119
+ Then /^the value for "(.*?)" should be a valid day abbreviation$/ do |key|
120
+ days = %w[Sun Mon Tue Wed Thu Fri Sat]
121
+ expect(days).to include @data[key]
122
+ end
123
+
124
+ When /^I add the blah translator$/ do
125
+ module Blah
126
+ def blah
127
+ 'foobar'
128
+ end
129
+ end
130
+ FigMagic.add_translator(Blah)
131
+
132
+ class TranslatorAdded
133
+ include FigMagic
134
+ end
135
+ ta = TranslatorAdded.new
136
+ @data = ta.data_for 'dynamic'
137
+ end
138
+
139
+ Then(/^the (?:first|second|third) value for the sequential data should be "(.*?)"$/) do |value|
140
+ expect(@data['ordered']).to eql value
141
+ end
142
+
143
+ When(/^I ask for the data again$/) do
144
+ @data = @tc.data_for 'dm'
145
+ end
146
+
147
+ Then(/^the nested value for this is_nested should be "(.*?)"$/) do |value|
148
+ expect(@data['this']['is_nested']).to eql value
149
+ end
150
+
151
+ Then(/^the value for "(.*?)" should be a phone number$/) do |value|
152
+ phone = @data[value]
153
+ if phone.split(' ').length == 2
154
+ expect(phone).to include "("
155
+ expect(phone).to include ")"
156
+ else
157
+ expect(phone.split(' ').length).to eql 1
158
+ end
159
+ end
160
+
161
+ Then(/^I should be able to call the (.+) translator$/) do |method|
162
+ value = FigMagic.send method
163
+ expect(value).not_to be_empty
164
+ end