data_magic 0.15.2 → 0.16

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5c7bbf3adc899115c9e7a9adf920fad08da35db0
4
- data.tar.gz: 27b97a2d7acffc7b80ed7aec7bd28b6e7e3d22de
3
+ metadata.gz: d48626546794c453b09023332575c55ae6483570
4
+ data.tar.gz: 52be062abe9e1806b7833b65c5768f11777648f8
5
5
  SHA512:
6
- metadata.gz: ef9a452bfdcb01ffb56ac7b45e4a75bbcff617ac00ed3a4baf9cf8383d138e70e8c325ea1daea970951cf207a4d9e8e1896e77893f70a7c8d7bac3423edb2cc2
7
- data.tar.gz: 8fea34907191332335c7c6a49201140bcd937bdd1b9a46bce24fe3e93f7ea46c5a928cdb09bc58bc094ee48dc121c73353cb88f485cd5fdd720ebbb38247a447
6
+ metadata.gz: 1f3b20c6ceb8f68a2a2b248054ea2781c7bb8bc7b6fed39c2841cf0c1006463b824f05bf4ddf4506711a1d90ab9337592cf82af1f5d6589debd5020d72051e3f
7
+ data.tar.gz: f5276d80839ece79ad9a34c048e68f8b70b2a62c52849c8fa6f95b9bfba2520390eb8e04514f367dcd7cd8c0802130cc3105368d4c6a64bc8abdd4c0455c268e
data/ChangeLog CHANGED
@@ -1,3 +1,7 @@
1
+ === Version 0.16 / 2013-8-31
2
+ * Enhancements
3
+ * Ability to support namespaces which will load a file with same name as namespace (Thanks Ben Cullen-Kerney)
4
+
1
5
  === Version 0.15.2 / 2013-7-17
2
6
  * Fixes
3
7
  * Display better message when key is not found (Thanks Guillaume Malette)
data/README.md CHANGED
@@ -15,14 +15,13 @@ DataMagic.yml_directory = 'data/yml'
15
15
 
16
16
  If you do not specify a directory the gem will default to using a directory named _config/data_.
17
17
 
18
-
19
18
  After setting the directory you must load a file. This can be accomplished by calling the _load_ method.
20
19
 
21
20
  ````ruby
22
21
  DataMagic.load 'filename.yml'
23
22
  ````
24
23
 
25
- 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 spcific test.
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.
26
25
 
27
26
  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 _DataMagic_ module in a [page-object](https://github.com/cheezy/page-object) and then populate a page with the data. Here's an example:
28
27
 
@@ -33,7 +32,7 @@ class MyPage
33
32
 
34
33
  ...
35
34
 
36
- def populage_page
35
+ def populate_page
37
36
  populate_page_with data_for :my_page
38
37
  end
39
38
  end
@@ -41,6 +40,14 @@ end
41
40
 
42
41
  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
42
 
43
+ To organize your data into namespaces, and load that data just in time for testing, use namespaced keys instead:
44
+
45
+ ````ruby
46
+ page.populate_page_with data_for "user_form/valid"
47
+ ````
48
+
49
+ This will load `user_form.yml`, and populate the page with the `valid:` record therein.
50
+
44
51
  Your data might look something like this:
45
52
 
46
53
  my_page:
@@ -52,7 +59,8 @@ Your data might look something like this:
52
59
  In order to access the data directly you can just call the method on the module like this:
53
60
 
54
61
  ````ruby
55
- my_data = DataMagic.data_for :my_test
62
+ page = MyPage.new
63
+ my_data = page.data_for :my_test
56
64
  ````
57
65
 
58
66
  ## Data generators
@@ -90,6 +98,7 @@ Here is a list of the built-in methods:
90
98
  | 3.days_from_today(format = '%D') | 3.days_ago(format = '%D') |
91
99
  | month | month_abbr |
92
100
  | day_of_week | day_of_week_abbr |
101
+ | sequential([]) | sequential(1..4)|
93
102
 
94
103
 
95
104
  If you wish to add your own built-in methods you can simply pass a module
@@ -0,0 +1,3 @@
1
+ valid:
2
+ name: Testy McTesterson
3
+ job: Tester
data/lib/data_magic.rb CHANGED
@@ -4,6 +4,7 @@ require "data_magic/version"
4
4
  require "data_magic/translation"
5
5
  require 'yml_reader'
6
6
  require 'faker'
7
+ require 'pry'
7
8
 
8
9
  module DataMagic
9
10
  extend YmlReader
@@ -18,8 +19,14 @@ module DataMagic
18
19
  end
19
20
 
20
21
  def data_for(key, additional={})
21
- DataMagic.load('default.yml') unless DataMagic.yml
22
- data = DataMagic.yml[key.to_s]
22
+ if key.is_a?(String) && key.match(%r{/})
23
+ filename, record = key.split('/')
24
+ DataMagic.load("#{filename}.yml")
25
+ else
26
+ record = key.to_s
27
+ DataMagic.load('default.yml') unless DataMagic.yml
28
+ end
29
+ data = DataMagic.yml[record]
23
30
  raise ArgumentError, "Undefined key #{key}" unless data
24
31
  prep_data data.merge(additional).clone
25
32
  end
@@ -1,3 +1,3 @@
1
1
  module DataMagic
2
- VERSION = "0.15.2"
2
+ VERSION = "0.16"
3
3
  end
@@ -23,4 +23,15 @@ describe DataMagic do
23
23
  DataMagic.load("fname")
24
24
  end
25
25
  end
26
+
27
+ context "namespaced keys" do
28
+ it "loads correct file and retrieves data" do
29
+ DataMagic.yml_directory = 'config/data'
30
+ class UserPage
31
+ include DataMagic
32
+ end
33
+ data = UserPage.new.data_for "user/valid"
34
+ expect(data.keys.sort).to eq(['job','name'])
35
+ end
36
+ end
26
37
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: data_magic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.2
4
+ version: '0.16'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Morgan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-17 00:00:00.000000000 Z
11
+ date: 2013-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faker
@@ -85,6 +85,7 @@ files:
85
85
  - README.md
86
86
  - Rakefile
87
87
  - config/data/default.yml
88
+ - config/data/user.yml
88
89
  - cucumber.yml
89
90
  - data_magic.gemspec
90
91
  - features/data_magic.feature