honkster-webrat 0.4.4.2 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (192) hide show
  1. data/.document +4 -0
  2. data/.gitignore +16 -0
  3. data/History.txt +56 -1
  4. data/Rakefile +79 -91
  5. data/VERSION +1 -0
  6. data/lib/webrat/{mechanize.rb → adapters/mechanize.rb} +5 -1
  7. data/lib/webrat/adapters/merb.rb +11 -0
  8. data/lib/webrat/adapters/rack.rb +25 -0
  9. data/lib/webrat/{rails.rb → adapters/rails.rb} +6 -30
  10. data/lib/webrat/adapters/sinatra.rb +9 -0
  11. data/lib/webrat/core/configuration.rb +6 -16
  12. data/lib/webrat/core/elements/area.rb +2 -2
  13. data/lib/webrat/core/elements/element.rb +3 -3
  14. data/lib/webrat/core/elements/field.rb +107 -31
  15. data/lib/webrat/core/elements/form.rb +4 -4
  16. data/lib/webrat/core/elements/label.rb +4 -4
  17. data/lib/webrat/core/elements/link.rb +5 -5
  18. data/lib/webrat/core/elements/select_option.rb +15 -2
  19. data/lib/webrat/core/locators/area_locator.rb +3 -3
  20. data/lib/webrat/core/locators/button_locator.rb +6 -6
  21. data/lib/webrat/core/locators/field_by_id_locator.rb +3 -3
  22. data/lib/webrat/core/locators/field_labeled_locator.rb +2 -2
  23. data/lib/webrat/core/locators/field_named_locator.rb +3 -3
  24. data/lib/webrat/core/locators/form_locator.rb +1 -1
  25. data/lib/webrat/core/locators/label_locator.rb +2 -2
  26. data/lib/webrat/core/locators/link_locator.rb +7 -7
  27. data/lib/webrat/core/locators/select_option_locator.rb +5 -5
  28. data/lib/webrat/core/locators.rb +1 -1
  29. data/lib/webrat/core/logging.rb +4 -5
  30. data/lib/webrat/core/matchers/have_content.rb +2 -7
  31. data/lib/webrat/core/matchers/have_xpath.rb +3 -28
  32. data/lib/webrat/core/methods.rb +5 -4
  33. data/lib/webrat/core/mime.rb +11 -22
  34. data/lib/webrat/core/scope.rb +17 -2
  35. data/lib/webrat/core/session.rb +28 -12
  36. data/lib/webrat/core/xml.rb +41 -84
  37. data/lib/webrat/core.rb +0 -1
  38. data/lib/webrat/integrations/merb.rb +10 -0
  39. data/lib/webrat/integrations/rails.rb +25 -0
  40. data/lib/webrat/integrations/rspec-rails.rb +10 -0
  41. data/lib/webrat/integrations/selenium.rb +11 -0
  42. data/lib/webrat/rspec-rails.rb +2 -10
  43. data/lib/webrat/selenium/application_servers/external.rb +1 -1
  44. data/lib/webrat/selenium/application_servers.rb +1 -1
  45. data/lib/webrat/selenium/location_strategy_javascript/label.js +31 -13
  46. data/lib/webrat/selenium/location_strategy_javascript/webrat.js +1 -0
  47. data/lib/webrat/selenium/location_strategy_javascript/webratlink.js +24 -4
  48. data/lib/webrat/selenium/selenium_rc_server.rb +4 -2
  49. data/lib/webrat/selenium/selenium_session.rb +21 -2
  50. data/lib/webrat/selenium/silence_stream.rb +1 -1
  51. data/lib/webrat/selenium.rb +0 -11
  52. data/lib/webrat.rb +10 -19
  53. data/spec/fakes/test_adapter.rb +37 -0
  54. data/spec/integration/mechanize/Rakefile +7 -0
  55. data/spec/integration/mechanize/config.ru +2 -0
  56. data/spec/integration/mechanize/sample_app.rb +20 -0
  57. data/spec/integration/mechanize/spec/mechanize_spec.rb +22 -0
  58. data/spec/integration/mechanize/spec/spec_helper.rb +27 -0
  59. data/spec/integration/merb/.gitignore +21 -0
  60. data/spec/integration/merb/Rakefile +35 -0
  61. data/spec/integration/merb/app/controllers/application.rb +2 -0
  62. data/spec/integration/merb/app/controllers/exceptions.rb +13 -0
  63. data/spec/integration/merb/app/controllers/testing.rb +27 -0
  64. data/spec/integration/merb/app/views/exceptions/not_acceptable.html.erb +63 -0
  65. data/spec/integration/merb/app/views/exceptions/not_found.html.erb +47 -0
  66. data/spec/integration/merb/app/views/layout/application.html.erb +12 -0
  67. data/spec/integration/merb/app/views/testing/show_form.html.erb +27 -0
  68. data/spec/integration/merb/app/views/testing/upload.html.erb +9 -0
  69. data/spec/integration/merb/config/environments/development.rb +15 -0
  70. data/spec/integration/merb/config/environments/rake.rb +11 -0
  71. data/spec/integration/merb/config/environments/test.rb +14 -0
  72. data/spec/integration/merb/config/init.rb +25 -0
  73. data/spec/integration/merb/config/rack.rb +11 -0
  74. data/spec/integration/merb/config/router.rb +34 -0
  75. data/spec/integration/merb/spec/spec.opts +1 -0
  76. data/spec/integration/merb/spec/spec_helper.rb +26 -0
  77. data/spec/integration/merb/spec/webrat_spec.rb +39 -0
  78. data/spec/integration/merb/tasks/merb.thor/app_script.rb +31 -0
  79. data/spec/integration/merb/tasks/merb.thor/common.rb +64 -0
  80. data/spec/integration/merb/tasks/merb.thor/gem_ext.rb +124 -0
  81. data/spec/integration/merb/tasks/merb.thor/main.thor +150 -0
  82. data/spec/integration/merb/tasks/merb.thor/ops.rb +93 -0
  83. data/spec/integration/merb/tasks/merb.thor/utils.rb +40 -0
  84. data/spec/integration/rack/Rakefile +5 -0
  85. data/spec/integration/rack/app.rb +89 -0
  86. data/spec/integration/rack/test/helper.rb +21 -0
  87. data/spec/integration/rack/test/webrat_rack_test.rb +73 -0
  88. data/spec/integration/rails/.gitignore +3 -0
  89. data/spec/integration/rails/Rakefile +30 -0
  90. data/spec/integration/rails/app/controllers/application.rb +15 -0
  91. data/spec/integration/rails/app/controllers/buttons_controller.rb +7 -0
  92. data/spec/integration/rails/app/controllers/fields_controller.rb +4 -0
  93. data/spec/integration/rails/app/controllers/links_controller.rb +7 -0
  94. data/spec/integration/rails/app/controllers/webrat_controller.rb +46 -0
  95. data/spec/integration/rails/app/helpers/buttons_helper.rb +2 -0
  96. data/spec/integration/rails/app/helpers/fields_helper.rb +2 -0
  97. data/spec/integration/rails/app/helpers/links_helper.rb +2 -0
  98. data/spec/integration/rails/app/views/buttons/show.html.erb +11 -0
  99. data/spec/integration/rails/app/views/fields/show.html.erb +9 -0
  100. data/spec/integration/rails/app/views/links/show.html.erb +5 -0
  101. data/spec/integration/rails/app/views/webrat/before_redirect_form.html.erb +4 -0
  102. data/spec/integration/rails/app/views/webrat/buttons.html.erb +11 -0
  103. data/spec/integration/rails/app/views/webrat/form.html.erb +28 -0
  104. data/spec/integration/rails/app/views/webrat/within.html.erb +3 -0
  105. data/spec/integration/rails/config/boot.rb +109 -0
  106. data/spec/integration/rails/config/environment.rb +12 -0
  107. data/spec/integration/rails/config/environments/development.rb +17 -0
  108. data/spec/integration/rails/config/environments/selenium.rb +22 -0
  109. data/spec/integration/rails/config/environments/test.rb +22 -0
  110. data/spec/integration/rails/config/initializers/inflections.rb +10 -0
  111. data/spec/integration/rails/config/initializers/mime_types.rb +5 -0
  112. data/spec/integration/rails/config/initializers/new_rails_defaults.rb +17 -0
  113. data/spec/integration/rails/config/locales/en.yml +5 -0
  114. data/spec/integration/rails/config/routes.rb +19 -0
  115. data/spec/integration/rails/public/404.html +30 -0
  116. data/spec/integration/rails/public/422.html +30 -0
  117. data/spec/integration/rails/public/500.html +33 -0
  118. data/spec/integration/rails/script/about +4 -0
  119. data/spec/integration/rails/script/console +3 -0
  120. data/spec/integration/rails/script/dbconsole +3 -0
  121. data/spec/integration/rails/script/destroy +3 -0
  122. data/spec/integration/rails/script/generate +3 -0
  123. data/spec/integration/rails/script/performance/benchmarker +3 -0
  124. data/spec/integration/rails/script/performance/profiler +3 -0
  125. data/spec/integration/rails/script/performance/request +3 -0
  126. data/spec/integration/rails/script/plugin +3 -0
  127. data/spec/integration/rails/script/process/inspector +3 -0
  128. data/spec/integration/rails/script/process/reaper +3 -0
  129. data/spec/integration/rails/script/process/spawner +3 -0
  130. data/spec/integration/rails/script/runner +3 -0
  131. data/spec/integration/rails/script/server +3 -0
  132. data/spec/integration/rails/test/integration/button_click_test.rb +80 -0
  133. data/spec/integration/rails/test/integration/fill_in_test.rb +24 -0
  134. data/spec/integration/rails/test/integration/link_click_test.rb +27 -0
  135. data/spec/integration/rails/test/integration/webrat_test.rb +122 -0
  136. data/spec/integration/rails/test/test_helper.rb +26 -0
  137. data/spec/integration/sinatra/Rakefile +5 -0
  138. data/spec/integration/sinatra/classic_app.rb +64 -0
  139. data/spec/integration/sinatra/modular_app.rb +16 -0
  140. data/spec/integration/sinatra/test/classic_app_test.rb +37 -0
  141. data/spec/integration/sinatra/test/modular_app_test.rb +18 -0
  142. data/spec/integration/sinatra/test/test_helper.rb +17 -0
  143. data/spec/private/core/configuration_spec.rb +87 -0
  144. data/spec/private/core/field_spec.rb +85 -0
  145. data/spec/private/core/link_spec.rb +24 -0
  146. data/spec/private/core/session_spec.rb +200 -0
  147. data/spec/private/mechanize/mechanize_adapter_spec.rb +73 -0
  148. data/spec/private/nokogiri_spec.rb +77 -0
  149. data/spec/private/rails/attaches_file_spec.rb +81 -0
  150. data/spec/private/rails/rails_adapter_spec.rb +86 -0
  151. data/spec/private/selenium/application_servers/rails_spec.rb +26 -0
  152. data/spec/public/basic_auth_spec.rb +24 -0
  153. data/spec/public/check_spec.rb +191 -0
  154. data/spec/public/choose_spec.rb +118 -0
  155. data/spec/public/click_area_spec.rb +106 -0
  156. data/spec/public/click_button_spec.rb +494 -0
  157. data/spec/public/click_link_spec.rb +511 -0
  158. data/spec/public/fill_in_spec.rb +224 -0
  159. data/spec/public/locators/field_by_xpath_spec.rb +19 -0
  160. data/spec/public/locators/field_labeled_spec.rb +172 -0
  161. data/spec/public/locators/field_with_id_spec.rb +16 -0
  162. data/spec/public/matchers/contain_spec.rb +114 -0
  163. data/spec/public/matchers/have_selector_spec.rb +146 -0
  164. data/spec/public/matchers/have_tag_spec.rb +39 -0
  165. data/spec/public/matchers/have_xpath_spec.rb +136 -0
  166. data/spec/public/reload_spec.rb +10 -0
  167. data/spec/public/save_and_open_spec.rb +70 -0
  168. data/spec/public/select_date_spec.rb +112 -0
  169. data/spec/public/select_datetime_spec.rb +137 -0
  170. data/spec/public/select_spec.rb +455 -0
  171. data/spec/public/select_time_spec.rb +100 -0
  172. data/spec/public/selenium/application_server_factory_spec.rb +49 -0
  173. data/spec/public/selenium/application_servers/external_spec.rb +12 -0
  174. data/spec/public/selenium/selenium_session_spec.rb +37 -0
  175. data/spec/public/set_hidden_field_spec.rb +5 -0
  176. data/spec/public/submit_form_spec.rb +5 -0
  177. data/spec/public/visit_spec.rb +58 -0
  178. data/spec/public/within_spec.rb +177 -0
  179. data/spec/rcov.opts +1 -0
  180. data/spec/spec.opts +2 -0
  181. data/spec/spec_helper.rb +54 -0
  182. data/vendor/selenium-server.jar +0 -0
  183. data/webrat.gemspec +360 -0
  184. metadata +292 -27
  185. data/lib/webrat/core/xml/hpricot.rb +0 -19
  186. data/lib/webrat/core/xml/nokogiri.rb +0 -76
  187. data/lib/webrat/core/xml/rexml.rb +0 -24
  188. data/lib/webrat/merb_multipart_support.rb +0 -27
  189. data/lib/webrat/merb_session.rb +0 -80
  190. data/lib/webrat/rack.rb +0 -24
  191. data/lib/webrat/rack_test.rb +0 -32
  192. data/lib/webrat/sinatra.rb +0 -44
