new_data_magic 1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8f5dc75eb29b8be63fd7c58614169a929af267c62fd71ee17522a4608b5c55b6
4
+ data.tar.gz: f973f4e29a9a0c074a9f57e132fa271d2bf53901a2e7165fb0dccff854b4dd42
5
+ SHA512:
6
+ metadata.gz: 9741ab6ea9632ae0752e4818a573c2706179f58579ea085528300dc9c6101e5447ea14b81d70ba1d2783e4594fbccbedb85bc0e4804031f665b0e2a36ad4ea99
7
+ data.tar.gz: 32ff1d495db9d306865139790e71cb4fc9862c79a3e970f80ff38e0e90a642979b8917cff98f4d38fd7c46e99eade369aa660c93a39bd9b7c8c6fd914f39e6d9
data/.DS_Store ADDED
Binary file
data/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .idea
19
+ .byebug_history
20
+ .rakeTasks
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ data_magic
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.5.1
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3
4
+ - 2.4
5
+
6
+
data/ChangeLog ADDED
@@ -0,0 +1,142 @@
1
+ == Version 1.2 / 2017-09-23
2
+ * Enhancements
3
+ * Data is translated each time a request is made for data (Thanks Vveliev)
4
+ * Array handling and translation (Thanks Vveliev)
5
+
6
+ == Version 1.1 / 2016-08-03
7
+ * Fixes
8
+ * Update so it works well on Ruby 2.4 (thanks Robert MacCracken)
9
+
10
+ === Version 1.0 / 2016-11-23
11
+ * Enhancements
12
+ * Allow merged to be a Hash of Hashes and find key that matches (thanks Donavan Stanley)
13
+ * Allow you to specify file to load with tag when using Cucumber (thanks Donavan Stanley)
14
+
15
+ === Version 0.22 / 2015-12-2
16
+ * Enhancements
17
+ * Better handling for nexted hash translation (thanks vveliev)
18
+
19
+ === Version 0.21 / 2015-4-12
20
+ * Enhancements
21
+ * Added support for locale
22
+ * Added credit_card_number translator
23
+ * Added credit_card_type translator
24
+
25
+ === Version 0.20 / 2014-9-21
26
+ * Enhancements
27
+ * Added the ability to nest entries under headings
28
+ * Added the ability to call the translation methods directlry on DataMagic module
29
+
30
+ === Version 0.19 / 2014-6-1
31
+ * Enhancements
32
+ * Can now include ERB in the yml file due to update in yml_reader
33
+
34
+ === Version 0.18 / 2014-3-2
35
+ * Enhancements
36
+ * Can now set the file to be used by setting a DATA_MAGIC_FILE environment file
37
+ * Fixes
38
+ * Only forcing available locales if it is available
39
+
40
+ === Version 0.17 / 2014-1-22
41
+ * Fixes
42
+ * Eliminated the deprecation message from I18n
43
+
44
+ === Version 0.16.1 / 2013-9-1
45
+ * Fixes
46
+ * Removed pry require
47
+
48
+ === Version 0.16 / 2013-8-31
49
+ * Enhancements
50
+ * Ability to support namespaces which will load a file with same name as namespace (Thanks Ben Cullen-Kerney)
51
+
52
+ === Version 0.15.2 / 2013-7-17
53
+ * Fixes
54
+ * Display better message when key is not found (Thanks Guillaume Malette)
55
+ * Properly handling numeric values (Thanks Guillaume Malette)
56
+
57
+ === Version 0.15.1 / 2013-7-11
58
+ * Fixes
59
+ * Fixed error when using sequential with entries that have spaces
60
+
61
+ === Version 0.15 / 2013-7-10
62
+ * Enhancements
63
+ * Added sequential translator
64
+
65
+ === Version 0.14 / 2013-2-14
66
+ * Enhancements
67
+ * Added months_abbr translator
68
+ * Added day_of_week translator
69
+ * Added day_of_week_abbr translator
70
+ * Changed so translator methods are not call after mixing with class
71
+
72
+ === Version 0.13 / 2013-2-7
73
+ * Enhancements
74
+ * Added add_translator method to DataMagic to allow custom translators to be added
75
+ * Added months translator
76
+ * Added dm_* aliases for all generators
77
+
78
+ === Version 0.12 / 2012-12-28
79
+ * Enhancements
80
+ * Added today translator
81
+ * Added tomorrow translator
82
+ * Added yesterday translator
83
+ * Added days_from_today to Fixnum to provide translator
84
+ * Added days_ago to Fixnum to provide translator
85
+
86
+ === Version 0.11 / 2012-12-22
87
+ * Enhancements
88
+ * Added title translator
89
+ * Added ability for street_address translator to also include secondary address
90
+ * Added ability for email_address to accept the name portion of the value
91
+ * Added url translator
92
+ * Added cell_phone translator
93
+ * Changed phone_number translator so it does not return an extension
94
+
95
+ === Version 0.10 / 2012-12-8
96
+ * Enhancements
97
+ * Added randomize translator to return random selection from Array or Range
98
+ * Added mask translator which accepts a mask. Will replace # with number, A with upper case letter, and a with lower case letter
99
+
100
+ === Version 0.9 / 2012-8-18
101
+ * Enhancements
102
+ * Added name_prefix translator
103
+ * Added name_suffix translator
104
+ * Added domain_name translator
105
+ * Added user_name translator
106
+ * Added characters translator
107
+
108
+ === Version 0.8 / 2012-6-9
109
+ * Enhancements
110
+ * Made yml writable
111
+ * Updated yml_reader dependency to version 0.2
112
+
113
+ === Version 0.7 / 2012-5-17
114
+ * Enhancements
115
+ * Refactored to use yml_reader to remove duplication
116
+ * Changed default directory from 'config' to 'config/data'
117
+ * Fixes
118
+ * Removed unused classes after refactoring
119
+
120
+ === Version 0.6 / 2012-5-4
121
+ * Fixes
122
+ * Minor fix so it works properly with ruby 1.8.7
123
+
124
+ === Version 0.5 / 2012-3-24
125
+ * Enhancements
126
+ * Added ability to use symbol for the key in the data_for method
127
+
128
+ === Version 0.4 / 2012-2-27
129
+ * Enhancements
130
+ * Support for boolean types (thanks jonbettinger)
131
+
132
+ === Version 0.3 / 2012-2-5
133
+ * Added additional data merge to #data_for
134
+
135
+ === Version 0.2 / 2012-1-26
136
+ * Defaulted yaml file to 'default.yaml'
137
+ * Cloned hash so data can be reused
138
+ * Renamed #name translation method to #full_name
139
+ * Renamed #email translation method to #email_address
140
+
141
+ === Version 0.1 / 2012-1-21
142
+ Initial Release
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'http://rubygems.org'
4
+
5
+ gem 'byebug'
6
+ gem 'fuubar'
7
+ gem 'growl'
8
+ gem 'guard-cucumber'
9
+ gem 'guard-rspec'
10
+ gem 'rake'
11
+ gem 'rb-fsevent', require: false if RUBY_PLATFORM =~ /darwin/i
12
+
13
+ # Specify your gem's dependencies in new_data_magic.gemspec
14
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ # A sample Guardfile
4
+ # More info at https://github.com/guard/guard#readme
5
+
6
+ guard 'rspec', cmd: 'rspec --color --format Fuubar' do
7
+ watch(%r{^spec/.+_spec\.rb$})
8
+ watch(%r{^lib/(.+)\.rb$}) { 'spec' }
9
+ watch('spec/spec_helper.rb') { 'spec' }
10
+ end
11
+
12
+ guard 'cucumber', notification: true, cli: '--profile focus' do
13
+ watch(%r{^features/.+\.feature$})
14
+ watch(%r{^features/support/.+$}) { 'features' }
15
+ watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' }
16
+ watch(%r{^lib/.+\.rb$}) { 'features' }
17
+ watch(%r{^features/yaml/.+$}) { 'features' }
18
+ 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,42 @@
1
+ # data_magic (updated version)
2
+
3
+ This gem is ported from the original data_magic gem -> [here](https://github.com/cheezy/data_magic). Please read the original documentation first.
4
+ I created this to make sure the gem stays updated with its dependencies. (The original gem seems to be unmaintained)
5
+
6
+ ## How to Use
7
+ Requirement:
8
+ * Ruby >= 2.5.1
9
+ * Faker >= 1.9
10
+
11
+ Update your Gemfile to
12
+
13
+ ````ruby
14
+ gem 'data_magic', git: 'https://github.com/firstlutfi/data_magic.git', branch: 'master'
15
+ ````
16
+ Then run
17
+ ````ruby
18
+ bundle install
19
+ ````
20
+ Any other configuration is exactly same as the original gem.
21
+
22
+ NOTE:
23
+ If you have previously used older version of Faker, I suggest you to install [rubocop-faker](https://github.com/koic/rubocop-faker) to automatically update from positional arguments to named arguments.
24
+
25
+ ## New & Updated Generator
26
+
27
+ Here is a list of the new and updated methods:
28
+
29
+ | new methods added | updated methods | replaced methods |
30
+ | --- | --- | --- |
31
+ | color_hex | job_title<sup>1</sup> | title |
32
+ | color_name |
33
+ | number(digits=5, leading_zero=true) |
34
+ | decimal(before_decimal=5, after_decimal=3) |
35
+ | merge(separator='_', [first_name, city, number(digits=3)]) |
36
+ | date_between(from='01/01/2021', to='31/01/2021', format='%d/%m/%Y') |
37
+
38
+ <sup>1</sup> In newer version of Faker, Faker::Name.title is changed to Faker::Job.title
39
+
40
+ ## Copyright
41
+
42
+ Copyright (c) 2012-2021 [Jeffrey S. Morgan](https://github.com/cheezy/data_magic). See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env rake
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/gem_tasks'
5
+
6
+ require 'rspec/core/rake_task'
7
+ require 'cucumber'
8
+ require 'cucumber/rake/task'
9
+
10
+ RSpec::Core::RakeTask.new(:spec) do |spec|
11
+ spec.ruby_opts = '-I lib:spec'
12
+ spec.pattern = 'spec/**/*_spec.rb'
13
+ end
14
+ task :spec
15
+
16
+ Cucumber::Rake::Task.new(:features, 'Run features') do |t|
17
+ t.profile = 'default'
18
+ end
19
+
20
+ desc 'Run all specs and cukes'
21
+ task test: %w[spec features]
22
+
23
+ task :lib do
24
+ $LOAD_PATH.unshift(File.expand_path('lib', File.dirname(__FILE__)))
25
+ end
26
+
27
+ 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
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,134 @@
1
+ Feature: Functionality of the data_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 "job_title" should have a minimum of 1 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 Outline: Translate values from nested hahs
122
+ Given overwrite @data with translate_nested
123
+ Then the nested hash should include <key>
124
+ And the value for "<key>" should <validate>
125
+ And the value for "<key>" should not mach <negative_validate>
126
+ Examples:
127
+ | key | validate | negative_validate |
128
+ | full_name | have a minimum of 2 words | ~full_name |
129
+ | first_name | be 1 word long | ~first_name |
130
+
131
+ Scenario: Should be able to call the translator methods on DataMagic module
132
+ Then I should be able to call the full_name translator
133
+ And I should be able to call the state translator
134
+ And I should be able to call the today translator
@@ -0,0 +1,8 @@
1
+ Feature: Default file and directory functionality of the data_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,175 @@
1
+ # frozen_string_literal: true
2
+
3
+ class TestClass
4
+ include DataMagic
5
+ end
6
+
7
+ Given(%r{^I have read the yaml file from features/yaml$}) do
8
+ DataMagic.yml_directory = 'features/yaml'
9
+ DataMagic.load 'example.yml'
10
+ end
11
+
12
+ Given(/^I have read the default yaml file from the default location$/) do
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
+ Then(/^the value for "(.+)" should be "(.+)"$/) do |key, value|
22
+ expect(@data[key]).to eql value
23
+ end
24
+
25
+ Then(/^the value for "(.+)" should be (true|false)$/) do |key, value|
26
+ expect(@data[key].to_s).to eql value
27
+ end
28
+
29
+ Then(/^the value for "(.+)" should be (\d+) word|words long$/) do |key, length|
30
+ expect(@data[key].split(' ').size).to eql length.to_i
31
+ end
32
+
33
+ Then(/^the value for "(.+)" should have a minimum of (\d+) word|wordss$/) do |key, length|
34
+ expect(@data[key].split(' ').size).to be >= length.to_i
35
+ end
36
+
37
+ Then(/^the value for "(.*?)" should be (\d+) characters long$/) do |key, length|
38
+ expect(@data[key].length).to eql length.to_i
39
+ end
40
+
41
+ Then(/^the value for "(.+)" should exist$/) do |key|
42
+ expect(@data[key]).not_to be_nil
43
+ end
44
+
45
+ When(/^I load the file "(.+)"$/) do |file_name|
46
+ DataMagic.load file_name
47
+ end
48
+
49
+ Then(/^the value for "(.*?)" should be either "(.*?)", "(.*?)", or "(.*?)"$/) do |key, vala, valb, valc|
50
+ expect([vala, valb, valc]).to include @data[key]
51
+ end
52
+
53
+ Then(/^the value for "(.*?)" should be between (\d+) and (\d+)$/) do |key, low, high|
54
+ value = @data[key]
55
+ expect(value).to be >= low.to_i
56
+ expect(value).to be <= high.to_i
57
+ end
58
+
59
+ Then(/^the value for "(.*?)" should begin with (\d+) numbers$/) do |key, num|
60
+ value = @data[key]
61
+ expect(value[0, num.to_i].is_integer).to be true
62
+ end
63
+
64
+ Then(/^the value for "(.*?)" should have (\d+) upper case letters after a dash$/) do |key, num|
65
+ value = @data[key]
66
+ expect(value[4, num.to_i].upcase).to eql value[4, 3]
67
+ end
68
+
69
+ Then(/^the value for "(.*?)" should end with (\d+) lower case letters$/) do |key, num|
70
+ value = @data[key]
71
+ expect(value[-1 * num.to_i, num.to_i].downcase).to eql value[-3, 3]
72
+ end
73
+
74
+ Then(/^the value for "(.*?)" should include "(.*?)"$/) do |key, value|
75
+ expect(@data[key]).to include value
76
+ end
77
+
78
+ Then(/^the value for "(.*?)" should be today's date$/) do |key|
79
+ expect(@data[key]).to eql Date.today.strftime('%D')
80
+ end
81
+
82
+ Then(/^the value for "(.*?)" should be tomorrow's date$/) do |key|
83
+ tomorrow = Date.today + 1
84
+ expect(@data[key]).to eql tomorrow.strftime('%D')
85
+ end
86
+
87
+ Then(/^the value for "(.*?)" should be yesterday's date$/) do |key|
88
+ yesterday = Date.today - 1
89
+ expect(@data[key]).to eql yesterday.strftime('%D')
90
+ end
91
+
92
+ Then(/^the value for "(.*?)" should be five days from today$/) do |key|
93
+ the_day = Date.today + 5
94
+ expect(@data[key]).to eql the_day.strftime('%D')
95
+ end
96
+
97
+ Then(/^the value for "(.*?)" should be five days ago$/) do |key|
98
+ the_day = Date.today - 5
99
+ expect(@data[key]).to eql the_day.strftime('%D')
100
+ end
101
+
102
+ Then(/^the value for "(.*?)" should be a valid month$/) do |key|
103
+ months = %w[January February March April May June July August September October November December]
104
+ expect(months).to include @data[key]
105
+ end
106
+
107
+ Then(/^the value for "(.*?)" should be a valid month abbreviation$/) do |key|
108
+ months = %w[Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec]
109
+ expect(months).to include @data[key]
110
+ end
111
+
112
+ Then(/^the value for "(.*?)" should be a valid day$/) do |key|
113
+ days = %w[Sunday Monday Tuesday Wednesday Thursday Friday Saturday]
114
+ expect(days).to include @data[key]
115
+ end
116
+
117
+ Then(/^the value for "(.*?)" should be a valid day abbreviation$/) do |key|
118
+ days = %w[Sun Mon Tue Wed Thu Fri Sat]
119
+ expect(days).to include @data[key]
120
+ end
121
+
122
+ When(/^I add the blah translator$/) do
123
+ module Blah
124
+ def blah
125
+ 'foobar'
126
+ end
127
+ end
128
+ DataMagic.add_translator(Blah)
129
+
130
+ class TranslatorAdded
131
+ include DataMagic
132
+ end
133
+ ta = TranslatorAdded.new
134
+ @data = ta.data_for 'dynamic'
135
+ end
136
+
137
+ Then(/^the (?:first|second|third) value for the sequential data should be "(.*?)"$/) do |value|
138
+ expect(@data['ordered']).to eql value
139
+ end
140
+
141
+ When(/^I ask for the data again$/) do
142
+ @data = @tc.data_for 'dm'
143
+ end
144
+
145
+ Then(/^the nested value for this is_nested should be "(.*?)"$/) do |value|
146
+ expect(@data['this']['is_nested']).to eql value
147
+ end
148
+
149
+ Then(/^the nested hash should include (.*?)$/) do |value|
150
+ expect(@data.keys).to include value
151
+ end
152
+
153
+ Then(/^the value for "(.*?)" should be a phone number$/) do |value|
154
+ phone = @data[value]
155
+ if phone.split(' ').length == 2
156
+ expect(phone).to include '('
157
+ expect(phone).to include ')'
158
+ else
159
+ expect(phone.split(' ').length).to eql 1
160
+ end
161
+ end
162
+
163
+ Then(/^I should be able to call the (.+) translator$/) do |method|
164
+ value = DataMagic.send method
165
+ expect(value).not_to be_empty
166
+ end
167
+
168
+ And(/^the value for "([^"]*)" should not mach (.*)$/) do |key, value|
169
+ expect(@data[key]).not_to eql value
170
+ end
171
+
172
+ Given(/^overwrite @data with (.*)$/) do |hash|
173
+ # This is a bit dangerous but quick way to make all steps to work with nested data
174
+ @data = @data['this'][hash]
175
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '../../', 'lib'))
4
+
5
+ require 'rspec/expectations'
6
+ require 'data_magic'
7
+
8
+ Before do
9
+ DataMagic.yml_directory = nil
10
+ DataMagic.yml = nil
11
+ end
@@ -0,0 +1,9 @@
1
+ other_file:
2
+ name: Sneezy
3
+ address: 555 Easy Money Drive
4
+ email: sneezy@example.com
5
+
6
+ more_info:
7
+ name: Wheezy
8
+ address: 999 Alergy Ave
9
+ email: wheezy@example.com