Renamed helpers to correspond to renamed Controller classes.
[merb_radiant.git] / radiant_extensions_plugins / plugins / scenarios / lib / scenarios / extensions / .svn / text-base / test_case.rb.svn-base
blob83c67db5210053382299bd2c47913b2faf31e353
1 module Test #:nodoc:
2   module Unit #:nodoc:
3     class TestCase #:nodoc:
4       superclass_delegating_accessor :scenario_classes
5       superclass_delegating_accessor :table_config
6       
7       # Changing either of these is not supported at this time.
8       self.use_transactional_fixtures = true
9       self.use_instantiated_fixtures = false
10       
11       include Scenarios::TableMethods
12       include Scenarios::Loading
13       
14       class << self
15         # This class method is mixed into RSpec and allows you to declare that
16         # you are using a given scenario or set of scenarios within a spec:
17         #
18         #   scenario :basic  # loads BasicScenario and any dependencies
19         #   scenario :posts, :comments  # loads PostsScenario and CommentsScenario
20         #
21         # It accepts an array of scenarios (strings, symbols, or classes) and
22         # will load them roughly in the order that they are specified.
23         def scenario(*names)
24           self.scenario_classes = []
25           names.each do |name|
26             scenario_class = name.to_scenario
27             scenario_classes.concat(scenario_class.used_scenarios + [scenario_class])
28           end
29           scenario_classes.uniq!
30         end
31       
32         # Overridden to provide before all and after all code which sets up and
33         # tears down scenarios
34         def suite_with_scenarios
35           suite = suite_without_scenarios
36           class << suite
37             attr_accessor :test_class
38             def run_with_scenarios(*args, &block)
39               run_without_scenarios(*args, &block)
40               test_class.table_config.loaded_scenarios.each { |s| s.unload } if test_class.table_config
41             end
42             alias_method_chain :run, :scenarios
43           end
44           suite.test_class = self
45           suite
46         end
47         alias_method_chain :suite, :scenarios
48       end
49       
50       # Hook into fixtures loading lifecycle to instead load scenarios. This
51       # is expected to be called in a fashion respective of
52       # use_transactional_fixtures. I feel like a leech.
53       def load_fixtures
54         if !scenarios_loaded? || !use_transactional_fixtures?
55           self.class.table_config = Scenarios::Configuration.new if !use_transactional_fixtures? || table_config.nil?
56           load_scenarios(scenario_classes)
57         end
58         self.extend scenario_helpers
59         self.extend table_readers
60       end
61       
62       # Here we are counting on existing logic to allow teardown method
63       # overriding as done in fixtures.rb. Only if transaction fixtures are
64       # not being used do we unload scenarios after a test. Otherwise, we wait
65       # until the end of the run of all tests on this test_case (collection of
66       # tests, right!). See the TestSuite extension done in _suite_ for
67       # behaviour when using transaction fixtures.
68       def teardown_with_scenarios
69         teardown_without_scenarios
70         loaded_scenarios.each { |s| s.unload } unless use_transactional_fixtures?
71       end
72       alias_method_chain :teardown, :scenarios
73       
74     end
75   end
76 end