Class: Tengine::RSpec::ContextWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/tengine/rspec/context_wrapper.rb

Overview

Kernelのcontextをラップするクラスです

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(kernel) ⇒ ContextWrapper

Returns a new instance of ContextWrapper.



8
9
10
11
# File 'lib/tengine/rspec/context_wrapper.rb', line 8

def initialize(kernel)
  @kernel = kernel
  @context = @kernel.context
end

Instance Attribute Details

#__driver__Object

Returns the value of attribute __driver__.



6
7
8
# File 'lib/tengine/rspec/context_wrapper.rb', line 6

def __driver__
  @__driver__
end

Instance Method Details

#__driver_class__Object



39
40
41
# File 'lib/tengine/rspec/context_wrapper.rb', line 39

def __driver_class__
  @__driver_class__ ||= __driver__.target_class_name.constantize
end

#__driver_object__Object



43
44
45
46
47
48
49
# File 'lib/tengine/rspec/context_wrapper.rb', line 43

def __driver_object__
  unless @__driver_object__
    @__driver_object__ = __driver_class__.new
    __driver_class__.stub(:new).and_return(@__driver_object__)
  end
  @__driver_object__
end

#receive(event_type_name, options = {}) ⇒ Object



13
14
15
16
17
18
# File 'lib/tengine/rspec/context_wrapper.rb', line 13

def receive(event_type_name, options = {})
  mock_headers = Object.new
  mock_headers.should_receive(:ack)
  raw_event = Tengine::Event.new({:event_type_name => event_type_name}.update(options || {}))
  @kernel.process_message(mock_headers, raw_event.to_json)
end

#should_fire(*args) ⇒ Object



28
29
30
# File 'lib/tengine/rspec/context_wrapper.rb', line 28

def should_fire(*args)
  @kernel.should_receive(:fire).with(*args)
end

#should_not_fire(*args) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/tengine/rspec/context_wrapper.rb', line 31

def should_not_fire(*args)
  if args.empty?
    @kernel.should_not_receive(:fire)
  else
    @kernel.should_not_receive(:fire).with(*args)
  end
end

#should_not_receive(*args) ⇒ Object



24
25
26
# File 'lib/tengine/rspec/context_wrapper.rb', line 24

def should_not_receive(*args)
  @context.should_not_receive(*args)
end

#should_receive(*args) ⇒ Object



20
21
22
# File 'lib/tengine/rspec/context_wrapper.rb', line 20

def should_receive(*args)
  @context.should_receive(*args)
end