Module: CallCenter::Test::DSL::ClassMethods

Defined in:
lib/call_center/test/dsl.rb

Instance Method Summary collapse

Instance Method Details

#call_center_state_field(field = nil) ⇒ Object



85
86
87
# File 'lib/call_center/test/dsl.rb', line 85

def call_center_state_field(field = nil)
  field.nil? ? @_call_center_state_field : (@_call_center_state_field = field)
end

#should_also(&block) ⇒ Object Also known as: and_also



89
90
91
92
93
94
# File 'lib/call_center/test/dsl.rb', line 89

def should_also(&block)
  line = block.to_s.match(/.*@(.*):([0-9]+)>/)[2]
  should "also satisfy block on line #{line}" do
    self.instance_eval(&block)
  end
end

#should_flow(options, &block) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/call_center/test/dsl.rb', line 45

def should_flow(options, &block)
  event = options.delete(:on)
  setup_block = options.delete(:when)
  setup_block_line = setup_block.to_s.match(/.*@(.*):([0-9]+)>/)[2] if setup_block
  state_field = self.call_center_state_field || options.delete(:state) || :state
  from, to = options.to_a.first
  description = ":#{from} => :#{to} via #{event}!#{setup_block_line.present? ? " when:#{setup_block_line}" : nil}"
  context "" do
    should "transition #{description}" do
      self.instance_eval(&setup_block) if setup_block
      @call.send(:"#{state_field}=", from.to_s)
      @call.send(:"#{event}")
      assert_equal to, @call.send(:"#{state_field}_name"), "status should be :#{to}, not :#{@call.send(state_field)}"
      if @call.respond_to?(:call_flow_run_deferred)
        @call.call_flow_run_deferred(:before_transition)
        @call.call_flow_run_deferred(:after_transition)
        @call.call_flow_run_deferred(:after_failure)
      end
    end

    if block.present?
      context "#{description} and :#{to}" do
        setup do
          self.instance_eval(&setup_block) if setup_block
          @call.send(:"#{state_field}=", from.to_s)
          @call.send(:"#{event}")
          body(@call.render) if @call.respond_to?(:render)
          if @call.respond_to?(:call_flow_run_deferred)
            @call.call_flow_run_deferred(:before_transition)
            @call.call_flow_run_deferred(:after_transition)
            @call.call_flow_run_deferred(:after_failure)
          end
        end

        self.instance_eval(&block)
      end
    end
  end
end

#should_render(&block) ⇒ Object Also known as: and_render



97
98
99
100
101
102
103
# File 'lib/call_center/test/dsl.rb', line 97

def should_render(&block)
  line = block.to_s.match(/.*@(.*):([0-9]+)>/)[2]
  should "render selector on line #{line}" do
    args = [self.instance_eval(&block)].flatten
    assert_select *args
  end
end