3 class TestCase #:nodoc:
4 superclass_delegating_accessor :scenario_classes
5 superclass_delegating_accessor :table_config
7 # Changing either of these is not supported at this time.
8 self.use_transactional_fixtures = true
9 self.use_instantiated_fixtures = false
11 include Scenarios::TableMethods
12 include Scenarios::Loading
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:
18 # scenario :basic # loads BasicScenario and any dependencies
19 # scenario :posts, :comments # loads PostsScenario and CommentsScenario
21 # It accepts an array of scenarios (strings, symbols, or classes) and
22 # will load them roughly in the order that they are specified.
24 self.scenario_classes = []
26 scenario_class = name.to_scenario
27 scenario_classes.concat(scenario_class.used_scenarios + [scenario_class])
29 scenario_classes.uniq!
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
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
42 alias_method_chain :run, :scenarios
44 suite.test_class = self
47 alias_method_chain :suite, :scenarios
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.
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)
58 self.extend scenario_helpers
59 self.extend table_readers
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?
72 alias_method_chain :teardown, :scenarios