@@ -32,16 +32,21 @@ module Webrat
32
32
 
33
33
  def self.load(session, element)
34
34
  return nil if element.nil?
35
- session.elements[Webrat::XML.xpath_to(element)] ||= field_class(element).new(session, element)
35
+ session.elements[element.path] ||= field_class(element).new(session, element)
36
36
  end
37
37
 
38
38
  def self.field_class(element)
39
39
  case element.name
40
40
  when "button" then ButtonField
41
- when "select" then SelectField
41
+ when "select"
42
+ if element.attributes["multiple"].nil?
43
+ SelectField
44
+ else
45
+ MultipleSelectField
46
+ end
42
47
  when "textarea" then TextareaField
43
48
  else
44
- case Webrat::XML.attribute(element, "type")
49
+ case element["type"]
45
50
  when "checkbox" then CheckboxField
46
51
  when "hidden" then HiddenField
47
52
  when "radio" then RadioField
@@ -67,11 +72,11 @@ module Webrat
67
72
  end
68
73
 
69
74
  def id
70
- Webrat::XML.attribute(@element, "id")
75
+ @element["id"]
71
76
  end
72
77
 
73
78
  def disabled?
74
- @element.attributes.has_key?("disabled") && Webrat::XML.attribute(@element, "disabled") != 'false'
79
+ @element.attributes.has_key?("disabled") && @element["disabled"] != 'false'
75
80
  end
