TestCase - Documentation

Index

API-Documentation

In general the project tries to provide the standard unit-testing API in two wariants, camelized and underscored. And additionally, once we all well know who use the Prototype library, the project provides some usual for the Ruby Test::Unit library aliases.

Standard Assertions
Camelized Underscored Ruby way Description
setUp() setup() If exists, called before each test
tearDown() teardown() If exists, called after each test
assertTrue(value[, message]) assert_true(value[, message]) assert(value[, message]) Asserts the given value as true
assertFalse(value[, message]) assert_false(value[, message]) Asserts the given value as false
assertNull(value[, message]) assert_null(value[, message]) assert_nil(value[, message]) Assert the give value as null
assertNotNull(value[, message]) assert_not_null(value[, message]) assert_not_nil(value[, message]) Assert the give value as not null
assertTypeOf(type, value[, message]) assert_type_of(type, value[, message]) assert_kind_of(type, value[, message]) Checks the value type (object, function, number, string, boolean)
assertInstanceOf(type, value[, message]) assert_instance_of(type, value[, message]) Checks the value instance type
assertEqual(original, comparable[, message]) assert_equal(original, comparable[, message]) Checks the variables values quality
assertNotEqual(original, comparable[, message]) assert_not_equal(original, comparable[, message]) Checks that the variables have different values
assertSame(value1, value2[, message]) assert_same(value1, value2[, message]) Asserts that the given variables point to the same object.
assertNotSame(value1, value2[, message]) assert_not_same(value1, value2[, message]) Asserts that the given variables do not point to the same object.
assertMatch(pattern, string[, message]) assert_match(pattern, string[, message]) Asserts that the given string matches the given pattern
assertNotMatch(pattern, string[, message]) assert_not_match(pattern, string[, message]) assert_no_match(pattern, string[, message]) Asserts that the given string does not matche the given pattern
assertThrows(func[, message]) assert_throws(func[, message]) Getting sure that the given function causes an exception
assertNothingThrown(func[, message]) assert_nothing_thrown(func[, message]) Getting sure that the given function does not raises any exceptions

Some In-Test Messaging Functionality
Camelized Underscored Ruby way Description
fail(message) fail(message) flunk(message) Raises a testing error
debug(vairable) debug(variable) Alerts a simple string representation of the given variable

 

Then, once it's a kinda front-side testing framework, in additional, the library has some handy test methods for page elements testing purposes.

Element related Assertions
Camelized Underscored Description
assertExists(css_rule[, message]) assert_exists(css_rule[, message]) Checks if an element (or elements) which matches the given css-rule exists on the page
assertNotExists(css_rule[, message]) assert_not_exists(css_rule[, message]) Getting sure that there's not such element on the page
assertHasChild(element, css_rule[, message]) assert_has_child(element, css_rule[, message]) Getting sure that the lement has a child element which matches the given css-rule
assertHasNoChild(element, css_rule[, message]) assert_has_no_child(element, css_rule[, message]) Checks that the element has no such child element
assertHasParent(element, css_rule[, message]) assert_has_parent(element, css_rule[, message]) Checks that the given element has a parent element which matches the given css-rule
assertHasNoParent(element, css_rule[, message]) assert_has_no_parent(element, css_rule[, message]) Checks that the given element has no such parent element
assertVisible(element_or_css_rule[, message]) assert_visible(element_or_css_rule[, message]) Asserts that the given element has not the 'display' style equal 'none' and the 'visiblity' equal 'hidden'
assertHidden(element_or_css_rule[, message]) assert_hidden(element_or_css_rule[, message]) Asserts that the given element has the 'display' style equal 'none' or the 'visibility' one equal 'hidden'
assertHasClassName(element, class_name[, message]) assert_has_class_name(element, class_name[, message]) Asserts that the given element has got the given class name
assertHasNoClassName(element, class_name[, message]) assert_has_no_class_name(element, class_name[, message]) Asserts that the given element has not got the given class name
assertStyle(element, style_hash[, message]) assert_style(element, style_hash[, message]) Asserts the given element has styles out of the given hash and with equal values

 

Sure that's not all the stuffs. Then we have got the functionality mocking methods. There are only few of them and they are quite plain.

Mocking Methods
Camelized Underscored Description
mockUp(object, method_name, mock) mockup(object, method_name, mock) Mocks the given object method with the given mock by the method name (a string name)
undoMockup(object, method_name) undo_mockup(object, method_name) Undos the object method mocking-up and gets back the original method
mockupEffects() mockup_effects() Mockups the hidding/appearing effects from the script.aculous library, macking them happen immidiately
undoEffectsMockup() undo_effects_mockup() Undos the effects mocking up

 

And this is still not all of the sweets. At the end we have got a good bunch of methods which allows you to easily fire test events on your elements. Each method fires it's event on the given element and returns the fired event instance. See the Events Firing Description for more details

Mouse Events Firging Functionality
Camelized Underscored Description
fireMouseEvent(element, eventName[, options]) fire_mouse_event(element, eventName[, options]) Firest the given event on the given element
fireClick(element[, options]) fire_click(element[, options]) A shortcut. Fires the usual left-click event on the element
fireMiddleClick(element[, options]) fire_middle_click(element[, options]) A shortcut. Fires the middle-click event on the element. Doesn't work with IE
fireRightClick(element[, options]) fire_right_click(element[, options]) A shortcut. Fires the right-click event on the element.
NOTE: Doesn't work in Opera.
NOTE: Rises 'contextmenu' event in IE
fireDoubleClick(element[, options]) fire_double_click(element[, options]) A shortcut. Fires the double-click event on the element
fireMouseDown(element[, options]) fire_mouse_down(element[, options]) A shortcut. Fires the mouse-down event on the element
fireMouseUp(element[, options]) fire_mouse_up(element[, options]) A shortcut. Fires the mouse-up event on the element
fireMouseOver(element[, options]) fire_mouse_over(element[, options]) A shortcut. Fires the mouse-over event on the element
fireMouseOut(element[, options]) fire_mouse_out(element[, options]) A shortcut. Fires the mouse-out event on the element

Keyboard Events Firging Functionality
Camelized Underscored Description
fireKeyEvent(element, eventName, keyCode[, options]) fire_key_event(element, eventName, keyCode[, options]) Fires the given key-event on the given element.
fireKeyPress(element, keyCode[, options]) fire_key_press(element, keyCode[, options]) A shortcut. fires the key-press on the element
fireKeyDown(element, keyCode[, options]) fire_key_down(element, keyCode[, options]) A shortcut. Fires the key-down event on the element
fireKeyUp(element, keyCode[, options]) fire_key_up(element, keyCode[, options]) A shortcut. Fires the key-up event on the element