diabolo-webrat 0.4.2 → 0.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. data/History.txt +22 -3
  2. data/Rakefile +6 -1
  3. data/lib/webrat/core/configuration.rb +4 -4
  4. data/lib/webrat/core/elements/area.rb +7 -7
  5. data/lib/webrat/core/elements/element.rb +11 -11
  6. data/lib/webrat/core/elements/field.rb +50 -50
  7. data/lib/webrat/core/elements/form.rb +17 -17
  8. data/lib/webrat/core/elements/label.rb +6 -6
  9. data/lib/webrat/core/elements/link.rb +13 -11
  10. data/lib/webrat/core/elements/select_option.rb +9 -9
  11. data/lib/webrat/core/locators/area_locator.rb +10 -10
  12. data/lib/webrat/core/locators/button_locator.rb +13 -13
  13. data/lib/webrat/core/locators/field_by_id_locator.rb +8 -8
  14. data/lib/webrat/core/locators/field_labeled_locator.rb +10 -10
  15. data/lib/webrat/core/locators/field_locator.rb +7 -7
  16. data/lib/webrat/core/locators/field_named_locator.rb +10 -10
  17. data/lib/webrat/core/locators/form_locator.rb +6 -6
  18. data/lib/webrat/core/locators/label_locator.rb +8 -8
  19. data/lib/webrat/core/locators/link_locator.rb +11 -12
  20. data/lib/webrat/core/locators/locator.rb +5 -5
  21. data/lib/webrat/core/locators/select_option_locator.rb +11 -11
  22. data/lib/webrat/core/locators.rb +2 -2
  23. data/lib/webrat/core/logging.rb +3 -3
  24. data/lib/webrat/core/matchers/have_content.rb +12 -12
  25. data/lib/webrat/core/matchers/have_selector.rb +9 -9
  26. data/lib/webrat/core/matchers/have_tag.rb +4 -4
  27. data/lib/webrat/core/matchers/have_xpath.rb +24 -24
  28. data/lib/webrat/core/methods.rb +9 -9
  29. data/lib/webrat/core/mime.rb +3 -3
  30. data/lib/webrat/core/save_and_open_page.rb +9 -9
  31. data/lib/webrat/core/scope.rb +51 -51
  32. data/lib/webrat/core/session.rb +7 -7
  33. data/lib/webrat/core/xml/hpricot.rb +3 -3
  34. data/lib/webrat/core/xml/nokogiri.rb +11 -11
  35. data/lib/webrat/core/xml/rexml.rb +3 -3
  36. data/lib/webrat/core/xml.rb +16 -16
  37. data/lib/webrat/core_extensions/blank.rb +1 -1
  38. data/lib/webrat/core_extensions/deprecate.rb +1 -1
  39. data/lib/webrat/core_extensions/detect_mapped.rb +4 -4
  40. data/lib/webrat/core_extensions/meta_class.rb +1 -1
  41. data/lib/webrat/mechanize.rb +9 -9
  42. data/lib/webrat/merb.rb +1 -1
  43. data/lib/webrat/merb_session.rb +10 -10
  44. data/lib/webrat/rails.rb +2 -2
  45. data/lib/webrat/rspec-rails.rb +2 -2
  46. data/lib/webrat/selenium/matchers/have_content.rb +4 -4
  47. data/lib/webrat/selenium/matchers/have_selector.rb +4 -4
  48. data/lib/webrat/selenium/matchers/have_tag.rb +16 -16
  49. data/lib/webrat/selenium/matchers/have_xpath.rb +4 -4
  50. data/lib/webrat/selenium/matchers.rb +1 -1
  51. data/lib/webrat/selenium/selenium_session.rb +12 -18
  52. data/lib/webrat/selenium.rb +3 -77
  53. data/lib/webrat.rb +4 -4
  54. metadata +1 -1
@@ -2,34 +2,34 @@ require "webrat/core/elements/element"
2
2
 
3
3
  module Webrat
4
4
  class SelectOption < Element #:nodoc:
5
-
5
+
6
6
  def self.xpath_search
7
7
  ".//option"
8
8
  end
9
-
9
+
10
10
  def choose
11
11
  select.raise_error_if_disabled
12
12
  select.set(value)
13
13
  end
14
-
14
+
15
15
  protected
16
-
16
+
17
17
  def select
18
18
  SelectField.load(@session, select_element)
19
19
  end
20
-
20
+
21
21
  def select_element
22
22
  parent = @element.parent
23
-
23
+
24
24
  while parent.respond_to?(:parent)
25
25
  return parent if parent.name == 'select'
