Created
April 3, 2009 20:34
-
-
Save seancribbs/89951 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/dataset.rb b/lib/dataset.rb | |
index 54bd20b..5be76d5 100644 | |
--- a/lib/dataset.rb | |
+++ b/lib/dataset.rb | |
@@ -69,7 +69,9 @@ require 'dataset/record/model' | |
# | |
module Dataset | |
def self.included(test_context) # :nodoc: | |
- if test_context.name =~ /TestCase\Z/ | |
+ if test_context.name =~ /World\Z/ | |
+ require 'dataset/extensions/cucumber' | |
+ elsif test_context.name =~ /TestCase\Z/ | |
require 'dataset/extensions/test_unit' | |
elsif test_context.name =~ /ExampleGroup\Z/ | |
require 'dataset/extensions/rspec' | |
diff --git a/lib/dataset/extensions/cucumber.rb b/lib/dataset/extensions/cucumber.rb | |
new file mode 100644 | |
index 0000000..cfefb05 | |
--- /dev/null | |
+++ b/lib/dataset/extensions/cucumber.rb | |
@@ -0,0 +1,20 @@ | |
+module Dataset | |
+ module Extensions # :nodoc: | |
+ | |
+ module CucumberWorld # :nodoc: | |
+ def dataset(*datasets, &block) | |
+ add_dataset(*datasets, &block) | |
+ | |
+ load = nil | |
+ $__cucumber_toplevel.Before do | |
+ load = dataset_session.load_datasets_for(self.class) | |
+ extend_from_dataset_load(load) | |
+ end | |
+ # Makes sure the datasets are reloaded after each scenario | |
+ Cucumber::Rails.use_transactional_fixtures | |
+ end | |
+ end | |
+ | |
+ end | |
+end | |
+Cucumber::Rails::World.extend Dataset::Extensions::CucumberWorld | |
\ No newline at end of file | |
diff --git a/spec/dataset/cucumber_spec.rb b/spec/dataset/cucumber_spec.rb | |
new file mode 100644 | |
index 0000000..953d3a2 | |
--- /dev/null | |
+++ b/spec/dataset/cucumber_spec.rb | |
@@ -0,0 +1,14 @@ | |
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') | |
+ | |
+require 'cucumber/rails/world' | |
+ | |
+class Cucumber::Rails::World | |
+ include Dataset | |
+end | |
+ | |
+describe Cucumber::Rails::World do | |
+ it "should have a dataset method" do | |
+ world = Class.new(Cucumber::Rails::World) | |
+ world.should respond_to(:dataset) | |
+ end | |
+end | |
\ No newline at end of file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Sets up the Rails environment for Cucumber | |
ENV["RAILS_ENV"] = "test" | |
require File.expand_path(File.dirname(__FILE__) + '/../../config/environment') | |
require 'cucumber/rails/world' | |
require 'cucumber/formatters/unicode' # Comment out this line if you don't want Cucumber Unicode support | |
require 'webrat' | |
Webrat.configure do |config| | |
config.mode = :rails | |
end | |
# Comment out the next two lines if you're not using RSpec's matchers (should / should_not) in your steps. | |
require 'cucumber/rails/rspec' | |
require 'dataset' | |
Cucumber::Rails::World.class_eval do | |
include Dataset | |
datasets_directory "#{Rails.root}/spec/datasets" | |
self.datasets_database_dump_path = "#{Rails.root}/tmp/dataset" | |
dataset :config, :pages_with_layouts, :snippets, :users_and_pages, :file_not_found, :markup_pages | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment