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


88
89
90
# File 'lib/call_center/test/dsl.rb', line 88

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


92
93
94
95
96
97
# File 'lib/call_center/test/dsl.rb', line 92

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


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
84
85
86
# File 'lib/call_center/test/dsl.rb', line 48

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


100
101
102
103
104
105
106
# File 'lib/call_center/test/dsl.rb', line 100

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