celerity 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. data/History.txt +10 -0
  2. data/README.txt +8 -11
  3. data/Rakefile +5 -3
  4. data/benchmark/bm_2000_spans.rb +48 -0
  5. data/benchmark/bm_digg.rb +26 -0
  6. data/benchmark/bm_google_images.rb +36 -0
  7. data/benchmark/bm_input_locator.rb +69 -0
  8. data/benchmark/loader.rb +9 -0
  9. data/lib/celerity.rb +3 -1
  10. data/lib/celerity/container.rb +23 -171
  11. data/lib/celerity/disabled_element.rb +1 -1
  12. data/lib/celerity/element.rb +78 -47
  13. data/lib/celerity/element_collections.rb +16 -32
  14. data/lib/celerity/element_locator.rb +135 -0
  15. data/lib/celerity/elements/button.rb +15 -0
  16. data/lib/celerity/elements/file_field.rb +1 -1
  17. data/lib/celerity/elements/form.rb +2 -1
  18. data/lib/celerity/elements/frame.rb +18 -21
  19. data/lib/celerity/elements/image.rb +2 -8
  20. data/lib/celerity/elements/label.rb +1 -3
  21. data/lib/celerity/elements/link.rb +1 -1
  22. data/lib/celerity/elements/option.rb +16 -0
  23. data/lib/celerity/elements/radio_check.rb +18 -7
  24. data/lib/celerity/elements/select_list.rb +1 -17
  25. data/lib/celerity/elements/table.rb +4 -4
  26. data/lib/celerity/elements/table_body.rb +6 -8
  27. data/lib/celerity/elements/table_cell.rb +3 -14
  28. data/lib/celerity/elements/table_row.rb +4 -10
  29. data/lib/celerity/elements/text_field.rb +16 -4
  30. data/lib/celerity/extra/method_generator.rb +144 -0
  31. data/lib/celerity/identifier.rb +10 -0
  32. data/lib/celerity/ie.rb +28 -13
  33. data/lib/celerity/input_element.rb +0 -4
  34. data/lib/celerity/non_control_elements.rb +12 -12
  35. data/lib/celerity/version.rb +1 -1
  36. data/spec/area_spec.rb +41 -41
  37. data/spec/areas_spec.rb +11 -11
  38. data/spec/button_spec.rb +73 -68
  39. data/spec/buttons_spec.rb +10 -10
  40. data/spec/checkbox_spec.rb +102 -96
  41. data/spec/checkboxes_spec.rb +10 -10
  42. data/spec/div_spec.rb +78 -73
  43. data/spec/divs_spec.rb +10 -10
  44. data/spec/element_spec.rb +20 -11
  45. data/spec/filefield_spec.rb +36 -41
  46. data/spec/filefields_spec.rb +10 -10
  47. data/spec/form_spec.rb +29 -29
  48. data/spec/forms_spec.rb +11 -11
  49. data/spec/frame_spec.rb +54 -49
  50. data/spec/hidden_spec.rb +43 -43
  51. data/spec/hiddens_spec.rb +10 -10
  52. data/spec/html/2000_spans.html +2009 -0
  53. data/spec/html/forms_with_input_elements.html +15 -9
  54. data/spec/html/non_control_elements.html +4 -2
  55. data/spec/ie_spec.rb +82 -48
  56. data/spec/image_spec.rb +83 -100
  57. data/spec/images_spec.rb +10 -10
  58. data/spec/label_spec.rb +29 -29
  59. data/spec/labels_spec.rb +10 -10
  60. data/spec/li_spec.rb +41 -41
  61. data/spec/link_spec.rb +65 -59
  62. data/spec/links_spec.rb +11 -11
  63. data/spec/lis_spec.rb +10 -10
  64. data/spec/map_spec.rb +30 -30
  65. data/spec/maps_spec.rb +10 -10
  66. data/spec/p_spec.rb +49 -49
  67. data/spec/pre_spec.rb +41 -41
  68. data/spec/pres_spec.rb +10 -10
  69. data/spec/ps_spec.rb +10 -10
  70. data/spec/radio_spec.rb +104 -97
  71. data/spec/radios_spec.rb +11 -11
  72. data/spec/select_list_spec.rb +118 -106
  73. data/spec/select_lists_spec.rb +15 -15
  74. data/spec/span_spec.rb +54 -54
  75. data/spec/spans_spec.rb +11 -11
  76. data/spec/spec.opts +1 -1
  77. data/spec/spec_helper.rb +23 -3
  78. data/spec/table_bodies.rb +8 -8
  79. data/spec/table_bodies_spec.rb +9 -9
  80. data/spec/table_body_spec.rb +28 -27
  81. data/spec/table_cell_spec.rb +25 -25
  82. data/spec/table_cells_spec.rb +16 -16
  83. data/spec/table_row_spec.rb +16 -16
  84. data/spec/table_rows_spec.rb +12 -12
  85. data/spec/table_spec.rb +36 -36
  86. data/spec/tables_spec.rb +12 -12
  87. data/spec/text_field_spec.rb +111 -92
  88. data/spec/text_fields_spec.rb +13 -13
  89. data/tasks/benchmark.rake +3 -0
  90. data/tasks/rspec.rake +2 -2
  91. data/tasks/testserver.rake +15 -0
  92. metadata +58 -46
  93. data/tasks/simple_ci.rake +0 -94
