diff --git a/examples/features/step_definitions/example_steps.rb b/examples/features/step_definitions/example_steps.rb index 1a3e28f..531f07c 100644 --- a/examples/features/step_definitions/example_steps.rb +++ b/examples/features/step_definitions/example_steps.rb @@ -4,13 +4,4 @@ end Then /^I should see 1 widget$/ do Widget.count.should == 1 -end - -When /^I create a sneaky widget$/ do - SneakyWidget.create! -end - -Then /^I should see 1 sneaky widget$/ do - SneakyWidget.count.should == 1 -end - +end \ No newline at end of file diff --git a/examples/features/support/env.rb b/examples/features/support/env.rb index 2d50903..8862233 100644 --- a/examples/features/support/env.rb +++ b/examples/features/support/env.rb @@ -10,7 +10,7 @@ if orm && strategy begin require "#{File.dirname(__FILE__)}/../../lib/#{orm}_models" - rescue LoadError + rescue LoadError => e raise "You don't have the #{orm} ORM installed" end diff --git a/features/step_definitions/database_cleaner_steps.rb b/features/step_definitions/database_cleaner_steps.rb index 475476f..92140bb 100644 --- a/features/step_definitions/database_cleaner_steps.rb +++ b/features/step_definitions/database_cleaner_steps.rb @@ -1,25 +1,31 @@ + Given /^I am using (ActiveRecord|DataMapper|MongoMapper|CouchPotato)$/ do |orm| - @orm = orm + @feature_runner = FeatureRunner.new + @feature_runner.orm = orm +end + +Given /^I am using (ActiveRecord|DataMapper|MongoMapper|CouchPotato) and (ActiveRecord|DataMapper|MongoMapper|CouchPotato)$/ do |orm1,orm2| + @feature_runner = FeatureRunner.new + @feature_runner.orm = orm1 + @feature_runner.another_orm = orm2 end Given /^the (.+) cleaning strategy$/ do |strategy| - @strategy = strategy + @feature_runner.strategy = strategy end When "I run my scenarios that rely on a clean database" do - full_dir ||= File.expand_path(File.dirname(__FILE__) + "/../../examples/") - Dir.chdir(full_dir) do - ENV['ORM'] = @orm.downcase - ENV['STRATEGY'] = @strategy - @out = `#{"jruby -S " if defined?(JRUBY_VERSION)}cucumber features` - @status = $?.exitstatus - end + @feature_runner.go 'example' +end + +When "I run my scenarios that rely on clean databases using multiple orms" do + @feature_runner.go 'example_multiple_orms' +end + +When "I run my scenarios that rely on clean databases using multiple orms" do + @feature_runner.go 'example_multiple_orms' end Then "I should see all green" do - unless @status == 0 - raise "Expected to see all green but we saw FAIL! Output:\n#{@out}" - end -end - - + fail "Feature failed with :#{@feature_runner.output}" unless @feature_runner.exit_status == 0 +end \ No newline at end of file diff --git a/features/support/feature_runner.rb b/features/support/feature_runner.rb new file mode 100644 index 0000000..b982460 --- /dev/null +++ b/features/support/feature_runner.rb @@ -0,0 +1,26 @@ +class FeatureRunner + attr_accessor :orm + attr_accessor :another_orm + attr_accessor :strategy + attr_accessor :exit_status + attr_accessor :output + + def strategy + @strategy || 'truncation' + end + + def go feature + full_dir ||= File.expand_path(File.dirname(__FILE__) + "/../../examples/") + Dir.chdir(full_dir) do + + ENV['ORM'] = orm.downcase + ENV['ANOTHER_ORM'] = another_orm.downcase if another_orm + ENV['STRATEGY'] = strategy + + self.output = `#{"jruby -S " if defined?(JRUBY_VERSION)}cucumber features/#{feature}.feature` + + self.exit_status = $?.exitstatus + end + end + +end \ No newline at end of file