26
26
  parent = parent.parent
27
27
  end
28
28
  end
29
-
29
+
30
30
  def value
31
31
  Webrat::XML.attribute(@element, "value") || Webrat::XML.inner_html(@element)
32
32
  end
33
-
33
+
34
34
  end
35
- end
35
+ end
@@ -2,37 +2,37 @@ require "webrat/core/locators/locator"
2
2
 
3
3
  module Webrat
4
4
  module Locators
5
-
5
+
6
6
  class AreaLocator < Locator # :nodoc:
7
-
7
+
8
8
  def locate
9
9
  Area.load(@session, area_element)
10
10
  end
11
-
11
+
12
12
  def area_element
13
13
  area_elements.detect do |area_element|
14
14
  Webrat::XML.attribute(area_element, "title") =~ matcher ||
15
15
  Webrat::XML.attribute(area_element, "id") =~ matcher
16
16
  end
17
17
  end
18
-
18
+
19
19
  def matcher
20
20
  /#{Regexp.escape(@value.to_s)}/i
21
21
  end
22
-
22
+
23
23
  def area_elements
24
24
  Webrat::XML.xpath_search(@dom, Area.xpath_search)
25
25
  end
26
-
26
+
27
27
  def error_message
28
28
  "Could not find area with name #{@value}"
29
29
  end
30
-
30
+
31
31
  end
32
-
32
+
33
33
  def find_area(id_or_title) #:nodoc:
34
34
  AreaLocator.new(@session, dom, id_or_title).locate!
35
35
  end
36
-
36
+
37
37
  end
38
- end
38
+ end
@@ -2,13 +2,13 @@ require "webrat/core/locators/locator"
2
2
 
3
3
  module Webrat
4
4
  module Locators
5
-
5
+
6
6
  class ButtonLocator < Locator # :nodoc:
7
-
7
+
8
8
  def locate
9
9
  ButtonField.load(@session, button_element)
10
10
  end
11
-
11
+
12
12
  def button_element
13
13
  button_elements.detect do |element|
14
14
  @value.nil? ||
@@ -18,37 +18,37 @@ module Webrat
18
18
  matches_alt?(element)
19
19
  end
20
20
  end
21
-
21
+
22
22
  def matches_id?(element)
23
23
  (@value.is_a?(Regexp) && Webrat::XML.attribute(element, "id") =~ @value) ||
24
24
  (!@value.is_a?(Regexp) && Webrat::XML.attribute(element, "id") == @value.to_s)
25
25
  end
26
-
26
+
27
27
  def matches_value?(element)
28
28
  Webrat::XML.attribute(element, "value") =~ /^\W*#{Regexp.escape(@value.to_s)}/i
29
29
  end
30
-
30
+
31
31
  def matches_html?(element)
32
32
  Webrat::XML.inner_html(element) =~ /#{Regexp.escape(@value.to_s)}/i
33
33
  end
34
-
34
+
35
35
  def matches_alt?(element)
36
36
  Webrat::XML.attribute(element, "alt") =~ /^\W*#{Regexp.escape(@value.to_s)}/i
37
37
  end
38
-
38
+
39
39
  def button_elements
40
40
  Webrat::XML.xpath_search(@dom, *ButtonField.xpath_search)
41
41
  end
42
-
42
+
43
43
  def error_message
44
44
  "Could not find button #{@value.inspect}"
45
45
  end
46
-
46
+
47
47
  end
48
-
48
+
49
49
  def find_button(value) #:nodoc:
50
50
  ButtonLocator.new(@session, dom, value).locate!
51
51
  end
52
-
52
+
53
53
  end
54
- end
54
+ end
@@ -2,13 +2,13 @@ require "webrat/core/locators/locator"
2
2
 
3
3
  module Webrat
4
4
  module Locators
5
-
5
+
6
6
  class FieldByIdLocator < Locator # :nodoc:
7
-
7
+
8
8
  def locate
9
9
  Field.load(@session, field_element)
10
10
  end
11
-
11
+
12
12
  def field_element
13
13
  field_elements.detect do |field_element|
14
14
  if @value.is_a?(Regexp)
@@ -18,7 +18,7 @@ module Webrat
18
18
  end
19
19
  end
20
20
  end
21
-
21
+
22
22
  def field_elements
23
23
  Webrat::XML.xpath_search(@dom, *Field.xpath_search)
24
24
  end
@@ -26,12 +26,12 @@ module Webrat
26
26
  def error_message
27
27
  "Could not find field with id #{@value.inspect}"
28
28
  end
29
-
29
+
30
30
  end