data/spec/span_spec.rb CHANGED
@@ -3,144 +3,144 @@ require File.dirname(__FILE__) + '/spec_helper.rb'
3
3
  describe "Span" do
4
4
 
5
5
  before :all do
6
- @ie = IE.new
7
- add_spec_checker(@ie)
6
+ @browser = IE.new
7
+ add_spec_checker(@browser)
8
8
  end
9
9
 
10
10
  before :each do
11
- @ie.goto(TEST_HOST + "/non_control_elements.html")
11
+ @browser.goto(TEST_HOST + "/non_control_elements.html")
12
12
  end
13
13
 
14
14
  # Exists method
15
15
  describe "#exist?" do
16
16
  it "should return true if the 'p' exists" do
17
- @ie.span(:id, "lead").should exist
18
- @ie.span(:id, /lead/).should exist
19
- @ie.span(:text, "Dubito, ergo cogito, ergo sum.").should exist
20
- @ie.span(:text, /Dubito, ergo cogito, ergo sum/).should exist
21
- @ie.span(:class, "lead").should exist
22
- @ie.span(:class, /lead/).should exist
23
- @ie.span(:index, 1).should exist
24
- @ie.span(:xpath, "//span[@id='lead']").should exist
17
+ @browser.span(:id, "lead").should exist
18
+ @browser.span(:id, /lead/).should exist
19
+ @browser.span(:text, "Dubito, ergo cogito, ergo sum.").should exist
20
+ @browser.span(:text, /Dubito, ergo cogito, ergo sum/).should exist
21
+ @browser.span(:class, "lead").should exist
22
+ @browser.span(:class, /lead/).should exist
23
+ @browser.span(:index, 1).should exist
24
+ @browser.span(:xpath, "//span[@id='lead']").should exist
25
25
  end
26
26
  it "should return false if the 'p' doesn't exist" do
27
- @ie.span(:id, "no_such_id").should_not exist
28
- @ie.span(:id, /no_such_id/).should_not exist
29
- @ie.span(:text, "no_such_text").should_not exist
30
- @ie.span(:text, /no_such_text/).should_not exist
31
- @ie.span(:class, "no_such_class").should_not exist
32
- @ie.span(:class, /no_such_class/).should_not exist
33
- @ie.span(:index, 1337).should_not exist
34
- @ie.span(:xpath, "//span[@id='no_such_id']").should_not exist
27
+ @browser.span(:id, "no_such_id").should_not exist
28
+ @browser.span(:id, /no_such_id/).should_not exist
29
+ @browser.span(:text, "no_such_text").should_not exist
30
+ @browser.span(:text, /no_such_text/).should_not exist
31
+ @browser.span(:class, "no_such_class").should_not exist
32
+ @browser.span(:class, /no_such_class/).should_not exist
33
+ @browser.span(:index, 1337).should_not exist
34
+ @browser.span(:xpath, "//span[@id='no_such_id']").should_not exist
35
35
  end
