Class: Waylon::RSpec::TestSense
- Defined in:
- lib/waylon/rspec/test_sense.rb
Overview
Extras for RSpec to facilitate testing Waylon Skills
Class Method Summary collapse
- .add_user_from_details(details) ⇒ Object
-
.channel_list ⇒ Array<Integer>
The list of TestChannel IDs for this TestSense.
-
.enqueue(route, request) ⇒ Object
Overrides the Sense.enqueue class method to avoid Resque.
-
.fake_queue ⇒ Queue
Allows access to the fake version of Resque.
-
.message_class ⇒ Class
Ensures we’re using the TestMessage class for Messages.
-
.message_from_request(request) ⇒ Waylon::Message
Provides a way to use an initial request to reconstitute a Sense-specific Message.
-
.message_list ⇒ Array<Hash>
The list of message details that were sent through this Sense.
-
.react(request, type) ⇒ void
Emulates reactions by sending a message with the reaction type.
-
.received_messages ⇒ Array<String>
Provides all message text sent to Waylon.
-
.reply(request, text) ⇒ void
Posts a reply to the channel.
-
.run(message_details) ⇒ void
Receives incoming message details and places work on a queue to be performed by a Skill.
-
.sent_messages ⇒ Array<String>
Provides all message text sent by Waylon.
-
.user_class ⇒ Class
Ensures we’re using the TestUser class for Users.
-
.user_list ⇒ Array<User>
The list of Users for this TestSense.
Methods inherited from Sense
codify, config_namespace, group_class, mention, perform, queue
Methods included from BaseComponent
Class Method Details
.add_user_from_details(details) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/waylon/rspec/test_sense.rb', line 11 def self.add_user_from_details(details) user_id = user_list.size user = user_class.new(user_id, details) user_list << user user end |
.channel_list ⇒ Array<Integer>
The list of TestChannel IDs for this TestSense
20 21 22 |
# File 'lib/waylon/rspec/test_sense.rb', line 20 def self.channel_list @channel_list ||= [] end |
.enqueue(route, request) ⇒ Object
Overrides the Sense.enqueue class method to avoid Resque
25 26 27 28 29 30 31 32 33 |
# File 'lib/waylon/rspec/test_sense.rb', line 25 def self.enqueue(route, request) details = { "sense" => self, "request" => request, "route" => route.name } fake_queue.push [route.destination, details] end |
.fake_queue ⇒ Queue
Allows access to the fake version of Resque
37 38 39 |
# File 'lib/waylon/rspec/test_sense.rb', line 37 def self.fake_queue @fake_queue ||= Queue.new end |
.message_class ⇒ Class
Ensures we’re using the TestMessage class for Messages
43 44 45 |
# File 'lib/waylon/rspec/test_sense.rb', line 43 def self. RSpec::TestMessage end |
.message_from_request(request) ⇒ Waylon::Message
Provides a way to use an initial request to reconstitute a Sense-specific Message
55 56 57 |
# File 'lib/waylon/rspec/test_sense.rb', line 55 def self.(request) .new(.size - 1, request) end |
.message_list ⇒ Array<Hash>
The list of message details that were sent through this Sense
49 50 51 |
# File 'lib/waylon/rspec/test_sense.rb', line 49 def self. @message_list ||= [] end |
.react(request, type) ⇒ void
This method returns an undefined value.
Emulates reactions by sending a message with the reaction type
63 64 65 66 |
# File 'lib/waylon/rspec/test_sense.rb', line 63 def self.react(request, type) msg = (request) msg.channel.(":#{type}:") end |
.received_messages ⇒ Array<String>
Provides all message text sent to Waylon
70 71 72 |
# File 'lib/waylon/rspec/test_sense.rb', line 70 def self. .reject { |m| m[:user_id] == TestUser.whoami.id }.map { |m| m[:text] } end |
.reply(request, text) ⇒ void
This method returns an undefined value.
Posts a reply to the channel
78 79 80 81 |
# File 'lib/waylon/rspec/test_sense.rb', line 78 def self.reply(request, text) msg = (request) msg.channel.(text) end |
.run(message_details) ⇒ void
This method returns an undefined value.
Receives incoming message details and places work on a queue to be performed by a Skill
86 87 88 89 90 91 92 |
# File 'lib/waylon/rspec/test_sense.rb', line 86 def self.run() << = .size - 1 msg = .new() route = SkillRegistry.route(msg) || SkillRegistry.instance.default_route(msg) enqueue(route, ) end |
.sent_messages ⇒ Array<String>
Provides all message text sent by Waylon
96 97 98 |
# File 'lib/waylon/rspec/test_sense.rb', line 96 def self. .select { |m| m[:user_id] == TestUser.whoami.id }.map { |m| m[:text] } end |
.user_class ⇒ Class
Ensures we’re using the TestUser class for Users
102 103 104 |
# File 'lib/waylon/rspec/test_sense.rb', line 102 def self.user_class RSpec::TestUser end |
.user_list ⇒ Array<User>
The list of Users for this TestSense
108 109 110 |
# File 'lib/waylon/rspec/test_sense.rb', line 108 def self.user_list @user_list ||= [] end |