Module: Replay::Scenario
- Defined in:
- lib/replay/scenario.rb,
lib/replay/scenario/context.rb,
lib/replay/scenario/version.rb,
lib/replay/scenario/sequence.rb
Defined Under Namespace
Modules: ReplayDefinitionMethods
Classes: Context, Sequence
Constant Summary
collapse
- VERSION =
'1.0.0'
Class Method Summary
collapse
Class Method Details
.abstract_include(scenario) ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/replay/scenario.rb', line 25
def self.abstract_include(scenario)
scenario.extend(scenario)
scenario.module_eval do
scenario_wrapper = Module.new do
define_method scenario::REPLAY_SCENARIO_NAME do
scenario.__replay_context
end
end
define_singleton_method(:included) do |scenario_includer|
scenario_includer.const_set(:REPLAY_INCLUSIONS, []) unless scenario_includer.const_defined?(:REPLAY_INCLUSIONS)
scenario_includer::REPLAY_INCLUSIONS << scenario_wrapper
scenario_includer.send(:include, scenario_wrapper)
end
define_singleton_method(:extended) do |scenario_extender|
scenario_extender.const_set(:REPLAY_EXTENSIONS, []) unless scenario_extender.const_defined?(:REPLAY_EXTENSIONS)
scenario_extender::REPLAY_EXTENSIONS << scenario_wrapper
scenario_extender.send(:extend, scenario_wrapper)
end
end
end
|
.included(scenario) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/replay/scenario.rb', line 10
def self.included(scenario)
case scenario
when Class
raise(ArgumentError, "Replay should only be included in modules: #{klass}")
when Module
scenario.const_set(:REPLAY_ACTIONS, {}) unless scenario.const_defined?(:REPLAY_ACTIONS)
scenario.const_set(:REPLAY_SEQUENCES, {}) unless scenario.const_defined?(:REPLAY_SEQUENCES)
scenario.const_set(:REPLAY_INCLUSIONS, []) unless scenario.const_defined?(:REPLAY_INCLUSIONS)
scenario.const_set(:REPLAY_EXTENSIONS, []) unless scenario.const_defined?(:REPLAY_EXTENSIONS)
scenario.const_set(:REPLAY_SCENARIO_NAME, scenario.name.split('::').last.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').gsub(/([a-z\d])([A-Z])/, '\1_\2').tr('-', '_').gsub(/\s/, '_').gsub(/__+/, '_').downcase)
scenario.extend(ReplayDefinitionMethods)
abstract_include(scenario)
end
end
|