Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Update variable name definitions to include any traits passed

  • Loading branch information...
commit b007566e6c06f2de522674a47e9d216575fe60f6 1 parent 19fdc64
@wireframe authored
View
2  README.md
@@ -33,7 +33,7 @@ describe User do
context 'when user is inactive' do
# instantiate FactoryGirl :user fixture with custom traits
with :user, :when_inactive
- it { user.should be_inactive }
+ it { user_when_inactive.should be_inactive }
end
end
```
View
2  lib/factory_girl/rspec/version.rb
@@ -1,5 +1,5 @@
module FactoryGirl
module Rspec
- VERSION = "1.0.0"
+ VERSION = "2.0.0.alpha2"
end
end
View
25 lib/factory_girl/rspec/with.rb
@@ -3,12 +3,29 @@
module FactoryGirl
module Rspec
module With
- def with(name, *args)
- let(name) { ::FactoryGirl.create(name, *args) }
+ # define an rspec helper method that lazily creates the referenced
+ # FactoryGirl fixture (via let)
+ # example usage:
+ # with :user
+ def with(*args)
+ register_factory 'let', *args
end
- def with!(name, *args)
- let!(name) { ::FactoryGirl.create(name, *args) }
+ # define an rspec helper method that eagerly creates the referenced
+ # FactoryGirl fixture (via let!)
+ # example usage:
+ # with! :user
+ def with!(*args)
+ register_factory 'let!', *args
+ end
+
+ private
+
+ def register_factory(method_name, *args)
+ variable_name = args.reject {|arg| arg.is_a?(Hash) }.join('_')
+ send(method_name, variable_name) do
+ ::FactoryGirl.create *args
+ end
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.