capybara-ui 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +7 -0
  2. data/lib/capybara-ui.rb +31 -0
  3. data/lib/capybara-ui/assertions.rb +19 -0
  4. data/lib/capybara-ui/capybara.rb +7 -0
  5. data/lib/capybara-ui/checkpoint.rb +111 -0
  6. data/lib/capybara-ui/conversions.rb +31 -0
  7. data/lib/capybara-ui/cucumber.rb +5 -0
  8. data/lib/capybara-ui/dsl.rb +107 -0
  9. data/lib/capybara-ui/instance_conversions.rb +19 -0
  10. data/lib/capybara-ui/matchers.rb +28 -0
  11. data/lib/capybara-ui/optional_dependencies.rb +5 -0
  12. data/lib/capybara-ui/rails.rb +5 -0
  13. data/lib/capybara-ui/rails/role.rb +9 -0
  14. data/lib/capybara-ui/role.rb +19 -0
  15. data/lib/capybara-ui/text_table.rb +107 -0
  16. data/lib/capybara-ui/text_table/cell_text.rb +7 -0
  17. data/lib/capybara-ui/text_table/mapping.rb +40 -0
  18. data/lib/capybara-ui/text_table/transformations.rb +13 -0
  19. data/lib/capybara-ui/text_table/void_mapping.rb +8 -0
  20. data/lib/capybara-ui/version.rb +3 -0
  21. data/lib/capybara-ui/widgets.rb +61 -0
  22. data/lib/capybara-ui/widgets/check_box.rb +26 -0
  23. data/lib/capybara-ui/widgets/cucumber_methods.rb +73 -0
  24. data/lib/capybara-ui/widgets/document.rb +19 -0
  25. data/lib/capybara-ui/widgets/dsl.rb +47 -0
  26. data/lib/capybara-ui/widgets/field.rb +22 -0
  27. data/lib/capybara-ui/widgets/field_group.rb +329 -0
  28. data/lib/capybara-ui/widgets/form.rb +26 -0
  29. data/lib/capybara-ui/widgets/list.rb +200 -0
  30. data/lib/capybara-ui/widgets/list_item.rb +22 -0
  31. data/lib/capybara-ui/widgets/parts/container.rb +46 -0
  32. data/lib/capybara-ui/widgets/parts/struct.rb +117 -0
  33. data/lib/capybara-ui/widgets/radio_button.rb +62 -0
  34. data/lib/capybara-ui/widgets/select.rb +57 -0
  35. data/lib/capybara-ui/widgets/string_value.rb +43 -0
  36. data/lib/capybara-ui/widgets/table.rb +76 -0
  37. data/lib/capybara-ui/widgets/text_field.rb +27 -0
  38. data/lib/capybara-ui/widgets/widget.rb +392 -0
  39. data/lib/capybara-ui/widgets/widget/node_filter.rb +48 -0
  40. data/lib/capybara-ui/widgets/widget_class.rb +11 -0
  41. data/lib/capybara-ui/widgets/widget_name.rb +56 -0
  42. metadata +240 -0
