Class: Kookaburra::APIDriver Abstract

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/kookaburra/api_driver.rb

Overview

This class is abstract.

Subclass and implement your Given DSL.

Your APIDriver subclass is used to define your testing DSL for setting up test preconditions. Unlike APIClient, which is meant to be a simple mapping to your application's API, a method in the APIDriver may be comprised of several distinct API calls as well as access to Kookaburra's test data store via #mental_model.

Examples:

APIDriver subclass

module MyApp
  module Kookaburra
    class APIDriver < ::Kookaburra::APIDriver
      def api
        @api ||= APIClient.new(configuration)
      end

      def a_widget(name, attributes = {})
        # Set up the data that will be passed to the API by merging any
        # passed attributes into the default data.
        data = {:name => 'Foo', :description => 'Bar baz'}.merge(attributes)

        # Call the API method and get the resulting response as Ruby data.
        result = api.create_widget(data)

        # Store the resulting widget data in the MentalModel object, so that
        # it can be referenced in other operations.
        mental_model.widgets[name] = result
      end
    end
  end
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ APIDriver

It is unlikely that you would call #initialize yourself; your APIDriver object is instantiated for you by Kookaburra#api.

Parameters:



42
43
44
# File 'lib/kookaburra/api_driver.rb', line 42

def initialize(configuration)
  @configuration = configuration
end

Instance Attribute Details

#configurationObject (readonly, protected)

Returns the value of attribute configuration.



48
49
50
# File 'lib/kookaburra/api_driver.rb', line 48

def configuration
  @configuration
end

#mental_modelObject (protected)

Access to the shared MentalModel instance



53
# File 'lib/kookaburra/api_driver.rb', line 53

def_delegator :configuration, :mental_model

Instance Method Details

#apiKookaburra::APIClient (protected)

This method is abstract.

Used to access your APIClient in your own APIDriver implementation

Returns:

Raises:

  • (Kookaburra::ConfigurationError)

    raised if you do not provide an implementation.



61
62
63
# File 'lib/kookaburra/api_driver.rb', line 61

def api
  raise ConfigurationError, "You must implement #api in your subclass."
end