page_magic 1.2.4 → 1.2.5.alpha1
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.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/page_magic/element.rb +12 -3
- data/lib/page_magic/element_context.rb +3 -1
- data/lib/page_magic/exceptions.rb +45 -11
- data/lib/page_magic/instance_methods.rb +5 -1
- data/lib/page_magic/watcher.rb +1 -1
- data/spec/element_spec.rb +12 -3
- data/spec/page_magic/element_context_spec.rb +24 -3
- data/spec/page_magic/instance_methods_spec.rb +1 -1
- data/spec/watcher_spec.rb +13 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6ce815c4de6f42f92abe1cd4ed039a149d24b345
|
4
|
+
data.tar.gz: 50c30aa422018e788ba192cafae8867872cbab32
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 08563d7022df224ce434f63e29a13d4f54663720e0641ee4ea41df8b0c4d53169ac6e174b66c707898558721a7853499a247f491b14de55bf2e66c518ba4787e
|
7
|
+
data.tar.gz: f214be5face9359d38fff47f5ea546a76081d7dee0adac598f25e389387a39290b9e560ae426a24f55583aefb51d8ea06a1ae75df5372e597260a07e16ed77e3
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.2.
|
1
|
+
1.2.5.alpha1
|
data/lib/page_magic/element.rb
CHANGED
@@ -85,15 +85,20 @@ module PageMagic
|
|
85
85
|
browser_element.send(method, *args)
|
86
86
|
end
|
87
87
|
end
|
88
|
+
|
88
89
|
def method_missing(method, *args, &block)
|
89
90
|
ElementContext.new(self).send(method, *args, &block)
|
90
91
|
rescue ElementMissingException
|
91
|
-
|
92
|
-
|
92
|
+
begin
|
93
|
+
return browser_element.send(method, *args, &block) if browser_element.respond_to?(method)
|
94
|
+
return parent_element.send(method, *args, &block)
|
95
|
+
rescue NoMethodError
|
96
|
+
super
|
97
|
+
end
|
93
98
|
end
|
94
99
|
|
95
100
|
def respond_to?(*args)
|
96
|
-
super ||
|
101
|
+
super || contains_element?(args.first) || browser_element.respond_to?(*args) || parent_element.respond_to?(*args)
|
97
102
|
end
|
98
103
|
|
99
104
|
# @!method session
|
@@ -115,6 +120,10 @@ module PageMagic
|
|
115
120
|
end
|
116
121
|
end
|
117
122
|
|
123
|
+
def contains_element?(name)
|
124
|
+
element_definitions.keys.include?(name)
|
125
|
+
end
|
126
|
+
|
118
127
|
def element_context
|
119
128
|
ElementContext.new(self)
|
120
129
|
end
|
@@ -19,6 +19,8 @@ module PageMagic
|
|
19
19
|
|
20
20
|
builder = page_element.element_by_name(method, *args)
|
21
21
|
|
22
|
+
super unless builder
|
23
|
+
|
22
24
|
prefecteched_element = builder.element
|
23
25
|
return builder.build(prefecteched_element) if prefecteched_element
|
24
26
|
|
@@ -27,7 +29,7 @@ module PageMagic
|
|
27
29
|
end
|
28
30
|
|
29
31
|
def respond_to?(*args)
|
30
|
-
page_element.
|
32
|
+
page_element.respond_to?(*args) || super
|
31
33
|
end
|
32
34
|
|
33
35
|
private
|
@@ -1,34 +1,68 @@
|
|
1
1
|
module PageMagic
|
2
|
-
class ElementMissingException <
|
2
|
+
class ElementMissingException < RuntimeError
|
3
3
|
end
|
4
4
|
|
5
|
-
class InvalidElementNameException <
|
5
|
+
class InvalidElementNameException < RuntimeError
|
6
6
|
end
|
7
7
|
|
8
|
-
class InvalidMethodNameException <
|
8
|
+
class InvalidMethodNameException < RuntimeError
|
9
9
|
end
|
10
10
|
|
11
|
-
class InvalidURLException <
|
11
|
+
class InvalidURLException < RuntimeError
|
12
12
|
end
|
13
13
|
|
14
|
-
class MatcherInvalidException <
|
14
|
+
class MatcherInvalidException < RuntimeError
|
15
15
|
end
|
16
16
|
|
17
|
-
class TimeoutException <
|
17
|
+
class TimeoutException < RuntimeError
|
18
18
|
end
|
19
19
|
|
20
|
-
class UnspportedBrowserException <
|
20
|
+
class UnspportedBrowserException < RuntimeError
|
21
21
|
end
|
22
22
|
|
23
|
-
class UnsupportedCriteriaException <
|
23
|
+
class UnsupportedCriteriaException < RuntimeError
|
24
24
|
end
|
25
25
|
|
26
|
-
class UnsupportedSelectorException <
|
26
|
+
class UnsupportedSelectorException < RuntimeError
|
27
27
|
end
|
28
28
|
|
29
|
-
class UndefinedSelectorException <
|
29
|
+
class UndefinedSelectorException < RuntimeError
|
30
30
|
end
|
31
31
|
|
32
|
-
class NotSupportedException <
|
32
|
+
class NotSupportedException < RuntimeError
|
33
|
+
end
|
34
|
+
end
|
35
|
+
module PageMagic
|
36
|
+
class ElementMissingException < RuntimeError
|
37
|
+
end
|
38
|
+
|
39
|
+
class InvalidElementNameException < RuntimeError
|
40
|
+
end
|
41
|
+
|
42
|
+
class InvalidMethodNameException < RuntimeError
|
43
|
+
end
|
44
|
+
|
45
|
+
class InvalidURLException < RuntimeError
|
46
|
+
end
|
47
|
+
|
48
|
+
class MatcherInvalidException < RuntimeError
|
49
|
+
end
|
50
|
+
|
51
|
+
class TimeoutException < RuntimeError
|
52
|
+
end
|
53
|
+
|
54
|
+
class UnspportedBrowserException < RuntimeError
|
55
|
+
end
|
56
|
+
|
57
|
+
class UnsupportedCriteriaException < RuntimeError
|
58
|
+
end
|
59
|
+
|
60
|
+
class UnsupportedSelectorException < RuntimeError
|
61
|
+
end
|
62
|
+
|
63
|
+
class UndefinedSelectorException < RuntimeError
|
64
|
+
end
|
65
|
+
|
66
|
+
class NotSupportedException < RuntimeError
|
33
67
|
end
|
34
68
|
end
|
@@ -33,7 +33,7 @@ module PageMagic
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def respond_to?(*args)
|
36
|
-
|
36
|
+
contains_element?(args.first) || super
|
37
37
|
end
|
38
38
|
|
39
39
|
# @return the current page title
|
@@ -55,6 +55,10 @@ module PageMagic
|
|
55
55
|
|
56
56
|
private
|
57
57
|
|
58
|
+
def contains_element?(method)
|
59
|
+
element_definitions.keys.include?(method)
|
60
|
+
end
|
61
|
+
|
58
62
|
def element_context
|
59
63
|
ElementContext.new(self)
|
60
64
|
end
|
data/lib/page_magic/watcher.rb
CHANGED
data/spec/element_spec.rb
CHANGED
@@ -196,7 +196,10 @@ module PageMagic
|
|
196
196
|
before do
|
197
197
|
page_class.class_eval do
|
198
198
|
element :form_by_css, css: '.form' do
|
199
|
-
|
199
|
+
def parent_method
|
200
|
+
:parent_method_called
|
201
|
+
end
|
202
|
+
link(:link_in_form, text: 'link in a form')
|
200
203
|
end
|
201
204
|
end
|
202
205
|
end
|
@@ -206,8 +209,14 @@ module PageMagic
|
|
206
209
|
end
|
207
210
|
|
208
211
|
context 'no element definition and not a capybara method' do
|
209
|
-
it '
|
210
|
-
expect
|
212
|
+
it 'calls method on parent element' do
|
213
|
+
expect(page.form_by_css.link_in_form.parent_method).to eq(:parent_method_called)
|
214
|
+
end
|
215
|
+
|
216
|
+
context 'method not found on parent' do
|
217
|
+
it 'throws and exception' do
|
218
|
+
expect { page.form_by_css.link_in_a_form.bobbins }.to raise_exception ElementMissingException
|
219
|
+
end
|
211
220
|
end
|
212
221
|
end
|
213
222
|
end
|
@@ -84,14 +84,35 @@ module PageMagic
|
|
84
84
|
described_class.new(page).prefetched
|
85
85
|
end
|
86
86
|
end
|
87
|
+
|
88
|
+
context 'method not found on page_element or as a element definition' do
|
89
|
+
it 'raises an error' do
|
90
|
+
expect { elements_page.missing_method }.to raise_error(NoMethodError)
|
91
|
+
end
|
92
|
+
end
|
87
93
|
end
|
88
94
|
|
89
95
|
describe '#respond_to?' do
|
96
|
+
let(:page_element) do
|
97
|
+
Class.new(Element) do
|
98
|
+
link(:a_link, css: '.link')
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
90
102
|
subject do
|
91
|
-
described_class.new(
|
103
|
+
described_class.new(page_element.new(session))
|
92
104
|
end
|
93
|
-
|
94
|
-
|
105
|
+
|
106
|
+
context 'page_element responds to method name' do
|
107
|
+
it 'returns true' do
|
108
|
+
expect(subject.respond_to?(:a_link)).to eq(true)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
context 'method is not on page_element' do
|
113
|
+
it 'calls super' do
|
114
|
+
expect(subject.respond_to?(:methods)).to eq(true)
|
115
|
+
end
|
95
116
|
end
|
96
117
|
end
|
97
118
|
end
|
data/spec/watcher_spec.rb
CHANGED
@@ -35,13 +35,25 @@ module PageMagic
|
|
35
35
|
end
|
36
36
|
|
37
37
|
context 'block supplied to constructor' do
|
38
|
+
def method_on_self(value = nil)
|
39
|
+
return @value unless value
|
40
|
+
@value = value
|
41
|
+
end
|
42
|
+
|
38
43
|
subject do
|
39
44
|
described_class.new(:custom_watcher) do
|
45
|
+
method_on_self(:called)
|
40
46
|
:result
|
41
47
|
end
|
42
48
|
end
|
49
|
+
|
50
|
+
it 'is called on self' do
|
51
|
+
subject.check(self)
|
52
|
+
expect(method_on_self).to be(:called)
|
53
|
+
end
|
54
|
+
|
43
55
|
it 'assigns last to the resut of the block' do
|
44
|
-
expect(subject.check.last).to eq(:result)
|
56
|
+
expect(subject.check(self).last).to eq(:result)
|
45
57
|
end
|
46
58
|
end
|
47
59
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: page_magic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.5.alpha1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Leon Davis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: capybara
|
@@ -194,12 +194,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
194
194
|
version: '2.1'
|
195
195
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
196
196
|
requirements:
|
197
|
-
- - "
|
197
|
+
- - ">"
|
198
198
|
- !ruby/object:Gem::Version
|
199
|
-
version:
|
199
|
+
version: 1.3.1
|
200
200
|
requirements: []
|
201
201
|
rubyforge_project:
|
202
|
-
rubygems_version: 2.4.
|
202
|
+
rubygems_version: 2.4.8
|
203
203
|
signing_key:
|
204
204
|
specification_version: 4
|
205
205
|
summary: Framework for modeling and interacting with webpages
|