Class: Apotomo::TestCase

Inherits:
Cell::TestCase
  • Object
show all
Includes:
TestMethods, WidgetShortcuts
Defined in:
lib/apotomo/test_case.rb

Overview

Testing is fun. Test your widgets!

This class helps you testing widgets where it can. It is similar as in a controller. A declarative test would look like

class BlogWidgetTest < Apotomo::TestCase
  has_widgets do |root|
    root << widget(:comments_widget, 'post-comments')
  end

  it "should be rendered nicely" do
    render_widget 'post-comments'

    assert_select "div#post-comments", "Comments for this post"
  end

  it "should redraw on :update" do
    trigger :update
    assert_response "jQuery(\"post-comments\").update ..."
  end

For unit testing, you can grab an instance of your tested widget.

it "should be visible" do
  assert root['post-comments'].visible?
end

See also in Cell::TestCase.

Defined Under Namespace

Modules: TestMethods

Instance Attribute Summary

Attributes included from TestMethods

#view_assigns

Instance Method Summary collapse

Methods included from TestMethods

#parent_controller, #render_widget, #root, #setup, #trigger

Methods included from WidgetShortcuts

#widget

Instance Method Details

#assert_response(*content) ⇒ Object

After a #trigger this assertion compares the actually triggered page updates with the passed.

Example:

trigger :submit, :source => "post-comments"
assert_response "alert(\":submit clicked!\")", /\jQuery\("post-comments"\).update/

108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/apotomo/test_case.rb', line 108

def assert_response(*content)
  updates = root.page_updates

  i = 0
  content.each do |assertion|
    if assertion.kind_of? Regexp
      assert_match assertion, updates[i]
    else
      assert_equal assertion, updates[i]
    end

    i+=1
  end
end