Module: Lita::RSpec

Defined in:
lib/lita/rspec.rb,
lib/lita/rspec/handler.rb,
lib/lita/rspec/matchers/deprecated.rb,
lib/lita/rspec/matchers/chat_route_matcher.rb,
lib/lita/rspec/matchers/http_route_matcher.rb,
lib/lita/rspec/matchers/event_route_matcher.rb

Overview

Extras for RSpec that facilitate the testing of Lita code.

Defined Under Namespace

Modules: Handler, Matchers

Class Method Summary collapse

Class Method Details

.included(base) ⇒ void

This method returns an undefined value.

Causes all interaction with Redis to use a test-specific namespace. Clears Redis before each example. Stubs the logger to prevent log messages from cluttering test output. Clears Lita’s global configuration.

Parameters:

  • base (Object)

    The class including the module.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/lita/rspec.rb', line 25

def included(base)
  base.class_eval do
    let(:registry) do
      if Lita.version_3_compatibility_mode?
        Lita
      else
        Registry.new
      end
    end

    before do
      logger = double("Logger").as_null_object
      allow(Lita).to receive(:logger).and_return(logger)
      stub_const("Lita::REDIS_NAMESPACE", "lita.test")
      keys = Lita.redis.keys("*")
      Lita.redis.del(keys) unless keys.empty?
      registry.clear_config if Lita.version_3_compatibility_mode?
    end
  end
end