Module: Twi::Mocking

Included in:
Twi
Defined in:
lib/twi/mocking.rb

Instance Method Summary collapse

Instance Method Details

#conversationObject



22
23
24
# File 'lib/twi/mocking.rb', line 22

def conversation(...)
  (@mock ? Mock::Conversation : Conversation).new(...)
end

#create_messageObject



18
19
20
# File 'lib/twi/mocking.rb', line 18

def create_message(...)
  message(...).tap &:create
end

#create_phoneObject



14
15
16
# File 'lib/twi/mocking.rb', line 14

def create_phone(...)
  phone(...).tap &:create
end

#eventObject



26
27
28
# File 'lib/twi/mocking.rb', line 26

def event(...)
  (@mock ? Mock::Event : Event).new(...)
end

#messageObject



34
35
36
# File 'lib/twi/mocking.rb', line 34

def message(...)
  (@mock ? Mock::Message : Message).new(...)
end

#mockObject



3
4
5
# File 'lib/twi/mocking.rb', line 3

def mock
  @mock ||= Twi::Mock.new
end

#phoneObject



30
31
32
# File 'lib/twi/mocking.rb', line 30

def phone(...)
  (@mock ? Mock::Phone : Phone).new(...)
end

#reset_mockObject

Forgets every answer arranged so far and starts mocking again from nothing. A test suite calls this before each test: the mock lives on the module, so without it one test answers for the next.



10
11
12
# File 'lib/twi/mocking.rb', line 10

def reset_mock
  @mock = Twi::Mock.new
end