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
beforeAll() before_all() If exists, called once before all tests
afterAll() after_all() If exists, called once after all tests
assertTrue(value[, message]) assert_true(...) assert(...) Asserts the given value as true
assertFalse(value[, message]) assert_false(...) Asserts the given value as false
assertNull(value[, message]) assert_null(...) assert_nil(...) Assert the give value as null
assertNotNull(value[, message]) assert_not_null(...) assert_not_nil(...) Assert the give value as not null
assertTypeOf(type, value[, message]) assert_type_of(...) assert_kind_of(...) Checks the value type (object, function, number, string, boolean)
assertInstanceOf(type, value[, message]) assert_instance_of(...) Checks the value instance type
assertEqual(original, comparable[, message]) assert_equal(...) Checks the variables values quality
assertNotEqual(original, comparable[, message]) assert_not_equal(...) Checks that the variables have different values
assertSame(value1, value2[, message]) assert_same(...) Asserts that the given variables point to the same object.
assertNotSame(value1, value2[, message]) assert_not_same(...) Asserts that the given variables do not point to the same object.
assertMatch(pattern, string[, message]) assert_match(...) Asserts that the given string matches the given pattern
assertNotMatch(pattern, string[, message]) assert_not_match(...) assert_no_match(...) Asserts that the given string does not matche the given pattern
assertThrows(func[, scope[, message]]) assert_throws(...) Getting sure that the given function causes an exception
assertNothingThrown(func[, scope[, message]]) assert_nothing_thrown(...) Getting sure that the given function does not raises any exceptions
assertCalled(object, method_name, func[, scope[, message]]) assert_called(...) Checks that the given object's method was called during the given function execution
assertNotCalled(object, method_name, func[, scope[, message]]) assert_not_called(...) The negative for the assert_called method.

Some In-Test Messaging Functionality
Camelized Underscored Ruby way Description
fail(message) fail(...) flunk(...) Raises a testing error
debug(vairable) debug(...) 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(...) Checks if an element (or elements) which matches the given css-rule exists on the page
assertNotExists(css_rule[, message]) assert_not_exists(...) Getting sure that there's not such element on the page
assertHasChild(element, css_rule[, message]) assert_has_child(...) Getting sure that the lement has a child element which matches the given css-rule
assertHasNoChild(element, css_rule[, message]) assert_has_no_child(...) Checks that the element has no such child element
assertHasParent(element, css_rule[, message]) assert_has_parent(...) Checks that the given element has a parent element which matches the given css-rule
assertHasNoParent(element, css_rule[, message]) assert_has_no_parent(...) Checks that the given element has no such parent element
assertVisible(element_or_css_rule[, message]) assert_visible(...) 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(...) 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(...) Asserts that the given element has got the given class name
assertHasNoClassName(element, class_name[, message]) assert_has_no_class_name(...) Asserts that the given element has not got the given class name
assertStyle(element, style_hash[, message]) assert_style(...) 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 More Aliaces Description
mockUp(object, method_name, mock) mockup(...) mock Mocks the given object method with the given mock by the method name (a string name)
undoMockup(object, method_name) undo_mockup(...) undo_mock, undoMock, undoMockUp Undos the object method mocking-up and gets back the original method
withMocked(object, method_name, mock, callback[, scope]) with_mocked(...) with_mock, withMock Wrappes the callback run with mocking and mocking_undo calls with the given arguments
mockupEffects() mockup_effects() mockUpEffects, mockEffects, mock_effects Mockups the hidding/appearing effects from the script.aculous library, macking them happen immidiately
undoEffectsMockup() undo_effects_mockup() undoMockUpEffects, undo_mockup_effects Undos the effects mocking up
withMockedEffects(callback[, scope]) with_mocked_effects(...) Wrappes the callback run with the effects mocking/unmocking calls.
mockupAjax(options) mockup_ajax(...) mockUpAjax Mocks up XHRs to make them return a predefined result.
undoAjaxMockup() undo_ajax_mockup() undoMockUpAjax, undoMockupAjax, undo_mockup_ajax Undos an ajax mockuping
withMockedAjax(options, callback[, scope]) with_mocked_ajax(...) Wrappes the callback run with an ajax mocking up/down with the given options

 

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(...) Firest the given event on the given element
fireClick(element[, options]) fire_click(...) A shortcut. Fires the usual left-click event on the element
fireMiddleClick(element[, options]) fire_middle_click(...) A shortcut. Fires the middle-click event on the element. Doesn't work with IE
fireRightClick(element[, options]) fire_right_click(...) 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(...) A shortcut. Fires the double-click event on the element
fireMouseDown(element[, options]) fire_mouse_down(...) A shortcut. Fires the mouse-down event on the element
fireMouseUp(element[, options]) fire_mouse_up(...) A shortcut. Fires the mouse-up event on the element
fireMouseOver(element[, options]) fire_mouse_over(...) A shortcut. Fires the mouse-over event on the element
fireMouseOut(element[, options]) fire_mouse_out(...) 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(...) Fires the given key-event on the given element.
fireKeyPress(element, keyCode[, options]) fire_key_press(...) A shortcut. fires the key-press on the element
fireKeyDown(element, keyCode[, options]) fire_key_down(...) A shortcut. Fires the key-down event on the element
fireKeyUp(element, keyCode[, options]) fire_key_up(...) A shortcut. Fires the key-up event on the element

Since the version 2.0, there is some internal util which might be usefull for your tests. You can call the methods from the this.util object inside the test-cases or by calling the TestCaseUtil object.

Some Internal Util Methods
Method Descrpition
create_class([parent, ]definition); Creates new class object
extend(object, definitions[, boolean dont_overwrite]) Extends teh object with the given definitions. NOTE: will overwrite the existing attributes if the third argument is not true
equal(mixed value1, mixed value2) Checks if the values are _internally_ equal. NOTE: they are not have to be the same object.
to_a(iterable) Converts the iterable object into an array
to_s(mixed value) Simple value to string representation
debug(mixed value) One-Level, non-recoursive value to string representation.
to_pretty_s(mixed value) Creates a nice string representation of the given value
get_object_class_name(mixed value) Returns a string class-name for the given value (returns 'Null' for null and 'Boolean' for booleans)
get_class_name(Object class) Returns the string name for the given class
Browswer.IE | Opera | WebKit | Gecko | MobileSafari | Konqueror The current browser markers
Element.visible(element) Checks if the element is visible
Element.up(element, css_rule) Search for the parent element which matches the css-rule
Element.down(element, css_rule) Search for the child element which matches the css-rule
Element.select(element, css_rule) Select all the child elements which match the css-rule
Element.has_class_name(element, class_name) Checks if the given element has the given css class-name

NOTE: the element selectors are virtual, they support css/css2 and most of css3 level specs (except some pseudoclasses) and works not on the page elements only but on in-memory elements which are not on the page yet as well.