36
- it "should raise ArgumentError when what argument is invalid" do
37
- lambda { @ie.span(:id, 3.14).exists? }.should raise_error(ArgumentError)
36
+ it "should raise ArgumentError when 'what' argument is invalid" do
37
+ lambda { @browser.span(:id, 3.14).exists? }.should raise_error(ArgumentError)
38
38
  end
39
- it "should raise MissingWayOfFindingObjectException when how argument is invalid" do
40
- lambda { @ie.span(:no_such_how, 'some_value').exists? }.should raise_error(MissingWayOfFindingObjectException)
39
+ it "should raise MissingWayOfFindingObjectException when 'how' argument is invalid" do
40
+ lambda { @browser.span(:no_such_how, 'some_value').exists? }.should raise_error(MissingWayOfFindingObjectException)
41
41
  end
42
42
  end
43
43
 
44
44
  # Attribute methods
45
45
  describe "#class_name" do
46
46
  it "should return the class attribute" do
47
- @ie.span(:index, 1).class_name.should == 'lead'
47
+ @browser.span(:index, 1).class_name.should == 'lead'
48
48
  end
49
49
  it "should return an empty string if the element exists and the attribute doesn't" do
50
- @ie.span(:index, 3).class_name.should == ''
50
+ @browser.span(:index, 3).class_name.should == ''
51
51
  end
52
52
  it "should raise UnknownObjectException if the span doesn't exist" do
53
- lambda { @ie.span(:id, 'no_such_id').class_name }.should raise_error(UnknownObjectException)
53
+ lambda { @browser.span(:id, 'no_such_id').class_name }.should raise_error(UnknownObjectException)
54
54
  end
55
55
  end
56
56
 
57
57
  describe "#id" do
58
58
  it "should return the id attribute" do
59
- @ie.span(:index, 1).id.should == "lead"
59
+ @browser.span(:index, 1).id.should == "lead"
60
60
  end
61
61
  it "should return an empty string if the element exists and the attribute doesn't" do
62
- @ie.span(:index, 3).id.should == ''
62
+ @browser.span(:index, 3).id.should == ''
63
63
  end
64
64
  it "should raise UnknownObjectException if the span doesn't exist" do
65
- lambda { @ie.span(:id, "no_such_id").id }.should raise_error(UnknownObjectException)
66
- lambda { @ie.span(:index, 1337).id }.should raise_error(UnknownObjectException)
65
+ lambda { @browser.span(:id, "no_such_id").id }.should raise_error(UnknownObjectException)
66
+ lambda { @browser.span(:index, 1337).id }.should raise_error(UnknownObjectException)
67
67
  end
68
68
  end
69
69
 
70
70
  describe "#name" do
71
71
  it "should return the name attribute" do
72
- @ie.span(:index, 2).name.should == "invalid_attribute"
72
+ @browser.span(:index, 2).name.should == "invalid_attribute"
73
73
  end
74
74
  it "should return an empty string if the element exists and the attribute doesn't" do
75
- @ie.span(:index, 3).name.should == ''
75
+ @browser.span(:index, 3).name.should == ''
76
76
  end
77
77
  it "should raise UnknownObjectException if the span doesn't exist" do
78
- lambda { @ie.span(:id, "no_such_id").name }.should raise_error(UnknownObjectException)
79
- lambda { @ie.span(:index, 1337).name }.should raise_error(UnknownObjectException)
78
+ lambda { @browser.span(:id, "no_such_id").name }.should raise_error(UnknownObjectException)
79
+ lambda { @browser.span(:index, 1337).name }.should raise_error(UnknownObjectException)
80
80
  end
81
81
  end
82
82
 
83
83
  describe "#title" do
84
84
  it "should return the title attribute" do