76
81
 
77
82
  def raise_error_if_disabled
@@ -82,16 +87,16 @@ module Webrat
82
87
  def to_param
83
88
  return nil if disabled?
84
89
 
85
- case Webrat.configuration.mode
90
+ params = case Webrat.configuration.mode
86
91
  when :rails
87
92
  parse_rails_request_params("#{name}=#{escaped_value}")
88
93
  when :merb
89
94
  ::Merb::Parse.query("#{name}=#{escaped_value}")
90
- when :mechanize
91
- { name => value }
92
95
  else
93
- { name => escaped_value }
96
+ { name => [*@value].first.to_s }
94
97
  end
98
+
99
+ unescape_params(params)
95
100
  end
96
101
 
97
102
  def set(value)
@@ -130,11 +135,26 @@ module Webrat
130
135
  end
131
136
 
132
137
  def name
133
- Webrat::XML.attribute(@element, "name")
138
+ @element["name"]
134
139
  end
135
140
 
136
141
  def escaped_value
137
- CGI.escape([*@value].first.to_s)
142
+ CGI.escape(@value.to_s)
143
+ end
144
+
145
+ # Because we have to escape it before sending it to the above case statement,
146
+ # we have to make sure we unescape each value when it gets back so assertions
147
+ # involving characters like <, >, and & work as expected
148
+ def unescape_params(params)
149
+ case params.class.name
150
+ when 'Hash', 'Mash'
151
+ params.each { |key,value| params[key] = unescape_params(value) }
152
+ params
153
+ when 'Array'
154
+ params.collect { |value| unescape_params(value) }
155
+ else
156
+ CGI.unescapeHTML(params)
157
+ end
138
158
  end
