factories 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +58 -9
- data/lib/factories/base_factory.rb +3 -1
- data/lib/factories/version.rb +1 -1
- data/lib/factories.rb +2 -0
- metadata +12 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 646d0842c1762febbea8ad679e8c2aaf254bf637
|
4
|
+
data.tar.gz: 460766260ed6859dbce67c65ea8b11f7d63f5f32
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4feaeaee5706bf4798e783302347c4007848a462a1034db1e42a770c25af148def95d3df38dfe59d02073007b362d06fc09937da82087ad47010cd7d00f2d25
|
7
|
+
data.tar.gz: db205472b835e46313863b632d3e57d40e3889c68eb44570f45c34d2a7eea55f4abe0676e5e2e2bc695895a671f601324dd965ef1bad36bc1143ace033bc5950
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
# Factories
|
2
2
|
|
3
|
-
TODO: Write a gem description
|
4
|
-
|
5
3
|
## Installation
|
6
4
|
|
7
5
|
Add this line to your application's Gemfile:
|
@@ -18,12 +16,63 @@ Or install it yourself as:
|
|
18
16
|
|
19
17
|
## Usage
|
20
18
|
|
21
|
-
|
19
|
+
`Factories` responds to `#build` and `#create` and does exactly what you
|
20
|
+
would expect:
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
class User < ActiveRecord::Base
|
24
|
+
validates :name, presence: true
|
25
|
+
end
|
26
|
+
|
27
|
+
module Factories
|
28
|
+
class UserFactory < BaseFactory
|
29
|
+
def defaults
|
30
|
+
{
|
31
|
+
name: "Nathan"
|
32
|
+
}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
user = Factories.build(:user)
|
38
|
+
user.persisted? # => false
|
39
|
+
|
40
|
+
user2 = Factories.create(:user)
|
41
|
+
user2.persisted? # => true
|
42
|
+
|
43
|
+
user3 = Factories.build(:user, name: "Jason")
|
44
|
+
user3.valid? # => true
|
45
|
+
|
46
|
+
user4 = Factories.build(:user, name: nil)
|
47
|
+
user4.valid? # => false
|
48
|
+
```
|
49
|
+
|
50
|
+
For the best result, `include Factories` into your test/spec scope.
|
51
|
+
|
52
|
+
An example `spec_helper.rb` could be:
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
ENV["RAILS_ENV"] ||= 'test'
|
56
|
+
require File.expand_path("../../config/environment", __FILE__)
|
57
|
+
require 'rspec/rails'
|
58
|
+
require 'rspec/autorun'
|
59
|
+
|
60
|
+
Dir[Rails.root.join("spec/{support,factories}/**/*.rb")].each { |f| require f }
|
61
|
+
|
62
|
+
RSpec.configure do |config|
|
63
|
+
include Factories
|
64
|
+
|
65
|
+
config.infer_base_class_for_anonymous_controllers = false
|
66
|
+
config.order = "random"
|
67
|
+
end
|
22
68
|
|
23
|
-
|
69
|
+
describe User do
|
70
|
+
context "with an invalid model" do
|
71
|
+
let(:user) { create(:user, name: nil) }
|
24
72
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
73
|
+
it "expects a name sucka" do
|
74
|
+
expect(user).to_not be_valid
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
```
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require "active_support/core_ext/string/inflections"
|
2
|
+
|
1
3
|
module Factories
|
2
4
|
class BaseFactory
|
3
5
|
def self.create(opts = {})
|
@@ -9,7 +11,7 @@ module Factories
|
|
9
11
|
end
|
10
12
|
|
11
13
|
def self.model_class
|
12
|
-
name.gsub(/Factory
|
14
|
+
name.gsub(/Factory$/, '').demodulize.constantize
|
13
15
|
end
|
14
16
|
|
15
17
|
def model_class
|
data/lib/factories/version.rb
CHANGED
data/lib/factories.rb
CHANGED
metadata
CHANGED
@@ -1,55 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: factories
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Herald
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-03-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.3'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.3'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: activesupport
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
description: Objects to build and create models
|
@@ -59,7 +59,7 @@ executables: []
|
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
-
- .gitignore
|
62
|
+
- ".gitignore"
|
63
63
|
- Gemfile
|
64
64
|
- LICENSE.txt
|
65
65
|
- README.md
|
@@ -78,17 +78,17 @@ require_paths:
|
|
78
78
|
- lib
|
79
79
|
required_ruby_version: !ruby/object:Gem::Requirement
|
80
80
|
requirements:
|
81
|
-
- -
|
81
|
+
- - ">="
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '0'
|
84
84
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
85
|
requirements:
|
86
|
-
- -
|
86
|
+
- - ">="
|
87
87
|
- !ruby/object:Gem::Version
|
88
88
|
version: '0'
|
89
89
|
requirements: []
|
90
90
|
rubyforge_project:
|
91
|
-
rubygems_version: 2.
|
91
|
+
rubygems_version: 2.2.2
|
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.
|