85
- @ie.span(:index, 1).title.should == 'Lorem ipsum'
85
+ @browser.span(:index, 1).title.should == 'Lorem ipsum'
86
86
  end
87
87
  it "should return an empty string if the element exists and the attribute doesn't" do
88
- @ie.span(:index, 3).title.should == ''
88
+ @browser.span(:index, 3).title.should == ''
89
89
  end
90
90
  it "should raise UnknownObjectException if the p doesn't exist" do
91
- lambda { @ie.span(:id, 'no_such_id').title }.should raise_error( UnknownObjectException)
92
- lambda { @ie.span(:xpath, "//span[@id='no_such_id']").title }.should raise_error( UnknownObjectException)
91
+ lambda { @browser.span(:id, 'no_such_id').title }.should raise_error( UnknownObjectException)
92
+ lambda { @browser.span(:xpath, "//span[@id='no_such_id']").title }.should raise_error( UnknownObjectException)
93
93
  end
94
94
  end
95
95
 
96
96
  describe "#text" do
97
97
  it "should return the text of the p" do
98
- @ie.span(:index, 2).text.should == 'Sed pretium metus et quam. Nullam odio dolor, vestibulum non, tempor ut, vehicula sed, sapien. Vestibulum placerat ligula at quam. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.'
98
+ @browser.span(:index, 2).text.should == 'Sed pretium metus et quam. Nullam odio dolor, vestibulum non, tempor ut, vehicula sed, sapien. Vestibulum placerat ligula at quam. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.'
99
99
  end
100
100
  it "should return an empty string if the element doesn't contain any text" do
101
- @ie.span(:index, 5).text.should == ''
101
+ @browser.span(:index, 5).text.should == ''
102
102
  end
103
103
  it "should raise UnknownObjectException if the p doesn't exist" do
104
- lambda { @ie.span(:id, 'no_such_id').text }.should raise_error( UnknownObjectException)
105
- lambda { @ie.span(:xpath , "//span[@id='no_such_id']").text }.should raise_error( UnknownObjectException)
104
+ lambda { @browser.span(:id, 'no_such_id').text }.should raise_error( UnknownObjectException)
105
+ lambda { @browser.span(:xpath , "//span[@id='no_such_id']").text }.should raise_error( UnknownObjectException)
106
106
  end
107
107
  end
108
108
 
109
109
  describe "#value" do
110
110
  it "should return the value attribute" do
111
- @ie.span(:index, 2).value.should == "invalid_attribute"
111
+ @browser.span(:index, 2).value.should == "invalid_attribute"
112
112
  end
113
113
  it "should return an empty string if the element exists and the attribute doesn't" do
114
- @ie.span(:index, 3).value.should == ''
114
+ @browser.span(:index, 3).value.should == ''
115
115
  end
116
116
  it "should raise UnknownObjectException if the p doesn't exist" do
117
- lambda { @ie.span(:id , "no_such_id").value }.should raise_error(UnknownObjectException)
118
- lambda { @ie.span(:index , 1337).value }.should raise_error(UnknownObjectException)
117
+ lambda { @browser.span(:id , "no_such_id").value }.should raise_error(UnknownObjectException)
118
+ lambda { @browser.span(:index , 1337).value }.should raise_error(UnknownObjectException)
119
119
  end
120
120
  end
121
121
 
122
122
  # Other
123
123
  describe "#click" do
124
124
  it "should fire events" do
125
- @ie.span(:id, 'footer').text.include?('Javascript').should_not be_true
126
- @ie.span(:id, 'footer').click
127
- @ie.span(:id, 'footer').text.include?('Javascript').should be_true
125
+ @browser.span(:name, 'footer').text.should_not include('Javascript')
126
+ @browser.span(:name, 'footer').click
127
+ @browser.span(:name, 'footer').text.should include('Javascript')
128
128
  end
129
129
  it "should raise UnknownObjectException if the span doesn't exist" do
