data_magic 0.5 → 0.6
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.
- data/.travis.yml +8 -0
- data/ChangeLog +4 -0
- data/README.md +43 -0
- data/data_magic.gemspec +1 -0
- data/features/data_magic.feature +22 -0
- data/features/step_definitions/data_magic_steps.rb +5 -0
- data/features/support/env.rb +1 -1
- data/features/yaml/another.yml +9 -0
- data/features/yaml/example.yml +5 -0
- data/lib/data_magic.rb +6 -13
- data/lib/data_magic/config.rb +6 -2
- data/lib/data_magic/reader.rb +1 -1
- data/lib/data_magic/version.rb +1 -1
- data/spec/lib/data_magic_spec.rb +8 -4
- data/spec/lib/translation_spec.rb +1 -1
- metadata +22 -8
data/.travis.yml
ADDED
data/ChangeLog
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,51 @@
|
|
1
1
|
# data_magic
|
2
2
|
|
3
|
+
[](http://travis-ci.org/cheezy/data_magic)
|
4
|
+
|
3
5
|
An easy to use gem that provides datasets that can be used by your application
|
4
6
|
and tests. The data is stored in yaml files.
|
5
7
|
|
8
|
+
## Using
|
9
|
+
|
10
|
+
In order to use _data_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
|
+
DataMagic.yml_directory = 'data/yml'
|
14
|
+
````
|
15
|
+
|
16
|
+
If you do not specify a directory the gem will default to using a directory named _config_. You should only have to set the directory once.
|
17
|
+
|
18
|
+
After setting the directory you must load a file. This can be accomplished by calling the _load_ method.
|
19
|
+
|
20
|
+
````ruby
|
21
|
+
DataMagic.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 spcific test.
|
25
|
+
|
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:
|
27
|
+
|
28
|
+
````ruby
|
29
|
+
class MyPage
|
30
|
+
include PageObject
|
31
|
+
include DataMagic
|
32
|
+
|
33
|
+
...
|
34
|
+
|
35
|
+
def populage_page
|
36
|
+
populate_page_with data_for :my_page
|
37
|
+
end
|
38
|
+
end
|
39
|
+
````
|
40
|
+
|
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.
|
42
|
+
|
43
|
+
In order to access the data directly you can just call the method on the module like this:
|
44
|
+
|
45
|
+
````ruby
|
46
|
+
my_data = DataMagic.data_for :my_test
|
47
|
+
````
|
48
|
+
|
6
49
|
## Known Issues
|
7
50
|
|
8
51
|
See [http://github.com/cheezy/data_magic/issues](http://github.com/cheezy/data_magic/issues)
|
data/data_magic.gemspec
CHANGED
@@ -17,6 +17,7 @@ Gem::Specification.new do |gem|
|
|
17
17
|
gem.require_paths = ["lib"]
|
18
18
|
|
19
19
|
gem.add_dependency 'faker', '>= 1.0.1'
|
20
|
+
gem.add_dependency 'yml_reader', '>= 0.1'
|
20
21
|
|
21
22
|
gem.add_development_dependency 'rspec', '>= 2.6.0'
|
22
23
|
gem.add_development_dependency 'cucumber', '>= 1.1.0'
|
data/features/data_magic.feature
CHANGED
@@ -41,3 +41,25 @@ Feature: Functionality of the data_magic gem
|
|
41
41
|
Scenario: Boolean values
|
42
42
|
Then the value for "bool_true" should be true
|
43
43
|
And the value for "bool_false" should be false
|
44
|
+
|
45
|
+
Scenario: Reading multiple data segments
|
46
|
+
When I ask for the data for "other"
|
47
|
+
Then the value for "name" should be "Cheezy"
|
48
|
+
And the value for "address" should be "123 Main Street"
|
49
|
+
And the value for "email" should be "cheezy@example.com"
|
50
|
+
|
51
|
+
Scenario: Reading from multiple yml files
|
52
|
+
When I load the file "another.yml"
|
53
|
+
And I ask for the data for "other_file"
|
54
|
+
Then the value for "name" should be "Sneezy"
|
55
|
+
And the value for "address" should be "555 Easy Money Drive"
|
56
|
+
And the value for "email" should be "sneezy@example.com"
|
57
|
+
|
58
|
+
Scenario: Reading multiple entries from same file
|
59
|
+
When I load the file "another.yml"
|
60
|
+
And I ask for the data for "other_file"
|
61
|
+
Then the value for "name" should be "Sneezy"
|
62
|
+
When I ask for the data for "more_info"
|
63
|
+
Then the value for "name" should be "Wheezy"
|
64
|
+
And the value for "address" should be "999 Alergy Ave"
|
65
|
+
And the value for "email" should be "wheezy@example.com"
|
data/features/support/env.rb
CHANGED
data/features/yaml/example.yml
CHANGED
data/lib/data_magic.rb
CHANGED
@@ -2,11 +2,13 @@ require "data_magic/version"
|
|
2
2
|
require "data_magic/config"
|
3
3
|
require "data_magic/reader"
|
4
4
|
require "data_magic/translation"
|
5
|
+
require 'yml_reader'
|
5
6
|
|
6
7
|
require 'faker'
|
7
8
|
|
8
9
|
module DataMagic
|
9
10
|
include Translation
|
11
|
+
extend YmlReader
|
10
12
|
|
11
13
|
def data_for(key, additional={})
|
12
14
|
DataMagic.load('default.yml') unless DataMagic.yml
|
@@ -20,27 +22,18 @@ module DataMagic
|
|
20
22
|
data.each do |key, value|
|
21
23
|
unless value.nil?
|
22
24
|
next unless value.respond_to? '[]'
|
23
|
-
data[key] = eval(value[1..-1]) if value[0] == "~"
|
25
|
+
data[key] = eval(value[1..-1]) if value[0,1] == "~"
|
24
26
|
end
|
25
27
|
end
|
26
28
|
data
|
27
29
|
end
|
28
30
|
|
29
|
-
|
30
31
|
class << self
|
31
32
|
attr_reader :yml
|
32
|
-
|
33
|
-
#
|
34
|
-
# load the provided filename from the config directory
|
35
|
-
#
|
36
|
-
def load(filename)
|
37
|
-
@yml = reader.load_file(filename)
|
38
|
-
end
|
39
|
-
|
40
|
-
private
|
41
33
|
|
42
|
-
def
|
43
|
-
|
34
|
+
def default_directory
|
35
|
+
'config'
|
44
36
|
end
|
45
37
|
end
|
38
|
+
|
46
39
|
end
|
data/lib/data_magic/config.rb
CHANGED
@@ -9,7 +9,9 @@ module DataMagic
|
|
9
9
|
# files will be located.
|
10
10
|
#
|
11
11
|
def yml_directory
|
12
|
-
|
12
|
+
$stderr.puts "*** DEPRECATION WARNING"
|
13
|
+
$stderr.puts "*** DataMagic::Config has being deprecated and will be removed soon."
|
14
|
+
$stderr.puts "*** Please use DataMagic.yml_directory."
|
13
15
|
end
|
14
16
|
|
15
17
|
#
|
@@ -17,7 +19,9 @@ module DataMagic
|
|
17
19
|
# all of the yml files.
|
18
20
|
#
|
19
21
|
def yml_directory=(value)
|
20
|
-
|
22
|
+
$stderr.puts "*** DEPRECATION WARNING"
|
23
|
+
$stderr.puts "*** DataMagic::Config has being deprecated and will be removed soon."
|
24
|
+
$stderr.puts "*** Please use DataMagic.yml_directory=."
|
21
25
|
end
|
22
26
|
|
23
27
|
end
|
data/lib/data_magic/reader.rb
CHANGED
@@ -6,7 +6,7 @@ module DataMagic
|
|
6
6
|
# load a file from the config directory and parse into a hash
|
7
7
|
#
|
8
8
|
def load_file(filename)
|
9
|
-
|
9
|
+
YAML.load_file "#{::DataMagic::Config.yml_directory}/#{filename}"
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
data/lib/data_magic/version.rb
CHANGED
data/spec/lib/data_magic_spec.rb
CHANGED
@@ -2,19 +2,23 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe DataMagic do
|
4
4
|
context "when configuring the yml directory" do
|
5
|
+
before(:each) do
|
6
|
+
DataMagic.yml_directory = nil
|
7
|
+
end
|
8
|
+
|
5
9
|
it "should default to a directory named config" do
|
6
|
-
DataMagic
|
10
|
+
DataMagic.yml_directory.should == 'config'
|
7
11
|
end
|
8
12
|
|
9
13
|
it "should store a yml directory" do
|
10
|
-
DataMagic
|
11
|
-
DataMagic
|
14
|
+
DataMagic.yml_directory = 'test_dir'
|
15
|
+
DataMagic.yml_directory.should == 'test_dir'
|
12
16
|
end
|
13
17
|
end
|
14
18
|
|
15
19
|
context "when reading yml files" do
|
16
20
|
it "should read files from the config directory" do
|
17
|
-
DataMagic
|
21
|
+
DataMagic.yml_directory = 'test'
|
18
22
|
YAML.should_receive(:load_file).with("test/fname").and_return({})
|
19
23
|
DataMagic.load("fname")
|
20
24
|
end
|
@@ -23,7 +23,7 @@ describe "DataMagic translations" do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
it "should default to use a file named 'default.yml'" do
|
26
|
-
DataMagic
|
26
|
+
DataMagic.yml_directory = 'test'
|
27
27
|
YAML.should_receive(:load_file).with("test/default.yml").and_return({})
|
28
28
|
DataMagic.should_receive(:yml).and_return(nil)
|
29
29
|
DataMagic.should_receive(:yml).and_return({'key' => {'field' => 'value'}})
|
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.6'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-05-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faker
|
16
|
-
requirement: &
|
16
|
+
requirement: &70359185872900 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,21 @@ dependencies:
|
|
21
21
|
version: 1.0.1
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70359185872900
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: yml_reader
|
27
|
+
requirement: &70359185871820 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0.1'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70359185871820
|
25
36
|
- !ruby/object:Gem::Dependency
|
26
37
|
name: rspec
|
27
|
-
requirement: &
|
38
|
+
requirement: &70359185869020 !ruby/object:Gem::Requirement
|
28
39
|
none: false
|
29
40
|
requirements:
|
30
41
|
- - ! '>='
|
@@ -32,10 +43,10 @@ dependencies:
|
|
32
43
|
version: 2.6.0
|
33
44
|
type: :development
|
34
45
|
prerelease: false
|
35
|
-
version_requirements: *
|
46
|
+
version_requirements: *70359185869020
|
36
47
|
- !ruby/object:Gem::Dependency
|
37
48
|
name: cucumber
|
38
|
-
requirement: &
|
49
|
+
requirement: &70359185868240 !ruby/object:Gem::Requirement
|
39
50
|
none: false
|
40
51
|
requirements:
|
41
52
|
- - ! '>='
|
@@ -43,7 +54,7 @@ dependencies:
|
|
43
54
|
version: 1.1.0
|
44
55
|
type: :development
|
45
56
|
prerelease: false
|
46
|
-
version_requirements: *
|
57
|
+
version_requirements: *70359185868240
|
47
58
|
description: Provides datasets to application stored in YAML files
|
48
59
|
email:
|
49
60
|
- jeff.morgan@leandog.com
|
@@ -54,6 +65,7 @@ files:
|
|
54
65
|
- .gitignore
|
55
66
|
- .rspec
|
56
67
|
- .rvmrc
|
68
|
+
- .travis.yml
|
57
69
|
- ChangeLog
|
58
70
|
- Gemfile
|
59
71
|
- Guardfile
|
@@ -65,6 +77,7 @@ files:
|
|
65
77
|
- features/data_magic.feature
|
66
78
|
- features/step_definitions/data_magic_steps.rb
|
67
79
|
- features/support/env.rb
|
80
|
+
- features/yaml/another.yml
|
68
81
|
- features/yaml/example.yml
|
69
82
|
- lib/data_magic.rb
|
70
83
|
- lib/data_magic/config.rb
|
@@ -102,6 +115,7 @@ test_files:
|
|
102
115
|
- features/data_magic.feature
|
103
116
|
- features/step_definitions/data_magic_steps.rb
|
104
117
|
- features/support/env.rb
|
118
|
+
- features/yaml/another.yml
|
105
119
|
- features/yaml/example.yml
|
106
120
|
- spec/lib/data_magic_spec.rb
|
107
121
|
- spec/lib/translation_spec.rb
|