Module: Kookaburra::TestHelpers

Extended by:
Forwardable
Defined in:
lib/kookaburra/test_helpers.rb

Overview

This module is intended to be mixed in to your testing context to provide convenient access to your Kookaburra objects. Examples for both RSpec and Cucumber are given below; mixing it in to other test setups should be pretty straight-forward.

Examples:

RSpec setup

# in 'spec/support/kookaburra_setup.rb'
require 'kookaburra/test_helpers'
require 'my_app/kookaburra/api_driver'
require 'my_app/kookaburra/ui_driver'

Kookaburra.configure do |c|
  c.api_driver_class = MyApp::Kookaburra::APIDriver,
  c.ui_driver_class = MyApp::Kookaburra::UIDriver,
  c.app_host = 'http://my_app.example.com:12345',
  c.browser = capybara,
  c.server_error_detection { |browser|
    browser.has_css?('h1', text: 'internal server error')
  }
end

RSpec.configure do |c|
  c.include(Kookaburra::TestHelpers, :type => :request)
end

# in 'spec/request/some_feature_spec.rb'
describe "Some Feature" do
  example "some test script" do
    api.create_widget(:foo)
    api.create_widget(:bar, :hidden => true)
    api.create_widget(:baz)

    ui.view_list_of_widgets

    ui.widget_list.widgets.should == k.get_data(:widgets).slice(:foo, :baz)

    ui.widget_list.hide_widget(:foo)

    ui.widget_list.widgets.should == k.get_data(:widgets).slice(:baz)
  end
end

Cucumber setup

# in 'features/support/kookaburra_setup.rb'
require 'kookaburra/test_helpers'
require 'my_app/kookaburra/api_driver'
require 'my_app/kookaburra/ui_driver'

Kookaburra.configure do |c|
  c.api_driver_class = MyApp::Kookaburra::APIDriver,
  c.ui_driver_class = MyApp::Kookaburra::UIDriver,
  c.app_host = 'http://my_app.example.com:12345',
  c.browser = capybara,
  c.server_error_detection { |browser|
    browser.has_css?('h1', text: 'internal server error')
  }
end

World(Kookaburra::TestHelpers)

# in 'features/step_definitions/some_steps.rb
Given /^there is a widget, "(\w+)"/ do |name|
  api.create_widget(name.to_sym)
end

Given /^there is a hidden widget, "(\w+)"/ do |name|
  api.create_widget(name.to_sym, :hidden => true)
end

When /^I view the widget list/ do
  ui.view_the_widget_list
end

Then /^I see the widget list contains the following widgets$/ do |widget_names|
  widgets = widget_names.hashes.map { |h| h['name'].to_sym }
  ui.widget_list.widgets.should == k.get_data(:widgets).slice(widgets)
end

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object

Will return the Kookaburra instance for any configured applications

After an application is configured via Configuration#application, the TestHelpers will respond to the name of that application by returning the associated Kookaburra instance. (Messages that do not match the name of a configured application will be handled with the usual #method_missing semantics.)

See Also:

  • Kookaburra::TestHelpers.[Kookaburra[Kookaburra::Configuration[Kookaburra::Configuration#application]


119
120
121
122
# File 'lib/kookaburra/test_helpers.rb', line 119

def method_missing(method_name, *args, &block)
  Kookaburra.configuration.applications[method_name.to_sym] \
    || super
end

Instance Method Details

#apiObject

Note:

This method will only be available when no named applications have been defined. (See Configuration#application.)

Delegates to main Kookaburra instance

Raises:

  • (Kookaburra::AmbiguousDriverError)

    if named applications have been configured.



93
# File 'lib/kookaburra/test_helpers.rb', line 93

def_delegator :kookaburra, :api

#get_data(*args) ⇒ Object

Delegates to main Kookaburra instance



106
107
108
# File 'lib/kookaburra/test_helpers.rb', line 106

def get_data(*args)
  main_kookaburra.get_data(*args)
end

#respond_to?(method_name) ⇒ Boolean

Returns:

  • (Boolean)

See Also:

  • Kookaburra::TestHelpers.[Kookaburra[Kookaburra::TestHelpers[Kookaburra::TestHelpers#method_missing]


125
126
127
128
# File 'lib/kookaburra/test_helpers.rb', line 125

def respond_to?(method_name)
  Kookaburra.configuration.applications.has_key?(method_name) \
    || super
end

#uiObject

Note:

This method will only be available when no named applications have been defined. (See Configuration#application.)

Delegates to main Kookaburra instance

Raises:

  • (Kookaburra::AmbiguousDriverError)

    if named applications have been configured.



103
# File 'lib/kookaburra/test_helpers.rb', line 103

def_delegator :kookaburra, :ui