130
- lambda { @ie.span(:id, "no_such_id").click }.should raise_error(UnknownObjectException)
131
- lambda { @ie.span(:title, "no_such_title").click }.should raise_error(UnknownObjectException)
130
+ lambda { @browser.span(:id, "no_such_id").click }.should raise_error(UnknownObjectException)
131
+ lambda { @browser.span(:title, "no_such_title").click }.should raise_error(UnknownObjectException)
132
132
  end
133
133
  end
134
134
 
135
135
  describe "#to_s" do
136
136
  it "should return a human readable representation of the element" do
137
- @ie.span(:index, 2).to_s.should == "tag: span\n" +
137
+ @browser.span(:index, 2).to_s.should == "tag: span\n" +
138
138
  " name: invalid_attribute\n" +
139
139
  " value: invalid_attribute\n" +
140
140
  " text: Sed pretium metus et quam. Nullam odio dolor, vestibulum non, tempor ut, vehicula sed, sapien. Vestibulum placerat ligula at quam. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas."
141
141
  end
142
142
  it "should raise UnknownObjectException if the p doesn't exist" do
143
- lambda { @ie.span(:xpath, "//span[@id='no_such_id']").to_s }.should raise_error( UnknownObjectException)
143
+ lambda { @browser.span(:xpath, "//span[@id='no_such_id']").to_s }.should raise_error( UnknownObjectException)
144
144
  end
145
145
  end
146
146
 
@@ -149,7 +149,7 @@ describe "Span" do
149
149
 
150
150
 
151
151
  after :all do
152
- @ie.close
152
+ @browser.close
153
153
  end
154
154
 
155
155
  end
data/spec/spans_spec.rb CHANGED
@@ -2,40 +2,40 @@ require File.dirname(__FILE__) + '/spec_helper.rb'
2
2
 
3
3
  describe "Spans" do
4
4
  before :all do
5
- @ie = IE.new
6
- add_spec_checker(@ie)
5
+ @browser = IE.new
6
+ add_spec_checker(@browser)
7
7
  end
8
8
 
9
9
  before :each do
10
- @ie.goto(TEST_HOST + "/non_control_elements.html")
10
+ @browser.goto(TEST_HOST + "/non_control_elements.html")
11
11
  end
12
12
 
13
13
 
14
14
  describe "#length" do
15
15
  it "should return the number of spans" do
16
- @ie.spans.length.should == 6
16
+ @browser.spans.length.should == 6
17
17
  end
18
18
  end
19
19
 
20
20
  describe "#[]" do
21
21
  it "should return the p at the given index" do
22
- @ie.spans[1].id.should == "lead"
22
+ @browser.spans[1].id.should == "lead"
23
23
  end
24
24
  end
25
25
 
26
26
  describe "#each" do
27
27
  it "should iterate through spans correctly" do
28
- @ie.spans.each_with_index do |s, index|
29
- s.name.should == @ie.span(:index, index+1).name
30
- s.id.should == @ie.span(:index, index+1).id
31
- s.value.should == @ie.span(:index, index+1).value
28
+ @browser.spans.each_with_index do |s, index|
29
+ s.name.should == @browser.span(:index, index+1).name
30
+ s.id.should == @browser.span(:index, index+1).id
31
+ s.value.should == @browser.span(:index, index+1).value
32
32
  end
33
33
  end
34
34
  end
35
35
 
36
36
  describe "#to_s" do
37
37
  it "should return a human readable representation of the collection" do
38
- @ie.spans.to_s.should == "tag: span\n" +
38
+ @browser.spans.to_s.should == "tag: span\n" +
39
39
  " id: lead\n" +
40
40
  " class: lead\n" +
41
41
  " title: Lorem ipsum\n" +
@@ -58,7 +58,7 @@ describe "Spans" do
58
58
  end
59
59
 
60
60
  after :all do
61
- @ie.close
61
+ @browser.close
62
62
  end
63
63
 
64
64
  end
data/spec/spec.opts CHANGED
@@ -1 +1 @@
1
- --colour --format html
1
+ --colour
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require "fileutils"
2
+
1
3
  begin
