Skip to content

Commit

Permalink
Support for cucumber.
Browse files Browse the repository at this point in the history
  • Loading branch information
jgarber committed Apr 6, 2009
1 parent d2e144d commit 665a3c0
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG
@@ -1,3 +1,6 @@
* Support for cucumber [jgarber, seancribbs]


*1.1.0 [STI, belongs_to] (February 14, 2009)

* STI is better supported for inserting, naming and finding records [aiwilliams]
Expand Down
4 changes: 3 additions & 1 deletion lib/dataset.rb
Expand Up @@ -69,7 +69,9 @@
#
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'
Expand Down
20 changes: 20 additions & 0 deletions 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
4 changes: 4 additions & 0 deletions plugit/descriptor.rb
Expand Up @@ -17,5 +17,9 @@
rspec.after_update { `git checkout -b rspecrelease 1.1.11 && mkdir -p #{vendor_directory} && ln -nsf #{File.expand_path('.')} #{vendor_directory + '/rspec'}` }
rspec.requires = %w{spec}
end
env.library :cucumber, :export => "git clone git://github.com/aslakhellesoy/cucumber.git" do |cukes|
cukes.after_update { `git fetch origin master; git checkout v0.2.3.1` }
cukes.requires = %w{cucumber}
end
end
end
54 changes: 54 additions & 0 deletions spec/dataset/cucumber_spec.rb
@@ -0,0 +1,54 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

$:.unshift(File.dirname(__FILE__) + '/../stubs')
require "mini_rails"

require 'cucumber/rails/world'
require 'cucumber/rails/rspec'
Cucumber::Rails::World.class_eval do
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

it 'should load the dataset when the feature is run' do
load_count = 0
my_dataset = Class.new(Dataset::Base) do
define_method(:load) do
load_count += 1
end
end

step_mother = Object.new
step_mother.extend(Cucumber::StepMother)
$__cucumber_toplevel = step_mother
step_mother.World do |world|
world = Cucumber::Rails::World.new
world.class.dataset(my_dataset)
world
end
step_mother.Given /true is true/ do |n|
true.should == true
end
visitor = Cucumber::Ast::Visitor.new(step_mother)

scenario = Cucumber::Ast::Scenario.new(
background=nil,
comment=Cucumber::Ast::Comment.new(""),
tags=Cucumber::Ast::Tags.new(98, []),
line=99,
keyword="",
name="",
steps=[
Cucumber::Ast::Step.new(8, "Given", "true is true")
])
visitor.visit_feature_element(scenario)

load_count.should be(1)
end
end
18 changes: 18 additions & 0 deletions spec/stubs/mini_rails.rb
@@ -0,0 +1,18 @@
# Define some stubs to fake Rails...
module ActiveRecord
class Base
end
end

module ActionController
class Dispatcher
end

class Base
end

class IntegrationTest
def self.use_transactional_fixtures=(x)
end
end
end
1 change: 1 addition & 0 deletions spec/stubs/test_help.rb
@@ -0,0 +1 @@
# This file is loaded by rails/world.rb

0 comments on commit 665a3c0

Please sign in to comment.