Module: Lita::RSpec::Handler
- Includes:
- Matchers::ChatRouteMatcher, Matchers::DeprecatedMethods, Matchers::EventRouteMatcher, Matchers::HTTPRouteMatcher
- Defined in:
- lib/lita/rspec/handler.rb
Overview
Extras for RSpec
to facilitate testing Lita handlers.
Class Method Summary collapse
-
.included(base) ⇒ Object
Sets up the RSpec environment to easily test Lita handlers.
Instance Method Summary collapse
-
#http ⇒ Faraday::Connection
Returns a Faraday connection hooked up to the currently running robot’s Rack app.
-
#replies ⇒ Array<String>
An array of strings that have been sent by the robot during the course of a test.
-
#send_command(body, as: user, from: nil, privately: false) ⇒ void
Sends a “command” message to the robot.
-
#send_message(body, as: user, from: nil, privately: false) ⇒ void
Sends a message to the robot.
Methods included from Matchers::DeprecatedMethods
#does_not_route, #does_not_route_command, #does_not_route_event, #does_not_route_http, #routes, #routes_command, #routes_event, #routes_http
Methods included from Matchers::ChatRouteMatcher
Class Method Details
.included(base) ⇒ Object
Sets up the RSpec environment to easily test Lita handlers.
17 18 19 20 21 22 23 24 |
# File 'lib/lita/rspec/handler.rb', line 17 def included(base) base.send(:include, Lita::RSpec) prepare_handlers(base) prepare_adapter(base) prepare_let_blocks(base) prepare_subject(base) end |
Instance Method Details
#http ⇒ Faraday::Connection
Returns a Faraday connection hooked up to the currently running robot’s Rack app.
111 112 113 114 115 116 117 118 119 |
# File 'lib/lita/rspec/handler.rb', line 111 def http begin require "rack/test" rescue LoadError raise LoadError, I18n.t("lita.rspec.rack_test_required") end unless Rack.const_defined?(:Test) Faraday::Connection.new { |c| c.adapter(:rack, robot.app) } end |
#replies ⇒ Array<String>
An array of strings that have been sent by the robot during the course of a test.
80 81 82 |
# File 'lib/lita/rspec/handler.rb', line 80 def replies robot.chat_service. end |
#send_command(body, as: user, from: nil, privately: false) ⇒ void
This method returns an undefined value.
Sends a “command” message to the robot.
104 105 106 |
# File 'lib/lita/rspec/handler.rb', line 104 def send_command(body, as: user, from: nil, privately: false) ("#{robot.mention_name}: #{body}", as: as, from: from, privately: privately) end |
#send_message(body, as: user, from: nil, privately: false) ⇒ void
This method returns an undefined value.
Sends a message to the robot.
89 90 91 92 93 94 95 96 97 |
# File 'lib/lita/rspec/handler.rb', line 89 def (body, as: user, from: nil, privately: false) = Message.new( robot, body, Source.new(user: as, room: from, private_message: privately) ) robot.receive() end |