changelog shortlog tags changeset manifest revisions annotate raw

vendor/plugins/rspec_on_rails/lib/spec/rails/story_adapter.rb

changeset 16: 01fd3f10ae84
author: moriq@moriq.com
date: Mon Mar 10 10:13:18 2008 +0900 (16 years ago)
permissions: -rw-r--r--
description: add plugins rspec_on_rails
1# WARNING - THIS IS PURELY EXPERIMENTAL AT THIS POINT
2# Courtesy of Brian Takita and Yurii Rashkovskii
3
4$:.unshift File.join(File.dirname(__FILE__), *%w[.. .. .. .. rspec lib])
5if defined?(ActiveRecord::Base)
6 require 'test_help'
7else
8 require 'action_controller/test_process'
9 require 'action_controller/integration'
10end
11require 'test/unit/testresult'
12require 'spec'
13require 'spec/rails'
14
15Test::Unit.run = true
16
17ActionController::Integration::Session.send(:include, Spec::Matchers)
18ActionController::Integration::Session.send(:include, Spec::Rails::Matchers)
19
20class RailsStory < ActionController::IntegrationTest
21 if defined?(ActiveRecord::Base)
22 self.use_transactional_fixtures = true
23 else
24 def self.fixture_table_names; []; end # Workaround for projects that don't use ActiveRecord
25 end
26
27 def initialize #:nodoc:
28 # TODO - eliminate this hack, which is here to stop
29 # Rails Stories from dumping the example summary.
30 Spec::Runner::Options.class_eval do
31 def examples_should_be_run?
32 false
33 end
34 end
35 @_result = Test::Unit::TestResult.new
36 end
37end
38
39class ActiveRecordSafetyListener
40 include Singleton
41 def scenario_started(*args)
42 if defined?(ActiveRecord::Base)
43 ActiveRecord::Base.send :increment_open_transactions unless Rails::VERSION::STRING == "1.1.6"
44 ActiveRecord::Base.connection.begin_db_transaction
45 end
46 end
47
48 def scenario_succeeded(*args)
49 if defined?(ActiveRecord::Base)
50 ActiveRecord::Base.connection.rollback_db_transaction
51 ActiveRecord::Base.send :decrement_open_transactions unless Rails::VERSION::STRING == "1.1.6"
52 end
53 end
54 alias :scenario_pending :scenario_succeeded
55 alias :scenario_failed :scenario_succeeded
56end
57
58class Spec::Story::Runner::ScenarioRunner
59 def initialize
60 @listeners = [ActiveRecordSafetyListener.instance]
61 end
62end
63
64class Spec::Story::GivenScenario
65 def perform(instance, name = nil)
66 scenario = Spec::Story::Runner::StoryRunner.scenario_from_current_story @name
67 runner = Spec::Story::Runner::ScenarioRunner.new
68 runner.instance_variable_set(:@listeners,[])
69 runner.run(scenario, instance)
70 end
71end