2
4
  require 'spec'
3
5
  rescue LoadError
@@ -14,7 +16,7 @@ if RUBY_PLATFORM =~ /java/
14
16
  require 'celerity'
15
17
  include Celerity
16
18
  include Celerity::Exception
17
- elsif ENV['WATIR_SPEC']
19
+ else
18
20
  require 'watir'
19
21
  include Watir
20
22
  include Watir::Exception
@@ -40,6 +42,11 @@ if RUBY_PLATFORM =~ /java/ || ENV['WATIR_SPEC']
40
42
  require 'webrick'
41
43
  doc_root = File.join(File.dirname(__FILE__), "html")
42
44
  log_file = File.join(File.dirname(__FILE__), "..", "log", "webrick_log.txt")
45
+ unless File.exist?(log_file)
46
+ FileUtils.mkdir_p(File.dirname(log_file))
47
+ FileUtils.touch(log_file)
48
+ end
49
+
43
50
  server_port = 2000
44
51
  tries = 0
45
52
  begin
@@ -58,11 +65,23 @@ if RUBY_PLATFORM =~ /java/ || ENV['WATIR_SPEC']
58
65
  end
59
66
  end
60
67
 
68
+ class PostServlet < WEBrick::HTTPServlet::AbstractServlet
69
+ def do_POST(req, resp)
70
+ resp['content-type'] = 'text/html'
71
+ resp.body << "<html><body>"
72
+ resp.body << "You posted the following content:\n"
73
+ resp.body << req.body
74
+ resp.body << "</body></html>"
75
+ end
76
+ end
77
+
61
78
  server.mount("/", WEBrick::HTTPServlet::FileHandler, doc_root, {:FancyIndexing=>true})
79
+ server.mount("/post_to_me", PostServlet)
62
80
  WEBRICK_SERVER = Thread.new { server.start }
63
81
  end
64
82
  else
65
83
  puts "Remember to run \"rake testserver\" before running these tests!"
84
+ TEST_HOST = "http://localhost:2000"
66
85
  end
67
86
 
68
87
  # ===========================
@@ -73,6 +92,7 @@ begin
73
92
  WEB_VIEWER = DRbObject.new_with_uri("druby://127.0.0.1:1337")
74
93
  end
75
94
  rescue IOError
95
+ rescue Errno::ENOENT
76
96
  end
77
97
 
78
98
  # ================
@@ -80,9 +100,9 @@ end
80
100
  # ================
81
101
 
82
102
  # define a checker that is run on every page
83
- def add_spec_checker(ie)
103
+ def add_spec_checker(browser)
84
104
  if defined? WEB_VIEWER
85
- ie.add_checker { WEB_VIEWER.render_html(ie.object.asXml, ie.base_url) }
105
+ ie.add_checker { WEB_VIEWER.render_html(browser.html, ie.base_url) }
86
106
  end
87
107
  end
88
108
 
data/spec/table_bodies.rb CHANGED
@@ -3,19 +3,19 @@ require File.dirname(__FILE__) + '/spec_helper.rb'
3
3
  describe "TableBody" do
4
4
 
5
5
  before :all do
6
- @ie = IE.new
7
- add_spec_checker(@ie)
6
+ @browser = IE.new
7
+ add_spec_checker(@browser)
8
8
  end
9
9
 
10
10
  before :each do
11
- @ie = IE.new
12
- @ie.goto(TEST_HOST + "/tables.html")
11
+ @browser = IE.new
12
+ @browser.goto(TEST_HOST + "/tables.html")
13
13
  end
14
14
 
15
15
  describe "#length" do
16
16
  it "should return the number of table bodies" do
17
- @ie.table(:index, 1).bodies.length.should == 2
18
- @ie.table(:index, 2).bodies.length.should == 0
17
+ @browser.table(:index, 1).bodies.length.should == 2
18
+ @browser.table(:index, 2).bodies.length.should == 0
19
19
  end
20
20
  end
21
21
 
@@ -27,14 +27,14 @@ describe "TableBody" do
27
27
 
