Module: Waylon::RSpec::Skill

Includes:
Matchers::RouteMatcher
Defined in:
lib/waylon/rspec/skill.rb

Overview

Extras for RSpec to facilitate testing Waylon Skills

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

Sets up the RSpec environment



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

def included(base)
  base.send(:include, Waylon::RSpec)

  init_let_blocks(base)
  init_subject(base)
end

Instance Method Details

#repliesArray<String>

An array of strings that have been sent by the bot during throughout a test

Returns:

  • (Array<String>)

    The replies.



46
47
48
# File 'lib/waylon/rspec/skill.rb', line 46

def replies
  TestSense.sent_messages
end

#send_message(body, from: testuser, channel: nil, privately: false) ⇒ void

This method returns an undefined value.

Sends a message to the bot

Parameters:

  • body (String)

    The message to send

  • from (TestUser) (defaults to: testuser)

    The user sending the message

  • channel (TestChannel) (defaults to: nil)

    Where the message is received

  • privately (Boolean) (defaults to: false)

    Is the message a DM



56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/waylon/rspec/skill.rb', line 56

def send_message(body, from: testuser, channel: nil, privately: false)
  msg_details = { person_id: from.id, text: body, created_at: Time.now }
  if privately
    msg_details[:type] = :private
    msg_details[:receiver_id] = robot.id
  else
    msg_details[:type] = :channel
    msg_details[:channel_id] = channel ? channel.id : chatroom.id
  end

  TestSense.perform(msg_details)
  TestWorker.handle(TestSense.fake_queue)
end