Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

rescue spec/rails/story_adapter from rspec-rails and stick it in rspe…

…c-stories
  • Loading branch information...
commit 6740c5c7e3bd389a3d832554be46eb5b76717d8a 1 parent ce3efc2
Sam Stokes authored
Showing with 80 additions and 0 deletions.
  1. +1 −0  Manifest.txt
  2. +79 −0 lib/spec/rails/story_adapter.rb
View
1  Manifest.txt
@@ -4,6 +4,7 @@ Manifest.txt
README.txt
Rakefile
init.rb
+lib/spec/rails/story_adapter.rb
lib/spec/runner/formatter/story/html_formatter.rb
lib/spec/runner/formatter/story/plain_text_formatter.rb
lib/spec/runner/formatter/story/progress_bar_formatter.rb
View
79 lib/spec/rails/story_adapter.rb
@@ -0,0 +1,79 @@
+# WARNING - THIS IS PURELY EXPERIMENTAL AT THIS POINT
+# Courtesy of Brian Takita and Yurii Rashkovskii
+
+$:.unshift File.join(File.dirname(__FILE__), *%w[.. .. .. .. rspec lib])
+if defined?(ActiveRecord::Base)
+ require 'test_help'
+else
+ require 'action_controller/test_process'
+ require 'action_controller/integration'
+end
+require 'test/unit/testresult'
+require 'spec'
+require 'spec/rails'
+
+Test::Unit.run = true
+
+ActionController::Integration::Session.__send__ :include, Spec::Matchers
+ActionController::Integration::Session.__send__ :include, Spec::Rails::Matchers
+
+class RailsStory < ActionController::IntegrationTest
+ if defined?(ActiveRecord::Base)
+ self.use_transactional_fixtures = true
+ else
+ def self.fixture_table_names; []; end # Workaround for projects that don't use ActiveRecord
+ end
+
+ def initialize #:nodoc:
+ # TODO - eliminate this hack, which is here to stop
+ # Rails Stories from dumping the example summary.
+ Spec::Runner::Options.class_eval do
+ def examples_should_be_run?
+ false
+ end
+ end
+ @_result = Test::Unit::TestResult.new
+ end
+end
+
+class ActiveRecordSafetyListener
+ include Singleton
+ def scenario_started(*args)
+ if defined?(ActiveRecord::Base)
+ if ActiveRecord::Base.connection.respond_to?(:increment_open_transactions)
+ ActiveRecord::Base.connection.increment_open_transactions
+ else
+ ActiveRecord::Base.__send__ :increment_open_transactions
+ end
+ end
+ ActiveRecord::Base.connection.begin_db_transaction
+ end
+
+ def scenario_succeeded(*args)
+ if defined?(ActiveRecord::Base)
+ ActiveRecord::Base.connection.rollback_db_transaction
+ if ActiveRecord::Base.connection.respond_to?(:decrement_open_transactions)
+ ActiveRecord::Base.connection.decrement_open_transactions
+ else
+ ActiveRecord::Base.__send__ :decrement_open_transactions
+ end
+ end
+ end
+ alias :scenario_pending :scenario_succeeded
+ alias :scenario_failed :scenario_succeeded
+end
+
+class Spec::Story::Runner::ScenarioRunner
+ def initialize
+ @listeners = [ActiveRecordSafetyListener.instance]
+ end
+end
+
+class Spec::Story::GivenScenario
+ def perform(instance, name = nil)
+ scenario = Spec::Story::Runner::StoryRunner.scenario_from_current_story @name
+ runner = Spec::Story::Runner::ScenarioRunner.new
+ runner.instance_variable_set(:@listeners,[])
+ runner.run(scenario, instance)
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.