capybara 0.4.0 → 0.4.1.rc

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/History.txt +35 -0
  2. data/README.rdoc +60 -19
  3. data/lib/capybara.rb +81 -5
  4. data/lib/capybara/driver/base.rb +1 -6
  5. data/lib/capybara/driver/celerity_driver.rb +19 -9
  6. data/lib/capybara/driver/node.rb +8 -0
  7. data/lib/capybara/driver/rack_test_driver.rb +42 -29
  8. data/lib/capybara/driver/selenium_driver.rb +11 -3
  9. data/lib/capybara/dsl.rb +11 -0
  10. data/lib/capybara/node/actions.rb +4 -14
  11. data/lib/capybara/node/base.rb +47 -0
  12. data/lib/capybara/node/document.rb +17 -0
  13. data/lib/capybara/node/element.rb +178 -0
  14. data/lib/capybara/node/finders.rb +78 -27
  15. data/lib/capybara/node/matchers.rb +40 -11
  16. data/lib/capybara/node/simple.rb +116 -0
  17. data/lib/capybara/rspec.rb +18 -0
  18. data/lib/capybara/server.rb +5 -10
  19. data/lib/capybara/session.rb +7 -16
  20. data/lib/capybara/spec/driver.rb +16 -1
  21. data/lib/capybara/spec/session.rb +1 -0
  22. data/lib/capybara/spec/session/all_spec.rb +5 -0
  23. data/lib/capybara/spec/session/attach_file_spec.rb +6 -0
  24. data/lib/capybara/spec/session/click_link_or_button_spec.rb +2 -3
  25. data/lib/capybara/spec/session/find_spec.rb +0 -6
  26. data/lib/capybara/spec/session/first_spec.rb +72 -0
  27. data/lib/capybara/spec/session/has_css_spec.rb +107 -1
  28. data/lib/capybara/spec/session/has_field_spec.rb +60 -0
  29. data/lib/capybara/spec/session/has_select_spec.rb +40 -0
  30. data/lib/capybara/spec/session/javascript.rb +4 -13
  31. data/lib/capybara/spec/session/within_spec.rb +10 -3
  32. data/lib/capybara/spec/test_app.rb +20 -1
  33. data/lib/capybara/spec/views/form.erb +27 -0
  34. data/lib/capybara/spec/views/with_html.erb +21 -5
  35. data/lib/capybara/util/save_and_open_page.rb +8 -5
  36. data/lib/capybara/version.rb +1 -1
  37. data/spec/basic_node_spec.rb +77 -0
  38. data/spec/capybara_spec.rb +18 -0
  39. data/spec/dsl_spec.rb +26 -0
  40. data/spec/rspec_spec.rb +47 -0
  41. data/spec/save_and_open_page_spec.rb +83 -7
  42. data/spec/server_spec.rb +20 -0
  43. data/spec/session/rack_test_session_spec.rb +10 -0
  44. data/spec/string_spec.rb +77 -0
  45. metadata +306 -295
  46. data/lib/capybara/node.rb +0 -221
