traver 0.3.1 → 0.3.2

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: d410eca0d4cce264e4b8190ad033658d2fd2d0ba
4
- data.tar.gz: b2c86ca50b69d88e4cb941ac12fc4a07c6b60ab9
3
+ metadata.gz: 23992917260bb77f633cbfb7d24dbe491c966ac4
4
+ data.tar.gz: e435d995edbaa5cb92dd02da794be371ade59921
5
5
  SHA512:
6
- metadata.gz: a57f7f7f769c5648ac84b35f684ad49f7e1b37d77f0d530249c4457561c54343f8d0e90e3403aca4def18c4170621567a4d6f4dae3e280b46c5d79c66a23ca79
7
- data.tar.gz: 074676078c6de79194a5189d6b300256d877d3ccd78d7d80b53efdd548dfcd1de53b54069a00402072f8ed9499224592ebcaf4056b8f18b8186396f137e61c17
6
+ metadata.gz: 8984fe4739d900b9c7d68368b35bd1df98d643f940d607b246ac989ded037abad1528e31f455f90c6c52e710bcaf25ebeb5fe91c1a3c7583fdc3222d33286ee4
7
+ data.tar.gz: 11153c311605240e4e8b543e4796301f90728c83befb9850a0d82cc33fb1a04d1a916f7e097aab17202990f70bd51ab30c04133672620e32aa01e188f692e885
data/README.md CHANGED
@@ -1,6 +1,20 @@
1
1
  # Traver [![Build Status](https://travis-ci.org/yukas/traver.svg?branch=master)](https://travis-ci.org/yukas/traver)
2
2
 
3
- Traver is a test data generation framework.
3
+ The problem with the FactoryGirl is that it is complicated. It helps you define almost anything in terms of how complex your data model is. The thing is though — the more complex your factories the more complex seem to be the design of your system. Nobody wants to work with overcomplicated systems.
4
+
5
+ We believe that factories should be simple and lightweight just to make it possible to pass validations, everything else should be defined inside the spec itself, so the person who's working with the spec has all the information in place. It is possible with FactoryGirl, but it is too verbose.
6
+
7
+ FactoryGirl:
8
+ ```ruby
9
+ user = FactoryGirl.create(:user)
10
+ blog = FactoryGirl.create(:blog, user: user)
11
+ posts = FactoryGirl.create_list(:post, 2, blog: blog, user: user)
12
+ ```
13
+
14
+ Traver:
15
+ ```ruby
16
+ FactoryGirl.create(:user, blog: { posts: 2 })
17
+ ```
4
18
 
5
19
  ## Installation
6
20
 
@@ -27,13 +41,15 @@ blog = Traver.create(blog: { title: "Blog" }) #=> #<Blog @title="Blog">
27
41
  Define and use factories:
28
42
 
29
43
  ```ruby
30
- Traver.define_factory(:user, {
31
- full_name: "Walter White"
32
- })
33
-
34
- Traver.define_factory(:post, {
35
- title: "Hello"
36
- })
44
+ Traver.factories do
45
+ factory :user, {
46
+ full_name: "Walter White"
47
+ }
48
+
49
+ factory :post, {
50
+ title: "Hello"
51
+ }
52
+ end
37
53
 
38
54
  Traver.create(:user) #=> #<User @full_name="Walter White">
39
55
  Traver.create(:post) #=> #<Post @title="Hello">
@@ -42,13 +58,19 @@ Traver.create(:post) #=> #<Post @title="Hello">
42
58
  Define child factories:
43
59
 
44
60
  ```ruby
45
- Traver.define_factory(:published_post, :post, {
46
- published: true
47
- })
48
-
49
- Traver.define_factory(:draft_post, :post, {
50
- published: false
51
- })
61
+ Traver.factories do
62
+ factory :post, {
63
+ title: "Hello"
64
+ }
65
+
66
+ factory :published_post, :post, {
67
+ published: true
68
+ }
69
+
70
+ factory :draft_post, :post, {
71
+ published: false
72
+ }
73
+ end
52
74
 
53
75
  Traver.create(:published_post) #=> #<Post @title="Hello", @published=true>
54
76
  Traver.create(:draft_post) #=> #<Post @title="Hello", @published=false>
@@ -68,7 +90,7 @@ blog.user #=> #<User @name="Mike">
68
90
  Create associated objects using factory names:
69
91
 
70
92
  ```ruby
71
- Traver.define_factory(:mike, :user, {
93
+ Traver.factory(:mike, :user, {
72
94
  name: "Mike"
73
95
  })
74
96
 
@@ -124,24 +146,38 @@ Graph is a convenient way to reference created objects:
124
146
  graph = Traver.create_graph(blog: { posts: [{ tags: 2 }] })
125
147
 
126
148
  graph.blog #=> #<Blog>
149
+
127
150
  graph.posts #=> [#<Post>]
151
+ graph.post #=> #<Post>
128
152
  graph.post1 #=> #<Post>
153
+
129
154
  graph.tags #=> [#<Tag>, #<Tag>]
155
+ graph.tag #=> #<Tag>
130
156
  graph.tag1 #=> #<Tag>
131
157
  graph.tag2 #=> #<Tag>
132
158
 
133
- blog, post = Traver.create_graph(blog: { posts: 1 })[:blog, :post]
159
+ # Delegates attributes:
160
+ graph.blog_title #=> "Hello"
161
+ graph.blog1_title #=> "Hello"
162
+
163
+ graph.post_tag_title #=> "Tag"
164
+ graph.post1_tag1_title #=> "Tag"
165
+
166
+ # Delegates methods:
167
+ graph.tags_length #=> 2
134
168
  ```
135
169
 
136
- Reference already created objects:
170
+ Use procs for dynamic attribute values:
137
171
 
138
172
  ```ruby
139
- blog = Traver.create(blog: {
140
- post: { tags: 1 }
141
- tags: [-> (graph) { graph.tag1 }]
173
+ blog = Traver.create(event: {
174
+ start_at: -> { 1.day.ago },
175
+ finish_at: -> { start_at + 2.days }
142
176
  })
143
177
  ```
144
178
 
179
+ Procs executed in the context of created object.
180
+
145
181
  ## Rails
146
182
 
147
183
  By default Traver loads factories from`test/factories.rb` or `spec/factories.rb` for rspec users.
@@ -1,3 +1,3 @@
1
1
  module Traver
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
3
3
  end
data/lib/traver.rb CHANGED
@@ -58,7 +58,11 @@ module Traver
58
58
 
59
59
  def factories_loader
60
60
  if defined?(Rails)
61
- FactoriesLoader.new(Rails.root, "spec")
61
+ if defined?(RSpec)
62
+ FactoriesLoader.new(Rails.root, "spec")
63
+ else
64
+ FactoriesLoader.new(Rails.root, "test")
65
+ end
62
66
  else
63
67
  NilFactoriesLoader.new
64
68
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: traver
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuri Kaspervich
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-04-04 00:00:00.000000000 Z
11
+ date: 2016-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport