Permalink
Browse files

Added Turnip and exercise its fabrication steps like we do with Cucumber

  • Loading branch information...
1 parent 74fa336 commit 809ac044a6f4b07f6a2fb14c3167ef9e84e5159a @bdmac bdmac committed with Nov 18, 2011
View
1 .rspec
@@ -1,3 +1,4 @@
--colour
--format Fuubar
--backtrace
+-r turnip
View
@@ -83,6 +83,9 @@ GEM
sequel (3.30.0)
sqlite3 (1.3.5)
term-ansicolor (1.0.7)
+ turnip (0.3.0)
+ gherkin (>= 2.5)
+ rspec (~> 2.0)
tzinfo (0.3.31)
PLATFORMS
@@ -105,3 +108,4 @@ DEPENDENCIES
ruby-debug19
sequel
sqlite3
+ turnip (>= 0.3)
View
@@ -12,5 +12,8 @@ Cucumber::Rake::Task.new(:cucumber) do |t|
t.cucumber_opts = "--format Cucumber::Formatter::Fuubar --tags ~@wip"
end
+RSpec::Core::RakeTask.new(:turnip) do |spec|
+ spec.pattern = "turnip/**/*.feature"
+end
-task :default => [:spec, :cucumber]
+task :default => [:spec, :cucumber, :turnip]
View
@@ -21,6 +21,7 @@ Gem::Specification.new do |s|
s.add_development_dependency("bson", ["~> 1.3.1"])
s.add_development_dependency("bson_ext", ["~> 1.3.1"])
s.add_development_dependency("cucumber")
+ s.add_development_dependency("turnip", [">= 0.3"])
s.add_development_dependency("ffaker")
s.add_development_dependency("fuubar")
s.add_development_dependency("fuubar-cucumber")
@@ -10,53 +10,47 @@
end
end
-placeholder :fabrication_model_name do
- match /([^"]*)/ do |model_name|
- model_name.to_s
- end
-end
-
steps_for :global do
def with_ivars(fabricator)
@they = yield fabricator
instance_variable_set("@#{fabricator.model}", @they)
end
- step ':fabrication_count :fabrication_model_name' do |count, model_name|
+ step ':fabrication_count :model_name' do |count, model_name|
with_ivars Fabrication::Cucumber::StepFabricator.new(model_name) do |fab|
fab.n(count)
end
end
- step 'the following :fabrication_model_name:' do |model_name, table|
+ step 'the following :model_name:' do |model_name, table|
with_ivars Fabrication::Cucumber::StepFabricator.new(model_name) do |fab|
fab.from_table(table)
end
end
- step 'that :fabrication_model_name has the following :fabrication_model_name:' do |parent, child, table|
+ step 'that :parent has the following :child:' do |parent, child, table|
with_ivars Fabrication::Cucumber::StepFabricator.new(child, :parent => parent) do |fab|
fab.from_table(table)
end
end
- step 'that :fabrication_model_name has :fabrication_count :fabrication_model_name' do |parent, count, child|
+ step 'that :parent has :fabrication_count :child' do |parent, count, child|
with_ivars Fabrication::Cucumber::StepFabricator.new(child, :parent => parent) do |fab|
fab.n(count)
end
end
- step 'that/those :fabrication_model_name belong/belongs to that :fabrication_model_name' do |children, parent|
+ step 'that/those :children belong/belongs to that :parent' do |children, parent|
with_ivars Fabrication::Cucumber::StepFabricator.new(parent) do |fab|
fab.has_many(children)
end
end
- step 'I should see :fabrication_count :fabrication_model_name in the database' do |count, model_name|
+ step 'I should see :fabrication_count :model_name in the database' do |count, model_name|
Fabrication::Cucumber::StepFabricator.new(model_name).klass.count.should == count
end
- step 'I should see the following :fabrication_model_name in the database:' do |model_name, table|
+ step 'I should see the following :model_name in the database:' do |model_name, table|
klass = Fabrication::Cucumber::StepFabricator.new(model_name).klass
klass.where(table.rows_hash).count.should == 1
end
View
@@ -6,6 +6,9 @@
Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f}
RSpec.configure do |config|
- config.before(:all) { TestMigration.up }
- config.before(:all) { clear_mongodb }
+ Turnip::Config.step_dirs = ['turnip', File.expand_path('lib/rails/generators/fabrication/turnip_steps/templates/')]
+ config.before(:each) do
+ TestMigration.up
+ clear_mongodb
+ end
end
@@ -0,0 +1,160 @@
+Feature: Active Record Objects
+
+ Scenario: some generic objects
+ Given 5 divisions
+ Then I should see 5 divisions in the database
+
+ Scenario: a single detailed object
+ Given the following division:
+ | name | Rasczak's Roughnecks |
+ Then I should see 1 division in the database
+ And I should see the following division in the database:
+ | name | Rasczak's Roughnecks |
+
+ Scenario: multiple detailed objects
+ Given the following divisions:
+ | name |
+ | Red Squadron |
+ | Yellow Squadron |
+ Then I should see 2 divisions in the database
+ And I should see the following division in the database:
+ | name | Red Squadron |
+ And I should see the following division in the database:
+ | name | Yellow Squadron |
+
+ Scenario: a parented single generic object
+ Given 1 company
+ And that company has 1 division
+ Then I should see 1 company in the database
+ And I should see 1 division in the database
+
+ Scenario: a parented single detailed object
+ Given 1 company
+ And that company has the following division:
+ | name | Everyone |
+ Then I should see 1 company in the database
+ And I should see 1 division in the database
+ And I should see the following division in the database:
+ | name | Everyone |
+ And that division should reference that company
+
+ Scenario: a parented single detailed object with inheritance
+ Given 1 company
+ And that company has the following squadron:
+ | name | Everyone |
+ Then I should see 1 company in the database
+ And I should see 1 squadron in the database
+ And I should see the following division in the database:
+ | name | Everyone |
+ And that squadron should reference that company
+
+ Scenario: a parented single detailed object whose parent has inheritance
+ Given 1 startup
+ And that startup has the following division:
+ | name | Everyone |
+ Then I should see 1 startup in the database
+ And I should see 1 division in the database
+ And I should see the following division in the database:
+ | name | Everyone |
+ And that division should reference that startup
+
+ Scenario: multiple parented detailed objects
+ Given 1 company
+ And that company has the following divisions:
+ | name |
+ | Red Squadron |
+ | Yellow Squadron |
+ Then I should see 1 company in the database
+ And I should see 2 divisions in the database
+ And I should see the following division in the database:
+ | name | Red Squadron |
+ And I should see the following division in the database:
+ | name | Yellow Squadron |
+ And they should reference that company
+
+ Scenario: multiple parented detailed objects with inheritance
+ Given 1 company
+ And that company has the following squadrons:
+ | name |
+ | Red Squadron |
+ | Yellow Squadron |
+ Then I should see 1 company in the database
+ And I should see 2 squadrons in the database
+ And I should see the following division in the database:
+ | name | Red Squadron |
+ And I should see the following division in the database:
+ | name | Yellow Squadron |
+ And they should reference that company
+
+ Scenario: multiple parented detailed objects whose parent has inheritance
+ Given 1 startup
+ And that startup has the following divisions:
+ | name |
+ | Red Squadron |
+ | Yellow Squadron |
+ Then I should see 1 startup in the database
+ And I should see 2 divisions in the database
+ And I should see the following division in the database:
+ | name | Red Squadron |
+ And I should see the following division in the database:
+ | name | Yellow Squadron |
+ And they should reference that startup
+
+ Scenario: a generic parent from the child
+ Given 1 division
+ And that division has 1 company
+ Then I should see 1 division in the database
+ And I should see 1 company in the database
+ And that division should reference that company
+
+ Scenario: a detailed parent from the child
+ Given 1 division
+ And that division has the following company:
+ | name | Hashrocket |
+ Then I should see 1 division in the database
+ And I should see 1 company in the database
+ And I should see the following company in the database:
+ | name | Hashrocket |
+ And that division should reference that company
+
+ Scenario: a parent with inheritance from the child
+ Given 1 division
+ And that division has the following startup:
+ | name | Hashrocket |
+ Then I should see 1 startup in the database
+ And I should see 1 division in the database
+ And I should see the following company in the database:
+ | name | Hashrocket |
+ And that division should reference that startup
+
+ Scenario: a child belongs to a parent
+ Given 1 company
+ And 1 division
+ And that division belongs to that company
+ Then I should see 1 division in the database
+ And I should see 1 company in the database
+ And that division should reference that company
+
+ Scenario: an inherited child belongs to a parent
+ Given 1 company
+ And 1 squadron
+ And that squadron belongs to that company
+ Then I should see 1 squadron in the database
+ And I should see 1 company in the database
+ And that squadron should reference that company
+
+ Scenario: a child belongs to an inherited parent
+ Given 1 startup
+ And 1 division
+ And that division belongs to that startup
+ Then I should see 1 division in the database
+ And I should see 1 startup in the database
+ And that division should reference that startup
+
+ Scenario: children belong to a parent
+ Given 1 company
+ And 2 divisions
+ And those divisions belong to that company
+ Then I should see 1 company in the database
+ And I should see 2 divisions in the database
+ And they should reference that company
View
@@ -0,0 +1,5 @@
+Feature: Not ORM specific
+
+ Scenario: fabricator doesn't exist
+ When I try to fabricate "god"
+ Then it should tell me that it isn't defined
@@ -0,0 +1,68 @@
+Feature: Mongoid Objects
+
+ Scenario: for some generic objects
+ Given 5 authors
+ Then I should see 5 authors in the database
+
+ Scenario: a single detailed object
+ Given the following author:
+ | name | George Orwell |
+ Then I should see 1 author in the database
+ And I should see the following author in the database:
+ | name | George Orwell |
+
+ Scenario: a single detailed object with a multi-word name
+ Given the following "publishing house":
+ | name | Random House |
+ Then I should see 1 "publishing house" in the database
+ And I should see the following "publishing house" in the database:
+ | name | Random House |
+
+ Scenario: multiple detailed objects
+ Given the following authors:
+ | name |
+ | Dr. Seuss |
+ | Shel Silverstein |
+ Then I should see 2 authors in the database
+ And I should see the following author in the database:
+ | name | Dr. Seuss |
+ And I should see the following author in the database:
+ | name | Shel Silverstein |
+
+ Scenario: a parented single detailed object
+ Given 1 author
+ And that author has the following book:
+ | title | 1984 |
+ Then I should see 1 author in the database
+ And that book should be persisted
+ And that book should have "1984" for a "title"
+ And that book should reference that author
+
+ Scenario: a parented object with a multi-word name
+ Given 1 "publishing house"
+ And that "publishing house" has the following "book promoter":
+ | name | Vinnie |
+ Then I should see 1 "publishing house" in the database
+ And that "book promoter" should be persisted
+ And that "book promoter" should have "Vinnie" for a "name"
+ And that "book promoter" should reference that "publishing house"
+
+ Scenario: a multi-word child belongs to a multi-word parent
+ Given 1 "publishing house"
+ And 1 "professional affiliation"
+ And that "publishing house" belongs to that "professional affiliation"
+ Then I should see 1 "publishing house" in the database
+ And I should see 1 "professional affiliation" in the database
+ And that "publishing house" should reference that "professional affiliation"
+
+ Scenario: multiple parented detailed objects
+ Given 1 author
+ And that author has the following books:
+ | title |
+ | 1984 |
+ | Animal Farm |
+ Then I should see 1 author in the database
+ And they should be persisted
+ And they should reference that author
+ And the first should have "1984" for a "title"
+ And the second should have "Animal Farm" for a "title"
Oops, something went wrong.

0 comments on commit 809ac04

Please sign in to comment.