r1 - 24 Jan 2007 - 17:43:14 - ChristianFoliniYou are here: TWiki >  Main Web > Task12Start

Task12Start - Add functional tests to main controller, view hello

See TasksExplained? for more infos about tasks. This task is based on the template at TaskTemplateStart

Category : gui
Date opened : 2007-01-24
Description : Add functional tests to main controller, view hello
Remarks :
Referenced in stories/tasks :
Status : closed
Commited revision : 23


Changelog

2007-01-24 - written the tests

The "Agile Web Development with Rails" book brings good idea with assert_select from page 199ff.

dune73@railsmachine ~/data/remo/trunk/remo>ruby test/functional/main_controller_test.rb 
Loaded suite test/functional/main_controller_test
Started
..
Finished in 0.328196 seconds.

2 tests, 60 assertions, 0 failures, 0 errors

code excerpt:

  def test_hello
    get :hello
    assert_template "hello"
    assert_select "title", 1

    def assert_exist_elementlist (list, num=1)
        list.each do |item|
                assert_select item, num, "ERROR: Page item " + item + " not found " + num.to_s + " time(s) as expected." # check that item exists <num> of times in the page
        end
    end
    # make sure we have the correct set of page elements
    #   classes
    elements = ["div.maincolumn",
                "div.detailarea", 
                "div.mainarea", 
                "div.statusarea"]
    assert_exist_elementlist elements, 2
    
    #   individual elements via id
    elements = ["div#banner", 
                "div#title",
                "div#logodiv",
                "div#rules-mainarea",
                "div#source-mainarea",
                "div#banner",
                "div#title",
                "div#logodiv",
                "div#maindiv",
                "div#source",
                "div#source-toolsetarea",
                "div#source-detailarea",
                "div#source-mainarea",
                "div#source-statusarea",
                "div#rules",
                "div#rules-toolsetarea",
                "div#rules-detailarea",
                "div#rules-mainarea",
                "div#rules-statusarea", 
                "div#rules-statusarea"]
    assert_exist_elementlist elements

    # check link to remo.netnea.com and www.modsecurity.org
    assert_select "div#title > h1 > a:first-child", /remo/
    assert_select "div#title > h1 > a[href=http://remo.netnea.com]", 1
    assert_select "div#title > h1 > a:nth-child(2)", /modsecurity/
    assert_select "div#title > h1 > a[href=http://www.modsecurity.org]", 1

    # check existence of logo
    assert_select "img#logo[src=/images/logo.png]", 1

  end

TaskStati
TaskStatus? closed
Task-Categories gui
Edit | Attach | Printable | Raw View | Backlinks: Web, All Webs | History: r1 | More topic actions
Main.TaskTemplateStart moved from Main.TaskTemplate on 19 Jan 2007 - 12:41 by ChristianFolini
 

No permission to view WebTopBar?

No permission to view WebBottomBar?