Class: LapillusTester

Inherits:
Object show all
Includes:
Test::Unit::Assertions
Defined in:
lib/lapillus/lapillus_testers.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLapillusTester

Returns a new instance of LapillusTester.



12
13
14
15
# File 'lib/lapillus/lapillus_testers.rb', line 12

def initialize
  super()
  RequestCycle.set(RequestCycle.new(Hash.new))
end

Instance Attribute Details

#htmlObject (readonly)

Returns the value of attribute html.



7
8
9
# File 'lib/lapillus/lapillus_testers.rb', line 7

def html
  @html
end

Instance Method Details

#assert_component(path, expected_component_class) ⇒ Object



34
35
36
37
# File 'lib/lapillus/lapillus_testers.rb', line 34

def assert_component(path, expected_component_class)
  component = get_component_from_last_rendered_page(path)
  assert_kind_of(expected_component_class, component,"Component #{component} on path #{path} is not a(n) #{expected_component_class}")
end

#assert_contains(expected_content, actual_content = @html) ⇒ Object



39
40
41
42
43
44
# File 'lib/lapillus/lapillus_testers.rb', line 39

def assert_contains(expected_content, actual_content=@html)
  full_message = build_message(nil, "content ? not found, but was ? ", expected_content, actual_content)
  assert_block full_message do
    !@html[expected_content].nil? 
  end
end

#assert_error_messages(expected_error_messages) ⇒ Object



46
47
48
49
# File 'lib/lapillus/lapillus_testers.rb', line 46

def assert_error_messages(expected_error_messages)
  # TODO: implement assert_error_messages(expected_error_messages)
  flunk 'You need to implement assert_error_messages(expected_error_messages) first!'
end

#assert_expire_previous_pageObject



51
52
53
54
# File 'lib/lapillus/lapillus_testers.rb', line 51

def assert_expire_previous_page
  # TODO: implement assert_expire_previous_page
  flunk 'You need to implement assert_expire_previous_page first!'
end

#assert_info_messages(expected_info_messages) ⇒ Object



56
57
58
59
# File 'lib/lapillus/lapillus_testers.rb', line 56

def assert_info_messages(expected_info_messages)
  # TODO: implement assert_info_messages(expected_info_messages)
  flunk 'You need to implement assert_info_messages(expected_info_messages) first!'
end

#assert_invisible(path) ⇒ Object



61
62
63
64
# File 'lib/lapillus/lapillus_testers.rb', line 61

def assert_invisible(path)
  # TODO: implement assert_invisible(path)
  flunk 'You need to implement assert_invisible(path) first!'
end

#assert_label(path, expected_label_text) ⇒ Object



66
67
68
69
# File 'lib/lapillus/lapillus_testers.rb', line 66

def assert_label(path, expected_label_text)
  assert_component(path, Lapillus::Label)
  assert_equal(expected_label_text, get_component_from_last_rendered_page(path).value)
end

#assert_list_view(path, expected_list) ⇒ Object



71
72
73
74
# File 'lib/lapillus/lapillus_testers.rb', line 71

def assert_list_view(path, expected_list)
  # TODO: implement assert_list_view(path, expected_list)
  flunk 'You need to implement assert_list_view(path, expected_list) first!'
end

#assert_no_error_messageObject



76
77
78
79
# File 'lib/lapillus/lapillus_testers.rb', line 76

def assert_no_error_message
  # TODO: implement assert_no_error_message
  flunk 'You need to implement assert_no_error_message first!'
end

#assert_no_info_messageObject



81
82
83
84
# File 'lib/lapillus/lapillus_testers.rb', line 81

def assert_no_info_message
  # TODO: implement assert_no_info_message
  flunk 'You need to implement assert_no_info_message first!'
end


86
87
88
89
# File 'lib/lapillus/lapillus_testers.rb', line 86

def assert_page_link(path, expected_page_class)
  click_link(path)
  assert_rendered_page(expected_page_class)
end

#assert_rendered_page(expected_rendered_page_class) ⇒ Object



91
92
93
# File 'lib/lapillus/lapillus_testers.rb', line 91

def assert_rendered_page(expected_rendered_page_class)
  assert_kind_of(expected_rendered_page_class, @page_instance)
end

#assert_visible(path) ⇒ Object



95
96
97
98
# File 'lib/lapillus/lapillus_testers.rb', line 95

def assert_visible(path)
  # TODO: implement assert_visible(path)
  flunk 'You need to implement assert_visible(path) first!'
end


100
101
102
103
104
105
106
# File 'lib/lapillus/lapillus_testers.rb', line 100

def click_link(path)
  link = get_component_from_last_rendered_page(path)
  assert_not_nil(link,"Link <#{path}> not found!")
  page_parameters = link.page_parameters
  @page_instance = @page_class.new(page_parameters)   # TODO: page can be found in the link!
  @html = @page_instance.render
end

#debug_component_treesObject



108
109
110
# File 'lib/lapillus/lapillus_testers.rb', line 108

def debug_component_trees
  # TODO: implement debug_component_trees
end

#dump_pageObject



112
113
114
# File 'lib/lapillus/lapillus_testers.rb', line 112

def dump_page
  puts @html
end

#get_component_from_last_rendered_page(path) ⇒ Object



116
117
118
119
120
121
122
123
124
125
# File 'lib/lapillus/lapillus_testers.rb', line 116

def get_component_from_last_rendered_page(path)
  path_parts=path.split(":")
  component=@page_instance[path_parts[0]]
  assert_not_nil(component, "No component found on path '#{path_parts[0]}'")
  (1..path_parts.size-1).each { |i| 
    component=component[path_parts[i]]
    assert_not_nil(component, "No component found on path '#{path_parts.slice(0..i).join(':')}'")
  }
  component
end

#get_messages(level) ⇒ Object



127
128
129
# File 'lib/lapillus/lapillus_testers.rb', line 127

def get_messages(level)
  # TODO: implement get_messages(level)
end

#new_form_tester(path) ⇒ Object



131
132
133
134
135
# File 'lib/lapillus/lapillus_testers.rb', line 131

def new_form_tester(path)
  form = get_component_from_last_rendered_page(path)
  assert_not_nil(form, "Form <#{path}> not found!")
  return FormTester.new(form, self)
end

#renderObject

TODO: should this method be public?



30
31
32
# File 'lib/lapillus/lapillus_testers.rb', line 30

def render
  @html = @page_instance.render
end

#start_page(page) ⇒ Object



17
18
19
20
21
# File 'lib/lapillus/lapillus_testers.rb', line 17

def start_page(page)
  @page_class = page
  @page_instance = @page_class.new()
  render
end

#start_page_instance(page_instance) ⇒ Object



23
24
25
26
27
# File 'lib/lapillus/lapillus_testers.rb', line 23

def start_page_instance(page_instance)
  @page_class = page_instance.class
  @page_instance = page_instance
  render
end