page_magic 1.2.4 → 1.2.5.alpha1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a01cd88b94fa1511623032da51898df9c1cb9de1
4
- data.tar.gz: 62713284d4126f200963f884b57e054ae617c01f
3
+ metadata.gz: 6ce815c4de6f42f92abe1cd4ed039a149d24b345
4
+ data.tar.gz: 50c30aa422018e788ba192cafae8867872cbab32
5
5
  SHA512:
6
- metadata.gz: 9d2e8fc5f2b2c04d02af1117fac8ed218d35a835fcaf6b2c52d4d8543d3845678f58bb3c329ba1255cc12c6f55bd4d7c189b87c337fdffa90a70f24136fba57d
7
- data.tar.gz: cb8af92ca9f20fc992a3db52be8f94e0c21d7501a84393f10b69df870b69b0825fb265076fd6099a1fb94d395b1b3341519908f3e33b74ddf218e6ec16205201
6
+ metadata.gz: 08563d7022df224ce434f63e29a13d4f54663720e0641ee4ea41df8b0c4d53169ac6e174b66c707898558721a7853499a247f491b14de55bf2e66c518ba4787e
7
+ data.tar.gz: f214be5face9359d38fff47f5ea546a76081d7dee0adac598f25e389387a39290b9e560ae426a24f55583aefb51d8ea06a1ae75df5372e597260a07e16ed77e3
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.4
1
+ 1.2.5.alpha1
@@ -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
- return super unless browser_element.respond_to?(method)
92
- browser_element.send(method, *args, &block)
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 || element_context.respond_to?(*args) || browser_element.respond_to?(*args)
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.element_definitions.keys.include?(args.first)
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 < Exception
2
+ class ElementMissingException < RuntimeError
3
3
  end
4
4
 
5
- class InvalidElementNameException < Exception
5
+ class InvalidElementNameException < RuntimeError
6
6
  end
7
7
 
8
- class InvalidMethodNameException < Exception
8
+ class InvalidMethodNameException < RuntimeError
9
9
  end
10
10
 
11
- class InvalidURLException < Exception
11
+ class InvalidURLException < RuntimeError
12
12
  end
13
13
 
14
- class MatcherInvalidException < Exception
14
+ class MatcherInvalidException < RuntimeError
15
15
  end
16
16
 
17
- class TimeoutException < Exception
17
+ class TimeoutException < RuntimeError
18
18
  end
19
19
 
20
- class UnspportedBrowserException < Exception
20
+ class UnspportedBrowserException < RuntimeError
21
21
  end
22
22
 
23
- class UnsupportedCriteriaException < Exception
23
+ class UnsupportedCriteriaException < RuntimeError
24
24
  end
25
25
 
26
- class UnsupportedSelectorException < Exception
26
+ class UnsupportedSelectorException < RuntimeError
27
27
  end
28
28
 
29
- class UndefinedSelectorException < Exception
29
+ class UndefinedSelectorException < RuntimeError
30
30
  end
31
31
 
32
- class NotSupportedException < Exception
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
- super || element_context.respond_to?(*args)
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
@@ -21,7 +21,7 @@ module PageMagic
21
21
  # @param [Object] subject - subject to run watcher against
22
22
  def check(subject = nil)
23
23
  @last = if block
24
- block.call
24
+ subject.instance_eval(&block)
25
25
  else
26
26
  object = subject.send(name)
27
27
  attribute ? object.send(attribute) : object
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
- link(:link_in_form, text: 'a in a form')
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 'throws and exception' do
210
- expect { page.form_by_css.bobbins }.to raise_exception NoMethodError
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(elements_page.new(session))
103
+ described_class.new(page_element.new(session))
92
104
  end
93
- it 'checks against the names of the elements passed in' do
94
- expect(subject.respond_to?(:a_link)).to eq(true)
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
@@ -40,7 +40,7 @@ module PageMagic
40
40
  expect(subject.respond_to?(:visit)).to eq(true)
41
41
  end
42
42
 
43
- it 'checks the current page' do
43
+ it 'checks element definitions' do
44
44
  expect(subject.respond_to?(:next_page)).to eq(true)
45
45
  end
46
46
  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
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-06-29 00:00:00.000000000 Z
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: '0'
199
+ version: 1.3.1
200
200
  requirements: []
201
201
  rubyforge_project:
202
- rubygems_version: 2.4.6
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