factory_json 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +3 -2
- data/README.md +14 -0
- data/factory_json.gemspec +11 -4
- data/lib/factory_girl/attribute_assigner_with_hash_support.rb +1 -1
- data/lib/factory_json/version.rb +1 -1
- data/spec/factory_girl/strategy/as_json_spec.rb +1 -1
- data/spec/factory_girl/strategy/json_spec.rb +1 -1
- data/spec/spec_helper.rb +7 -7
- data/spec/support/shared_examples/strategy.rb +42 -1
- metadata +78 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c1f961754dad7697c6a16ddcd68a90873cd86d5a
|
4
|
+
data.tar.gz: e5d402e38bf49d9e3788f823e686e57fb0a2d5bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2263468e77128fa5330fd160bf0bb29224dce606fca2f92d75f4ba9608c276731e19af27be92963b9a1c31fcb444e06ad5aad3448cf9b30b042137d6ff3a7960
|
7
|
+
data.tar.gz: 1e4411dbe3fd8ab39f7eb087384b04b5f45ad9d3e1739c17bc55ad684529a2b6e6500169a294dfc858fe72312d344a0fd1dd0259cb88b5b24a7b904bbf13d2e4
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -126,6 +126,20 @@ user_hash = FactoryGirl.as_json(:user, :with_profile) # to return data as a Ruby
|
|
126
126
|
user_json = FactoryGirl.json(:user, :with_profile) # to return string, that contains valid JSON
|
127
127
|
```
|
128
128
|
|
129
|
+
## Testing
|
130
|
+
|
131
|
+
Testing is pretty much standard
|
132
|
+
|
133
|
+
```bash
|
134
|
+
rspec spec
|
135
|
+
```
|
136
|
+
|
137
|
+
Testing compatibility with FactoryGirl
|
138
|
+
|
139
|
+
```bash
|
140
|
+
rspec `bundle show factory_girl`/spec
|
141
|
+
```
|
142
|
+
|
129
143
|
## Contributing
|
130
144
|
|
131
145
|
1. Fork it ( https://github.com/[my-github-username]/factory_json/fork )
|
data/factory_json.gemspec
CHANGED
@@ -22,11 +22,18 @@ Gem::Specification.new do |spec|
|
|
22
22
|
|
23
23
|
spec.add_dependency "factory_girl"
|
24
24
|
|
25
|
-
spec.add_development_dependency "bundler", "~> 1.6"
|
26
25
|
spec.add_development_dependency "rake"
|
27
|
-
spec.add_development_dependency "
|
28
|
-
spec.add_development_dependency "
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
27
|
+
spec.add_development_dependency "rspec", "~> 2.12.0"
|
28
|
+
spec.add_development_dependency "cucumber", "~> 1.3.15"
|
29
|
+
spec.add_development_dependency "aruba"
|
30
|
+
spec.add_development_dependency "mocha", ">= 0.12.8"
|
29
31
|
spec.add_development_dependency "bourne"
|
30
|
-
|
32
|
+
spec.add_development_dependency "appraisal", "~> 1.0.0"
|
33
|
+
spec.add_development_dependency "timecop"
|
31
34
|
spec.add_development_dependency "activerecord", ">= 3.0.0"
|
35
|
+
|
36
|
+
# Compatibility test
|
37
|
+
spec.add_development_dependency "factory_girl_rails"
|
38
|
+
|
32
39
|
end
|
@@ -7,7 +7,7 @@ module FactoryGirl
|
|
7
7
|
attributes_to_set_on_instance.each do |attribute|
|
8
8
|
if instance.respond_to?("#{attribute}=")
|
9
9
|
instance.public_send("#{attribute}=", get(attribute))
|
10
|
-
elsif instance.
|
10
|
+
elsif instance.kind_of?(Hash)
|
11
11
|
instance[attribute] = get(attribute)
|
12
12
|
else
|
13
13
|
raise NoMethodError.new("undefined method `#{attribute}=' for #{instance}")
|
data/lib/factory_json/version.rb
CHANGED
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe FactoryGirl::Strategy::AsJSON do
|
4
4
|
it_should_behave_like "strategy with association support", :build
|
5
|
-
it_should_behave_like "strategy with callbacks", {}, :after_build, :before_json
|
5
|
+
it_should_behave_like "json strategy with callbacks", {}, :after_build, :before_json
|
6
6
|
it_should_behave_like "strategy with strategy: :build", :build
|
7
7
|
|
8
8
|
context "Object source" do
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe FactoryGirl::Strategy::JSON do
|
4
4
|
it_should_behave_like "strategy with association support", :build
|
5
|
-
it_should_behave_like "strategy with callbacks", "{}", :after_build, :before_json
|
5
|
+
it_should_behave_like "json strategy with callbacks", "{}", :after_build, :before_json
|
6
6
|
it_should_behave_like "strategy with strategy: :build", :build
|
7
7
|
|
8
8
|
context "Object source" do
|
data/spec/spec_helper.rb
CHANGED
@@ -4,31 +4,31 @@ $LOAD_PATH << File.join(File.dirname(__FILE__))
|
|
4
4
|
require 'rubygems'
|
5
5
|
require 'rspec'
|
6
6
|
require 'rspec/autorun'
|
7
|
+
|
7
8
|
require 'mocha/api'
|
8
9
|
require 'bourne'
|
10
|
+
require 'timecop'
|
9
11
|
|
10
12
|
require 'factory_girl'
|
11
13
|
require 'factory_json'
|
12
14
|
|
13
|
-
|
15
|
+
source_path = Gem::Specification.find_by_name('factory_girl').gem_dir
|
14
16
|
|
15
|
-
files = File.join(
|
17
|
+
files = File.join(source_path, 'spec', 'support', 'macros', '**', '*.rb')
|
16
18
|
Dir[files].each { |f| require File.expand_path(f) }
|
17
19
|
|
18
|
-
files = File.join(
|
20
|
+
files = File.join(source_path, 'spec', 'support', 'matchers', '**', '*.rb')
|
19
21
|
Dir[files].each { |f| require File.expand_path(f) }
|
20
22
|
|
21
23
|
require "support/shared_examples/strategy"
|
22
24
|
|
23
25
|
RSpec.configure do |config|
|
24
|
-
config.expect_with :rspec do |expectations|
|
25
|
-
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
26
|
-
end
|
27
26
|
|
28
27
|
config.mock_framework = :mocha
|
29
28
|
config.include DeclarationMatchers
|
30
29
|
|
31
30
|
config.after do
|
31
|
+
Timecop.return
|
32
32
|
FactoryGirl.reload
|
33
33
|
end
|
34
|
-
end
|
34
|
+
end
|
@@ -1,3 +1,23 @@
|
|
1
|
+
shared_examples_for "strategy without association support" do
|
2
|
+
let(:factory) { stub("associate_factory") }
|
3
|
+
let(:attribute) { FactoryGirl::Attribute::Association.new(:user, :user, {}) }
|
4
|
+
|
5
|
+
def association_named(name, overrides)
|
6
|
+
runner = FactoryGirl::FactoryRunner.new(name, :build, [overrides])
|
7
|
+
subject.association(runner)
|
8
|
+
end
|
9
|
+
|
10
|
+
before do
|
11
|
+
FactoryGirl.stubs(factory_by_name: factory)
|
12
|
+
factory.stubs(:compile)
|
13
|
+
factory.stubs(:run)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "returns nil when accessing an association" do
|
17
|
+
expect(association_named(:user, {})).to be_nil
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
1
21
|
shared_examples_for "strategy with association support" do |factory_girl_strategy_name|
|
2
22
|
let(:factory) { stub("associate_factory") }
|
3
23
|
|
@@ -48,7 +68,28 @@ shared_examples_for "strategy with strategy: :build" do |factory_girl_strategy_n
|
|
48
68
|
end
|
49
69
|
end
|
50
70
|
|
51
|
-
shared_examples_for "strategy with callbacks" do
|
71
|
+
shared_examples_for "strategy with callbacks" do |*callback_names|
|
72
|
+
let(:result_instance) do
|
73
|
+
define_class("ResultInstance") do
|
74
|
+
attr_accessor :id
|
75
|
+
end.new
|
76
|
+
end
|
77
|
+
|
78
|
+
let(:evaluation) { stub("evaluation", object: result_instance, notify: true, create: nil) }
|
79
|
+
|
80
|
+
it "runs the callbacks #{callback_names} with the evaluation's object" do
|
81
|
+
subject.result(evaluation)
|
82
|
+
callback_names.each do |name|
|
83
|
+
expect(evaluation).to have_received(:notify).with(name, evaluation.object)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
it "returns the object from the evaluation" do
|
88
|
+
expect(subject.result(evaluation)).to eq evaluation.object
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
shared_examples_for "json strategy with callbacks" do |result_instance, *callback_names|
|
52
93
|
let(:object) {{}}
|
53
94
|
let(:evaluation) { stub("evaluation", object: object, notify: true, create: nil) }
|
54
95
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: factory_json
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- E-Max
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: factory_girl
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -39,7 +53,35 @@ dependencies:
|
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: '1.6'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.12.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.12.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: cucumber
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.3.15
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.3.15
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: aruba
|
43
85
|
requirement: !ruby/object:Gem::Requirement
|
44
86
|
requirements:
|
45
87
|
- - ">="
|
@@ -53,7 +95,21 @@ dependencies:
|
|
53
95
|
- !ruby/object:Gem::Version
|
54
96
|
version: '0'
|
55
97
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
98
|
+
name: mocha
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.12.8
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.12.8
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: bourne
|
57
113
|
requirement: !ruby/object:Gem::Requirement
|
58
114
|
requirements:
|
59
115
|
- - ">="
|
@@ -67,21 +123,21 @@ dependencies:
|
|
67
123
|
- !ruby/object:Gem::Version
|
68
124
|
version: '0'
|
69
125
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
126
|
+
name: appraisal
|
71
127
|
requirement: !ruby/object:Gem::Requirement
|
72
128
|
requirements:
|
73
129
|
- - "~>"
|
74
130
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0.
|
131
|
+
version: 1.0.0
|
76
132
|
type: :development
|
77
133
|
prerelease: false
|
78
134
|
version_requirements: !ruby/object:Gem::Requirement
|
79
135
|
requirements:
|
80
136
|
- - "~>"
|
81
137
|
- !ruby/object:Gem::Version
|
82
|
-
version: 0.
|
138
|
+
version: 1.0.0
|
83
139
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
140
|
+
name: timecop
|
85
141
|
requirement: !ruby/object:Gem::Requirement
|
86
142
|
requirements:
|
87
143
|
- - ">="
|
@@ -108,6 +164,20 @@ dependencies:
|
|
108
164
|
- - ">="
|
109
165
|
- !ruby/object:Gem::Version
|
110
166
|
version: 3.0.0
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: factory_girl_rails
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
111
181
|
description: FactoryGirl can now handle JSON representation for an object.
|
112
182
|
email:
|
113
183
|
- max.zab87@gmail.com
|