Class: CallCenter::Test::MiniTest::DSL::ItShouldFlow
- Inherits:
-
Object
- Object
- CallCenter::Test::MiniTest::DSL::ItShouldFlow
show all
- Defined in:
- lib/call_center/test/minitest/dsl.rb
Defined Under Namespace
Classes: Condition, Expectation, Expects, IfCondition, Stubs, UnlessCondition
Instance Method Summary
collapse
Constructor Details
#initialize(context, &block) ⇒ ItShouldFlow
Returns a new instance of ItShouldFlow.
18
19
20
21
|
# File 'lib/call_center/test/minitest/dsl.rb', line 18
def initialize(context, &block)
@context = context
self.instance_eval(&block) if block_given?
end
|
Instance Method Details
#after_transition_methods(s_m) ⇒ Object
125
126
127
|
# File 'lib/call_center/test/minitest/dsl.rb', line 125
def after_transition_methods(s_m)
s_m.callbacks.values.flatten.map { |c| c.instance_variable_get(:@methods) }.flatten.select { |m| m.is_a?(Symbol) }
end
|
#expects(method_name, &blk) ⇒ Object
85
86
87
88
89
|
# File 'lib/call_center/test/minitest/dsl.rb', line 85
def expects(method_name, &blk)
@expectations ||= []
@expectations << Expects.new(method_name, &blk)
self
end
|
#from(from_state) ⇒ Object
28
29
30
31
|
# File 'lib/call_center/test/minitest/dsl.rb', line 28
def from(from_state)
@from = from_state.to_s
self
end
|
#if(condition) ⇒ Object
97
98
99
100
101
|
# File 'lib/call_center/test/minitest/dsl.rb', line 97
def if(condition)
@expectations ||= []
@expectations << IfCondition.new(condition)
self
end
|
#if_and_unless_conditions(s_m) ⇒ Object
129
130
131
132
|
# File 'lib/call_center/test/minitest/dsl.rb', line 129
def if_and_unless_conditions(s_m)
branches = s_m.events.map(&:branches).flatten
branches.map(&:if_condition).compact | branches.map(&:unless_condition).compact
end
|
#on(event) ⇒ Object
23
24
25
26
|
# File 'lib/call_center/test/minitest/dsl.rb', line 23
def on(event)
@event = event
self
end
|
#restubs(object, *without) ⇒ Object
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/call_center/test/minitest/dsl.rb', line 109
def restubs(object, *without)
without = [without].flatten
s_m = object.class.current_state_machine
stub_methods = (after_transition_methods(s_m) | if_and_unless_conditions(s_m)).uniq - without
object.reset_mocha
stub_methods.each do |m|
if m.instance_of?(CallCenter::ConditionalStack::Evaluator)
m.stack.map(&:name).each do |name|
object.stubs(name)
end
else
object.stubs(m)
end
end
end
|
#send_event(subject, event) ⇒ Object
154
155
156
|
# File 'lib/call_center/test/minitest/dsl.rb', line 154
def send_event(subject, event)
subject.send(:"#{event}!")
end
|
#stubs(method_name, &blk) ⇒ Object
91
92
93
94
95
|
# File 'lib/call_center/test/minitest/dsl.rb', line 91
def stubs(method_name, &blk)
@expectations ||= []
@expectations << Stubs.new(method_name, &blk)
self
end
|
#to(to_state) ⇒ Object
33
34
35
36
|
# File 'lib/call_center/test/minitest/dsl.rb', line 33
def to(to_state)
@to = to_state.to_s
self
end
|
#unless(condition) ⇒ Object
103
104
105
106
107
|
# File 'lib/call_center/test/minitest/dsl.rb', line 103
def unless(condition)
@expectations ||= []
@expectations << UnlessCondition.new(condition)
self
end
|
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
# File 'lib/call_center/test/minitest/dsl.rb', line 134
def verify
event, from, to = @event, @from, @to
expectations = @expectations || []
helper = self
@context.it(description) do
helper.restubs(subject, expectations.map(&:name))
expectations.each do |expectation|
expectation.setup(subject)
end
state_field = defined?(call_center_state_field) ? call_center_state_field.to_sym : :state
subject.send(:"#{state_field}=", from)
helper.verify_send(subject, event, state_field, to)
if subject.respond_to?(:call_flow_run_deferred)
subject.call_flow_run_deferred(:before_transition)
subject.call_flow_run_deferred(:after_transition)
subject.call_flow_run_deferred(:after_failure)
end
end
end
|
#verify_send(subject, event, state_field, to) ⇒ Object
158
159
160
161
|
# File 'lib/call_center/test/minitest/dsl.rb', line 158
def verify_send(subject, event, state_field, to)
send_event(subject, event)
subject.send(state_field).must_equal(to)
end
|