module Testable::Context

Public Instance Methods

on(definition, &block) click to toggle source

Creates a definition context for actions. If an existing context exists, that context will be re-used. You can use this simply to keep the context for a script clear. For example, say you have the following interface definitions for pages:

class Home
  include Testable
  url_is "http://localhost:9292"
end

class Navigation
  include Testable
end

You could then do this:

on_visit(Home)
on(Navigation)

The Home definition needs the url_is attribute in order for the on_view factory to work. But Navigation does not because the `on` method is not attempting to visit, simply to reference.

# File lib/testable/context.rb, line 44
def on(definition, &block)
  create_active(definition)
  call_block(&block)
end
on_visit(definition, &block) click to toggle source

Creates a definition context for actions and establishes the context for execution. Given an interface definition for a page like this:

class TestPage
  include Testable

  url_is "http://localhost:9292"
end

You can do the following:

on_visit(TestPage)
# File lib/testable/context.rb, line 15
def on_visit(definition, &block)
  create_active(definition)
  @context.visit
  verify_page(@context)
  call_block(&block)
end

Private Instance Methods

call_block() { |context| ... } click to toggle source
# File lib/testable/context.rb, line 68
def call_block(&block)
  yield @context if block
  @context
end
create_active(definition) click to toggle source
# File lib/testable/context.rb, line 64
def create_active(definition)
  @context = definition.new unless @context.is_a?(definition)
end
verify_page(context) click to toggle source

This method is used to provide a means for checking if a page has been navigated to correctly as part of a context. This is useful because the context signature should remain highly readable, and checks for whether a given page has been reached would make the context definition look sloppy.

# File lib/testable/context.rb, line 56
def verify_page(context)
  return unless defined?(context.url_match_attribute)
  return if context.url_match_attribute.nil?
  return if context.has_correct_url?

  raise Testable::Errors::PageURLFromFactoryNotVerified
end