data_magic 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.rvmrc +1 -0
- data/Gemfile +12 -0
- data/Guardfile +16 -0
- data/LICENSE +22 -0
- data/README.md +22 -0
- data/Rakefile +25 -0
- data/cucumber.yml +1 -0
- data/data_magic.gemspec +23 -0
- data/features/data_magic.feature +40 -0
- data/features/step_definitions/data_magic_steps.rb +29 -0
- data/features/support/env.rb +6 -0
- data/features/yaml/example.yml +21 -0
- data/lib/data_magic.rb +44 -0
- data/lib/data_magic/config.rb +26 -0
- data/lib/data_magic/reader.rb +13 -0
- data/lib/data_magic/translation.rb +130 -0
- data/lib/data_magic/version.rb +3 -0
- data/spec/lib/data_magic_spec.rb +22 -0
- data/spec/lib/translation_spec.rb +181 -0
- data/spec/spec_helper.rb +30 -0
- metadata +107 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm 1.9.3-p0@data_magic --create
|
data/Gemfile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
source 'http://rubygems.org'
|
2
|
+
|
3
|
+
gem 'rake'
|
4
|
+
gem 'fuubar'
|
5
|
+
gem 'fuubar-cucumber'
|
6
|
+
gem 'rb-fsevent', :require => false if RUBY_PLATFORM =~ /darwin/i
|
7
|
+
gem 'growl'
|
8
|
+
gem 'guard-rspec'
|
9
|
+
gem 'guard-cucumber'
|
10
|
+
|
11
|
+
# Specify your gem's dependencies in data_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', :cli => '--color --format Fuubar' do
|
5
|
+
watch(%r{^spec/.+_spec\.rb$})
|
6
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
7
|
+
watch('spec/spec_helper.rb') { "spec" }
|
8
|
+
end
|
9
|
+
|
10
|
+
guard 'cucumber', :notification => true, :cli => '--profile default' 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,22 @@
|
|
1
|
+
# data_magic
|
2
|
+
|
3
|
+
An easy to use gem that provides datasets that can be used by your application
|
4
|
+
and tests. The data is stored in yaml files.
|
5
|
+
|
6
|
+
## Known Issues
|
7
|
+
|
8
|
+
See [http://github.com/cheezy/data_magic/issues](http://github.com/cheezy/data_magic/issues)
|
9
|
+
|
10
|
+
## Contributing
|
11
|
+
|
12
|
+
Please ensure all contributions contain proper tests.
|
13
|
+
|
14
|
+
1. Fork it
|
15
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
16
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
17
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
18
|
+
5. Create new Pull Request
|
19
|
+
|
20
|
+
## Copyright
|
21
|
+
|
22
|
+
Copyright (c) 2012 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
|
data/cucumber.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
default: --no-source --color --format Cucumber::Formatter::Fuubar
|
data/data_magic.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/data_magic/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.name = "data_magic"
|
6
|
+
gem.version = DataMagic::VERSION
|
7
|
+
gem.platform = Gem::Platform::RUBY
|
8
|
+
gem.authors = ["Jeff Morgan"]
|
9
|
+
gem.email = ["jeff.morgan@leandog.com"]
|
10
|
+
gem.homepage = "http://github.com/cheezy/data_magic"
|
11
|
+
gem.summary = %q{Provides datasets to application via YAML files}
|
12
|
+
gem.description = %q{Provides datasets to application stored in YAML files}
|
13
|
+
|
14
|
+
gem.files = `git ls-files`.split("\n")
|
15
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
gem.require_paths = ["lib"]
|
18
|
+
|
19
|
+
gem.add_dependency 'faker', '>= 1.0.1'
|
20
|
+
|
21
|
+
gem.add_development_dependency 'rspec', '>= 2.6.0'
|
22
|
+
gem.add_development_dependency 'cucumber', '>= 1.1.0'
|
23
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
Feature: Functionality of the data_magic gem
|
2
|
+
|
3
|
+
Background:
|
4
|
+
Given I have read the yaml file
|
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
|
+
|
16
|
+
Scenario: Getting addresses from the yaml
|
17
|
+
Then the value for "street" should have a minimum of 2 words
|
18
|
+
And the value for "city" should have a minimum of 1 word
|
19
|
+
And the value for "state" should have a minimum of 1 word
|
20
|
+
And the value for "state_ab" should be 1 word long
|
21
|
+
And the value for "zip" should be 1 word long
|
22
|
+
And the value for "country" should have a minimum of 1 word
|
23
|
+
And the value for "second_address" should have a minimum of 1 words
|
24
|
+
|
25
|
+
Scenario: Getting a company name from the yaml
|
26
|
+
Then the value for "company" should have a minimum of 1 word
|
27
|
+
|
28
|
+
Scenario: Getting an email address from the yaml
|
29
|
+
Then the value for "email" should be 1 word long
|
30
|
+
|
31
|
+
Scenario: Getting a phone number
|
32
|
+
Then the value for "phone" should have a minimum of 1 word
|
33
|
+
|
34
|
+
Scenario: Random phrases
|
35
|
+
Then the value for "catch_phrase" should exist
|
36
|
+
And the value for "words" should exist
|
37
|
+
And the value for "sentence" should exist
|
38
|
+
And the value for "sentences" should exist
|
39
|
+
And the value for "paragraphs" should exist
|
40
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class TestClass
|
2
|
+
include DataMagic
|
3
|
+
end
|
4
|
+
|
5
|
+
|
6
|
+
Given /^I have read the yaml file$/ do
|
7
|
+
DataMagic.load "example.yml"
|
8
|
+
end
|
9
|
+
|
10
|
+
When /^I ask for the data for "(.+)"$/ do |key|
|
11
|
+
@data = TestClass.new.data_for key
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
Then /^the value for "(.+)" should be "(.+)"$/ do |key, value|
|
16
|
+
@data[key].should == value
|
17
|
+
end
|
18
|
+
|
19
|
+
Then /^the value for "(.+)" should be (\d+) word|words long$/ do |key, length|
|
20
|
+
@data[key].split(' ').size.should == length.to_i
|
21
|
+
end
|
22
|
+
|
23
|
+
Then /^the value for "(.+)" should have a minimum of (\d+) word|wordss$/ do |key, length|
|
24
|
+
@data[key].split(' ').size.should >= length.to_i
|
25
|
+
end
|
26
|
+
|
27
|
+
Then /^the value for "(.+)" should exist$/ do |key|
|
28
|
+
@data[key].should_not be_nil
|
29
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
dm:
|
2
|
+
value1: this is value 1
|
3
|
+
value2: this is value 2
|
4
|
+
full_name: ~name
|
5
|
+
first_name: ~first_name
|
6
|
+
last_name: ~last_name
|
7
|
+
street: ~street_address
|
8
|
+
city: ~city
|
9
|
+
state: ~state
|
10
|
+
state_ab: ~state_abbr
|
11
|
+
zip: ~zip_code
|
12
|
+
country: ~country
|
13
|
+
second_address: ~secondary_address
|
14
|
+
company: ~company_name
|
15
|
+
email: ~email
|
16
|
+
phone: ~phone_number
|
17
|
+
catch_phrase: ~catch_phrase
|
18
|
+
words: ~words
|
19
|
+
sentence: ~sentence
|
20
|
+
sentences: ~sentences
|
21
|
+
paragraphs: ~paragraphs
|
data/lib/data_magic.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require "data_magic/version"
|
2
|
+
require "data_magic/config"
|
3
|
+
require "data_magic/reader"
|
4
|
+
require "data_magic/translation"
|
5
|
+
|
6
|
+
require 'faker'
|
7
|
+
|
8
|
+
module DataMagic
|
9
|
+
include Translation
|
10
|
+
|
11
|
+
def data_for(key)
|
12
|
+
data = DataMagic.yml[key]
|
13
|
+
prep_data data
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def prep_data(data)
|
19
|
+
data.each do |key, value|
|
20
|
+
unless value.nil?
|
21
|
+
data[key] = eval(value[1..-1]) if value[0] == "~"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
data
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
class << self
|
29
|
+
attr_reader :yml
|
30
|
+
|
31
|
+
#
|
32
|
+
# load the provided filename from the config directory
|
33
|
+
#
|
34
|
+
def load(filename)
|
35
|
+
@yml = reader.load_file(filename)
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def reader
|
41
|
+
@reader ||= DataMagic::Reader.new
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module DataMagic
|
2
|
+
module Config
|
3
|
+
|
4
|
+
class << self
|
5
|
+
attr_accessor :data_magic_yml_directory
|
6
|
+
|
7
|
+
#
|
8
|
+
# retrieve the yml_directory - the location where all of the yml
|
9
|
+
# files will be located.
|
10
|
+
#
|
11
|
+
def yml_directory
|
12
|
+
@data_magic_yml_directory ||= 'config'
|
13
|
+
end
|
14
|
+
|
15
|
+
#
|
16
|
+
# set the yml_directory - this is where the gem will look for
|
17
|
+
# all of the yml files.
|
18
|
+
#
|
19
|
+
def yml_directory=(value)
|
20
|
+
@data_magic_yml_directory = value
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,130 @@
|
|
1
|
+
module DataMagic
|
2
|
+
module Translation
|
3
|
+
#
|
4
|
+
# return a random name (first and last)
|
5
|
+
#
|
6
|
+
def name
|
7
|
+
Faker::Name.name
|
8
|
+
end
|
9
|
+
|
10
|
+
#
|
11
|
+
# return a random first name
|
12
|
+
#
|
13
|
+
def first_name
|
14
|
+
Faker::Name.first_name
|
15
|
+
end
|
16
|
+
|
17
|
+
#
|
18
|
+
# return a random last name
|
19
|
+
#
|
20
|
+
def last_name
|
21
|
+
Faker::Name.last_name
|
22
|
+
end
|
23
|
+
|
24
|
+
#
|
25
|
+
# return a random street address
|
26
|
+
#
|
27
|
+
def street_address
|
28
|
+
Faker::Address.street_address
|
29
|
+
end
|
30
|
+
|
31
|
+
#
|
32
|
+
# return a random secondary address
|
33
|
+
#
|
34
|
+
def secondary_address
|
35
|
+
Faker::Address.secondary_address
|
36
|
+
end
|
37
|
+
|
38
|
+
#
|
39
|
+
# return a random city
|
40
|
+
#
|
41
|
+
def city
|
42
|
+
Faker::Address.city
|
43
|
+
end
|
44
|
+
|
45
|
+
#
|
46
|
+
# return a random state
|
47
|
+
#
|
48
|
+
def state
|
49
|
+
Faker::Address.state
|
50
|
+
end
|
51
|
+
|
52
|
+
#
|
53
|
+
# return a random state abbreviation
|
54
|
+
#
|
55
|
+
def state_abbr
|
56
|
+
Faker::Address.state_abbr
|
57
|
+
end
|
58
|
+
|
59
|
+
#
|
60
|
+
# return a random zip code
|
61
|
+
#
|
62
|
+
def zip_code
|
63
|
+
Faker::Address.zip_code
|
64
|
+
end
|
65
|
+
|
66
|
+
#
|
67
|
+
# return a random country
|
68
|
+
#
|
69
|
+
def country
|
70
|
+
Faker::Address.country
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
#
|
75
|
+
# return a random company name
|
76
|
+
#
|
77
|
+
def company_name
|
78
|
+
Faker::Company.name
|
79
|
+
end
|
80
|
+
|
81
|
+
#
|
82
|
+
# return a random catch phrase
|
83
|
+
#
|
84
|
+
def catch_phrase
|
85
|
+
Faker::Company.catch_phrase
|
86
|
+
end
|
87
|
+
|
88
|
+
#
|
89
|
+
# return random words - default is 3 words
|
90
|
+
#
|
91
|
+
def words(number = 3)
|
92
|
+
Faker::Lorem.words(number).join(' ')
|
93
|
+
end
|
94
|
+
|
95
|
+
#
|
96
|
+
# return a random sentence - default minimum word count is 4
|
97
|
+
#
|
98
|
+
def sentence(min_word_count = 4)
|
99
|
+
Faker::Lorem.sentence(min_word_count)
|
100
|
+
end
|
101
|
+
|
102
|
+
#
|
103
|
+
# return random sentences - default is 3 sentences
|
104
|
+
#
|
105
|
+
def sentences(sentence_count = 3)
|
106
|
+
Faker::Lorem.sentences(sentence_count).join(' ')
|
107
|
+
end
|
108
|
+
|
109
|
+
#
|
110
|
+
# return random paragraphs - default is 3 paragraphs
|
111
|
+
#
|
112
|
+
def paragraphs(paragraph_count = 3)
|
113
|
+
Faker::Lorem.paragraphs(paragraph_count).join('\n\n')
|
114
|
+
end
|
115
|
+
|
116
|
+
#
|
117
|
+
# return a random email address
|
118
|
+
#
|
119
|
+
def email
|
120
|
+
Faker::Internet.email
|
121
|
+
end
|
122
|
+
|
123
|
+
#
|
124
|
+
# return a random phone number
|
125
|
+
#
|
126
|
+
def phone_number
|
127
|
+
Faker::PhoneNumber.phone_number
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DataMagic do
|
4
|
+
context "when configuring the yml directory" do
|
5
|
+
it "should default to a directory named config" do
|
6
|
+
DataMagic::Config.yml_directory.should == 'config'
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should store a yml directory" do
|
10
|
+
DataMagic::Config.yml_directory = 'test_dir'
|
11
|
+
DataMagic::Config.yml_directory.should == 'test_dir'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context "when reading yml files" do
|
16
|
+
it "should read files from the config directory" do
|
17
|
+
DataMagic::Config.yml_directory = 'test'
|
18
|
+
YAML.should_receive(:load_file).with("test/fname").and_return({})
|
19
|
+
DataMagic.load("fname")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,181 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class TestSubject
|
4
|
+
include DataMagic
|
5
|
+
end
|
6
|
+
|
7
|
+
describe "DataMagic translations" do
|
8
|
+
context "when delivering data" do
|
9
|
+
let(:example) { TestSubject.new }
|
10
|
+
|
11
|
+
def set_field_value(value)
|
12
|
+
DataMagic.should_receive(:yml).and_return({'key' => {'field' => value}})
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should deliver the hash from the yaml" do
|
16
|
+
set_field_value 'value'
|
17
|
+
example.data_for('key').should have_field_value 'value'
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
context "translating random names" do
|
22
|
+
it "should add a name" do
|
23
|
+
Faker::Name.should_receive(:name).and_return('Joseph')
|
24
|
+
set_field_value '~name'
|
25
|
+
example.data_for('key').should have_field_value 'Joseph'
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should add first name" do
|
29
|
+
Faker::Name.should_receive(:first_name).and_return('Sam')
|
30
|
+
set_field_value '~first_name'
|
31
|
+
example.data_for('key').should have_field_value 'Sam'
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should add last name" do
|
35
|
+
Faker::Name.should_receive(:last_name).and_return('Smith')
|
36
|
+
set_field_value '~last_name'
|
37
|
+
example.data_for('key').should have_field_value 'Smith'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "translating random addresses" do
|
42
|
+
it "should add a street address" do
|
43
|
+
Faker::Address.should_receive(:street_address).and_return("123 Main")
|
44
|
+
set_field_value '~street_address'
|
45
|
+
example.data_for('key').should have_field_value '123 Main'
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should add a city" do
|
49
|
+
Faker::Address.should_receive(:city).and_return('Cleveland')
|
50
|
+
set_field_value '~city'
|
51
|
+
example.data_for('key').should have_field_value 'Cleveland'
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should add a state" do
|
55
|
+
Faker::Address.should_receive(:state).and_return('Ohio')
|
56
|
+
set_field_value '~state'
|
57
|
+
example.data_for('key').should have_field_value 'Ohio'
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should add a state abbreviation" do
|
61
|
+
Faker::Address.should_receive(:state_abbr).and_return('OH')
|
62
|
+
set_field_value '~state_abbr'
|
63
|
+
example.data_for('key').should have_field_value 'OH'
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should add a zip code" do
|
67
|
+
Faker::Address.should_receive(:zip_code).and_return('11111')
|
68
|
+
set_field_value '~zip_code'
|
69
|
+
example.data_for('key').should have_field_value '11111'
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should add a country" do
|
73
|
+
Faker::Address.should_receive(:country).and_return("United States")
|
74
|
+
set_field_value '~country'
|
75
|
+
example.data_for('key').should have_field_value 'United States'
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should add a secondary address" do
|
79
|
+
Faker::Address.should_receive(:secondary_address).and_return('2nd floor')
|
80
|
+
set_field_value '~secondary_address'
|
81
|
+
example.data_for('key').should have_field_value '2nd floor'
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context "translating company names" do
|
86
|
+
it "should add a company name" do
|
87
|
+
Faker::Company.should_receive(:name).and_return('LeanDog')
|
88
|
+
set_field_value '~company_name'
|
89
|
+
example.data_for('key').should have_field_value 'LeanDog'
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context "translating email address" do
|
94
|
+
it "should add an email address" do
|
95
|
+
Faker::Internet.should_receive(:email).and_return('buddy@example.com')
|
96
|
+
set_field_value '~email'
|
97
|
+
example.data_for('key').should have_field_value 'buddy@example.com'
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
context "translating phone numbers" do
|
102
|
+
it "shold add a phone number" do
|
103
|
+
Faker::PhoneNumber.should_receive(:phone_number).and_return('555-555-5555')
|
104
|
+
set_field_value '~phone_number'
|
105
|
+
example.data_for('key').should have_field_value '555-555-5555'
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
context "translating random phrases" do
|
110
|
+
it "should add a catch phrase" do
|
111
|
+
Faker::Company.should_receive(:catch_phrase).and_return('Ruby is cool')
|
112
|
+
set_field_value '~catch_phrase'
|
113
|
+
example.data_for('key').should have_field_value 'Ruby is cool'
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should add random words" do
|
117
|
+
Faker::Lorem.should_receive(:words).and_return(['random', 'words'])
|
118
|
+
set_field_value '~words'
|
119
|
+
example.data_for('key').should have_field_value 'random words'
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should default to returning 3 words" do
|
123
|
+
set_field_value '~words'
|
124
|
+
example.data_for('key')['field'].split.size.should == 3
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should allow you to specify the number of words" do
|
128
|
+
set_field_value '~words(4)'
|
129
|
+
example.data_for('key')['field'].split.size.should == 4
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should add a random sentence" do
|
133
|
+
Faker::Lorem.should_receive(:sentence).and_return('a sentence')
|
134
|
+
set_field_value '~sentence'
|
135
|
+
example.data_for('key').should have_field_value 'a sentence'
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should default to returning a minimum of 4 words" do
|
139
|
+
set_field_value '~sentence'
|
140
|
+
example.data_for('key')['field'].split.size.should >= 4
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should allow you to specify a minimum word count" do
|
144
|
+
set_field_value '~sentence(20)'
|
145
|
+
example.data_for('key')['field'].split.size.should >= 20
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should add sentences" do
|
149
|
+
Faker::Lorem.should_receive(:sentences).and_return(['this is sentences'])
|
150
|
+
set_field_value '~sentences'
|
151
|
+
example.data_for('key').should have_field_value 'this is sentences'
|
152
|
+
end
|
153
|
+
|
154
|
+
it "should default to returning a default of 3 sentences" do
|
155
|
+
set_field_value '~sentences'
|
156
|
+
example.data_for('key')['field'].split('.').size.should >= 3
|
157
|
+
end
|
158
|
+
|
159
|
+
it "should allow you to specify the number of sentences" do
|
160
|
+
set_field_value '~sentences(10)'
|
161
|
+
example.data_for('key')['field'].split('.').size.should >= 10
|
162
|
+
end
|
163
|
+
|
164
|
+
it "should add a paragraphs" do
|
165
|
+
Faker::Lorem.should_receive(:paragraphs).and_return(['this is a paragraph'])
|
166
|
+
set_field_value '~paragraphs'
|
167
|
+
example.data_for('key').should have_field_value 'this is a paragraph'
|
168
|
+
end
|
169
|
+
|
170
|
+
it "should return 3 paragraphs by default" do
|
171
|
+
set_field_value '~paragraphs'
|
172
|
+
example.data_for('key')['field'].split('\n\n').size.should == 3
|
173
|
+
end
|
174
|
+
|
175
|
+
it "should allow you to specify the number of paragraphs" do
|
176
|
+
set_field_value '~paragraphs(10)'
|
177
|
+
example.data_for('key')['field'].split('\n\n').size.should == 10
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
4
|
+
|
5
|
+
if ENV['coverage']
|
6
|
+
raise "simplecov only works on Ruby 1.9" unless RUBY_VERSION =~ /^1\.9/
|
7
|
+
|
8
|
+
require 'simplecov'
|
9
|
+
SimpleCov.start { add_filter "spec/" }
|
10
|
+
end
|
11
|
+
|
12
|
+
require 'rspec'
|
13
|
+
|
14
|
+
require 'data_magic'
|
15
|
+
|
16
|
+
RSpec::Matchers.define :have_field_value do |expected|
|
17
|
+
match do |actual|
|
18
|
+
actual['field'] == expected
|
19
|
+
end
|
20
|
+
|
21
|
+
failure_message_for_should do |actual|
|
22
|
+
"expected '#{expected}' to equal the field value '#{actual['field']}'"
|
23
|
+
end
|
24
|
+
|
25
|
+
failure_message_for_should_not do |actual|
|
26
|
+
"expected '#{expected}' to not equal to field value '#{actual['field']}'"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: data_magic
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jeff Morgan
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-01-21 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: faker
|
16
|
+
requirement: &70166151279480 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.0.1
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70166151279480
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
requirement: &70166151278860 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.6.0
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70166151278860
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: cucumber
|
38
|
+
requirement: &70166151278280 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 1.1.0
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70166151278280
|
47
|
+
description: Provides datasets to application stored in YAML files
|
48
|
+
email:
|
49
|
+
- jeff.morgan@leandog.com
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- .gitignore
|
55
|
+
- .rspec
|
56
|
+
- .rvmrc
|
57
|
+
- Gemfile
|
58
|
+
- Guardfile
|
59
|
+
- LICENSE
|
60
|
+
- README.md
|
61
|
+
- Rakefile
|
62
|
+
- cucumber.yml
|
63
|
+
- data_magic.gemspec
|
64
|
+
- features/data_magic.feature
|
65
|
+
- features/step_definitions/data_magic_steps.rb
|
66
|
+
- features/support/env.rb
|
67
|
+
- features/yaml/example.yml
|
68
|
+
- lib/data_magic.rb
|
69
|
+
- lib/data_magic/config.rb
|
70
|
+
- lib/data_magic/reader.rb
|
71
|
+
- lib/data_magic/translation.rb
|
72
|
+
- lib/data_magic/version.rb
|
73
|
+
- spec/lib/data_magic_spec.rb
|
74
|
+
- spec/lib/translation_spec.rb
|
75
|
+
- spec/spec_helper.rb
|
76
|
+
homepage: http://github.com/cheezy/data_magic
|
77
|
+
licenses: []
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
requirements: []
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 1.8.10
|
97
|
+
signing_key:
|
98
|
+
specification_version: 3
|
99
|
+
summary: Provides datasets to application via YAML files
|
100
|
+
test_files:
|
101
|
+
- features/data_magic.feature
|
102
|
+
- features/step_definitions/data_magic_steps.rb
|
103
|
+
- features/support/env.rb
|
104
|
+
- features/yaml/example.yml
|
105
|
+
- spec/lib/data_magic_spec.rb
|
106
|
+
- spec/lib/translation_spec.rb
|
107
|
+
- spec/spec_helper.rb
|