capybara-ui 0.10.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/capybara/ui.rb +33 -0
- data/lib/capybara/ui/assertions.rb +21 -0
- data/lib/{capybara-ui → capybara/ui}/capybara.rb +0 -0
- data/lib/capybara/ui/checkpoint.rb +113 -0
- data/lib/capybara/ui/conversions.rb +33 -0
- data/lib/capybara/ui/cucumber.rb +5 -0
- data/lib/capybara/ui/dsl.rb +109 -0
- data/lib/capybara/ui/instance_conversions.rb +21 -0
- data/lib/{capybara-ui → capybara/ui}/matchers.rb +4 -4
- data/lib/capybara/ui/optional_dependencies.rb +7 -0
- data/lib/capybara/ui/rails.rb +5 -0
- data/lib/capybara/ui/rails/role.rb +11 -0
- data/lib/capybara/ui/role.rb +21 -0
- data/lib/capybara/ui/text_table.rb +109 -0
- data/lib/capybara/ui/text_table/cell_text.rb +9 -0
- data/lib/capybara/ui/text_table/mapping.rb +42 -0
- data/lib/capybara/ui/text_table/transformations.rb +15 -0
- data/lib/capybara/ui/text_table/void_mapping.rb +10 -0
- data/lib/capybara/ui/version.rb +5 -0
- data/lib/capybara/ui/widgets.rb +63 -0
- data/lib/capybara/ui/widgets/check_box.rb +28 -0
- data/lib/capybara/ui/widgets/cucumber_methods.rb +75 -0
- data/lib/capybara/ui/widgets/document.rb +21 -0
- data/lib/capybara/ui/widgets/dsl.rb +49 -0
- data/lib/capybara/ui/widgets/field.rb +24 -0
- data/lib/capybara/ui/widgets/field_group.rb +331 -0
- data/lib/capybara/ui/widgets/form.rb +28 -0
- data/lib/capybara/ui/widgets/list.rb +202 -0
- data/lib/capybara/ui/widgets/list_item.rb +24 -0
- data/lib/capybara/ui/widgets/parts/container.rb +48 -0
- data/lib/capybara/ui/widgets/parts/struct.rb +119 -0
- data/lib/capybara/ui/widgets/radio_button.rb +64 -0
- data/lib/capybara/ui/widgets/select.rb +59 -0
- data/lib/capybara/ui/widgets/string_value.rb +45 -0
- data/lib/capybara/ui/widgets/table.rb +78 -0
- data/lib/capybara/ui/widgets/text_field.rb +29 -0
- data/lib/capybara/ui/widgets/widget.rb +394 -0
- data/lib/capybara/ui/widgets/widget/node_filter.rb +50 -0
- data/lib/capybara/ui/widgets/widget_class.rb +13 -0
- data/lib/capybara/ui/widgets/widget_name.rb +58 -0
- metadata +47 -43
- data/lib/capybara-ui.rb +0 -31
- data/lib/capybara-ui/assertions.rb +0 -19
- data/lib/capybara-ui/checkpoint.rb +0 -111
- data/lib/capybara-ui/conversions.rb +0 -31
- data/lib/capybara-ui/cucumber.rb +0 -5
- data/lib/capybara-ui/dsl.rb +0 -107
- data/lib/capybara-ui/instance_conversions.rb +0 -19
- data/lib/capybara-ui/optional_dependencies.rb +0 -5
- data/lib/capybara-ui/rails.rb +0 -5
- data/lib/capybara-ui/rails/role.rb +0 -9
- data/lib/capybara-ui/role.rb +0 -19
- data/lib/capybara-ui/text_table.rb +0 -107
- data/lib/capybara-ui/text_table/cell_text.rb +0 -7
- data/lib/capybara-ui/text_table/mapping.rb +0 -40
- data/lib/capybara-ui/text_table/transformations.rb +0 -13
- data/lib/capybara-ui/text_table/void_mapping.rb +0 -8
- data/lib/capybara-ui/version.rb +0 -3
- data/lib/capybara-ui/widgets.rb +0 -61
- data/lib/capybara-ui/widgets/check_box.rb +0 -26
- data/lib/capybara-ui/widgets/cucumber_methods.rb +0 -73
- data/lib/capybara-ui/widgets/document.rb +0 -19
- data/lib/capybara-ui/widgets/dsl.rb +0 -47
- data/lib/capybara-ui/widgets/field.rb +0 -22
- data/lib/capybara-ui/widgets/field_group.rb +0 -329
- data/lib/capybara-ui/widgets/form.rb +0 -26
- data/lib/capybara-ui/widgets/list.rb +0 -200
- data/lib/capybara-ui/widgets/list_item.rb +0 -22
- data/lib/capybara-ui/widgets/parts/container.rb +0 -46
- data/lib/capybara-ui/widgets/parts/struct.rb +0 -117
- data/lib/capybara-ui/widgets/radio_button.rb +0 -62
- data/lib/capybara-ui/widgets/select.rb +0 -57
- data/lib/capybara-ui/widgets/string_value.rb +0 -43
- data/lib/capybara-ui/widgets/table.rb +0 -76
- data/lib/capybara-ui/widgets/text_field.rb +0 -27
- data/lib/capybara-ui/widgets/widget.rb +0 -392
- data/lib/capybara-ui/widgets/widget/node_filter.rb +0 -48
- data/lib/capybara-ui/widgets/widget_class.rb +0 -11
- data/lib/capybara-ui/widgets/widget_name.rb +0 -56
data/lib/capybara-ui/dsl.rb
DELETED
@@ -1,107 +0,0 @@
|
|
1
|
-
module CapybaraUI
|
2
|
-
module DSL
|
3
|
-
attr_writer :widget_lookup_scope
|
4
|
-
|
5
|
-
# Clicks the widget defined by +name+ and optional +args+.
|
6
|
-
#
|
7
|
-
# Makes no distinction between links or buttons.
|
8
|
-
#
|
9
|
-
# class MyWidget < CapybaraUI::Widget
|
10
|
-
# root { |text| ['.my-widget', text: text] }
|
11
|
-
# end
|
12
|
-
#
|
13
|
-
# # <a href="#one" class="my-widget">One</li>
|
14
|
-
# # <a href="#two" class="my-widget">Two</li> <!-- clicks this node -->
|
15
|
-
# click :my_widget, 'Two'
|
16
|
-
def click(name, *args)
|
17
|
-
widget(name, *args).click
|
18
|
-
end
|
19
|
-
|
20
|
-
# Hovers the widget defined by +name+ and optional +args+.
|
21
|
-
def hover(name, *args)
|
22
|
-
widget(name, *args).hover
|
23
|
-
end
|
24
|
-
|
25
|
-
# Double clicks the widget defined by +name+ and optional +args+.
|
26
|
-
def double_click(name, *args)
|
27
|
-
widget(name, *args).double_click
|
28
|
-
end
|
29
|
-
|
30
|
-
# Right clicks the widget defined by +name+ and optional +args+.
|
31
|
-
def right_click(name, *args)
|
32
|
-
widget(name, *args).right_click
|
33
|
-
end
|
34
|
-
|
35
|
-
# @return [Document] the current document with the class of the
|
36
|
-
# current object set as the widget lookup scope.
|
37
|
-
def document
|
38
|
-
Document.new(widget_lookup_scope)
|
39
|
-
end
|
40
|
-
|
41
|
-
# @return [Boolean] Whether one or more widgets exist in the current
|
42
|
-
# document.
|
43
|
-
def has_widget?(name, *args)
|
44
|
-
document.has_widget?(name, *args)
|
45
|
-
end
|
46
|
-
|
47
|
-
alias_method :widget?, :has_widget?
|
48
|
-
|
49
|
-
def visible?(name, *args)
|
50
|
-
document.visible?(name, *args)
|
51
|
-
end
|
52
|
-
|
53
|
-
def not_visible?(name, *args)
|
54
|
-
document.not_visible?(name, *args)
|
55
|
-
end
|
56
|
-
|
57
|
-
def set(name, fields)
|
58
|
-
widget(name).set fields
|
59
|
-
end
|
60
|
-
|
61
|
-
def submit(name, fields = {})
|
62
|
-
widget(name).submit_with fields
|
63
|
-
end
|
64
|
-
|
65
|
-
def value(name, *args)
|
66
|
-
widget(name, *args).value
|
67
|
-
end
|
68
|
-
|
69
|
-
def values(name, *args)
|
70
|
-
widgets(name, *args).map(&:value)
|
71
|
-
end
|
72
|
-
|
73
|
-
def visit(path)
|
74
|
-
Capybara.current_session.visit path
|
75
|
-
end
|
76
|
-
|
77
|
-
# Returns a widget instance for the given name.
|
78
|
-
#
|
79
|
-
# @param name [String, Symbol]
|
80
|
-
def widget(name, *args)
|
81
|
-
eventually { document.widget(name, *args) }
|
82
|
-
end
|
83
|
-
|
84
|
-
# Returns a list of widget instances for the given name.
|
85
|
-
#
|
86
|
-
# @param name [String, Symbol]
|
87
|
-
def widgets(name, *args)
|
88
|
-
document.widgets(name, *args)
|
89
|
-
end
|
90
|
-
|
91
|
-
def widget_lookup_scope
|
92
|
-
@widget_lookup_scope ||= default_widget_lookup_scope
|
93
|
-
end
|
94
|
-
|
95
|
-
# re-run one or more assertions until either they all pass,
|
96
|
-
# or CapybaraUI times out, which will result in a test failure.
|
97
|
-
def eventually(wait_time = Capybara.default_max_wait_time, &block)
|
98
|
-
Checkpoint.wait_for wait_time, &block
|
99
|
-
end
|
100
|
-
|
101
|
-
private
|
102
|
-
|
103
|
-
def default_widget_lookup_scope
|
104
|
-
Module === self ? self : self.class
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module CapybaraUI
|
2
|
-
module InstanceConversions
|
3
|
-
def self.included(base)
|
4
|
-
base.send :include, CapybaraUI::Conversions
|
5
|
-
end
|
6
|
-
|
7
|
-
def to_boolean
|
8
|
-
Boolean(self)
|
9
|
-
end
|
10
|
-
|
11
|
-
def to_a
|
12
|
-
List(self)
|
13
|
-
end
|
14
|
-
|
15
|
-
def to_time
|
16
|
-
Timeish(self)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
data/lib/capybara-ui/rails.rb
DELETED
data/lib/capybara-ui/role.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
module CapybaraUI
|
2
|
-
class Role < CapybaraUI::Rails::Role
|
3
|
-
extend Widgets::DSL
|
4
|
-
|
5
|
-
include CapybaraUI::DSL
|
6
|
-
|
7
|
-
def see?(name, *args)
|
8
|
-
if respond_to?("see_#{name}?")
|
9
|
-
send("see_#{name}?", *args)
|
10
|
-
else
|
11
|
-
visible?(name, *args)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def inspect
|
16
|
-
self.class.name
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,107 +0,0 @@
|
|
1
|
-
module CapybaraUI
|
2
|
-
class TextTable
|
3
|
-
extend Forwardable
|
4
|
-
|
5
|
-
include Enumerable
|
6
|
-
include Conversions
|
7
|
-
|
8
|
-
class << self
|
9
|
-
def Array(table)
|
10
|
-
new(table).to_a
|
11
|
-
end
|
12
|
-
|
13
|
-
def Hash(table)
|
14
|
-
new(table).to_h
|
15
|
-
end
|
16
|
-
|
17
|
-
def map(name, options = {}, &block)
|
18
|
-
case name
|
19
|
-
when :*
|
20
|
-
set_default_mapping options, &block
|
21
|
-
else
|
22
|
-
set_mapping name, options, &block
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def mappings
|
27
|
-
@mappings ||= Hash.
|
28
|
-
new { |h, k| h[k] = Mapping.new }.
|
29
|
-
merge(with_parent_mappings)
|
30
|
-
end
|
31
|
-
|
32
|
-
def skip(name)
|
33
|
-
case name
|
34
|
-
when :*
|
35
|
-
set_default_mapping VoidMapping
|
36
|
-
else
|
37
|
-
raise ArgumentError, "can't convert #{name.inspect} to name"
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
private
|
42
|
-
|
43
|
-
def set_default_mapping(options, &block)
|
44
|
-
case options
|
45
|
-
when Hash
|
46
|
-
@mappings = Hash.
|
47
|
-
new { |h, k|
|
48
|
-
h[k] = Mapping.new(key_transformer: options[:to],
|
49
|
-
value_transformer: block) }.
|
50
|
-
merge(mappings)
|
51
|
-
when Class
|
52
|
-
@mappings = Hash.new { |h, k| h[k] = options.new }.merge(mappings)
|
53
|
-
else
|
54
|
-
raise ArgumentError, "can't convert #{options.inspect} to mapping"
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def set_mapping(name, options, &block)
|
59
|
-
mappings[name] = Mapping.
|
60
|
-
new(key: options[:to], value_transformer: block)
|
61
|
-
end
|
62
|
-
|
63
|
-
def with_parent_mappings
|
64
|
-
if superclass.respond_to?(:mappings)
|
65
|
-
superclass.send(:mappings).dup
|
66
|
-
else
|
67
|
-
{}
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def_delegators 'self.class', :mappings
|
73
|
-
|
74
|
-
def initialize(table)
|
75
|
-
self.table = table
|
76
|
-
end
|
77
|
-
|
78
|
-
def each(&block)
|
79
|
-
rows.each(&block)
|
80
|
-
end
|
81
|
-
|
82
|
-
def rows
|
83
|
-
@rows ||= table.hashes.map { |h| new_row(h) }
|
84
|
-
end
|
85
|
-
|
86
|
-
def single_row
|
87
|
-
@single_row ||= new_row(table.rows_hash)
|
88
|
-
end
|
89
|
-
|
90
|
-
alias_method :to_a, :rows
|
91
|
-
alias_method :to_h, :single_row
|
92
|
-
|
93
|
-
private
|
94
|
-
|
95
|
-
attr_accessor :table
|
96
|
-
|
97
|
-
def new_row(hash)
|
98
|
-
hash.each_with_object({}) { |(k, v), h|
|
99
|
-
mapping_for(k).set(self, h, k, CellText.new(v))
|
100
|
-
}
|
101
|
-
end
|
102
|
-
|
103
|
-
def mapping_for(header)
|
104
|
-
mappings[header]
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
module CapybaraUI
|
2
|
-
class TextTable
|
3
|
-
class Mapping
|
4
|
-
def initialize(settings = {})
|
5
|
-
self.key = settings[:key]
|
6
|
-
self.value_transformer = transformer(settings[:value_transformer], :pass)
|
7
|
-
self.key_transformer = transformer(settings[:key_transformer], :keyword)
|
8
|
-
end
|
9
|
-
|
10
|
-
def set(instance, row, key, value)
|
11
|
-
row[transform_key(instance, key)] = transform_value(instance, value)
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
attr_accessor :key, :value_transformer, :key_transformer
|
17
|
-
|
18
|
-
def transform_key(_, k)
|
19
|
-
key || key_transformer.(k)
|
20
|
-
end
|
21
|
-
|
22
|
-
def transform_value(instance, value)
|
23
|
-
instance.instance_exec(value, &value_transformer)
|
24
|
-
end
|
25
|
-
|
26
|
-
def transformer(set, fallback)
|
27
|
-
case set
|
28
|
-
when Symbol
|
29
|
-
Transformations.send(set)
|
30
|
-
when Proc
|
31
|
-
set
|
32
|
-
when nil
|
33
|
-
Transformations.send(fallback)
|
34
|
-
else
|
35
|
-
raise ArgumentError, "can't convert #{set.inspect} to transformer"
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
data/lib/capybara-ui/version.rb
DELETED
data/lib/capybara-ui/widgets.rb
DELETED
@@ -1,61 +0,0 @@
|
|
1
|
-
# This file describes the organization of the major Widget API components.
|
2
|
-
#
|
3
|
-
# === Parts
|
4
|
-
#
|
5
|
-
# Widget parts encapsulate the set of behaviours that constitute a widget.
|
6
|
-
module CapybaraUI
|
7
|
-
module Constructors
|
8
|
-
def Widget(*selector, &block)
|
9
|
-
if block_given?
|
10
|
-
WidgetClass.new(selector.flatten) do
|
11
|
-
define_method :value do
|
12
|
-
block.call(text)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
else
|
16
|
-
WidgetClass.new(selector.flatten)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
alias_method :String, :Widget
|
21
|
-
|
22
|
-
def Integer(*selector)
|
23
|
-
Widget(selector) { |text| Kernel::Integer(text) }
|
24
|
-
end
|
25
|
-
|
26
|
-
require 'bigdecimal'
|
27
|
-
|
28
|
-
def Decimal(*selector)
|
29
|
-
Widget(selector) { |text|
|
30
|
-
# ensure we can convert to float first
|
31
|
-
Float(text) && BigDecimal.new(text)
|
32
|
-
}
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
extend Constructors
|
37
|
-
end
|
38
|
-
|
39
|
-
module CapybaraUI::WidgetParts; end
|
40
|
-
|
41
|
-
require 'capybara-ui/widgets/parts/struct'
|
42
|
-
require 'capybara-ui/widgets/parts/container'
|
43
|
-
|
44
|
-
require 'capybara-ui/widgets/cucumber_methods'
|
45
|
-
require 'capybara-ui/widgets/dsl'
|
46
|
-
require 'capybara-ui/widgets/widget_class'
|
47
|
-
require 'capybara-ui/widgets/widget_name'
|
48
|
-
require 'capybara-ui/widgets/widget'
|
49
|
-
require 'capybara-ui/widgets/widget/node_filter'
|
50
|
-
require 'capybara-ui/widgets/list_item'
|
51
|
-
require 'capybara-ui/widgets/list'
|
52
|
-
require 'capybara-ui/widgets/field'
|
53
|
-
require 'capybara-ui/widgets/check_box'
|
54
|
-
require 'capybara-ui/widgets/radio_button'
|
55
|
-
require 'capybara-ui/widgets/select'
|
56
|
-
require 'capybara-ui/widgets/text_field'
|
57
|
-
require 'capybara-ui/widgets/field_group'
|
58
|
-
require 'capybara-ui/widgets/form'
|
59
|
-
require 'capybara-ui/widgets/document'
|
60
|
-
require 'capybara-ui/widgets/table'
|
61
|
-
require 'capybara-ui/widgets/string_value'
|
@@ -1,26 +0,0 @@
|
|
1
|
-
module CapybaraUI
|
2
|
-
# A check box.
|
3
|
-
class CheckBox < Field
|
4
|
-
# @!method set(value)
|
5
|
-
# Checks or unchecks the current checkbox.
|
6
|
-
#
|
7
|
-
# @param value [Boolean] +true+ to check the checkbox, +false+
|
8
|
-
# otherwise.
|
9
|
-
def_delegator :root, :set
|
10
|
-
|
11
|
-
# @return [Boolean] +true+ if the checkbox is checked, +false+
|
12
|
-
# otherwise.
|
13
|
-
def get
|
14
|
-
!! root.checked?
|
15
|
-
end
|
16
|
-
|
17
|
-
def to_cell
|
18
|
-
to_s
|
19
|
-
end
|
20
|
-
|
21
|
-
# @return +"yes"+ if the checkbox is checked, +"no"+ otherwise.
|
22
|
-
def to_s
|
23
|
-
get ? 'yes' : 'no'
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|