139
159
 
140
160
  def labels
@@ -157,14 +177,14 @@ module Webrat
157
177
  end
158
178
 
159
179
  unless id.blank?
160
- @label_elements += Webrat::XML.xpath_search(form.element, ".//label[@for = '#{id}']")
180
+ @label_elements += form.element.xpath(".//label[@for = '#{id}']")
161
181
  end
162
182
 
163
183
  @label_elements
164
184
  end
165
185
 
166
186
  def default_value
167
- Webrat::XML.attribute(@element, "value")
187
+ @element["value"]
168
188
  end
169
189
 
170
190
  def replace_param_value(params, oval, nval)
@@ -201,7 +221,7 @@ module Webrat
201
221
 
202
222
  def click
203
223
  raise_error_if_disabled
204
- set(Webrat::XML.attribute(@element, "value")) unless Webrat::XML.attribute(@element, "name").blank?
224
+ set(@element["value"]) unless @element["name"].blank?
205
225
  form.submit
206
226
  end
207
227
 
@@ -248,11 +268,11 @@ module Webrat
248
268
 
249
269
  def check
250
270
  raise_error_if_disabled
251
- set(Webrat::XML.attribute(@element, "value") || "on")
271
+ set(@element["value"] || "on")
252
272
  end
253
273
 
254
274
  def checked?
255
- Webrat::XML.attribute(@element, "checked") == "checked"
275
+ @element["checked"] == "checked"
256
276
  end
257
277
 
258
278
  def uncheck
@@ -263,8 +283,8 @@ module Webrat
263
283
  protected
264
284
 
265
285
  def default_value
266
- if Webrat::XML.attribute(@element, "checked") == "checked"
267
- Webrat::XML.attribute(@element, "value") || "on"
286
+ if @element["checked"] == "checked"
287
+ @element["value"] || "on"
268
288
  else
269
289
  nil
