Skip to content

Adapters

Mark McEahern edited this page Mar 25, 2015 · 3 revisions

By default, Vigia uses Vigia::Adapters::Blueprint adapter. This adapter takes an Api Blueprint compatible file and parses it using RedSnow. Then, it builds up the test structure accordingly.

If needed, Vigia can be configured to use a custom adapter. To do so, you just need to specify the adapter class inside the vigia configuration block:

Vigia.configure do |config|
  config.adapter = MyBlogAdapter
end

Then, inside your adapter class, you can use the setup_adapter method to define the groups and contexts that the adapter will provide:

# Post
class MyBlogAdapter < Vigia::Adapter
  setup_adapter do
    group :resource,
      primary: true,
      contexts: [ :default ]
      describes: [ :post, :pages ]

    context :default,
      http_client_options: {
        url: -> { "/#{ resource }" },
        method: :get
        },
      expectations: {
        code: 200,
        headers: {},
        body: -> { adapter.body_for(resource) }
      }
  end

  def body_for(resource)
    case resource
    when :post
      # Your post index expected body
    when :pages
      # Your pages index expected body
    else
      'Unknown resource. WTH!'
    end
  end
end

When vigia starts, it fetchs the first group defined as primary. For each group, Vigia will loop on each element of the describes option (:post, :page in this example), and will set a rspec memoized object named as the group (let(:resource) { :post }). Then, it will run the children (if any) and the contexts in this group, setting up the http_client_options and expectations memoized objects per context.

See Vigia::Adapters::Blueprint class for more information about configuring and setting up an adapter.

Clone this wiki locally