Top Level Namespace

Defined Under Namespace

Modules: Coach

Instance Method Summary collapse

Instance Method Details

#build_middleware(name) ⇒ Object

Middleware stubbing ######################################



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/spec/matchers.rb', line 6

def build_middleware(name)
  Class.new(Coach::Middleware) do
    # To access `name`, we need to use `define_method` instead of `def`
    define_method(:to_s) { "<Middleware#{name}>" }
    define_method(:name) { name }
    define_singleton_method(:name) { name }

    def call
      config[:callback].call if config.include?(:callback)
      (Hash[name.to_sym, true])

      # Build up a list of middleware called, in the order they were called
      if next_middleware
        [name].concat(next_middleware.call)
      else
        [name]
      end
    end
  end
end

#null_middlewareObject



27
28
29
# File 'lib/spec/matchers.rb', line 27

def null_middleware
  double(call: nil)
end