270
290
  end
@@ -297,11 +317,11 @@ module Webrat
297
317
  option.set(nil)
298
318
  end
299
319
 
300
- set(Webrat::XML.attribute(@element, "value") || "on")
320
+ set(@element["value"] || "on")
301
321
  end
302
322
 
303
323
  def checked?
304
- Webrat::XML.attribute(@element, "checked") == "checked"
324
+ @element["checked"] == "checked"
305
325
  end
306
326
 
307
327
  protected
@@ -311,8 +331,8 @@ module Webrat
311
331
  end
312
332
 
313
333
  def default_value
314
- if Webrat::XML.attribute(@element, "checked") == "checked"
315
- Webrat::XML.attribute(@element, "value") || "on"
334
+ if @element["checked"] == "checked"
335
+ @element["value"] || "on"
316
336
  else
317
337
  nil
318
338
  end
@@ -329,7 +349,7 @@ module Webrat
329
349
  protected
330
350
 
331
351
  def default_value
332
- Webrat::XML.inner_html(@element)
352
+ @element.inner_html
333
353
  end
334
354
 
335
355
  end
@@ -365,9 +385,8 @@ module Webrat
365
385
  else
366
386
  ActionController::TestUploadedFile.new(@value)
367
387
  end
368
- when :merb
369
- # TODO: support content_type
370
- File.new(@value)
388
+ when :rack, :merb
389
+ Rack::Test::UploadedFile.new(@value, content_type)
371
390
  end
372
391
  end
373
392
 
@@ -381,31 +400,88 @@ module Webrat
381
400
 
382
401
  class ResetField < Field #:nodoc:
383
402
  def self.xpath_search
384
- ".//input[@type = 'reset']"
403
+ [".//input[@type = 'reset']"]
385
404
  end
386
405
  end
387
406
 
388
407
  class SelectField < Field #:nodoc:
389
408
 
390
409
  def self.xpath_search
391
- ".//select"
410
+ [".//select[not(@multiple)]"]
392
411
  end
393
412
 
394
413
  def options
395
414
  @options ||= SelectOption.load_all(@session, @element)
396
415
  end
397
416
 
417
+ def unset(value)
418
+ @value = nil
419
+ end
420
+
398
421
  protected
399
422
 
400
423
  def default_value
401
- selected_options = Webrat::XML.xpath_search(@element, ".//option[@selected = 'selected']")
402
- selected_options = Webrat::XML.xpath_search(@element, ".//option[position() = 1]") if selected_options.empty?
424
+ selected_options = @element.xpath(".//option[@selected = 'selected']")
425
+ selected_options = @element.xpath(".//option[position() = 1]") if selected_options.empty?
403
426
 
404
427
  selected_options.map do |option|
405
428
  return "" if option.nil?
406
- Webrat::XML.attribute(option, "value") || Webrat::XML.inner_html(option)
429
+ option["value"] || option.inner_html
430
+ end.uniq.first
431
+ end
432
+
433
+ end
434
+
435
+ class MultipleSelectField < Field #:nodoc:
436
+
437
+ def self.xpath_search
438
+ [".//select[@multiple='multiple']"]
439
+ end
440
+
441
+ def options
442
+ @options ||= SelectOption.load_all(@session, @element)
443
+ end
444
+
445
+ def set(value)
446
+ @value << value
447
+ end
448
+
449
+ def unset(value)
450
+ @value.delete(value)
451
+ end
452
+
453
+ # We have to overide how the uri string is formed when dealing with multiples
454
+ # Where normally a select field might produce name=value with a multiple,
455
+ # we need to form something like name[]=value1&name[]=value2
456
+ def to_param
457
+ return nil if disabled?
458
+
459
+ uri_string = @value.collect {|value| "#{name}=#{CGI.escape(value)}"}.join("&")
460
+ params = case Webrat.configuration.mode
461
+ when :rails
462
+ parse_rails_request_params(uri_string)
463
+ when :merb
464
+ ::Merb::Parse.query(uri_string)
465
+ else
466
+ { name => @value }
467
+ end
468
+
469
+ unescape_params(params)
470
+ end
471
+
472
+ protected
473
+
474
+ # Overwrite SelectField definition because we don't want to select the first option
475
+ # (mutliples don't select the first option unlike their non multiple versions)
476
+ def default_value
477
+ selected_options = @element.xpath(".//option[@selected = 'selected']")
478
+
479
+ selected_options.map do |option|
480
+ return "" if option.nil?
481
+ option["value"] || option.inner_html
407
482
  end.uniq
408
483
  end
409
484
 
410
485
  end
486
+
411
487
  end
@@ -9,7 +9,7 @@ module Webrat
9
9
  attr_reader :element