28
28
  describe "#each" do
29
29
  it "should iterate through table bodies correctly" do
30
- #@ie.table(:index, 1).bodies.each_with_index do |body, index|
30
+ #@browser.table(:index, 1).bodies.each_with_index do |body, index|
31
31
  #end
32
32
  pending
33
33
  end
34
34
  end
35
35
 
36
36
  after :all do
37
- @ie.close
37
+ @browser.close
38
38
  end
39
39
 
40
40
  end
@@ -3,31 +3,31 @@ require File.dirname(__FILE__) + '/spec_helper.rb'
3
3
  describe "TableBodies" do
4
4
 
5
5
  before :all do
6
- @ie = IE.new
7
- add_spec_checker(@ie)
6
+ @browser = IE.new
7
+ add_spec_checker(@browser)
8
8
  end
9
9
 
10
10
  before :each do
11
- @ie = IE.new
12
- @ie.goto(TEST_HOST + "/tables.html")
11
+ @browser = IE.new
12
+ @browser.goto(TEST_HOST + "/tables.html")
13
13
  end
14
14
 
15
15
  describe "#length" do
16
16
  it "should return the correct number of table bodies" do
17
- @ie.table(:index, 1).bodies.length.should == 2
17
+ @browser.table(:index, 1).bodies.length.should == 2
18
18
  end
19
19
  end
20
20
 
21
21
  describe "#[]" do
22
22
  it "should return the row at the given index" do
23
- @ie.table(:index, 1).bodies[1].id.should == "first"
24
- @ie.table(:index, 1).bodies[2].name.should == "second"
23
+ @browser.table(:index, 1).bodies[1].id.should == "first"
24
+ @browser.table(:index, 1).bodies[2].name.should == "second"
25
25
  end
26
26
  end
27
27
 
28
28
  describe "#each" do
29
29
  it "should iterate through table bodies correctly" do
30
- table = @ie.table(:index, 1)
30
+ table = @browser.table(:index, 1)
31
31
  table.bodies.each_with_index do |body, index|
32
32
  body.name.should == table.body(:index, index+1).name
33
33
  body.id.should == table.body(:index, index+1).id
@@ -36,7 +36,7 @@ describe "TableBodies" do
36
36
  end
37
37
 
38
38
  after :all do
39
- @ie.close
39
+ @browser.close
40
40
  end
41
41
 
42
42
  end
@@ -3,58 +3,58 @@ require File.dirname(__FILE__) + '/spec_helper.rb'
3
3
  describe "TableBody" do
4
4
 
5
5
  before :all do
6
- @ie = IE.new
7
- add_spec_checker(@ie)
6
+ @browser = IE.new
7
+ add_spec_checker(@browser)
8
8
  end
9
9
 
10
10
  before :each do
11
- @ie = IE.new
12
- @ie.goto(TEST_HOST + "/tables.html")
11
+ @browser = IE.new
12
+ @browser.goto(TEST_HOST + "/tables.html")
13
13
  end
14
14
 
15
15
  describe "#exists" do
16
16
  it "should return true if the table body exists" do
17
- @ie.table(:index, 1).body(:id, 'first').should exist
18
- @ie.table(:index, 1).body(:id, /first/).should exist
19
- @ie.table(:index, 1).body(:name, 'second').should exist
20
- @ie.table(:index, 1).body(:name, /second/).should exist
21
- @ie.table(:index, 1).body(:index, 1).should exist
22
- @ie.table(:index, 1).body(:xpath, "//tbody[@id='first']").should exist
17
+ @browser.table(:index, 1).body(:id, 'first').should exist
18
+ @browser.table(:index, 1).body(:id, /first/).should exist
19
+ @browser.table(:index, 1).body(:name, 'second').should exist
20
+ @browser.table(:index, 1).body(:name, /second/).should exist
21
+ @browser.table(:index, 1).body(:index, 1).should exist
22
+ @browser.table(:index, 1).body(:xpath, "//tbody[@id='first']").should exist
23
23
  end
