page_magic 1.0.0.alpha4 → 1.0.0.alpha5
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/.rubocop.yml +9 -0
- data/Gemfile +7 -8
- data/Gemfile.lock +15 -30
- data/Rakefile +12 -10
- data/VERSION +1 -1
- data/lib/ext/string.rb +6 -6
- data/lib/page_magic/driver.rb +2 -2
- data/lib/page_magic/drivers/poltergeist.rb +1 -2
- data/lib/page_magic/drivers/rack_test.rb +1 -1
- data/lib/page_magic/drivers/selenium.rb +2 -2
- data/lib/page_magic/drivers.rb +5 -6
- data/lib/page_magic/element.rb +50 -43
- data/lib/page_magic/element_context.rb +14 -14
- data/lib/page_magic/elements.rb +9 -10
- data/lib/page_magic/exceptions.rb +1 -2
- data/lib/page_magic/page_magic.rb +12 -9
- data/lib/page_magic/session.rb +21 -16
- data/lib/page_magic.rb +7 -10
- data/page_magic.gemspec +57 -58
- data/spec/element_spec.rb +34 -27
- data/spec/helpers/capybara.rb +4 -4
- data/spec/member_methods_spec.rb +1 -10
- data/spec/page_magic/driver_spec.rb +5 -5
- data/spec/page_magic/drivers/poltergeist_spec.rb +4 -3
- data/spec/page_magic/drivers/rack_test_spec.rb +4 -3
- data/spec/page_magic/drivers/selenium_spec.rb +3 -2
- data/spec/page_magic/drivers_spec.rb +3 -5
- data/spec/page_magic/element_context_spec.rb +17 -29
- data/spec/page_magic/elements_spec.rb +13 -30
- data/spec/page_magic/page_magic_spec.rb +19 -0
- data/spec/page_magic/session_spec.rb +52 -31
- data/spec/page_magic/usage/defining_pages_spec.rb +3 -7
- data/spec/page_magic/usage/include_page_magic_spec.rb +2 -2
- data/spec/page_magic/usage/interacting_with_pages_spec.rb +0 -2
- data/spec/page_magic/usage/starting_a_session_spec.rb +4 -7
- data/spec/page_magic_spec.rb +4 -6
- data/spec/spec_helper.rb +14 -22
- metadata +5 -19
- data/Guardfile +0 -8
- data/spec/page_magic/usage/defining_page_elements_spec.rb +0 -7
@@ -1,12 +1,11 @@
|
|
1
1
|
describe PageMagic::ElementContext do
|
2
|
-
|
3
2
|
include_context :webapp
|
4
3
|
|
5
4
|
let!(:page1) do
|
6
5
|
Class.new do
|
7
6
|
include PageMagic
|
8
7
|
url '/page1'
|
9
|
-
link(:next, :
|
8
|
+
link(:next, text: 'next page')
|
10
9
|
end
|
11
10
|
end
|
12
11
|
|
@@ -14,7 +13,7 @@ describe PageMagic::ElementContext do
|
|
14
13
|
Class.new do
|
15
14
|
include PageMagic
|
16
15
|
url '/elements'
|
17
|
-
link(:a_link, :
|
16
|
+
link(:a_link, text: 'a link')
|
18
17
|
end
|
19
18
|
end
|
20
19
|
|
@@ -23,11 +22,10 @@ describe PageMagic::ElementContext do
|
|
23
22
|
end
|
24
23
|
|
25
24
|
describe 'resolving field definitions' do
|
26
|
-
|
27
25
|
it 'should only evaluate the targeted field definition' do
|
28
26
|
page1.class_eval do
|
29
27
|
link(:link, :selector) do
|
30
|
-
fail(
|
28
|
+
fail('should not have been evaluated')
|
31
29
|
end
|
32
30
|
end
|
33
31
|
page = page1.new
|
@@ -63,7 +61,6 @@ describe PageMagic::ElementContext do
|
|
63
61
|
|
64
62
|
describe 'accessing page sections' do
|
65
63
|
it 'should go through page sections' do
|
66
|
-
|
67
64
|
elements_page.class_eval do
|
68
65
|
section :form do
|
69
66
|
selector css: '.form'
|
@@ -77,20 +74,14 @@ describe PageMagic::ElementContext do
|
|
77
74
|
described_class.new(page, page.browser, self).form
|
78
75
|
end
|
79
76
|
|
80
|
-
|
81
77
|
it 'should delegate to page element if method not found' do
|
82
|
-
#TODO call page method, look for subelement, delagate to capybara object
|
78
|
+
# TODO: call page method, look for subelement, delagate to capybara object
|
83
79
|
end
|
84
80
|
end
|
85
81
|
|
86
|
-
|
87
|
-
|
88
82
|
describe 'hooks' do
|
89
|
-
|
90
83
|
subject(:page) do
|
91
|
-
elements_page.new.tap
|
92
|
-
p.visit
|
93
|
-
end
|
84
|
+
elements_page.new.tap(&:visit)
|
94
85
|
end
|
95
86
|
|
96
87
|
before do
|
@@ -99,20 +90,14 @@ describe PageMagic::ElementContext do
|
|
99
90
|
browser.should_receive(:call_in_after_before_hook)
|
100
91
|
end
|
101
92
|
|
102
|
-
|
103
93
|
context 'section' do
|
104
94
|
it 'applies the hooks' do
|
105
|
-
|
106
95
|
elements_page.section(:form, id: 'form') do
|
107
96
|
link :form_link, id: 'form_link'
|
108
97
|
|
109
|
-
before
|
110
|
-
page_browser.call_in_before_hook
|
111
|
-
end
|
98
|
+
before(&:call_in_before_hook)
|
112
99
|
|
113
|
-
after
|
114
|
-
page_browser.call_in_after_before_hook
|
115
|
-
end
|
100
|
+
after(&:call_in_after_before_hook)
|
116
101
|
end
|
117
102
|
|
118
103
|
described_class.new(page, page.browser, self).form.click
|
@@ -121,18 +106,21 @@ describe PageMagic::ElementContext do
|
|
121
106
|
|
122
107
|
it 'should execute a before and after action that gives access to the browser' do
|
123
108
|
elements_page.link(:create, text: 'a link') do
|
124
|
-
before
|
125
|
-
page_browser.call_in_before_hook
|
126
|
-
end
|
109
|
+
before(&:call_in_before_hook)
|
127
110
|
|
128
|
-
after
|
129
|
-
page_browser.call_in_after_before_hook
|
130
|
-
end
|
111
|
+
after(&:call_in_after_before_hook)
|
131
112
|
end
|
132
113
|
|
133
114
|
described_class.new(page, page.browser, self).create.click
|
134
115
|
end
|
135
|
-
|
136
116
|
end
|
137
117
|
|
118
|
+
describe '#respond_to?' do
|
119
|
+
subject do
|
120
|
+
described_class.new(page1.new(session), session, self)
|
121
|
+
end
|
122
|
+
it 'checks against the names of the elements passed in' do
|
123
|
+
expect(subject.respond_to?(:next)).to eq(true)
|
124
|
+
end
|
125
|
+
end
|
138
126
|
end
|
@@ -1,20 +1,17 @@
|
|
1
1
|
describe PageMagic::Elements do
|
2
|
-
|
3
|
-
|
4
2
|
let(:page_elements) do
|
5
3
|
Class.new do
|
6
4
|
extend(PageMagic::Elements)
|
7
5
|
end
|
8
6
|
end
|
9
7
|
|
10
|
-
let(:selector) { {id: 'id'} }
|
8
|
+
let(:selector) { { id: 'id' } }
|
11
9
|
let(:browser_element) { double('browser_element', find: :browser_element) }
|
12
10
|
let(:parent_page_element) do
|
13
11
|
double('parent_page_element', browser_element: browser_element)
|
14
12
|
end
|
15
13
|
|
16
14
|
describe 'adding elements' do
|
17
|
-
|
18
15
|
context 'using a selector' do
|
19
16
|
it 'should add an element' do
|
20
17
|
expected_element = PageMagic::Element.new(:name, parent_page_element, type: :text_field, selector: selector)
|
@@ -24,17 +21,12 @@ describe PageMagic::Elements do
|
|
24
21
|
end
|
25
22
|
|
26
23
|
context 'complex elements' do
|
27
|
-
|
28
|
-
|
29
24
|
let!(:section_class) do
|
30
25
|
Class.new(PageMagic::Element) do
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
other.name == self.name &&
|
35
|
-
other.browser_element == self.browser_element
|
26
|
+
def ==(other)
|
27
|
+
other.name == name &&
|
28
|
+
other.browser_element == browser_element
|
36
29
|
end
|
37
|
-
|
38
30
|
end
|
39
31
|
end
|
40
32
|
|
@@ -51,7 +43,6 @@ describe PageMagic::Elements do
|
|
51
43
|
section_class.stub(:name).and_return('PageSection')
|
52
44
|
page_elements.section section_class, selector
|
53
45
|
page_elements.elements(parent_page_element).first.name.should == :page_section
|
54
|
-
|
55
46
|
end
|
56
47
|
end
|
57
48
|
|
@@ -60,13 +51,12 @@ describe PageMagic::Elements do
|
|
60
51
|
end
|
61
52
|
end
|
62
53
|
|
63
|
-
|
64
54
|
context 'using a block' do
|
65
|
-
|
66
55
|
context 'browser_element' do
|
67
56
|
before :each do
|
68
|
-
|
69
|
-
@
|
57
|
+
@browser = double('browser')
|
58
|
+
@element = double('element')
|
59
|
+
@parent_page_element = double('parent_page_element')
|
70
60
|
@parent_page_element.stub(:browser_element).and_return(@browser)
|
71
61
|
@browser.should_receive(:find).with(:css, :selector).and_return(@element)
|
72
62
|
end
|
@@ -93,26 +83,24 @@ describe PageMagic::Elements do
|
|
93
83
|
end
|
94
84
|
end
|
95
85
|
|
96
|
-
|
97
86
|
it 'should pass args through to the block' do
|
98
87
|
page_elements.section :page_section, css: '.blah' do |arg|
|
99
88
|
arg[:passed_through] = true
|
100
89
|
end
|
101
90
|
|
102
|
-
arg
|
91
|
+
arg = {}
|
92
|
+
browser = double('browser', find: :browser_element)
|
103
93
|
parent_page_element = double('parent_browser_element', browser_element: browser)
|
104
94
|
page_elements.elements(parent_page_element, arg)
|
105
95
|
arg[:passed_through].should be_true
|
106
96
|
end
|
107
97
|
|
108
|
-
|
109
98
|
it 'should return your a copy of the core definition' do
|
110
99
|
page_elements.section section_class, :page_section, selector
|
111
100
|
first = page_elements.element_definitions[:page_section].call(parent_page_element)
|
112
101
|
second = page_elements.element_definitions[:page_section].call(parent_page_element)
|
113
102
|
first.should_not equal(second)
|
114
103
|
end
|
115
|
-
|
116
104
|
end
|
117
105
|
|
118
106
|
describe 'location' do
|
@@ -134,17 +122,14 @@ describe PageMagic::Elements do
|
|
134
122
|
section = page_elements.element_definitions[:page_section].call(parent)
|
135
123
|
|
136
124
|
section.session.should == :current_session
|
137
|
-
|
138
125
|
end
|
139
126
|
|
140
127
|
it 'should be on instances created dynamically using the section method' do
|
141
|
-
|
142
128
|
browser_element = double('browser_element')
|
143
129
|
browser_element.stub(:find)
|
144
130
|
parent = double('parent', session: :current_session, browser_element: browser_element)
|
145
131
|
|
146
132
|
page_elements.section :page_section, css: :selector do
|
147
|
-
|
148
133
|
end
|
149
134
|
|
150
135
|
section = page_elements.element_definitions[:page_section].call(parent)
|
@@ -163,15 +148,13 @@ describe PageMagic::Elements do
|
|
163
148
|
end
|
164
149
|
end
|
165
150
|
|
166
|
-
|
167
|
-
|
168
151
|
describe 'restrictions' do
|
169
152
|
it 'should not allow method names that match element names' do
|
170
153
|
expect do
|
171
154
|
page_elements.class_eval do
|
172
155
|
link(:hello, text: 'world')
|
173
156
|
|
174
|
-
def hello
|
157
|
+
def hello
|
175
158
|
end
|
176
159
|
end
|
177
160
|
end.to raise_error(PageMagic::Elements::InvalidMethodNameException)
|
@@ -180,7 +163,7 @@ describe PageMagic::Elements do
|
|
180
163
|
it 'should not allow element names that match method names' do
|
181
164
|
expect do
|
182
165
|
page_elements.class_eval do
|
183
|
-
def hello
|
166
|
+
def hello
|
184
167
|
end
|
185
168
|
|
186
169
|
link(:hello, text: 'world')
|
@@ -200,10 +183,10 @@ describe PageMagic::Elements do
|
|
200
183
|
it 'should not evaluate the elements when applying naming checks' do
|
201
184
|
page_elements.class_eval do
|
202
185
|
link(:link1, :selector) do
|
203
|
-
fail(
|
186
|
+
fail('should not have been evaluated')
|
204
187
|
end
|
205
188
|
link(:link2, :selector)
|
206
189
|
end
|
207
190
|
end
|
208
191
|
end
|
209
|
-
end
|
192
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
describe PageMagic do
|
2
|
+
context '#respond_to?' do
|
3
|
+
subject do
|
4
|
+
page_class = Class.new do
|
5
|
+
include PageMagic
|
6
|
+
element :sub_element, id: 'sub-element'
|
7
|
+
end
|
8
|
+
page_class.new
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'checks self' do
|
12
|
+
expect(subject.respond_to?(:visit)).to eq(true)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'checks the current page' do
|
16
|
+
expect(subject.respond_to?(:sub_element)).to eq(true)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,45 +1,50 @@
|
|
1
1
|
describe PageMagic::Session do
|
2
|
-
|
3
2
|
let(:page) do
|
4
3
|
Class.new do
|
5
4
|
include PageMagic
|
6
5
|
url '/page1'
|
7
|
-
|
8
|
-
def my_method
|
9
|
-
:called
|
10
|
-
end
|
11
6
|
end
|
12
7
|
end
|
13
8
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
9
|
+
subject { PageMagic::Session.new(browser) }
|
10
|
+
|
11
|
+
let(:browser) { double('browser', current_url: 'url', visit: nil, current_path: :current_path) }
|
12
|
+
|
13
|
+
describe '#current_url' do
|
14
|
+
it "returns the browser's current url" do
|
15
|
+
expect(subject.current_url).to eq(browser.current_url)
|
18
16
|
end
|
19
17
|
end
|
20
18
|
|
21
|
-
|
19
|
+
describe '#current_path' do
|
20
|
+
it "returns the browser's current path" do
|
21
|
+
expect(subject.current_path).to eq(browser.current_path)
|
22
|
+
end
|
23
|
+
end
|
22
24
|
|
23
25
|
describe '#current_page' do
|
24
|
-
|
25
|
-
|
26
|
-
|
26
|
+
let(:another_page_class) do
|
27
|
+
Class.new do
|
28
|
+
include PageMagic
|
29
|
+
url '/another_page1'
|
27
30
|
end
|
28
31
|
end
|
32
|
+
|
33
|
+
before do
|
34
|
+
subject.define_page_mappings another_page_class.url => another_page_class
|
35
|
+
subject.visit(page)
|
36
|
+
end
|
37
|
+
|
29
38
|
context 'page url has not changed' do
|
30
39
|
it 'returns the original page' do
|
31
|
-
browser.
|
32
|
-
allow(browser).to receive(:current_path).and_return('/page1')
|
33
|
-
subject.visit(page)
|
40
|
+
allow(browser).to receive(:current_path).and_return(page.url)
|
34
41
|
expect(subject.current_page).to be_an_instance_of(page)
|
35
42
|
end
|
36
43
|
end
|
37
44
|
|
38
45
|
context 'page url has changed' do
|
39
46
|
it 'returns the mapped page object' do
|
40
|
-
browser.
|
41
|
-
subject.visit(page)
|
42
|
-
allow(browser).to receive(:current_path).and_return('/another_page1')
|
47
|
+
allow(browser).to receive(:current_path).and_return(another_page_class.url)
|
43
48
|
expect(subject.current_page).to be_an_instance_of(another_page_class)
|
44
49
|
end
|
45
50
|
end
|
@@ -75,29 +80,45 @@ describe PageMagic::Session do
|
|
75
80
|
it 'uses this url instead of the one defined on the page class' do
|
76
81
|
expect(browser).to receive(:visit).with(:custom_url)
|
77
82
|
session = PageMagic::Session.new(browser).visit(page, url: :custom_url)
|
78
|
-
session.current_page.
|
83
|
+
expect(session.current_page).to be_a(page)
|
79
84
|
end
|
80
85
|
end
|
81
86
|
|
82
87
|
it 'visits the url on defined on the page class' do
|
83
88
|
browser.should_receive(:visit).with(page.url)
|
84
89
|
session = PageMagic::Session.new(browser).visit(page)
|
85
|
-
session.current_page.
|
90
|
+
expect(session.current_page).to be_a(page)
|
86
91
|
end
|
87
92
|
end
|
88
93
|
|
89
|
-
|
90
|
-
|
91
|
-
it 'should return the current url' do
|
92
|
-
session = PageMagic::Session.new(browser)
|
93
|
-
session.current_url.should == 'url'
|
94
|
-
end
|
95
|
-
|
96
|
-
context 'method_missing' do
|
94
|
+
context '#method_missing' do
|
97
95
|
it 'should delegate to current page' do
|
98
|
-
|
96
|
+
page.class_eval do
|
97
|
+
def my_method
|
98
|
+
:called
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
99
102
|
session = PageMagic::Session.new(browser).visit(page)
|
100
103
|
session.my_method.should be(:called)
|
101
104
|
end
|
102
105
|
end
|
103
|
-
|
106
|
+
|
107
|
+
context '#respond_to?' do
|
108
|
+
subject do
|
109
|
+
PageMagic::Session.new(browser).tap do |s|
|
110
|
+
s.current_page = page.new
|
111
|
+
end
|
112
|
+
end
|
113
|
+
it 'checks self' do
|
114
|
+
expect(subject.respond_to?(:current_url)).to eq(true)
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'checks the current page' do
|
118
|
+
page.class_eval do
|
119
|
+
def my_method; end
|
120
|
+
end
|
121
|
+
expect(subject.respond_to?(:my_method)).to eq(true)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
@@ -1,14 +1,12 @@
|
|
1
1
|
describe 'The Elements of a Page' do
|
2
|
-
|
3
2
|
describe 'instances' do
|
4
|
-
|
5
3
|
include_context :webapp
|
6
4
|
|
7
5
|
let(:my_page_class) do
|
8
6
|
Class.new do
|
9
7
|
include PageMagic
|
10
8
|
url '/page1'
|
11
|
-
link(:next, :
|
9
|
+
link(:next, text: 'next page')
|
12
10
|
end
|
13
11
|
end
|
14
12
|
|
@@ -23,7 +21,6 @@ describe 'The Elements of a Page' do
|
|
23
21
|
@page = my_page_class.new
|
24
22
|
end
|
25
23
|
|
26
|
-
|
27
24
|
describe 'browser integration' do
|
28
25
|
it "should use capybara's default session if a one is not supplied" do
|
29
26
|
Capybara.default_driver = :rack_test
|
@@ -31,7 +28,6 @@ describe 'The Elements of a Page' do
|
|
31
28
|
end
|
32
29
|
end
|
33
30
|
|
34
|
-
|
35
31
|
it 'should copy fields on to element' do
|
36
32
|
new_page = my_page_class.new
|
37
33
|
@page.element_definitions[:next].call(@page).should_not equal(new_page.element_definitions[:next].call(new_page))
|
@@ -59,7 +55,7 @@ describe 'The Elements of a Page' do
|
|
59
55
|
let(:parent_page) do
|
60
56
|
Class.new do
|
61
57
|
include PageMagic
|
62
|
-
link(:next, :
|
58
|
+
link(:next, text: 'next page')
|
63
59
|
end
|
64
60
|
end
|
65
61
|
|
@@ -82,4 +78,4 @@ describe 'The Elements of a Page' do
|
|
82
78
|
end
|
83
79
|
end
|
84
80
|
end
|
85
|
-
end
|
81
|
+
end
|
@@ -3,7 +3,7 @@ describe 'including PageMagic' do
|
|
3
3
|
|
4
4
|
context 'lets you define pages' do
|
5
5
|
let :page_class do
|
6
|
-
Class.new{include PageMagic}
|
6
|
+
Class.new { include PageMagic }
|
7
7
|
end
|
8
8
|
|
9
9
|
it 'gives a method for defining the url' do
|
@@ -15,4 +15,4 @@ describe 'including PageMagic' do
|
|
15
15
|
page_class.is_a?(PageMagic::Elements).should be_true
|
16
16
|
end
|
17
17
|
end
|
18
|
-
end
|
18
|
+
end
|
@@ -1,14 +1,13 @@
|
|
1
1
|
describe 'PageMagic.session' do
|
2
|
-
|
3
2
|
let(:app_class) do
|
4
3
|
Class.new do
|
5
|
-
def call
|
6
|
-
[200, {}, [
|
4
|
+
def call(_env)
|
5
|
+
[200, {}, ['hello world!!']]
|
7
6
|
end
|
8
7
|
end
|
9
8
|
end
|
10
9
|
|
11
|
-
def registered_driver
|
10
|
+
def registered_driver(browser)
|
12
11
|
Capybara.drivers[browser].call(nil)
|
13
12
|
end
|
14
13
|
|
@@ -20,7 +19,6 @@ describe 'PageMagic.session' do
|
|
20
19
|
end
|
21
20
|
|
22
21
|
context 'testing against rack applications' do
|
23
|
-
|
24
22
|
it 'requires the app to be supplied' do
|
25
23
|
session = PageMagic.session(application: app_class.new)
|
26
24
|
session.raw_session.visit('/')
|
@@ -34,5 +32,4 @@ describe 'PageMagic.session' do
|
|
34
32
|
session.raw_session.text.should == 'hello world!!'
|
35
33
|
end
|
36
34
|
end
|
37
|
-
|
38
|
-
end
|
35
|
+
end
|
data/spec/page_magic_spec.rb
CHANGED
@@ -3,9 +3,7 @@ require 'page_magic'
|
|
3
3
|
describe PageMagic do
|
4
4
|
describe '::drivers' do
|
5
5
|
it 'returns loaded drivers' do
|
6
|
-
expected_drivers = described_class::Drivers.new.tap
|
7
|
-
drivers.load
|
8
|
-
end
|
6
|
+
expected_drivers = described_class::Drivers.new.tap(&:load)
|
9
7
|
|
10
8
|
expect(described_class.drivers).to eq(expected_drivers)
|
11
9
|
end
|
@@ -28,7 +26,7 @@ describe PageMagic do
|
|
28
26
|
|
29
27
|
context 'specifying options' do
|
30
28
|
it 'passes the options to the browser driver' do
|
31
|
-
options = {option: :config}
|
29
|
+
options = { option: :config }
|
32
30
|
session = described_class.session(options: options, browser: :chrome)
|
33
31
|
|
34
32
|
expect(session.raw_session.driver.options).to include(options)
|
@@ -37,8 +35,8 @@ describe PageMagic do
|
|
37
35
|
|
38
36
|
context 'driver for browser not found' do
|
39
37
|
it 'raises an error' do
|
40
|
-
expect{described_class.session(browser: :invalid)}.to raise_exception described_class::UnspportedBrowserException
|
38
|
+
expect { described_class.session(browser: :invalid) }.to raise_exception described_class::UnspportedBrowserException
|
41
39
|
end
|
42
40
|
end
|
43
41
|
end
|
44
|
-
end
|
42
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -3,8 +3,7 @@ $LOAD_PATH.unshift("#{File.dirname(__FILE__)}/lib")
|
|
3
3
|
if ENV['coverage']
|
4
4
|
require 'simplecov'
|
5
5
|
SimpleCov.start do
|
6
|
-
|
7
|
-
add_filter "/spec/"
|
6
|
+
add_filter '/spec/'
|
8
7
|
end
|
9
8
|
end
|
10
9
|
require 'page_magic'
|
@@ -21,41 +20,40 @@ end
|
|
21
20
|
shared_context :rack_application do
|
22
21
|
let(:rack_application) do
|
23
22
|
Class.new do
|
24
|
-
def call
|
25
|
-
[200, {}, [
|
23
|
+
def call(_env)
|
24
|
+
[200, {}, ['hello world!!']]
|
26
25
|
end
|
27
26
|
end
|
28
27
|
end
|
29
28
|
end
|
30
29
|
|
31
30
|
RSpec.configure do
|
32
|
-
|
33
31
|
module PageMagic
|
34
32
|
class Element
|
35
33
|
class << self
|
36
34
|
def default_before_hook
|
37
|
-
@default_before_hook ||=
|
35
|
+
@default_before_hook ||= proc {}
|
38
36
|
end
|
39
37
|
|
40
38
|
def default_after_hook
|
41
|
-
@default_after_hook ||=
|
39
|
+
@default_after_hook ||= proc {}
|
42
40
|
end
|
43
41
|
end
|
44
42
|
alias_method :initialize_backup, :initialize
|
45
|
-
def initialize
|
43
|
+
def initialize(*args, &block)
|
46
44
|
initialize_backup *args, &block
|
47
|
-
@before_hook
|
45
|
+
@before_hook = self.class.default_before_hook
|
46
|
+
@after_hook = self.class.default_after_hook
|
48
47
|
end
|
49
48
|
|
50
|
-
def ==
|
49
|
+
def ==(page_element)
|
51
50
|
page_element.is_a?(Element) &&
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
51
|
+
@type == page_element.type &&
|
52
|
+
@name == page_element.name &&
|
53
|
+
@selector == page_element.selector
|
54
|
+
@before_hook == page_element.before &&
|
55
|
+
@after_hook == page_element.after
|
57
56
|
end
|
58
|
-
|
59
57
|
end
|
60
58
|
end
|
61
59
|
|
@@ -64,7 +62,6 @@ RSpec.configure do
|
|
64
62
|
|
65
63
|
rack_app = Class.new(Sinatra::Base) do
|
66
64
|
get '/page1' do
|
67
|
-
|
68
65
|
"<html><head><title>page1</title></head><body><a href='/page2'>next page</a></body></html>"
|
69
66
|
end
|
70
67
|
|
@@ -81,11 +78,9 @@ RSpec.configure do
|
|
81
78
|
<a id='form_link' href='/page2'>a in a form</a>
|
82
79
|
</form>
|
83
80
|
ELEMENTS
|
84
|
-
|
85
81
|
end
|
86
82
|
end
|
87
83
|
|
88
|
-
|
89
84
|
before :each do
|
90
85
|
Capybara.app = rack_app
|
91
86
|
end
|
@@ -94,7 +89,4 @@ RSpec.configure do
|
|
94
89
|
Capybara.reset!
|
95
90
|
end
|
96
91
|
end
|
97
|
-
|
98
92
|
end
|
99
|
-
|
100
|
-
|