10
10
 
11
11
  def self.xpath_search
12
- ".//form"
12
+ [".//form"]
13
13
  end
14
14
 
15
15
  def fields
@@ -27,7 +27,7 @@ module Webrat
27
27
  protected
28
28
 
29
29
  def dom
30
- Webrat::XML.xpath_at(@session.dom, path)
30
+ @session.dom.xpath(path).first
31
31
  end
32
32
 
33
33
  def fields_by_type(field_types)
@@ -50,11 +50,11 @@ module Webrat
50
50
  end
51
51
 
52
52
  def form_method
53
- Webrat::XML.attribute(@element, "method").blank? ? :get : Webrat::XML.attribute(@element, "method").downcase
53
+ @element["method"].blank? ? :get : @element["method"].downcase
54
54
  end
55
55
 
56
56
  def form_action
57
- Webrat::XML.attribute(@element, "action").blank? ? @session.current_url : Webrat::XML.attribute(@element, "action")
57
+ @element["action"].blank? ? @session.current_url : @element["action"]
58
58
  end
59
59
 
60
60
  def merge(all_params, new_param)
@@ -6,11 +6,11 @@ module Webrat
6
6
  attr_reader :element
7
7
 
8
8
  def self.xpath_search
9
- ".//label"
9
+ [".//label"]
10
10
  end
11
11
 
12
12
  def for_id
13
- Webrat::XML.attribute(@element, "for")
13
+ @element["for"]
14
14
  end
15
15
 
16
16
  def field
@@ -21,9 +21,9 @@ module Webrat
21
21
 
22
22
  def field_element
23
23
  if for_id.blank?
24
- Webrat::XML.xpath_at(@element, *Field.xpath_search_excluding_hidden)
24
+ @element.xpath(*Field.xpath_search_excluding_hidden).first
25
25
  else
26
- Webrat::XML.css_search(@session.current_dom, "#" + for_id).first
26
+ @session.current_dom.css("#" + for_id).first
27
27
  end
28
28
  end
29
29
 
@@ -7,7 +7,7 @@ module Webrat
7
7
  class Link < Element #:nodoc:
8
8
 
9
9
  def self.xpath_search
10
- ".//a[@href]"
10
+ [".//a[@href]"]
11
11
  end
12
12
 
13
13
  def click(options = {})
@@ -26,7 +26,7 @@ module Webrat
26
26
  protected
27
27
 
28
28
  def id
29
- Webrat::XML.attribute(@element, "id")
29
+ @element["id"]
30
30
  end
31
31
 
32
32
  def data
@@ -34,11 +34,11 @@ module Webrat
34
34
  end
35
35
 
36
36
  def title
37
- Webrat::XML.attribute(@element, "title")
37
+ @element["title"]
38
38
  end
39
39
 
40
40
  def href
41
- Webrat::XML.attribute(@element, "href")
41
+ @element["href"]
42
42
  end
43
43
 
44
44
  def absolute_href
@@ -58,7 +58,7 @@ module Webrat
58
58
  end
59
59
 
60
60
  def onclick
61
- Webrat::XML.attribute(@element, "onclick")
61
+ @element["onclick"]
62
62
  end
63
63
 
64
64
  def http_method
@@ -4,7 +4,7 @@ module Webrat
4
4
  class SelectOption < Element #:nodoc:
5
5
 
6
6
  def self.xpath_search
7
- ".//option"
7
+ [".//option"]
8
8
  end
9
9
 
10
10
  def choose
@@ -12,6 +12,15 @@ module Webrat
12
12
  select.set(value)
13
13
  end
14
14
 
15
+ def unchoose
16
+ select.raise_error_if_disabled
17
+ select.unset(value)
18
+ end
19
+
20
+ def inner_text
21
+ @element.inner_text
22
+ end
23
+
15
24
  protected
16
25
 
17
26
  def select
@@ -28,7 +37,11 @@ module Webrat
28
37
  end
29
38
 
30
39
  def value
31
- Webrat::XML.attribute(@element, "value") || Webrat::XML.inner_html(@element)
40
+ @element["value"] || @element.inner_html
41
+ end
42
+
43
+ def label
44
+ @element.inner_html
32
45
  end
33
46
 
34
47
  end
@@ -11,8 +11,8 @@ module Webrat
11
11
 
12
12
  def area_element
13
13
  area_elements.detect do |area_element|
14
- Webrat::XML.attribute(area_element, "title") =~ matcher ||
15
- Webrat::XML.attribute(area_element, "id") =~ matcher
14
+ area_element["title"] =~ matcher ||
15
+ area_element["id"] =~ matcher
16
16
  end
17
17
  end
18
18
 