24
24
  it "should return false if the table body exists" do
25
- @ie.table(:index, 1).body(:id, 'no_such_id').should_not exist
26
- @ie.table(:index, 1).body(:id, /no_such_id/).should_not exist
27
- @ie.table(:index, 1).body(:name, 'no_such_name').should_not exist
28
- @ie.table(:index, 1).body(:name, /no_such_name/).should_not exist
29
- @ie.table(:index, 1).body(:index, 1337).should_not exist
30
- @ie.table(:index, 1).body(:xpath, "//tbody[@id='no_such_id']").should_not exist
25
+ @browser.table(:index, 1).body(:id, 'no_such_id').should_not exist
26
+ @browser.table(:index, 1).body(:id, /no_such_id/).should_not exist
27
+ @browser.table(:index, 1).body(:name, 'no_such_name').should_not exist
28
+ @browser.table(:index, 1).body(:name, /no_such_name/).should_not exist
29
+ @browser.table(:index, 1).body(:index, 1337).should_not exist
30
+ @browser.table(:index, 1).body(:xpath, "//tbody[@id='no_such_id']").should_not exist
31
31
  end
32
- it "should raise ArgumentError when what argument is invalid" do
33
- lambda { @ie.table(:index, 1).body(:id, 3.14).exists? }.should raise_error(ArgumentError)
32
+ it "should raise ArgumentError when 'what' argument is invalid" do
33
+ lambda { @browser.table(:index, 1).body(:id, 3.14).exists? }.should raise_error(ArgumentError)
34
34
  end
35
- it "should raise MissingWayOfFindingObjectException when how argument is invalid" do
36
- lambda { @ie.table(:index, 1).body(:no_such_how, 'some_value').exists? }.should raise_error(MissingWayOfFindingObjectException)
35
+ it "should raise MissingWayOfFindingObjectException when 'how' argument is invalid" do
36
+ lambda { @browser.table(:index, 1).body(:no_such_how, 'some_value').exists? }.should raise_error(MissingWayOfFindingObjectException)
37
37
  end
38
38
  end
39
39
 
40
40
  describe "#length" do
41
41
  it "should return the correct number of table bodies" do
42
- @ie.table(:index, 1).body(:id, 'first').length.should == 3
43
- @ie.table(:index, 1).body(:name, 'second').length.should == 3
42
+ @browser.table(:index, 1).body(:id, 'first').length.should == 3
43
+ @browser.table(:index, 1).body(:name, 'second').length.should == 3
44
44
  end
45
45
  end
46
46
 
47
47
  describe "#[]" do
48
48
  it "should return the row at the given index" do
49
- @ie.table(:index, 1).body(:id, 'first')[1].text.should == 'March 2008'
50
- @ie.table(:index, 1).body(:id, 'first')[2][1].text.should == 'Gregory House'
51
- @ie.table(:index, 1).body(:id, 'first')[3][1].text.should == 'Hugh Laurie'
49
+ @browser.table(:index, 1).body(:id, 'first')[1].text.should == 'March 2008'
50
+ @browser.table(:index, 1).body(:id, 'first')[2][1].text.should == 'Gregory House'
51
+ @browser.table(:index, 1).body(:id, 'first')[3][1].text.should == 'Hugh Laurie'
52
52
  end
53
53
  end
54
54
 
55
55
  describe "#each" do
56
56
  it "should iterate through rows correctly" do
57
- body = @ie.table(:index, 1).body(:id, 'first')
57
+ body = @browser.table(:index, 1).body(:id, 'first')
58
58
  index = 1
59
59
  body.each do |r|
60
60
  r.name.should == body.row(:index, index).name
@@ -62,11 +62,12 @@ describe "TableBody" do
62
62
  r.value.should == body.row(:index, index).value
63
63
  index += 1
64
64
  end
65
+ index.should_not == 1
65
66
  end
66
67
  end
67
68
 
68
69
  after :all do
69
- @ie.close
70
+ @browser.close
70
71
  end
71
72
 
72
73
  end