new_data_magic 1.2
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/.DS_Store +0 -0
- data/.gitignore +20 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +6 -0
- data/ChangeLog +142 -0
- data/Gemfile +14 -0
- data/Guardfile +18 -0
- data/LICENSE +22 -0
- data/README.md +42 -0
- data/Rakefile +27 -0
- data/config/data/default.yml +3 -0
- data/config/data/user.yml +3 -0
- data/cucumber.yml +2 -0
- data/features/data_magic.feature +134 -0
- data/features/defaults.feature +8 -0
- data/features/step_definitions/data_magic_steps.rb +175 -0
- data/features/support/env.rb +11 -0
- data/features/yaml/another.yml +9 -0
- data/features/yaml/example.yml +65 -0
- data/lib/data_magic/core_ext/hash.rb +7 -0
- data/lib/data_magic/core_ext/integer.rb +13 -0
- data/lib/data_magic/core_ext/string.rb +9 -0
- data/lib/data_magic/date_translation.rb +100 -0
- data/lib/data_magic/standard_translation.rb +370 -0
- data/lib/data_magic/translation.rb +15 -0
- data/lib/data_magic/version.rb +5 -0
- data/lib/data_magic.rb +114 -0
- data/new_data_magic.gemspec +28 -0
- data/spec/lib/data_magic_spec.rb +113 -0
- data/spec/lib/translation_spec.rb +326 -0
- data/spec/spec_helper.rb +30 -0
- metadata +143 -0
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.expand_path('lib/data_magic/version', __dir__)
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.name = 'new_data_magic'
|
7
|
+
gem.version = DataMagic::VERSION
|
8
|
+
gem.platform = Gem::Platform::RUBY
|
9
|
+
gem.authors = ['Jeff Morgan','Lutfi Fitroh Hadi']
|
10
|
+
gem.email = ['jeff.morgan@leandog.com','lutfi1304@gmail.com']
|
11
|
+
gem.license = 'MIT'
|
12
|
+
gem.homepage = 'http://github.com/firstlutfi/data_magic'
|
13
|
+
gem.summary = 'Provides datasets to application via YAML files'
|
14
|
+
gem.description = 'Provides datasets to application stored in YAML files'
|
15
|
+
|
16
|
+
gem.files = `git ls-files`.split("\n")
|
17
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
19
|
+
gem.require_paths = ['lib']
|
20
|
+
|
21
|
+
gem.required_ruby_version = '>= 2.5'
|
22
|
+
|
23
|
+
gem.add_dependency 'faker', '>= 1.9'
|
24
|
+
gem.add_dependency 'yml_reader', '>= 0.6'
|
25
|
+
|
26
|
+
gem.add_development_dependency 'cucumber', '>= 1.2.0'
|
27
|
+
gem.add_development_dependency 'rspec', '>= 2.12.0'
|
28
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
class UserPage
|
6
|
+
include DataMagic
|
7
|
+
end
|
8
|
+
|
9
|
+
class MockScenario
|
10
|
+
attr_accessor :tags
|
11
|
+
|
12
|
+
def initialize(tags)
|
13
|
+
@tags = tags
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class MockTag
|
18
|
+
attr_reader :name, :line
|
19
|
+
|
20
|
+
def initialize(name, line)
|
21
|
+
@name = name
|
22
|
+
@line = line
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe DataMagic do
|
27
|
+
context 'when configuring the yml directory' do
|
28
|
+
before(:each) do
|
29
|
+
DataMagic.yml_directory = nil
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should default to a directory named config' do
|
33
|
+
expect(DataMagic.yml_directory).to eql 'config/data'
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should store a yml directory' do
|
37
|
+
DataMagic.yml_directory = 'test_dir'
|
38
|
+
expect(DataMagic.yml_directory).to eql 'test_dir'
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should accept and use locale' do
|
42
|
+
expect(Faker::Config).to receive(:locale=).with('blah')
|
43
|
+
DataMagic.locale = 'blah'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'when reading yml files' do
|
48
|
+
it 'should read files from the config directory' do
|
49
|
+
DataMagic.yml = nil
|
50
|
+
DataMagic.load('user.yml')
|
51
|
+
data = UserPage.new.data_for 'valid'
|
52
|
+
expect(data.keys.sort).to eq(%w[job name])
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should default to reading a file named default.yml' do
|
56
|
+
DataMagic.yml_directory = 'config/data'
|
57
|
+
DataMagic.yml = nil
|
58
|
+
data = UserPage.new.data_for :dm
|
59
|
+
expect(data.keys).to include('value1')
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should use the value of DATA_MAGIC_FILE if it exists' do
|
63
|
+
DataMagic.yml_directory = 'config/data'
|
64
|
+
DataMagic.yml = nil
|
65
|
+
ENV['DATA_MAGIC_FILE'] = 'user.yml'
|
66
|
+
data = UserPage.new.data_for 'valid'
|
67
|
+
expect(data.keys.sort).to eq(%w[job name])
|
68
|
+
ENV['DATA_MAGIC_FILE'] = nil
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'should merge additional data to the same key if not present in addtional' do
|
72
|
+
DataMagic.yml_directory = 'config/data'
|
73
|
+
data = UserPage.new.data_for 'user/valid', { 'job' => 'Overlord' }
|
74
|
+
expect(data['job']).to eq('Overlord')
|
75
|
+
end
|
76
|
+
it 'should merge additional data to resulting hash if present in additional data' do
|
77
|
+
DataMagic.yml_directory = 'config/data'
|
78
|
+
data = UserPage.new.data_for 'user/valid', { 'valid' => { 'job' => 'Overlord' } }
|
79
|
+
expect(data['job']).to eq('Overlord')
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
context 'namespaced keys' do
|
84
|
+
it 'loads correct file and retrieves data' do
|
85
|
+
DataMagic.yml_directory = 'config/data'
|
86
|
+
data = UserPage.new.data_for 'user/valid'
|
87
|
+
expect(data.keys.sort).to eq(%w[job name])
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
context 'loading fixtures for cucumber scenarios' do
|
92
|
+
it 'loads the fixture for a scenario' do
|
93
|
+
DataMagic.yml_directory = 'config/data'
|
94
|
+
scenario = MockScenario.new([MockTag.new('@tag', 1), MockTag.new('@datamagic_user', 1)])
|
95
|
+
expect(DataMagic).to receive(:load).with('user.yml')
|
96
|
+
DataMagic.load_for_scenario scenario
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'uses the last fixture listed for a scenario if multiple exist' do
|
100
|
+
scenario = MockScenario.new([MockTag.new('@fixture_default', 1), MockTag.new('@datamagic_user', 1)])
|
101
|
+
expect(DataMagic).to receive(:load).with('user.yml')
|
102
|
+
DataMagic.load_for_scenario scenario
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'allows you to force loading from a different folder without stepping on the global folder' do
|
106
|
+
DataMagic.yml_directory = 'features'
|
107
|
+
scenario = MockScenario.new([MockTag.new('@tag', 1), MockTag.new('@datamagic_user', 1)])
|
108
|
+
expect(DataMagic).to receive(:load).with('user.yml')
|
109
|
+
DataMagic.load_for_scenario scenario, 'config/data'
|
110
|
+
expect(DataMagic.yml_directory).to eq('features')
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,326 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
describe 'DataMagic translations' do
|
5
|
+
context 'when delivering data' do
|
6
|
+
let(:example) { (Class.new { include DataMagic }).new }
|
7
|
+
|
8
|
+
def set_field_value(value)
|
9
|
+
expect(DataMagic).to receive(:yml).twice.and_return({ 'key' => { 'field' => value } })
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should deliver the hash from the yaml' do
|
13
|
+
set_field_value 'value'
|
14
|
+
expect(example.data_for('key')).to have_field_value 'value'
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should allow you to use a symbol for the key' do
|
18
|
+
set_field_value 'value'
|
19
|
+
expect(example.data_for(:key)).to have_field_value 'value'
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should default to use a file named 'default.yml'" do
|
23
|
+
hsh = double('hash')
|
24
|
+
DataMagic.yml_directory = 'test'
|
25
|
+
expect(File).to receive(:read).with('test/default.yml')
|
26
|
+
expect(ERB).to receive(:new).and_return hsh
|
27
|
+
expect(hsh).to receive(:result)
|
28
|
+
expect(YAML).to receive(:load).and_return(test: 'test')
|
29
|
+
expect(DataMagic).to receive(:yml).and_return(nil)
|
30
|
+
expect(DataMagic).to receive(:yml).and_return({ 'key' => { 'field' => 'value' } })
|
31
|
+
expect(example.data_for('key')).to have_field_value 'value'
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should clone the data returned so it can be resued' do
|
35
|
+
yaml = double('yaml')
|
36
|
+
expect(yaml).to receive(:merge).and_return(yaml)
|
37
|
+
expect(DataMagic).to receive(:yml).twice.and_return(yaml)
|
38
|
+
expect(yaml).to receive(:[]).and_return(yaml)
|
39
|
+
expect(yaml).to receive(:deep_copy).and_return({ 'field' => 'value' })
|
40
|
+
expect(example.data_for('key')).to have_field_value 'value'
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should merge the provided data with the yaml data' do
|
44
|
+
yaml = double('yaml')
|
45
|
+
expect(DataMagic).to receive(:yml).twice.and_return(yaml)
|
46
|
+
expect(yaml).to receive(:[]).and_return(yaml)
|
47
|
+
expect(yaml).to receive(:merge).and_return(yaml)
|
48
|
+
expect(yaml).to receive(:deep_copy).and_return({ 'field' => 'value' })
|
49
|
+
expect(example.data_for('key')).to have_field_value 'value'
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'translating random names' do
|
53
|
+
it 'should add a name' do
|
54
|
+
expect(Faker::Name).to receive(:name).and_return('Joseph')
|
55
|
+
set_field_value '~full_name'
|
56
|
+
expect(example.data_for('key')).to have_field_value 'Joseph'
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should add first name' do
|
60
|
+
expect(Faker::Name).to receive(:first_name).and_return('Sam')
|
61
|
+
set_field_value '~first_name'
|
62
|
+
expect(example.data_for('key')).to have_field_value 'Sam'
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'should add last name' do
|
66
|
+
expect(Faker::Name).to receive(:last_name).and_return('Smith')
|
67
|
+
set_field_value '~last_name'
|
68
|
+
expect(example.data_for('key')).to have_field_value 'Smith'
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'should add name prefix' do
|
72
|
+
expect(Faker::Name).to receive(:prefix).and_return('Mr')
|
73
|
+
set_field_value '~name_prefix'
|
74
|
+
expect(example.data_for('key')).to have_field_value 'Mr'
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'should add name suffix' do
|
78
|
+
expect(Faker::Name).to receive(:suffix).and_return('Jr')
|
79
|
+
set_field_value '~name_suffix'
|
80
|
+
expect(example.data_for('key')).to have_field_value 'Jr'
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
context 'translating random addresses' do
|
85
|
+
it 'should add a street address' do
|
86
|
+
expect(Faker::Address).to receive(:street_address).and_return('123 Main')
|
87
|
+
set_field_value '~street_address'
|
88
|
+
expect(example.data_for('key')).to have_field_value '123 Main'
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'should add a city' do
|
92
|
+
expect(Faker::Address).to receive(:city).and_return('Cleveland')
|
93
|
+
set_field_value '~city'
|
94
|
+
expect(example.data_for('key')).to have_field_value 'Cleveland'
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'should add a state' do
|
98
|
+
expect(Faker::Address).to receive(:state).and_return('Ohio')
|
99
|
+
set_field_value '~state'
|
100
|
+
expect(example.data_for('key')).to have_field_value 'Ohio'
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'should add a state abbreviation' do
|
104
|
+
expect(Faker::Address).to receive(:state_abbr).and_return('OH')
|
105
|
+
set_field_value '~state_abbr'
|
106
|
+
expect(example.data_for('key')).to have_field_value 'OH'
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'should add a zip code' do
|
110
|
+
expect(Faker::Address).to receive(:zip).and_return('11111')
|
111
|
+
set_field_value '~zip_code'
|
112
|
+
expect(example.data_for('key')).to have_field_value '11111'
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'should add a country' do
|
116
|
+
expect(Faker::Address).to receive(:country).and_return('United States')
|
117
|
+
set_field_value '~country'
|
118
|
+
expect(example.data_for('key')).to have_field_value 'United States'
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'should add a secondary address' do
|
122
|
+
expect(Faker::Address).to receive(:secondary_address).and_return('2nd floor')
|
123
|
+
set_field_value '~secondary_address'
|
124
|
+
expect(example.data_for('key')).to have_field_value '2nd floor'
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
context 'translating company names' do
|
129
|
+
it 'should add a company name' do
|
130
|
+
expect(Faker::Company).to receive(:name).and_return('LeanDog')
|
131
|
+
set_field_value '~company_name'
|
132
|
+
expect(example.data_for('key')).to have_field_value 'LeanDog'
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
context 'translating business' do
|
137
|
+
it 'should add a credit card number' do
|
138
|
+
expect(Faker::Business).to receive(:credit_card_number).and_return('123')
|
139
|
+
set_field_value '~credit_card_number'
|
140
|
+
expect(example.data_for('key')).to have_field_value '123'
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'should add credit card type' do
|
144
|
+
expect(Faker::Business).to receive(:credit_card_type)
|
145
|
+
.and_return('visa')
|
146
|
+
set_field_value '~credit_card_type'
|
147
|
+
expect(example.data_for('key')).to have_field_value 'visa'
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
context 'translating internet names' do
|
152
|
+
it 'should add an email address' do
|
153
|
+
expect(Faker::Internet).to receive(:email).and_return('buddy@example.com')
|
154
|
+
set_field_value '~email_address'
|
155
|
+
expect(example.data_for('key')).to have_field_value 'buddy@example.com'
|
156
|
+
end
|
157
|
+
|
158
|
+
it 'should add a domain name' do
|
159
|
+
expect(Faker::Internet).to receive(:domain_name).and_return('google.com')
|
160
|
+
set_field_value '~domain_name'
|
161
|
+
expect(example.data_for('key')).to have_field_value 'google.com'
|
162
|
+
end
|
163
|
+
|
164
|
+
it 'should add a user name' do
|
165
|
+
expect(Faker::Internet).to receive(:user_name).and_return('very_cheezy')
|
166
|
+
set_field_value '~user_name'
|
167
|
+
expect(example.data_for('key')).to have_field_value 'very_cheezy'
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
context 'translating phone numbers' do
|
172
|
+
it 'shold add a phone number' do
|
173
|
+
expect(Faker::PhoneNumber).to receive(:phone_number).and_return('555-555-5555')
|
174
|
+
set_field_value '~phone_number'
|
175
|
+
expect(example.data_for('key')).to have_field_value '555-555-5555'
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
context 'translating random phrases' do
|
180
|
+
it 'should add a catch phrase' do
|
181
|
+
expect(Faker::Company).to receive(:catch_phrase).and_return('Ruby is cool')
|
182
|
+
set_field_value '~catch_phrase'
|
183
|
+
expect(example.data_for('key')).to have_field_value 'Ruby is cool'
|
184
|
+
end
|
185
|
+
|
186
|
+
it 'should add random words' do
|
187
|
+
expect(Faker::Lorem).to receive(:words).and_return(%w[random words])
|
188
|
+
set_field_value '~words'
|
189
|
+
expect(example.data_for('key')).to have_field_value 'random words'
|
190
|
+
end
|
191
|
+
|
192
|
+
it 'should default to returning 3 words' do
|
193
|
+
set_field_value '~words'
|
194
|
+
expect(example.data_for('key')['field'].split.size).to eql 3
|
195
|
+
end
|
196
|
+
|
197
|
+
it 'should allow you to specify the number of words' do
|
198
|
+
set_field_value '~words(4)'
|
199
|
+
expect(example.data_for('key')['field'].split.size).to eql 4
|
200
|
+
end
|
201
|
+
|
202
|
+
it 'should add a random sentence' do
|
203
|
+
expect(Faker::Lorem).to receive(:sentence).and_return('a sentence')
|
204
|
+
set_field_value '~sentence'
|
205
|
+
expect(example.data_for('key')).to have_field_value 'a sentence'
|
206
|
+
end
|
207
|
+
|
208
|
+
it 'should default to returning a minimum of 4 words' do
|
209
|
+
set_field_value '~sentence'
|
210
|
+
expect(example.data_for('key')['field'].split.size).to be >= 4
|
211
|
+
end
|
212
|
+
|
213
|
+
it 'should allow you to specify a minimum word count' do
|
214
|
+
set_field_value '~sentence(20)'
|
215
|
+
expect(example.data_for('key')['field'].split.size).to be >= 20
|
216
|
+
end
|
217
|
+
|
218
|
+
it 'should add sentences' do
|
219
|
+
expect(Faker::Lorem).to receive(:sentences).and_return(['this is sentences'])
|
220
|
+
set_field_value '~sentences'
|
221
|
+
expect(example.data_for('key')).to have_field_value 'this is sentences'
|
222
|
+
end
|
223
|
+
|
224
|
+
it 'should default to returning a default of 3 sentences' do
|
225
|
+
set_field_value '~sentences'
|
226
|
+
expect(example.data_for('key')['field'].split('.').size).to be >= 3
|
227
|
+
end
|
228
|
+
|
229
|
+
it 'should allow you to specify the number of sentences' do
|
230
|
+
set_field_value '~sentences(10)'
|
231
|
+
expect(example.data_for('key')['field'].split('.').size).to be >= 10
|
232
|
+
end
|
233
|
+
|
234
|
+
it 'should add a paragraphs' do
|
235
|
+
expect(Faker::Lorem).to receive(:paragraphs).and_return(['this is a paragraph'])
|
236
|
+
set_field_value '~paragraphs'
|
237
|
+
expect(example.data_for('key')).to have_field_value 'this is a paragraph'
|
238
|
+
end
|
239
|
+
|
240
|
+
it 'should return 3 paragraphs by default' do
|
241
|
+
set_field_value '~paragraphs'
|
242
|
+
expect(example.data_for('key')['field'].split('\n\n').size).to eql 3
|
243
|
+
end
|
244
|
+
|
245
|
+
it 'should allow you to specify the number of paragraphs' do
|
246
|
+
set_field_value '~paragraphs(10)'
|
247
|
+
expect(example.data_for('key')['field'].split('\n\n').size).to eql 10
|
248
|
+
end
|
249
|
+
|
250
|
+
it 'should add characters' do
|
251
|
+
expect(Faker::Lorem).to receive(:characters).and_return('abcdefg')
|
252
|
+
set_field_value '~characters'
|
253
|
+
expect(example.data_for('key')).to have_field_value 'abcdefg'
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
context 'translating boolean values' do
|
258
|
+
it 'should resolve true' do
|
259
|
+
set_field_value true
|
260
|
+
expect(example.data_for('key')).to have_field_value true
|
261
|
+
end
|
262
|
+
|
263
|
+
it 'should resolve false' do
|
264
|
+
set_field_value false
|
265
|
+
expect(example.data_for('key')).to have_field_value false
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
context 'with numeric values' do
|
270
|
+
it "doesn't translate values" do
|
271
|
+
set_field_value(1)
|
272
|
+
expect(example.data_for('key')).to have_field_value 1
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
276
|
+
context 'with values not in the yaml' do
|
277
|
+
it 'throws a ArgumentError' do
|
278
|
+
expect { example.data_for('inexistant_key') }.to raise_error ArgumentError
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
282
|
+
context 'providing date values' do
|
283
|
+
it "should provide today's date" do
|
284
|
+
set_field_value '~today'
|
285
|
+
expect(example.data_for('key')).to have_field_value Date.today.strftime('%D')
|
286
|
+
end
|
287
|
+
|
288
|
+
it "should provide tomorrow's date" do
|
289
|
+
set_field_value '~tomorrow'
|
290
|
+
tomorrow = Date.today + 1
|
291
|
+
expect(example.data_for('key')).to have_field_value tomorrow.strftime('%D')
|
292
|
+
end
|
293
|
+
|
294
|
+
it "should provide yesterday's date" do
|
295
|
+
set_field_value '~yesterday'
|
296
|
+
yesterday = Date.today - 1
|
297
|
+
expect(example.data_for('key')).to have_field_value yesterday.strftime('%D')
|
298
|
+
end
|
299
|
+
|
300
|
+
it 'should provide a date that is some number of days from now' do
|
301
|
+
set_field_value '~5.days_from_today'
|
302
|
+
the_date = Date.today + 5
|
303
|
+
expect(example.data_for('key')).to have_field_value the_date.strftime('%D')
|
304
|
+
end
|
305
|
+
|
306
|
+
it 'should provide a date that is some number of days ago' do
|
307
|
+
set_field_value '~5.days_ago'
|
308
|
+
the_date = Date.today - 5
|
309
|
+
expect(example.data_for('key')).to have_field_value the_date.strftime('%D')
|
310
|
+
end
|
311
|
+
end
|
312
|
+
context 'should fail when translation call methos is not defined' do
|
313
|
+
it 'should fail if method does not exist' do
|
314
|
+
set_field_value '~non_existing_method'
|
315
|
+
expect { example.data_for('key') }.to raise_error(/non_existing_method/)
|
316
|
+
end
|
317
|
+
end
|
318
|
+
|
319
|
+
context 'array translation test' do
|
320
|
+
it 'should be able to translate ' do
|
321
|
+
set_field_value ["~'user' + 'name'", 'second']
|
322
|
+
expect(example.data_for('key')).to have_field_value %w[username second]
|
323
|
+
end
|
324
|
+
end
|
325
|
+
end
|
326
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
4
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
5
|
+
|
6
|
+
if ENV['coverage']
|
7
|
+
raise 'simplecov only works on Ruby 1.9' unless RUBY_VERSION =~ /^1\.9/
|
8
|
+
|
9
|
+
require 'simplecov'
|
10
|
+
SimpleCov.start { add_filter 'spec/' }
|
11
|
+
end
|
12
|
+
|
13
|
+
require 'rspec'
|
14
|
+
|
15
|
+
require 'data_magic'
|
16
|
+
|
17
|
+
RSpec::Matchers.define :have_field_value do |expected|
|
18
|
+
supports_block_expectations
|
19
|
+
match do |actual|
|
20
|
+
actual['field'] === expected
|
21
|
+
end
|
22
|
+
|
23
|
+
failure_message do |actual|
|
24
|
+
"expected '#{expected}' to equal the field value '#{actual['field']}'"
|
25
|
+
end
|
26
|
+
|
27
|
+
failure_message_when_negated do |actual|
|
28
|
+
"expected '#{expected}' to not equal to field value '#{actual['field']}'"
|
29
|
+
end
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: new_data_magic
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.2'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jeff Morgan
|
8
|
+
- Lutfi Fitroh Hadi
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2021-10-29 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: faker
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.9'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.9'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: yml_reader
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0.6'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0.6'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: cucumber
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 1.2.0
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 1.2.0
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rspec
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 2.12.0
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 2.12.0
|
70
|
+
description: Provides datasets to application stored in YAML files
|
71
|
+
email:
|
72
|
+
- jeff.morgan@leandog.com
|
73
|
+
- lutfi1304@gmail.com
|
74
|
+
executables: []
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- ".DS_Store"
|
79
|
+
- ".gitignore"
|
80
|
+
- ".rspec"
|
81
|
+
- ".ruby-gemset"
|
82
|
+
- ".ruby-version"
|
83
|
+
- ".travis.yml"
|
84
|
+
- ChangeLog
|
85
|
+
- Gemfile
|
86
|
+
- Guardfile
|
87
|
+
- LICENSE
|
88
|
+
- README.md
|
89
|
+
- Rakefile
|
90
|
+
- config/data/default.yml
|
91
|
+
- config/data/user.yml
|
92
|
+
- cucumber.yml
|
93
|
+
- features/data_magic.feature
|
94
|
+
- features/defaults.feature
|
95
|
+
- features/step_definitions/data_magic_steps.rb
|
96
|
+
- features/support/env.rb
|
97
|
+
- features/yaml/another.yml
|
98
|
+
- features/yaml/example.yml
|
99
|
+
- lib/data_magic.rb
|
100
|
+
- lib/data_magic/core_ext/hash.rb
|
101
|
+
- lib/data_magic/core_ext/integer.rb
|
102
|
+
- lib/data_magic/core_ext/string.rb
|
103
|
+
- lib/data_magic/date_translation.rb
|
104
|
+
- lib/data_magic/standard_translation.rb
|
105
|
+
- lib/data_magic/translation.rb
|
106
|
+
- lib/data_magic/version.rb
|
107
|
+
- new_data_magic.gemspec
|
108
|
+
- spec/lib/data_magic_spec.rb
|
109
|
+
- spec/lib/translation_spec.rb
|
110
|
+
- spec/spec_helper.rb
|
111
|
+
homepage: http://github.com/firstlutfi/data_magic
|
112
|
+
licenses:
|
113
|
+
- MIT
|
114
|
+
metadata: {}
|
115
|
+
post_install_message:
|
116
|
+
rdoc_options: []
|
117
|
+
require_paths:
|
118
|
+
- lib
|
119
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '2.5'
|
124
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
requirements: []
|
130
|
+
rubygems_version: 3.0.9
|
131
|
+
signing_key:
|
132
|
+
specification_version: 4
|
133
|
+
summary: Provides datasets to application via YAML files
|
134
|
+
test_files:
|
135
|
+
- features/data_magic.feature
|
136
|
+
- features/defaults.feature
|
137
|
+
- features/step_definitions/data_magic_steps.rb
|
138
|
+
- features/support/env.rb
|
139
|
+
- features/yaml/another.yml
|
140
|
+
- features/yaml/example.yml
|
141
|
+
- spec/lib/data_magic_spec.rb
|
142
|
+
- spec/lib/translation_spec.rb
|
143
|
+
- spec/spec_helper.rb
|