Sha256: 9b435390fc52ab4efb72fc7c0b9c4a9e5a5793d9c7414aeede8a3b940471465f

Contents?: true

Size: 1.36 KB

Versions: 8

Compression:

Stored size: 1.36 KB

Contents

module Riot

  class ContextMiddleware
    # Registers the current middleware class with Riot so that it may be included in the set of middlewares
    # Riot will poke before executing a Context.
    #
    #   class MyContextMiddleware < Riot::ContextMiddleware
    #     register
    #     def call(context)
    #       context.setup { ... }
    #       middleware.call(context) # this can go anywhere
    #       context.hookup { ... }
    #     end
    #   end
    def self.register; Context.middlewares << self; end

    attr_reader :middleware # Theoretically, the next middleware in the stack

    def initialize(middleware)
      @middleware = middleware
    end

    # The meat. Because you have access to the Context, you can add your own setups,
    # hookups, etc. +call+ will be called before any tests are run, but after the Context is configured.
    def call(context)
      raise "You should implement call yourself"
    end
  end # ContextMiddleware

  # Special middleware used by Context directly. It will always be the last in the chain and is the actual
  # place where the user's runtime context is processed.
  class AllImportantMiddleware < ContextMiddleware
    def initialize(&context_definition)
      @context_definition = context_definition
    end

    def call(context) context.instance_eval(&@context_definition); end
  end # AllImportantMiddleware

end # Riot

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
riot-0.12.1 lib/riot/middleware.rb
riot-0.12.0 lib/riot/middleware.rb
riot-0.12.0.pre lib/riot/middleware.rb
riot-0.11.4 lib/riot/middleware.rb
riot-0.11.4.pre lib/riot/middleware.rb
riot-0.11.3 lib/riot/middleware.rb
riot-0.11.2 lib/riot/middleware.rb
riot-0.11.1 lib/riot/middleware.rb