factories 0.1.0 → 0.2.0

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: b5dec7a43a3f9588c6d90206821ba1a8abccc927
4
- data.tar.gz: 1e4ebdc76cbca2ac27acbdf58276d2b3d0c3d20b
3
+ metadata.gz: 49462fc87b70c002eec2a5bf71e8a2392da86996
4
+ data.tar.gz: bccbaf079b5b0dc8737f321857c6df240238d9ba
5
5
  SHA512:
6
- metadata.gz: 4e2d11dd43e93adb2c2206a67c9afe472c85c2d2e5fe3b6b676ada769aef0fdca58f7196f7c21816e21247c479e5f5c63059b6f124b287adfdb5054497a97484
7
- data.tar.gz: 70d456f0778b0a19d4fb04e895ed68898c3bf7d3b52c77927831ba5b977eaeb7863358629a92f813ae01e1df70a0604c087d8afcae33de93784570d3b3ebc38a
6
+ metadata.gz: 31361b6aff21b1f452a8d6ffbc691d5b804ba2147e1f1f97ab397ae5cada9b19bccc39908be44aa0dab3d53403b9038da07868b86661218d4d800d0eca7a45fc
7
+ data.tar.gz: db6ac7360322730335a5d79d0cf9f368cb8fb957f7140ceb6d99236f93cf11b7ac777e7155a14545b39aad68aeeab52453a1fd9fe8e0ad2d7942e0a9041ef045
data/README.md CHANGED
@@ -24,13 +24,11 @@ class User < ActiveRecord::Base
24
24
  validates :name, presence: true
25
25
  end
26
26
 
27
- module Factories
28
- class UserFactory < BaseFactory
29
- def defaults
30
- {
31
- name: "Nathan"
32
- }
33
- end
27
+ Factories.gen :user do
28
+ def defaults
29
+ {
30
+ name: "Nathan"
31
+ }
34
32
  end
35
33
  end
36
34
 
@@ -47,6 +45,20 @@ user4 = Factories.build(:user, name: nil)
47
45
  user4.valid? # => false
48
46
  ```
49
47
 
48
+ If you don't want to use the fancy `#gen` method, the equivilent is:
49
+
50
+ ```ruby
51
+ module Factories
52
+ class UserFactory < BaseFactory
53
+ def defaults
54
+ {
55
+ name: "Nathan"
56
+ }
57
+ end
58
+ end
59
+ end
60
+ ```
61
+
50
62
  For the best result, `include Factories` into your test/spec scope.
51
63
 
52
64
  An example `spec_helper.rb` could be:
@@ -1,3 +1,3 @@
1
1
  module Factories
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/factories.rb CHANGED
@@ -1,21 +1,30 @@
1
1
  require "inflecto"
2
2
 
3
3
  module Factories
4
+ def self.gen(name, &blk)
5
+ klass = Class.new(BaseFactory, &blk)
6
+ Factories.const_set(factory_class_name_from_string(name).intern, klass)
7
+ klass
8
+ end
9
+
10
+ def self.class_from_name(name)
11
+ factory_name = factory_class_name_from_string(name)
12
+ class_name = "Factories::#{factory_name}"
13
+ Inflecto.constantize class_name
14
+ end
15
+
16
+ def self.factory_class_name_from_string(name)
17
+ Inflecto.classify "#{name}_factory"
18
+ end
19
+
4
20
  module_function
5
21
 
6
22
  def create(name, opts = {})
7
- class_from_name(name).create(opts)
23
+ Factories.class_from_name(name).create(opts)
8
24
  end
9
25
 
10
26
  def build(name, opts = {})
11
- class_from_name(name).build(opts)
12
- end
13
-
14
- def class_from_name(name)
15
- class_name = "#{name}_factory"
16
- class_name = Inflecto.classify class_name
17
- class_name = "Factories::#{class_name}"
18
- Inflecto.constantize class_name
27
+ Factories.class_from_name(name).build(opts)
19
28
  end
20
29
  end
21
30
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: factories
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Herald
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-28 00:00:00.000000000 Z
11
+ date: 2015-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -88,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
88
  version: '0'
89
89
  requirements: []
90
90
  rubyforge_project:
91
- rubygems_version: 2.2.2
91
+ rubygems_version: 2.4.5
92
92
  signing_key:
93
93
  specification_version: 4
94
94
  summary: Super simple way to use build(:author) or create(:book) in your tests.