domkey 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/domkey/version.rb +1 -1
- data/lib/domkey/view/checkbox_group.rb +9 -5
- data/lib/domkey/view/option_selectable.rb +9 -0
- data/lib/domkey/view/option_selectable_group.rb +5 -3
- data/lib/domkey/view/page_object.rb +6 -6
- data/lib/domkey/view/radio_group.rb +8 -2
- data/lib/domkey/view/select_list.rb +11 -5
- data/lib/domkey/view/widgetry/dispatcher.rb +8 -0
- data/spec/checkbox_group_spec.rb +15 -5
- data/spec/option_selectable_spec.rb +13 -0
- data/spec/page_object_delegates_spec.rb +27 -12
- data/spec/radio_group_spec.rb +11 -1
- data/spec/select_list_spec.rb +7 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6db2446775f3d86af13cba9df7fc019216d3839a
|
4
|
+
data.tar.gz: 7354d30f4de4efadde733996bb66d0e8bb9002d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d0ae9df2963b01dfb954326d3375a9095c281ad68be78fd15cf836c02399b650be455f6367cec18971daef426858e0e44c60ebba8225f03ad4ce8106854915b
|
7
|
+
data.tar.gz: 9d24abfc09c0da8a15471c80d87225d06e11f03029c0fa37b06cbad1b40f42e71aa25e368b2e8daf59fa365ea8540d228fa3e177503afbfc6ba19ce4de1d872f
|
data/lib/domkey/version.rb
CHANGED
@@ -13,11 +13,15 @@ module Domkey
|
|
13
13
|
|
14
14
|
private
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
def set_by_symbol value
|
17
|
+
case value
|
18
|
+
when FalseClass
|
19
|
+
each { |o| o.set false }
|
20
|
+
when TrueClass
|
21
|
+
return #noop
|
22
|
+
else
|
23
|
+
fail(Exception::NotImplementedError, "Unknown way of setting by value: #{value.inspect}")
|
24
|
+
end
|
21
25
|
end
|
22
26
|
end
|
23
27
|
end
|
@@ -55,6 +55,8 @@ module Domkey
|
|
55
55
|
# strategy for selecting OptionSelectable object
|
56
56
|
def set_strategy value
|
57
57
|
case value
|
58
|
+
when TrueClass, FalseClass, Symbol
|
59
|
+
set_by_symbol(value)
|
58
60
|
when String, Regexp
|
59
61
|
set_by_value(value)
|
60
62
|
when Array
|
@@ -70,9 +72,16 @@ module Domkey
|
|
70
72
|
set_by_value(value)
|
71
73
|
end
|
72
74
|
end
|
75
|
+
else
|
76
|
+
fail(Exception::NotImplementedError, "Unable to be set by this value: #{value.inspect}")
|
73
77
|
end
|
74
78
|
end
|
75
79
|
|
80
|
+
# true, false, or some symbol identifier
|
81
|
+
def set_by_symbol value
|
82
|
+
fail Exception::NotImplementedError, "Subclass responsible for implementing"
|
83
|
+
end
|
84
|
+
|
76
85
|
# default strategy. set by value attribute
|
77
86
|
def set_by_value value
|
78
87
|
fail Exception::NotImplementedError, "Subclass responsible for implementing"
|
@@ -9,6 +9,10 @@ module Domkey
|
|
9
9
|
|
10
10
|
include OptionSelectable
|
11
11
|
|
12
|
+
def before_set
|
13
|
+
validate_scope
|
14
|
+
end
|
15
|
+
|
12
16
|
def set_by_index value
|
13
17
|
[*value].each { |i| self[i.to_i].set(true) }
|
14
18
|
end
|
@@ -23,10 +27,8 @@ module Domkey
|
|
23
27
|
find { |o| o.value == value }
|
24
28
|
when Regexp
|
25
29
|
find { |o| o.value.match(value) }
|
26
|
-
else
|
27
|
-
false
|
28
30
|
end
|
29
|
-
o ? o.element.set : fail(Exception::NotFoundError, "Element not found with value: #{
|
31
|
+
o ? o.element.set : fail(Exception::NotFoundError, "Element not found with value: #{value.inspect}")
|
30
32
|
end
|
31
33
|
|
32
34
|
def value_by_default
|
@@ -81,7 +81,7 @@ module Domkey
|
|
81
81
|
# @api private
|
82
82
|
# delegate to element when element responds to message
|
83
83
|
def method_missing(message, *args, &block)
|
84
|
-
if
|
84
|
+
if element.respond_to?(message)
|
85
85
|
element.__send__(message, *args, &block)
|
86
86
|
else
|
87
87
|
super
|
@@ -91,7 +91,7 @@ module Domkey
|
|
91
91
|
# @api private
|
92
92
|
# ruturn true when element.respond_to? message so we can delegate with confidence
|
93
93
|
def respond_to_missing?(message, include_private = false)
|
94
|
-
element.respond_to?(message)
|
94
|
+
element.respond_to?(message) || super
|
95
95
|
end
|
96
96
|
|
97
97
|
private
|
@@ -116,16 +116,16 @@ module Domkey
|
|
116
116
|
rescue StandardError
|
117
117
|
return package #suitecase exploded, proc returned
|
118
118
|
end
|
119
|
-
if peeked_inside.
|
119
|
+
if peeked_inside.kind_of?(Hash)
|
120
120
|
return initialize_this peeked_inside
|
121
|
-
elsif peeked_inside.
|
121
|
+
elsif peeked_inside.kind_of?(Watir::Container)
|
122
122
|
return lambda { peeked_inside }
|
123
|
-
elsif peeked_inside.
|
123
|
+
elsif peeked_inside.kind_of?(PageObject)
|
124
124
|
return peeked_inside.package
|
125
125
|
else
|
126
126
|
fail Exception::Error, "package must be kind of hash, watirelement or pageobject but I got this: #{package}"
|
127
127
|
end
|
128
|
-
elsif package.respond_to?(:package) #pageobject
|
128
|
+
elsif package.respond_to?(:package, true) #pageobject
|
129
129
|
return package.package
|
130
130
|
else
|
131
131
|
fail Exception::Error, "package must be kind of hash, watirelement or pageobject but I got this: #{package}"
|
@@ -13,9 +13,15 @@ module Domkey
|
|
13
13
|
|
14
14
|
private
|
15
15
|
|
16
|
-
def
|
17
|
-
|
16
|
+
def set_by_symbol value
|
17
|
+
case value
|
18
|
+
when FalseClass, TrueClass
|
19
|
+
return #noop
|
20
|
+
else
|
21
|
+
fail(Exception::NotImplementedError, "Unknown way of setting by value: #{value.inspect}")
|
22
|
+
end
|
18
23
|
end
|
24
|
+
|
19
25
|
end
|
20
26
|
end
|
21
27
|
end
|
@@ -7,6 +7,8 @@ module Domkey
|
|
7
7
|
|
8
8
|
include OptionSelectable
|
9
9
|
|
10
|
+
private
|
11
|
+
|
10
12
|
# by position in options array
|
11
13
|
def set_by_index value
|
12
14
|
[*value].each { |i| element.options[i].select }
|
@@ -42,12 +44,16 @@ module Domkey
|
|
42
44
|
end
|
43
45
|
end
|
44
46
|
|
45
|
-
|
46
|
-
|
47
|
-
|
47
|
+
def set_by_symbol value
|
48
|
+
case value
|
49
|
+
when FalseClass
|
50
|
+
element.clear if element.multiple?
|
51
|
+
when TrueClass
|
52
|
+
return #noop
|
53
|
+
else
|
54
|
+
fail(Exception::NotImplementedError, "Unknown way of setting by value: #{value.inspect}")
|
55
|
+
end
|
48
56
|
end
|
49
|
-
|
50
|
-
|
51
57
|
end
|
52
58
|
end
|
53
59
|
end
|
data/spec/checkbox_group_spec.rb
CHANGED
@@ -35,11 +35,8 @@ describe Domkey::View::CheckboxGroup do
|
|
35
35
|
@v = CollectionAsPageObjectCheckboxGroupView.new
|
36
36
|
@v.group.count.should == 3
|
37
37
|
@v.group.to_a.each { |e| e.should be_kind_of(Domkey::View::PageObject) }
|
38
|
-
|
39
|
-
|
40
|
-
it 'initial value on test page' do
|
41
|
-
@v.group.value.should eql ['other']
|
42
|
-
@v.group.value(:value, :index, :label).should eql [value: 'other', index: 2, label: 'Other']
|
38
|
+
# clear all selections first
|
39
|
+
@v.group.set false
|
43
40
|
end
|
44
41
|
|
45
42
|
it 'set string' do
|
@@ -52,6 +49,19 @@ describe Domkey::View::CheckboxGroup do
|
|
52
49
|
@v.group.value.should eql ['other']
|
53
50
|
end
|
54
51
|
|
52
|
+
it 'set by not implemented symbol' do
|
53
|
+
expect { @v.group.set :hello_world }.to raise_error(Domkey::Exception::NotImplementedError)
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'set appends by defulat' do
|
57
|
+
@v.group.set 'tomato'
|
58
|
+
@v.group.value.should eql ['tomato']
|
59
|
+
@v.group.set 'other'
|
60
|
+
@v.group.value.should eql ['tomato', 'other']
|
61
|
+
@v.group.set false
|
62
|
+
@v.group.value.should eql []
|
63
|
+
end
|
64
|
+
|
55
65
|
it 'set array of strings or regexp' do
|
56
66
|
@v.group.set ['tomato']
|
57
67
|
@v.group.value.should eql ['tomato']
|
@@ -17,6 +17,15 @@ describe Domkey::View::OptionSelectable do
|
|
17
17
|
@widget.set('fake')
|
18
18
|
end
|
19
19
|
|
20
|
+
it 'set by symbol' do
|
21
|
+
expect(@widget).to receive(:set_by_symbol)
|
22
|
+
@widget.set :hello_world
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'set by not implemented strategy' do
|
26
|
+
expect { @widget.set Object.new }.to raise_error(Domkey::Exception::NotImplementedError)
|
27
|
+
end
|
28
|
+
|
20
29
|
it 'set regex' do
|
21
30
|
expect(@widget).to receive(:set_by_value)
|
22
31
|
@widget.set(/fake/)
|
@@ -66,6 +75,10 @@ describe Domkey::View::OptionSelectable do
|
|
66
75
|
expect { @widget.set(:value => 'fake') }.to raise_error(Domkey::Exception::NotImplementedError)
|
67
76
|
end
|
68
77
|
|
78
|
+
it ':symbol' do
|
79
|
+
expect { @widget.set :hello_world }.to raise_error(Domkey::Exception::NotImplementedError)
|
80
|
+
end
|
81
|
+
|
69
82
|
end
|
70
83
|
|
71
84
|
context 'value' do
|
@@ -9,22 +9,37 @@ describe Domkey::View::PageObject do
|
|
9
9
|
goto_html("test.html")
|
10
10
|
end
|
11
11
|
|
12
|
-
context '
|
13
|
-
|
14
|
-
|
15
|
-
end
|
12
|
+
context 'wrapping single watir elements' do
|
13
|
+
|
14
|
+
context 'dispatcher bridges set value and options messages' do
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
it 'select' do
|
17
|
+
o = Domkey::View::PageObject.new -> { select_list(id: 'fruit_list') }
|
18
|
+
o.set 'Tomato'
|
19
|
+
o.value.should eql 'tomato'
|
20
|
+
end
|
20
21
|
|
21
|
-
@o.should respond_to(:click)
|
22
|
-
@o.click
|
23
22
|
end
|
24
23
|
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
context 'delegate unimplmemented messages' do
|
25
|
+
|
26
|
+
before :all do
|
27
|
+
@o = Domkey::View::PageObject.new -> { text_field(id: 'city1') }
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should delegate to element when element responds' do
|
31
|
+
@o.should respond_to(:id)
|
32
|
+
@o.id.should eql 'city1'
|
33
|
+
|
34
|
+
@o.should respond_to(:click)
|
35
|
+
@o.click
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should not delegate to element when element does not repsond' do
|
39
|
+
@o.should_not respond_to(:textaramabada)
|
40
|
+
expect { @o.textaramabada }.to raise_error(NoMethodError)
|
41
|
+
end
|
28
42
|
end
|
43
|
+
|
29
44
|
end
|
30
45
|
end
|
data/spec/radio_group_spec.rb
CHANGED
@@ -67,11 +67,21 @@ describe Domkey::View::RadioGroup do
|
|
67
67
|
@v.group.value([:index, :label]).should eql [{:index=>0, :label=>"Cucumber"}]
|
68
68
|
end
|
69
69
|
|
70
|
-
it 'set false
|
70
|
+
it 'set false noop' do
|
71
71
|
@v.group.set false
|
72
72
|
@v.group.value.should eql ['other']
|
73
73
|
end
|
74
74
|
|
75
|
+
it 'set true noop' do
|
76
|
+
@v.group.set false
|
77
|
+
@v.group.value.should eql ['other']
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'set by not implemented symbol errors' do
|
81
|
+
expect { @v.group.set :hello_world }.to raise_error(Domkey::Exception::NotImplementedError)
|
82
|
+
end
|
83
|
+
|
84
|
+
|
75
85
|
it 'set empty array has no effect' do
|
76
86
|
@v.group.set []
|
77
87
|
@v.group.value.should eql ['other']
|
data/spec/select_list_spec.rb
CHANGED
@@ -25,13 +25,12 @@ describe Domkey::View::SelectList do
|
|
25
25
|
|
26
26
|
before :each do
|
27
27
|
goto_html("test.html")
|
28
|
+
@widget.set false
|
28
29
|
end
|
29
30
|
|
30
|
-
it 'initial
|
31
|
+
it 'initial example' do
|
32
|
+
@widget.set ["2", "3"]
|
31
33
|
@widget.value.should eql ["2", "3"]
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'initial value by keys on the test page' do
|
35
34
|
# array
|
36
35
|
@widget.value([:index, :text, :value]).should eql [{:index=>1, :text=>"English", :value=>"2"}, {:index=>2, :text=>"Norwegian", :value=>"3"}]
|
37
36
|
# splat list
|
@@ -107,6 +106,10 @@ describe Domkey::View::SelectList do
|
|
107
106
|
@widget.value.should eql ["1", "2", "", "Swedish"]
|
108
107
|
end
|
109
108
|
|
109
|
+
it 'set by symbol' do
|
110
|
+
expect { @widget.set :hello_world }.to raise_error(Domkey::Exception::NotImplementedError)
|
111
|
+
end
|
112
|
+
|
110
113
|
it 'options by default' do
|
111
114
|
@widget.options.should eql ["1", "2", "3", "", "Swedish"]
|
112
115
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: domkey
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- rubytester
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-04-
|
12
|
+
date: 2014-04-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: watir-webdriver
|