module Apotomo::TestCase::TestMethods

Generic test methods to be used in Test::Unit, RSpec, etc.

Attributes

view_assigns[R]

Public Instance Methods

controller_path() click to toggle source
# File lib/apotomo/test_case.rb, line 45
def controller_path
  'barn'
end
parent_controller() click to toggle source
# File lib/apotomo/test_case.rb, line 81
def parent_controller
  @controller
end
render_widget(*args) click to toggle source

Renders the widget name.

# File lib/apotomo/test_case.rb, line 53
def render_widget(*args)
  @view_assigns = extract_state_ivars_for(root[args.first]) do
    @last_invoke = root.render_widget(*args)
  end
  cleanup_assigns!(@view_assigns)

  @last_invoke
end
root() click to toggle source

Returns the widget tree from TestCase.has_widgets.

# File lib/apotomo/test_case.rb, line 74
def root
  blk = self.class.has_widgets_blocks or raise "Please setup a widget tree using has_widgets()"
  @root ||= Apotomo::Widget.new(parent_controller, "root").tap do |root|
     self.instance_exec(root, &blk)
  end
end
setup() click to toggle source
Calls superclass method
# File lib/apotomo/test_case.rb, line 41
def setup
  super # defined in Cell::TestCase::CommonTestMethods.

  @controller.instance_eval do
    def controller_path
      'barn'
    end
  end
  @controller.extend Apotomo::Rails::ControllerMethods
end
trigger(type, source, options={}) click to toggle source

Triggers an event of type. You have to pass the source as second options.

Example:

trigger :submit, :comments
# File lib/apotomo/test_case.rb, line 67
def trigger(type, source, options={})
  source = root.find_widget(source)
  source.fire(type, options)
  root.page_updates
end

Private Instance Methods

cleanup_assigns!(assigns) click to toggle source
# File lib/apotomo/test_case.rb, line 86
def cleanup_assigns!(assigns)
  assigns.delete(:lookup_context) # dirty but it works.
end