31
-
31
+
32
32
  def field_with_id(id, *field_types)
33
33
  FieldByIdLocator.new(@session, dom, id, *field_types).locate!
34
34
  end
35
-
35
+
36
36
  end
37
- end
37
+ end
@@ -3,13 +3,13 @@ require "webrat/core/locators/locator"
3
3
 
4
4
  module Webrat
5
5
  module Locators
6
-
6
+
7
7
  class FieldLabeledLocator < Locator # :nodoc:
8
-
8
+
9
9
  def locate
10
10
  matching_labels.any? && matching_labels.detect_mapped { |label| label.field }
11
11
  end
12
-
12
+
13
13
  def matching_labels
14
14
  matching_label_elements.sort_by do |label_element|
15
15
  text(label_element).length
@@ -17,21 +17,21 @@ module Webrat
17
17
  Label.load(@session, label_element)
18
18
  end
19
19
  end
20
-
20
+
21
21
  def matching_label_elements
22
22
  label_elements.select do |label_element|
23
23
  text(label_element) =~ /^\W*#{Regexp.escape(@value.to_s)}\b/i
24
24
  end
25
25
  end
26
-
26
+
27
27
  def label_elements
28
28
  Webrat::XML.xpath_search(@dom, Label.xpath_search)
29
29
  end
30
-
30
+
31
31
  def error_message
32
32
  "Could not find field labeled #{@value.inspect}"
33
33
  end
34
-
34
+
35
35
  def text(element)
36
36
  str = Webrat::XML.all_inner_text(element)
37
37
  str.gsub!("\n","")
@@ -39,9 +39,9 @@ module Webrat
39
39
  str.squeeze!(" ")
40
40
  str
41
41
  end
42
-
42
+
43
43
  end
44
-
44
+
45
45
  # Locates a form field based on a <tt>label</tt> element in the HTML source.
46
46
  # This can be useful in order to verify that a field is pre-filled with the
47
47
  # correct value.
@@ -51,6 +51,6 @@ module Webrat
51
51
  def field_labeled(label, *field_types)
52
52
  FieldLabeledLocator.new(@session, dom, label, *field_types).locate!
53
53
  end
54
-
54
+
55
55
  end
56
56
  end
@@ -2,24 +2,24 @@ require "webrat/core/locators/locator"
2
2
 
3
3
  module Webrat
4
4
  module Locators
5
-
5
+
6
6
  class FieldLocator < Locator # :nodoc:
7
-
7
+
8
8
  def locate
9
9
  FieldByIdLocator.new(@session, @dom, @value).locate ||
10
10
  FieldNamedLocator.new(@session, @dom, @value, *@field_types).locate ||
11
11
  FieldLabeledLocator.new(@session, @dom, @value, *@field_types).locate
12
12
  end
13
-
13
+
14
14
  def error_message
15
15
  "Could not find field: #{@value.inspect}"
16
16
  end
17
-
17
+
18
18
  end
19
-
19
+
20
20
  def field(*args) # :nodoc:
21
21
  FieldLocator.new(@session, dom, *args).locate!
22
22
  end
23
-
23
+
24
24
  end
25
- end
25
+ end
@@ -2,23 +2,23 @@ require "webrat/core/locators/locator"
2
2
 
3
3
  module Webrat
4
4
  module Locators
5
-
5
+
6
6
  class FieldNamedLocator < Locator # :nodoc:
7
-
7
+
8
8
  def locate
9
9
  Field.load(@session, field_element)
10
10
  end
11
-
11
+
12
12
  def field_element
13
13
  field_elements.detect do |field_element|
14
14
  Webrat::XML.attribute(field_element, "name") == @value.to_s
15
15
  end
16
16
  end
17
-
17
+
18
18
  def field_elements
