Permalink
Browse files

include FactoryGirl methods into rspec context

  • Loading branch information...
1 parent cd0120c commit 846d34c3d7859e466f02486106dc2f819bd0af65 @wireframe committed Oct 18, 2013
Showing with 24 additions and 7 deletions.
  1. +5 −4 README.md
  2. +1 −1 lib/factory_girl/rspec/{with.rb → dsl.rb}
  3. +3 −2 lib/factory_girl_rspec.rb
  4. +15 −0 spec/factory_girl_rspec_spec.rb
View
@@ -2,6 +2,11 @@
Integrate FactoryGirl fixture initialization into the RSpec DSL.
+## Features
+* clean and concise DSL for instantiating FactoryGirl fixtures
+* easily configure factory variations with FactoryGirl traits or optional parameter hash
+* [includes FactoryGirl DSL into main Rspec context to DRY up creation](https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md#using-factories)
+
## Usage
Basic usage:
@@ -38,10 +43,6 @@ describe User do
end
```
-## Features
-* clean and concise DSL for instantiating FactoryGirl fixtures
-* easily configure deviations in fixtures with optional parameter hash
-
## Installation
```ruby
@@ -2,7 +2,7 @@
module FactoryGirl
module Rspec
- module With
+ module Dsl
# define an rspec helper method that lazily creates the referenced
# FactoryGirl fixture (via let)
# example usage:
@@ -1,6 +1,7 @@
-require 'factory_girl/rspec/with'
+require 'factory_girl/rspec/dsl'
require 'rspec'
RSpec.configure do |config|
- config.extend FactoryGirl::Rspec::With
+ config.extend FactoryGirl::Rspec::Dsl
+ config.include FactoryGirl::Syntax::Methods
end
@@ -44,4 +44,19 @@
end
end
end
+
+ describe FactoryGirl::Syntax::Methods do
+ context 'create' do
+ it 'is available without FactoryGirl prefix' do
+ user = create :user
+ expect(user).to_not be_nil
+ end
+ end
+ context 'build' do
+ it 'is available without FactoryGirl prefix' do
+ user = build :user
+ expect(user).to_not be_nil
+ end
+ end
+ end
end

0 comments on commit 846d34c

Please sign in to comment.