data/lib/capybara/node.rb DELETED
@@ -1,221 +0,0 @@
1
- require 'capybara/node/finders'
2
- require 'capybara/node/actions'
3
- require 'capybara/node/matchers'
4
-
5
- module Capybara
6
-
7
- ##
8
- #
9
- # A {Capybara::Node} represents either an element on a page through the subclass
10
- # {Capybara::Element} or a document through {Capybara::Document}.
11
- #
12
- # Both types of Node share the same methods, used for interacting with the
13
- # elements on the page. These methods are divided into three categories,
14
- # finders, actions and matchers. These are found in the modules
15
- # {Capybara::Node::Finders}, {Capybara::Node::Actions} and {Capybara::Node::Matchers}
16
- # respectively.
17
- #
18
- # A {Capybara::Session} exposes all methods from {Capybara::Document} directly:
19
- #
20
- # session = Capybara::Session.new(:rack_test, my_app)
21
- # session.visit('/')
22
- # session.fill_in('Foo', :with => 'Bar') # from Capybara::Node::Actions
23
- # bar = session.find('#bar') # from Capybara::Node::Finders
24
- # bar.select('Baz', :from => 'Quox') # from Capybara::Node::Actions
25
- # session.has_css?('#foobar') # from Capybara::Node::Matchers
26
- #
27
- class Node
28
- attr_reader :session, :base
29
-
30
- include Capybara::Node::Finders
31
- include Capybara::Node::Actions
32
- include Capybara::Node::Matchers
33
-
34
- def initialize(session, base)
35
- @session = session
36
- @base = base
37
- end
38
-
39
- protected
40
-
41
- def driver
42
- session.driver
43
- end
44
- end
45
-
46
- ##
47
- #
48
- # A {Capybara::Element} represents a single element on the page. It is possible
49
- # to interact with the contents of this element the same as with a document:
50
- #
51
- # session = Capybara::Session.new(:rack_test, my_app)
52
- #
53
- # bar = session.find('#bar') # from Capybara::Node::Finders
54
- # bar.select('Baz', :from => 'Quox') # from Capybara::Node::Actions
55
- #
56
- # {Capybara::Element} also has access to HTML attributes and other properties of the
57
- # element:
58
- #
59
- # bar.value
60
- # bar.text
61
- # bar[:title]
62
- #
63
- # @see Capybara::Node
64
- #
65
- class Element < Node
66
-
67
- ##
68
- #
69
- # @return [Object] The native element from the driver, this allows access to driver specific methods
70
- #
71
- def native
72
- base.native
73
- end
74
-
75
- ##
76
- #
77
- # @deprecated node is deprecated, please use {Capybara::Element#native} instead
78
- #
79
- def node
80
- Capybara.deprecate("node", "native")
81
- native
82
- end
83
-
84
- ##
85
- #
86
- # @return [String] The text of the element
87
- #
88
- def text
89
- base.text
90
- end
91
-
92
- ##
93
- #
94
- # Retrieve the given attribute
95
- #
96
- # element[:title] # => HTML title attribute
97
- #
98
- # @param [Symbol] attribute The attribute to retrieve
99
- # @return [String] The value of the attribute
100
- #
101
- def [](attribute)
102
- base[attribute]
103
- end
104
-
105
- ##
106
- #
107
- # @return [String] The value of the form element
108
- #
109
- def value
110
- base.value
111
- end
112
-
113
- ##
114
- #
115
- # Set the value of the form element to the given value.
116
- #
117
- # @param [String] value The new value
118
- #
119
- def set(value)
120
- base.set(value)
121
- end
122
-
123
- ##
124
- #
125
- # Select this node if is an option element inside a select tag
126
- #
127
- def select_option
128
- base.select_option
129
- end
130
-
131
- ##
132
- #
133
- # Unselect this node if is an option element inside a multiple select tag
134
- #
135
- def unselect_option
136
- base.unselect_option
137
- end
138
-
139
- ##
140
- #
141
- # Click the Element
142
- #
143
- def click
144
- base.click
145
- end
146
-
147
- ##
148
- #
149
- # @return [String] The tag name of the element
150
- #
151
- def tag_name
152
- base.tag_name
153
- end
154
-
155
- ##
156
- #
157
- # Whether or not the element is visible. Not all drivers support CSS, so
158
- # the result may be inaccurate.
159
- #
160
- # @return [Boolean] Whether the element is visible
161
- #
162
- def visible?
163
- base.visible?
164
- end
165
-
166
- ##
167
- #
168
- # An XPath expression describing where on the page the element can be found
169
- #
170
- # @return [String] An XPath expression
171
- #
172
- def path
173
- base.path
174
- end
175
-
176
- ##
177
- #
178
- # Trigger any event on the current element, for example mouseover or focus
179
- # events. Does not work in Selenium.
180
- #
181
- # @param [String] event The name of the event to trigger
182
- #
183
- def trigger(event)
184
- base.trigger(event)
185
- end
186
-
187
- ##
188
- #
189
- # Drag the element to the given other element.
190
- #
191
- # source = page.find('#foo')
192
- # target = page.find('#bar')
193
- # source.drag_to(target)
194
- #
195
- # @param [Capybara::Element] node The element to drag to
196
- #
197
- def drag_to(node)
198
- base.drag_to(node.base)
199
- end
200
-
201
- def inspect
202
- %(#<Capybara::Element tag="#{tag_name}" path="#{path}">)
203
- rescue NotSupportedByDriverError
204
- %(#<Capybara::Element tag="#{tag_name}">)
205
- end
206
-
207
- end
208
-
209
- ##
210
- #
211
- # A {Capybara::Document} represents an HTML document. Any operation
212
- # performed on it will be performed on the entire document.
213
- #
214
- # @see Capybara::Node
215
- #
216
- class Document < Node
217
- def inspect
218
- %(#<Capybara::Document>)
219
- end
220
- end
221
- end