@@ -0,0 +1,48 @@
1
+ module CapybaraUI
2
+ class Widget
3
+ class NodeFilter
4
+ attr_reader :selector
5
+
6
+ def initialize(*selector)
7
+ @selector = selector.flatten
8
+ end
9
+
10
+ def node(parent_widget, *args)
11
+ parent_widget.root.find(*capybara_selector(*args))
12
+ end
13
+
14
+ def node?(parent_widget, *args)
15
+ parent_widget.root.has_selector?(*capybara_selector(*args))
16
+ end
17
+
18
+ def nodeless?(parent_widget, *args)
19
+ parent_widget.root.has_no_selector?(*capybara_selector(*args))
20
+ end
21
+
22
+ def nodes(parent_widget, *args)
23
+ parent_widget.root.all(*capybara_selector(*args))
24
+ end
25
+
26
+ private
27
+
28
+ def capybara_selector(*args)
29
+ # TODO detect signature errors (e.g., passing a different arity than the
30
+ # one required by the selector proc, etc)
31
+ selector = if @selector.first.respond_to?(:call)
32
+ @selector.first.call(*args)
33
+ else
34
+ @selector
35
+ end
36
+ selector = Array(selector).flatten
37
+
38
+ defaults = {:wait => 0}
39
+
40
+ if Hash === selector.last
41
+ selector + [defaults.merge(selector.pop)]
42
+ else
43
+ selector + [defaults]
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,11 @@
1
+ module CapybaraUI
2
+ module WidgetClass
3
+ def self.new(selector, parent = Widget, &extensions)
4
+ klass = Class.new(parent) { root selector }
5
+
6
+ klass.class_eval(&extensions) if block_given?
7
+
8
+ klass
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,56 @@
1
+ module CapybaraUI
2
+ # The name of a widget in a format-independent representation.
3
+ class WidgetName < String
4
+ CAMEL_CASE_FORMAT = /\A([A-Z][a-z]*)+\Z/
5
+ SNAKE_CASE_FORMAT = /\A\w+\Z/
6
+
7
+ # Constructs the widget name.
8
+ #
9
+ # @param name [String, Symbol] the name of the widget in primitive form
10
+ def initialize(name)
11
+ @name = name
12
+ @canonical = canonical(@name)
13
+ end
14
+
15
+ # Returns the class for this widget name, in the given scope.
16
+ def to_class(scope = Object)
17
+ const = scope.const_get(@canonical)
18
+
19
+ raise TypeError, "`#{@canonical}' is not a widget in this scope" \
20
+ unless const < Widget
21
+
22
+ const
23
+ rescue NameError
24
+ raise Missing, "couldn't find `#{@name}' widget in this scope"
25
+ end
26
+
27
+ def to_sym
28
+ @canonical.to_sym
29
+ end
30
+
31
+ private
32
+
33
+ def canonical(name)
34
+ str = name.to_s
35
+
36
+ case str
37
+ when SNAKE_CASE_FORMAT
38
+ camel_case_from_snake_case(str)
39
+ when CAMEL_CASE_FORMAT
40
+ str
41
+ else
42
+ raise ArgumentError, "`#{str.inspect}' is an unrecognized format. Try snake case or camel case."
43
+ end
44
+ end
45
+
46
+ def camel_case_from_snake_case(name)
47
+ capitalize_word = ->(word) { word[0].upcase + word[1..-1] }
48
+ word_separator = '_'
49
+
50
+ name
51
+ .split(word_separator)
52
+ .map(&capitalize_word)
53
+ .join
54
+ end
55
+ end
56
+ end
metadata ADDED
@@ -0,0 +1,240 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capybara-ui
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.10.0
5
+ platform: ruby
6
+ authors:
7
+ - David Leal
8
+ - Adam Steel
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2016-01-16 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: chronic
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: capybara
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '2.5'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '2.5'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rspec-given
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: 3.5.0
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: 3.5.0
56
+ - !ruby/object:Gem::Dependency
57
+ name: capybara-webkit
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: 1.7.0
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: 1.7.0
70
+ - !ruby/object:Gem::Dependency
71
+ name: poltergeist
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: 1.5.0
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: 1.5.0
84
+ - !ruby/object:Gem::Dependency
85
+ name: cucumber
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: 1.3.0
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: 1.3.0
98
+ - !ruby/object:Gem::Dependency
99
+ name: pry
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: pry-nav
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: sinatra
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ - !ruby/object:Gem::Dependency
141
+ name: rails
142
+ requirement: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - "~>"
145
+ - !ruby/object:Gem::Version
146
+ version: 4.0.0
147
+ type: :development
148
+ prerelease: false
149
+ version_requirements: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - "~>"
152
+ - !ruby/object:Gem::Version
153
+ version: 4.0.0
154
+ - !ruby/object:Gem::Dependency
155
+ name: codeclimate-test-reporter
156
+ requirement: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ type: :development
162
+ prerelease: false
163
+ version_requirements: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ description: See https://github.com/mojotech/capybara-ui/README.md
169
+ email:
170
+ - dleal@mojotech.com
171
+ - ags@mojotech.com
172
+ executables: []
173
+ extensions: []
174
+ extra_rdoc_files: []
175
+ files:
176
+ - lib/capybara-ui.rb
177
+ - lib/capybara-ui/assertions.rb
178
+ - lib/capybara-ui/capybara.rb
179
+ - lib/capybara-ui/checkpoint.rb
180
+ - lib/capybara-ui/conversions.rb
181
+ - lib/capybara-ui/cucumber.rb
182
+ - lib/capybara-ui/dsl.rb
183
+ - lib/capybara-ui/instance_conversions.rb
184
+ - lib/capybara-ui/matchers.rb
185
+ - lib/capybara-ui/optional_dependencies.rb
186
+ - lib/capybara-ui/rails.rb
187
+ - lib/capybara-ui/rails/role.rb
188
+ - lib/capybara-ui/role.rb
189
+ - lib/capybara-ui/text_table.rb
190
+ - lib/capybara-ui/text_table/cell_text.rb
191
+ - lib/capybara-ui/text_table/mapping.rb
192
+ - lib/capybara-ui/text_table/transformations.rb
193
+ - lib/capybara-ui/text_table/void_mapping.rb
194
+ - lib/capybara-ui/version.rb
195
+ - lib/capybara-ui/widgets.rb
196
+ - lib/capybara-ui/widgets/check_box.rb
197
+ - lib/capybara-ui/widgets/cucumber_methods.rb
198
+ - lib/capybara-ui/widgets/document.rb
199
+ - lib/capybara-ui/widgets/dsl.rb
200
+ - lib/capybara-ui/widgets/field.rb
201
+ - lib/capybara-ui/widgets/field_group.rb
202
+ - lib/capybara-ui/widgets/form.rb
203
+ - lib/capybara-ui/widgets/list.rb
204
+ - lib/capybara-ui/widgets/list_item.rb
205
+ - lib/capybara-ui/widgets/parts/container.rb
206
+ - lib/capybara-ui/widgets/parts/struct.rb
207
+ - lib/capybara-ui/widgets/radio_button.rb
208
+ - lib/capybara-ui/widgets/select.rb
209
+ - lib/capybara-ui/widgets/string_value.rb
210
+ - lib/capybara-ui/widgets/table.rb
211
+ - lib/capybara-ui/widgets/text_field.rb
212
+ - lib/capybara-ui/widgets/widget.rb
213
+ - lib/capybara-ui/widgets/widget/node_filter.rb
214
+ - lib/capybara-ui/widgets/widget_class.rb
215
+ - lib/capybara-ui/widgets/widget_name.rb
216
+ homepage: https://github.com/mojotech/capybara-ui
217
+ licenses:
218
+ - MIT
219
+ metadata: {}
220
+ post_install_message:
221
+ rdoc_options: []
222
+ require_paths:
223
+ - lib
224
+ required_ruby_version: !ruby/object:Gem::Requirement
225
+ requirements:
226
+ - - ">="
227
+ - !ruby/object:Gem::Version
228
+ version: '0'
229
+ required_rubygems_version: !ruby/object:Gem::Requirement
230
+ requirements:
231
+ - - ">="
232
+ - !ruby/object:Gem::Version
233
+ version: '0'
234
+ requirements: []
235
+ rubyforge_project: "[none]"
236
+ rubygems_version: 2.4.8
237
+ signing_key:
238
+ specification_version: 4
239
+ summary: A set of helpers to ease integration testing
240
+ test_files: []