Skip to content
Browse files

Dataset session is now reset before each scenario is run.

  • Loading branch information...
1 parent 931c508 commit 3c831c594dcba6bc6c3f29a8104dc9c7807241c6 @mscottford mscottford committed Feb 7, 2010
Showing with 34 additions and 21 deletions.
  1. +32 −12 lib/dataset/extensions/cucumber.rb
  2. +2 −9 spec/dataset/cucumber_spec.rb
View
44 lib/dataset/extensions/cucumber.rb
@@ -5,19 +5,39 @@ module Extensions # :nodoc:
class CucumberInitializer # :nodoc:
include Dataset
+ def initialize
+ @datasets = []
+ @cucumber_has_been_setup = false
+ end
+
+ def datasets
+ @datasets
+ end
+
def load(*datasets)
- datasets.each do |dataset|
- self.class.add_dataset(dataset)
- end
+ @datasets += datasets
- load = nil
- initializer = self
- $__cucumber_toplevel.Before do
- load = initializer.dataset_session.load_datasets_for(initializer.class)
- extend_from_dataset_load(load)
+ unless @cucumber_has_been_setup
+ load = nil
+ initializer = self
+ $__cucumber_toplevel.Before do
+ # reset the dataset session before each scenario
+ unless initializer.dataset_session.nil?
+ initializer.dataset_session.reset!
+ end
+
+ initializer.datasets.each do |dataset|
+ initializer.class.add_dataset(dataset)
+ end
+
+ load = initializer.dataset_session.load_datasets_for(initializer.class)
+ extend_from_dataset_load(load)
+ end
+ # Makes sure the datasets are reloaded after each scenario
+ ::Cucumber::Rails::World.use_transactional_fixtures = true
+
+ @cucumber_has_been_setup = true
end
- # Makes sure the datasets are reloaded after each scenario
- ::Cucumber::Rails::World.use_transactional_fixtures = true
end
alias_method :use, :load
@@ -34,8 +54,8 @@ module Cucumber # :nodoc:
def Datasets(&block)
raise "A block is required when calling Datasets" unless block_given?
- initializer = CucumberInitializer.new
- initializer.instance_eval(&block)
+ @initializer = CucumberInitializer.new unless defined? @initalizer
+ @initializer.instance_eval(&block)
end
def self.load_world(target)
View
11 spec/dataset/cucumber_spec.rb
@@ -19,7 +19,6 @@
describe "Cucumber Support" do
before do
@step_mother, @rb_language = create_step_mother_and_language
- raise "What?!" if @rb_language.nil?
@visitor = Cucumber::Ast::TreeWalker.new(@step_mother)
@visitor.options = {}
@@ -28,12 +27,6 @@
@cucumber_world = $__cucumber_root
Dataset::Extensions::Cucumber.load_world(@cucumber_world)
- # reset the dataset session before each test
- unless Dataset::Extensions::CucumberInitializer.dataset_session.nil?
- Dataset::Extensions::CucumberInitializer.dataset_session.reset!
- end
-
- @it_ran = true
end
describe "cucumber root object" do
@@ -223,15 +216,15 @@
dataset_two_load_count += 1
end
end
-
+
@cucumber_world.Datasets do
use dataset_one
end
@cucumber_world.Datasets do
use :dataset_two
end
-
+
dataset_one_load_count.should be(0)
dataset_two_load_count.should be(0)
run_cucumber

0 comments on commit 3c831c5

Please sign in to comment.
Something went wrong with that request. Please try again.