File: chained_context_middleware_test.rb

package info (click to toggle)
ruby-riot 0.12.7-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, forky, sid, trixie
  • size: 512 kB
  • sloc: ruby: 2,557; makefile: 2
file content (49 lines) | stat: -rw-r--r-- 1,263 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
require 'teststrap'

context "Chaining ContextMiddleware" do

  teardown { Riot::Context.middlewares.clear }

  context("when middleware halts the call chain") do
    hookup do
      Class.new(Riot::ContextMiddleware) do
        register
        def initialize(middleware); end
        def call(context) "whoops"; end
      end
    end

    setup do
      situation = Riot::Situation.new
      Riot::Context.new("Foo") do
        setup { "foo" }
      end.local_run(MockReporter.new, situation)
      situation
    end

    asserts("situation topic") { topic.topic }.nil
  end # when middleware halts the call chain

  context("when middleware continues the call chain") do
    hookup do
      Class.new(Riot::ContextMiddleware) do
        register
        def call(context)
          context.setup { ["foo"] }
          middleware.call(context)
          context.hookup { topic << "baz" }
        end
      end
    end

    setup do
      situation = Riot::Situation.new
      Riot::Context.new("Foo") do
        hookup { topic << "bar" }
      end.local_run(MockReporter.new, situation)
      situation
    end

    asserts("situation topic") { topic.topic }.equals(%w[foo bar baz])
  end # when middleware halts the call chain
end # Chaining ContextMiddleware