@@ -21,7 +21,7 @@ module Webrat
21
21
  end
22
22
 
23
23
  def area_elements
24
- Webrat::XML.xpath_search(@dom, Area.xpath_search)
24
+ @dom.xpath(*Area.xpath_search)
25
25
  end
26
26
 
27
27
  def error_message
@@ -20,24 +20,24 @@ module Webrat
20
20
  end
21
21
 
22
22
  def matches_id?(element)
23
- (@value.is_a?(Regexp) && Webrat::XML.attribute(element, "id") =~ @value) ||
24
- (!@value.is_a?(Regexp) && Webrat::XML.attribute(element, "id") == @value.to_s)
23
+ (@value.is_a?(Regexp) && element["id"] =~ @value) ||
24
+ (!@value.is_a?(Regexp) && element["id"] == @value.to_s)
25
25
  end
26
26
 
27
27
  def matches_value?(element)
28
- Webrat::XML.attribute(element, "value") =~ /^\W*#{Regexp.escape(@value.to_s)}/i
28
+ element["value"] =~ /^\W*#{Regexp.escape(@value.to_s)}/i
29
29
  end
30
30
 
31
31
  def matches_html?(element)
32
- Webrat::XML.inner_html(element) =~ /#{Regexp.escape(@value.to_s)}/i
32
+ element.inner_html =~ /#{Regexp.escape(@value.to_s)}/i
33
33
  end
34
34
 
35
35
  def matches_alt?(element)
36
- Webrat::XML.attribute(element, "alt") =~ /^\W*#{Regexp.escape(@value.to_s)}/i
36
+ element["alt"] =~ /^\W*#{Regexp.escape(@value.to_s)}/i
37
37
  end
38
38
 
39
39
  def button_elements
40
- Webrat::XML.xpath_search(@dom, *ButtonField.xpath_search)
40
+ @dom.xpath(*ButtonField.xpath_search)
41
41
  end
42
42
 
43
43
  def error_message
@@ -12,15 +12,15 @@ module Webrat
12
12
  def field_element
13
13
  field_elements.detect do |field_element|
14
14
  if @value.is_a?(Regexp)
15
- Webrat::XML.attribute(field_element, "id") =~ @value
15
+ field_element["id"] =~ @value
16
16
  else
17
- Webrat::XML.attribute(field_element, "id") == @value.to_s
17
+ field_element["id"] == @value.to_s
18
18
  end
19
19
  end
20
20
  end
21
21
 
22
22
  def field_elements
23
- Webrat::XML.xpath_search(@dom, *Field.xpath_search)
23
+ @dom.xpath(*Field.xpath_search)
24
24
  end
25
25
 
26
26
  def error_message
@@ -25,7 +25,7 @@ module Webrat
25
25
  end
26
26
 
27
27
  def label_elements
28
- Webrat::XML.xpath_search(@dom, Label.xpath_search)
28
+ @dom.xpath(*Label.xpath_search)
29
29
  end
30
30
 
31
31
  def error_message
@@ -33,7 +33,7 @@ module Webrat
33
33
  end
34
34
 
35
35
  def text(element)
36
- str = Webrat::XML.all_inner_text(element)
36
+ str = element.inner_text
37
37
  str.gsub!("\n","")
38
38
  str.strip!
39
39
  str.squeeze!(" ")
@@ -11,19 +11,19 @@ module Webrat
11
11
 
12
12
  def field_element
13
13
  field_elements.detect do |field_element|
14
- Webrat::XML.attribute(field_element, "name") == @value.to_s
14
+ field_element["name"] == @value.to_s
15
15
  end
16
16
  end
17
17
 
18
18
  def field_elements
19
- Webrat::XML.xpath_search(@dom, *xpath_searches)
19
+ @dom.xpath(*xpath_searches)
20
20
  end
21
21
 
22
22
  def xpath_searches
23
23
  if @field_types.any?
24
24
  @field_types.map { |field_type| field_type.xpath_search }.flatten
25
25
  else
26
- Array(Field.xpath_search)
26
+ Field.xpath_search
27
27
  end
28
28
  end
29
29
 
@@ -10,7 +10,7 @@ module Webrat
10
10
  end
11
11
 
12
12
  def form_element
13
- Webrat::XML.css_at(@dom, "#" + @value)
13
+ @dom.css("#" + @value).first
14
14
  end
15
15
 
16
16
  end
@@ -17,11 +17,11 @@ module Webrat
17
17
  end
18
18
 
19
19
  def label_elements
20
- Webrat::XML.xpath_search(@dom, Label.xpath_search)
20
+ @dom.xpath(*Label.xpath_search)
21
21
  end
22
22
 
23
23
  def text(label_element)
