Permalink
Browse files

Create from Fabrication feature

  • Loading branch information...
1 parent a1172ca commit 3c1c0896a7960477b6eb3f5f34108c28287e05f5 @dabit dabit committed with Sep 19, 2011
Showing with 63 additions and 1 deletion.
  1. +11 −1 features/app/app.rb
  2. +6 −0 features/app/fabricators.rb
  3. +46 −0 features/pickle/create_from_fabrication.feature
View
@@ -31,6 +31,11 @@
t.decimal :attitude_score, :precision => 4, :scale => 2
t.boolean :has_stale_password, :default => false
end
+
+ create_table :knives, :force => true do |t|
+ t.string :name
+ t.boolean :sharp, :null => false
+ end
end
end
@@ -59,6 +64,11 @@ class Spoon < ActiveRecord::Base
validates_presence_of :name
end
+# Fabricator class
+class Knife < ActiveRecord::Base
+ validates_presence_of :name
+end
+
# we don't want abstract classes getting in there
class AbstractUser < ActiveRecord::Base
self.abstract_class = true
@@ -115,4 +125,4 @@ def email(to, subject, body)
@subject = subject
@body = body
end
-end
+end
@@ -0,0 +1,6 @@
+require 'fabrication'
+
+Fabricator(:knife) do
+ name 'David'
+ sharp true
+end
@@ -0,0 +1,46 @@
+Feature: I can easily create models with Fabrication
+
+ As a fabrication user
+ I want to be able to leverage my fabricators
+ So that I can create models quickly and easily in my features
+
+ Scenario: I create a knife, and see if it looks right
+ Given a knife exists
+ Then the knife should be sharp
+ And the knife's sharp should be true
+
+ Scenario: I create a blunt knife, and see if it looks right
+ Given a knife exists with sharp: false
+ Then the knife should not be sharp
+
+ Scenario: I create a named knife, and see if it has the name
+ Given a knife exists with name: "John", sharp: false
+ Then a knife should exist with name: "John"
+ And the knife should not be sharp
+
+ Scenario: I create 7 knives of various sharpness
+ Given 2 knives exist with sharp: false
+ And 2 knives exist with sharp: true
+ And a knife exists with sharp: false
+
+ Then the 1st knife should not be sharp
+ And the 2nd knife should not be sharp
+ And the 3rd knife should be sharp
+ And the 4th knife should be sharp
+ And the 5th knife should not be sharp
+
+ And 3 knives should exist with sharp: false
+ And the 1st knife should not be sharp
+ And the 2nd knife should not be sharp
+ And the last knife should not be sharp
+
+ And 2 knives should exist with sharp: true
+ And the first knife should be sharp
+ And the last knife should be sharp
+
+ Scenario: ModelNotKnownError should be informative when failing to find
+ Given a knife exists with sharp: true
+ Then the following should raise a Pickle::Session::ModelNotFoundError with "Can't find a knife with sharp: false from the orm in this scenario":
+ """
+ Then a knife should exist with sharp: false
+ """

0 comments on commit 3c1c089

Please sign in to comment.