19
19
  Webrat::XML.xpath_search(@dom, *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
@@ -26,16 +26,16 @@ module Webrat
26
26
  Array(Field.xpath_search)
27
27
  end
28
28
  end
29
-
29
+
30
30
  def error_message
31
31
  "Could not find field named #{@value.inspect}"
32
32
  end
33
-
33
+
34
34
  end
35
-
35
+
36
36
  def field_named(name, *field_types)
37
37
  FieldNamedLocator.new(@session, dom, name, *field_types).locate!
38
38
  end
39
-
39
+
40
40
  end
41
- end
41
+ end
@@ -2,18 +2,18 @@ require "webrat/core/locators/locator"
2
2
 
3
3
  module Webrat
4
4
  module Locators
5
-
5
+
6
6
  class FormLocator < Locator # :nodoc:
7
-
7
+
8
8
  def locate
9
9
  Form.load(@session, form_element)
10
10
  end
11
-
11
+
12
12
  def form_element
13
13
  Webrat::XML.css_at(@dom, "#" + @value)
14
14
  end
15
-
15
+
16
16
  end
17
-
17
+
18
18
  end
19
- end
19
+ end
@@ -3,23 +3,23 @@ require "webrat/core/locators/locator"
3
3
 
4
4
  module Webrat
5
5
  module Locators
6
-
6
+
7
7
  class LabelLocator < Locator # :nodoc:
8
-
8
+
9
9
  def locate
10
10
  Label.load(@session, label_element)
11
11
  end
12
-
12
+
13
13
  def label_element
14
14
  label_elements.detect do |label_element|
15
15
  text(label_element) =~ /^\W*#{Regexp.escape(@value.to_s)}\b/i
16
16
  end
17
17
  end
18
-
18
+
19
19
  def label_elements
20
20
  Webrat::XML.xpath_search(@dom, Label.xpath_search)
21
21
  end
22
-
22
+
23
23
  def text(label_element)
24
24
  str = Webrat::XML.all_inner_text(label_element)
25
25
  str.gsub!("\n","")
@@ -27,8 +27,8 @@ module Webrat
27
27
  str.squeeze!(" ")
28
28
  str
29
29
  end
30
-
30
+
31
31
  end
32
-
32
+
33
33
  end
34
- end
34
+ end
@@ -2,17 +2,17 @@ require "webrat/core/locators/locator"
2
2
 
3
3
  module Webrat
4
4
  module Locators
5
-
5
+
6
6
  class LinkLocator < Locator # :nodoc:
7
-
7
+
8
8
  def locate
9
9
  Link.load(@session, link_element)
10
10
  end
11
-
11
+
12
12
  def link_element
13
13
  matching_links.min { |a, b| Webrat::XML.all_inner_text(a).length <=> Webrat::XML.all_inner_text(b).length }
14
14
  end
15
-
15
+
16
16
  def matching_links
17
17
  @matching_links ||= link_elements.select do |link_element|
18
18
  matches_text?(link_element) ||
@@ -20,7 +20,7 @@ module Webrat
20
20
  matches_class?(link_element)
21
21
  end
22
22
  end
23
-
23
+
24
24
  def matches_text?(link)
25
25
  if @value.is_a?(Regexp)
26
26
  matcher = @value
@@ -49,11 +49,10 @@ module Webrat
49
49
  end
50
50
  end
51
51
 
52
-
53
52
  def link_elements
54
53
  Webrat::XML.xpath_search(@dom, *Link.xpath_search)
55
54
  end
56
-
55
+
57
56
  def replace_nbsp(str)
58
57
  str.gsub([0xA0].pack('U'), ' ')
59
58
  end
@@ -61,16 +60,16 @@ module Webrat
61
60
  def replace_nbsp_ref(str)
62
61
  str.gsub('&#xA0;',' ').gsub('&nbsp;', ' ')
63
62
  end
64
-
63
+
65
64
  def error_message
66
65
  "Could not find link with text, title, id or class #{@value.inspect}"
67
66
  end
68
-
67
+
69
68
  end
70
-
69
+
71
70
  def find_link(text_or_title_or_id) #:nodoc:
72
71
  LinkLocator.new(@session, dom, text_or_title_or_id).locate!
73
72
  end
74
-
73
+
75
74
  end
76
- end
75
+ end
@@ -1,6 +1,6 @@
1
1
  module Webrat
2
2
  module Locators
3
-
3
+
4
4
  class Locator # :nodoc:
5
5
 
6
6
  def initialize(session, dom, value, *field_types)
@@ -9,12 +9,12 @@ module Webrat
9
9
  @value = value
10
10
  @field_types = field_types
11
11
  end
12
-
12
+
13
13
  def locate!
14
14
  locate || raise(NotFoundError.new(error_message))
15
15
  end
16
-
16
+
17
17
  end
18
-
18
+
19
19
  end
20
- end
20
+ end
@@ -3,20 +3,20 @@ require "webrat/core/locators/locator"
3
3
 
4
4
  module Webrat
5
5
  module Locators
6
-
6
+
7
7
  class SelectOptionLocator < Locator # :nodoc:
8
-
8
+
9
9
  def initialize(session, dom, option_text, id_or_name_or_label)
10
10
  @session = session
11
11
  @dom = dom
12
12
  @option_text = option_text
13
13
  @id_or_name_or_label = id_or_name_or_label
14
14
  end
15
-
15
+
16
16
  def locate
17
17
  if @id_or_name_or_label
18
18
  field = FieldLocator.new(@session, @dom, @id_or_name_or_label, SelectField).locate!
19
-
19
+
20
20
  field.options.detect do |o|
21
21
  if @option_text.is_a?(Regexp)
22
22
  Webrat::XML.inner_html(o.element) =~ @option_text
@@ -32,15 +32,15 @@ module Webrat
32
32
  Webrat::XML.inner_html(o) == @option_text.to_s
33
33
  end
34
34
  end
35
-
35
+
36
36
  SelectOption.load(@session, option_element)
37
37
  end
38
38
  end
39
-
39
+
40
40
  def option_elements
41
41
  Webrat::XML.xpath_search(@dom, *SelectOption.xpath_search)
42
42
  end
43
-
43
+
44
44
  def error_message
45
45
  if @id_or_name_or_label
46
46
  "The '#{@option_text}' option was not found in the #{@id_or_name_or_label.inspect} select box"
@@ -48,12 +48,12 @@ module Webrat
48
48
  "Could not find option #{@option_text.inspect}"
49
49
  end
50
50
  end
51
-
51
+
52
52
  end
53
-
53
+
54
54
  def select_option(option_text, id_or_name_or_label = nil) #:nodoc:
55
55
  SelectOptionLocator.new(@session, dom, option_text, id_or_name_or_label).locate!
56
56
  end
57
-
57
+
58
58
  end
59
- end
59
+ end
@@ -11,10 +11,10 @@ require "webrat/core/locators/form_locator"
11
11
 
12
12
  module Webrat
13
13
  module Locators
14
-
14
+
15
15
  def field_by_xpath(xpath)
16
16
  Field.load(@session, Webrat::XML.xpath_at(dom, xpath))
17
17
  end
18
-
18
+
19
19
  end
20
20
  end
@@ -1,6 +1,6 @@
1
1
  module Webrat
2
2
  module Logging #:nodoc:
3
-
3
+
4
4
  def debug_log(message) # :nodoc:
5
5
  return unless logger
6
6
  logger.debug message
@@ -16,6 +16,6 @@ module Webrat
16
16
  nil
17
17
  end
18
18
  end
19
-
19
+
20
20
  end
21
- end
21
+ end
@@ -1,20 +1,20 @@
1
1
  module Webrat
2
2
  module Matchers
3
-
3
+
4
4
  class HasContent #:nodoc:
5
5
  def initialize(content)
6
6
  @content = content
7
7
  end
8
-
8
+
9
9
  def matches?(stringlike)
10
10
  if Webrat.configuration.parse_with_nokogiri?
11
11
  @document = Webrat.nokogiri_document(stringlike)
12
12
  else
13
13
  @document = Webrat.hpricot_document(stringlike)
14
14
  end
15
-
15
+
16
16
  @element = Webrat::XML.inner_text(@document)
17
-
17
+
18
18
  case @content
19
19
  when String
20
20
  @element.include?(@content)
@@ -22,7 +22,7 @@ module Webrat
22
22
  @element.match(@content)
23
23
  end
24
24
  end
25
-
25
+
26
26
  # ==== Returns
27
27
  # String:: The failure message.
28
28
  def failure_message
@@ -34,11 +34,11 @@ module Webrat
34
34
  def negative_failure_message
35
35
  "expected the following element's content to not #{content_message}:\n#{squeeze_space(@element)}"
36
36
  end
37
-
37
+
38
38
  def squeeze_space(inner_text)
39
39
  inner_text.gsub(/^\s*$/, "").squeeze("\n")
40
40
  end
41
-
41
+
42
42
  def content_message
43
43
  case @content
44
44
  when String
@@ -48,26 +48,26 @@ module Webrat
48
48
  end
49
49
  end
50
50
  end
51
-
51
+
52
52
  # Matches the contents of an HTML document with
53
53
  # whatever string is supplied
54
54
  def contain(content)
55
55
  HasContent.new(content)
56
56
  end
57
-
57
+
58
58
  # Asserts that the body of the response contain
59
59
  # the supplied string or regexp
60
60
  def assert_contain(content)
61
61
  hc = HasContent.new(content)
62
62
  assert hc.matches?(response_body), hc.failure_message
63
63
  end
64
-
64
+
65
65
  # Asserts that the body of the response
66
66
  # does not contain the supplied string or regepx
67
67
  def assert_not_contain(content)
68
68
  hc = HasContent.new(content)
69
69
  assert !hc.matches?(response_body), hc.negative_failure_message
70
70
  end
71
-
71
+
72
72
  end
73
- end
73
+ end