24
- str = Webrat::XML.all_inner_text(label_element)
24
+ str = label_element.inner_text
25
25
  str.gsub!("\n","")
26
26
  str.strip!
27
27
  str.squeeze!(" ")
@@ -10,7 +10,7 @@ module Webrat
10
10
  end
11
11
 
12
12
  def link_element
13
- matching_links.min { |a, b| Webrat::XML.all_inner_text(a).length <=> Webrat::XML.all_inner_text(b).length }
13
+ matching_links.min { |a, b| a.inner_text.length <=> b.inner_text.length }
14
14
  end
15
15
 
16
16
  def matching_links
@@ -27,21 +27,21 @@ module Webrat
27
27
  matcher = /#{Regexp.escape(@value.to_s)}/i
28
28
  end
29
29
 
30
- replace_nbsp(Webrat::XML.all_inner_text(link)) =~ matcher ||
31
- replace_nbsp_ref(Webrat::XML.inner_html(link)) =~ matcher ||
32
- Webrat::XML.attribute(link, "title")=~ matcher
30
+ replace_nbsp(link.inner_text) =~ matcher ||
31
+ replace_nbsp_ref(link.inner_html) =~ matcher ||
32
+ link["title"] =~ matcher
33
33
  end
34
34
 
35
35
  def matches_id?(link)
36
36
  if @value.is_a?(Regexp)
37
- (Webrat::XML.attribute(link, "id") =~ @value) ? true : false
37
+ link["id"] =~ @value ? true : false
38
38
  else
39
- (Webrat::XML.attribute(link, "id") == @value) ? true : false
39
+ link["id"] == @value ? true : false
40
40
  end
41
41
  end
42
42
 
43
43
  def link_elements
44
- Webrat::XML.xpath_search(@dom, *Link.xpath_search)
44
+ @dom.xpath(*Link.xpath_search)
45
45
  end
46
46
 
47
47
  def replace_nbsp(str)
@@ -19,17 +19,17 @@ module Webrat
19
19
 
20
20
  field.options.detect do |o|
21
21
  if @option_text.is_a?(Regexp)
22
- Webrat::XML.inner_html(o.element) =~ @option_text
22
+ o.element.inner_text =~ @option_text
23
23
  else
24
- Webrat::XML.inner_html(o.element) == @option_text.to_s
24
+ o.inner_text == @option_text.to_s
25
25
  end
26
26
  end
27
27
  else
28
28
  option_element = option_elements.detect do |o|
29
29
  if @option_text.is_a?(Regexp)
30
- Webrat::XML.inner_html(o) =~ @option_text
30
+ o.inner_text =~ @option_text
31
31
  else
32
- Webrat::XML.inner_html(o) == @option_text.to_s
32
+ o.inner_text == @option_text.to_s
33
33
  end
34
34
  end
35
35
 
@@ -38,7 +38,7 @@ module Webrat
38
38
  end
39
39
 
40
40
  def option_elements
41
- Webrat::XML.xpath_search(@dom, *SelectOption.xpath_search)
41
+ @dom.xpath(*SelectOption.xpath_search)
42
42
  end
43
43
 
44
44
  def error_message
@@ -13,7 +13,7 @@ module Webrat
13
13
  module Locators
14
14
 
15
15
  def field_by_xpath(xpath)
16
- Field.load(@session, Webrat::XML.xpath_at(dom, xpath))
16
+ Field.load(@session, dom.xpath(xpath).first)
17
17
  end
18
18
 
19
19
  end
@@ -1,3 +1,5 @@
1
+ require "logger"
2
+
1
3
  module Webrat
2
4
  module Logging #:nodoc:
3
5
 
@@ -11,12 +13,9 @@ module Webrat
11
13
  when :rails
12
14
  defined?(RAILS_DEFAULT_LOGGER) ? RAILS_DEFAULT_LOGGER : nil
13
15
  when :merb
14
- Merb.logger
16
+ ::Merb.logger
15
17
  else
16
- @logger ||= begin
17
- require "logger"
18
- ::Logger.new("webrat.log")
19
- end
18
+ @logger ||= ::Logger.new("webrat.log")
20
19
  end
21
20
  end
22
21
 
@@ -7,13 +7,8 @@ module Webrat
7
7
  end
8
8
 
9
9
  def matches?(stringlike)
10
- if Webrat.configuration.parse_with_nokogiri?
11
- @document = Webrat.nokogiri_document(stringlike)
12
- else
13
- @document = Webrat.hpricot_document(stringlike)
14
- end
15
-
16
- @element = Webrat::XML.inner_text(@document)
10
+ @document = Webrat::XML.document(stringlike)
11
+ @element = @document.inner_text
17
12
 
18
13
  case @content
19
14
  when String