factory_girl_rspec 1.0.0 → 2.0.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: 804fad498c84e1a206ea07757c425dde3f25dafc
4
- data.tar.gz: 6729fb8227461010cfe1ee02f921fc7a8c88a7dc
3
+ metadata.gz: f430609277352762527d818bbda9c23db1898439
4
+ data.tar.gz: ee39364decfc0d02e57eadbf397310304f52b65b
5
5
  SHA512:
6
- metadata.gz: a6ede4e36b769d2f013905c2841959ab9bff140fc7235dd604a08c70968c1a3319c4bc270310d546db50ee1f7f95b2a527c698af9d4c23c049c922550f3aefd9
7
- data.tar.gz: 38fb876cdcd022caa629baf0bae792c27fbc7f9fe4f58fac70c4da78352d8df67801327753a2f8e83e694b668ad30c8db2010b97d4d015364a54e3cdcd514346
6
+ metadata.gz: 0ac7ef19aff949d84ffabfd7b9c5d8ee4591e220abd76a9ecbe79a83676fdb9053d15752d78f01eae5f922fccf5bc0ed11cf3cea7cb61b07c9e3a35348d2b1af
7
+ data.tar.gz: c9985ff30d8b069d1c244e3842de08d56f31b13510f51e8ad7d1921ae18748c0e24337925ffcb056779dbb89e6ce0656e9ed4ca05958928ea9ca0c47854f8df9
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/README.md CHANGED
@@ -33,7 +33,7 @@ describe User do
33
33
  context 'when user is inactive' do
34
34
  # instantiate FactoryGirl :user fixture with custom traits
35
35
  with :user, :when_inactive
36
- it { user.should be_inactive }
36
+ it { user_when_inactive.should be_inactive }
37
37
  end
38
38
  end
39
39
  ```
data/Rakefile CHANGED
@@ -1,2 +1,6 @@
1
1
  require 'bundler'
2
2
  Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec)
6
+ task :default => :spec
@@ -17,6 +17,8 @@ Gem::Specification.new do |s|
17
17
  s.add_runtime_dependency 'rspec', '>= 2.0'
18
18
  s.add_runtime_dependency 'factory_girl', '>= 2.0'
19
19
 
20
+ s.add_development_dependency 'sqlite3'
21
+
20
22
  s.files = `git ls-files`.split("\n")
21
23
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
22
24
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
@@ -1,5 +1,5 @@
1
1
  module FactoryGirl
2
2
  module Rspec
3
- VERSION = "1.0.0"
3
+ VERSION = "2.0.0"
4
4
  end
5
5
  end
@@ -3,12 +3,29 @@ require 'factory_girl'
3
3
  module FactoryGirl
4
4
  module Rspec
5
5
  module With
6
- def with(name, *args)
7
- let(name) { ::FactoryGirl.create(name, *args) }
6
+ # define an rspec helper method that lazily creates the referenced
7
+ # FactoryGirl fixture (via let)
8
+ # example usage:
9
+ # with :user
10
+ def with(*args)
11
+ register_factory 'let', *args
8
12
  end
9
13
 
10
- def with!(name, *args)
11
- let!(name) { ::FactoryGirl.create(name, *args) }
14
+ # define an rspec helper method that eagerly creates the referenced
15
+ # FactoryGirl fixture (via let!)
16
+ # example usage:
17
+ # with! :user
18
+ def with!(*args)
19
+ register_factory 'let!', *args
20
+ end
21
+
22
+ private
23
+
24
+ def register_factory(method_name, *args)
25
+ variable_name = args.reject {|arg| arg.is_a?(Hash) }.join('_')
26
+ send(method_name, variable_name) do
27
+ ::FactoryGirl.create *args
28
+ end
12
29
  end
13
30
  end
14
31
  end
@@ -0,0 +1,10 @@
1
+ FactoryGirl.define do
2
+ factory :user do
3
+ name 'John Doe'
4
+
5
+ trait :when_name_is_empty do
6
+ name nil
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+ describe FactoryGirl::Rspec do
4
+ describe '.with' do
5
+ context 'with factory' do
6
+ with :user
7
+ it 'creates helper method' do
8
+ expect(user).to_not be_nil
9
+ end
10
+ end
11
+ context 'with traits' do
12
+ with :user, :when_name_is_empty
13
+ it 'creates helper method name with factory + traits' do
14
+ expect(user_when_name_is_empty).to_not be_nil
15
+ expect(user_when_name_is_empty.name).to be_nil
16
+ end
17
+ end
18
+ context 'with overridden properties' do
19
+ with :user, name: 'Bob'
20
+ it 'configures instance with overridden properties' do
21
+ expect(user.name).to eq 'Bob'
22
+ end
23
+ end
24
+ end
25
+
26
+ describe '.with!' do
27
+ context 'with factory' do
28
+ with! :user
29
+ it 'creates helper method' do
30
+ expect(user).to_not be_nil
31
+ end
32
+ end
33
+ context 'with traits' do
34
+ with! :user, :when_name_is_empty
35
+ it 'creates helper method name with factory + traits' do
36
+ expect(user_when_name_is_empty).to_not be_nil
37
+ expect(user_when_name_is_empty.name).to be_nil
38
+ end
39
+ end
40
+ context 'with overridden properties' do
41
+ with! :user, name: 'Bob'
42
+ it 'configures instance with overridden properties' do
43
+ expect(user.name).to eq 'Bob'
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,6 @@
1
+ class User
2
+ attr_accessor :name
3
+
4
+ def save!
5
+ end
6
+ end
@@ -0,0 +1,12 @@
1
+ require 'factory_girl_rspec'
2
+ require 'models/user'
3
+
4
+ FactoryGirl.find_definitions
5
+
6
+ RSpec.configure do |config|
7
+ config.treat_symbols_as_metadata_keys_with_true_values = true
8
+ config.run_all_when_everything_filtered = true
9
+ config.filter_run :focus
10
+
11
+ config.order = 'random'
12
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: factory_girl_rspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Sonnek
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-03 00:00:00.000000000 Z
11
+ date: 2013-10-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: sqlite3
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  description: add helper methods to quickly instantiate and assign factory girl fixtures
42
56
  to your test context
43
57
  email:
@@ -47,6 +61,7 @@ extensions: []
47
61
  extra_rdoc_files: []
48
62
  files:
49
63
  - .gitignore
64
+ - .rspec
50
65
  - .ruby-gemset
51
66
  - .ruby-version
52
67
  - CONTRIBUTORS.txt
@@ -58,6 +73,10 @@ files:
58
73
  - lib/factory_girl/rspec/version.rb
59
74
  - lib/factory_girl/rspec/with.rb
60
75
  - lib/factory_girl_rspec.rb
76
+ - spec/factories/users.rb
77
+ - spec/factory_girl_rspec_spec.rb
78
+ - spec/models/user.rb
79
+ - spec/spec_helper.rb
61
80
  homepage: ''
62
81
  licenses: []
63
82
  metadata: {}
@@ -77,8 +96,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
96
  version: '0'
78
97
  requirements: []
79
98
  rubyforge_project: factory_girl_rspec
80
- rubygems_version: 2.0.6
99
+ rubygems_version: 2.1.5
81
100
  signing_key:
82
101
  specification_version: 4
83
102
  summary: integrate factory_girl directly into the RSpec DSL
84
- test_files: []
103
+ test_files:
104
+ - spec/factories/users.rb
105
+ - spec/factory_girl_rspec_spec.rb
106
+ - spec/models/user.rb
107
+ - spec/spec_helper.rb