page_magic 1.0.0.alpha7 → 1.0.0.alpha8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/page_magic/elements.rb +18 -26
- data/spec/page_magic/elements_spec.rb +79 -91
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dfda87e1bb18198d7cd95b36a339ff68be3cf778
|
4
|
+
data.tar.gz: 3d95a82ed45417528a116e49ee141a30b0537d41
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2bfc886d3de8e0a2ae4993c9820eee29cff4816663a9dd55891d55ebf221a6fbb046f838e38c85873f59e158a072160a08c149eddd3dc24297c4ec0d95be64c1
|
7
|
+
data.tar.gz: 908fcba5e372276d9d0729cba67d093d0bdeb50c42f598c7eb7f34ebf461e20f969e871be7def748e69901313ff894d949ba93a9147100100a4f7b1439508311
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.0.
|
1
|
+
1.0.0.alpha8
|
data/lib/page_magic/elements.rb
CHANGED
@@ -29,41 +29,27 @@ module PageMagic
|
|
29
29
|
end
|
30
30
|
|
31
31
|
TYPES = [:element, :text_field, :button, :link, :checkbox, :select_list, :radios, :textarea, :section]
|
32
|
-
TYPES.each do |type|
|
33
|
-
define_method type do |*args, &block|
|
34
|
-
first_arg = args.first
|
35
|
-
if first_arg.is_a?(Symbol)
|
36
|
-
name, object = args
|
37
|
-
options = { type: type }
|
38
|
-
if object.is_a?(Hash)
|
39
|
-
options[:selector] = object
|
40
|
-
else
|
41
|
-
options[:browser_element] = object
|
42
|
-
end
|
43
32
|
|
44
|
-
add_element_definition(name) do |*e_args|
|
45
|
-
Element.new(name, e_args.delete_at(0), options).tap do |section|
|
46
|
-
section.expand(*e_args, &(block || proc {}))
|
47
|
-
end
|
48
|
-
end
|
49
33
|
|
50
|
-
|
51
|
-
|
34
|
+
TYPES.each do |type|
|
35
|
+
define_method type do |*args, &block|
|
52
36
|
|
53
|
-
|
54
|
-
args.delete(selector)
|
37
|
+
section_class = remove_argument(args, Class) || Element
|
55
38
|
|
56
|
-
|
39
|
+
selector = remove_argument(args, Hash)
|
40
|
+
selector ||= section_class.selector if section_class.respond_to?(:selector)
|
57
41
|
|
58
|
-
|
42
|
+
name = remove_argument(args, Symbol)
|
43
|
+
name ||= section_class.name.demodulize.to_snake_case.to_sym unless section_class.is_a?(Element)
|
59
44
|
|
60
|
-
|
45
|
+
options = selector ? {selector: selector} : {browser_element: args.delete_at(0)}
|
61
46
|
|
62
|
-
|
63
|
-
|
47
|
+
add_element_definition(name) do |parent_browser_element, *e_args|
|
48
|
+
section_class.new(name, parent_browser_element, options.merge(type: type)).tap do |section|
|
49
|
+
section.expand(*e_args, &(block || proc {}))
|
64
50
|
end
|
65
|
-
|
66
51
|
end
|
52
|
+
|
67
53
|
end
|
68
54
|
end
|
69
55
|
|
@@ -79,5 +65,11 @@ module PageMagic
|
|
79
65
|
def element_definitions
|
80
66
|
@element_definitions ||= {}
|
81
67
|
end
|
68
|
+
|
69
|
+
private
|
70
|
+
def remove_argument(args, clazz)
|
71
|
+
argument = args.find { |arg| arg.is_a?(clazz) }
|
72
|
+
args.delete(argument)
|
73
|
+
end
|
82
74
|
end
|
83
75
|
end
|
@@ -12,6 +12,7 @@ describe PageMagic::Elements do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
describe 'adding elements' do
|
15
|
+
|
15
16
|
context 'using a selector' do
|
16
17
|
it 'should add an element' do
|
17
18
|
expected_element = PageMagic::Element.new(:name, parent_page_element, type: :text_field, selector: selector)
|
@@ -20,6 +21,11 @@ describe PageMagic::Elements do
|
|
20
21
|
end
|
21
22
|
end
|
22
23
|
|
24
|
+
it 'uses the supplied name' do
|
25
|
+
page_elements.text_field :alias, selector
|
26
|
+
expect(page_elements.elements(parent_page_element).first.name).to eq(:alias)
|
27
|
+
end
|
28
|
+
|
23
29
|
context 'complex elements' do
|
24
30
|
let!(:section_class) do
|
25
31
|
Class.new(PageMagic::Element) do
|
@@ -32,132 +38,114 @@ describe PageMagic::Elements do
|
|
32
38
|
|
33
39
|
context 'using a predefined class' do
|
34
40
|
|
35
|
-
it 'should add
|
41
|
+
it 'should add an element using that class section' do
|
36
42
|
expected_section = section_class.new(:page_section, parent_page_element, type: :section, selector: selector)
|
37
43
|
|
38
44
|
page_elements.section section_class, :page_section, selector
|
39
45
|
page_elements.elements(parent_page_element).first.should == expected_section
|
40
46
|
end
|
41
47
|
|
42
|
-
|
43
|
-
it '
|
44
|
-
|
48
|
+
context 'with no selector supplied' do
|
49
|
+
it 'defaults the selector to the one on the class' do
|
50
|
+
section_class.selector selector
|
51
|
+
page_elements.section section_class, :alias
|
45
52
|
expect(page_elements.elements(parent_page_element).first.selector).to eq(selector)
|
46
53
|
end
|
47
|
-
|
48
|
-
context 'with no selector supplied' do
|
49
|
-
it 'defaults the selector to the one on the class' do
|
50
|
-
section_class.selector selector
|
51
|
-
page_elements.section section_class, :alias
|
52
|
-
expect(page_elements.elements(parent_page_element).first.selector).to eq(selector)
|
53
|
-
end
|
54
|
-
end
|
55
54
|
end
|
56
55
|
|
57
|
-
context 'name' do
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
page_elements.elements(parent_page_element).first.name.should == :page_section
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
it 'should use the supplied name' do
|
67
|
-
page_elements.section section_class, :alias, selector
|
68
|
-
expect(page_elements.elements(parent_page_element).first.name).to eq(:alias)
|
56
|
+
context 'with no name supplied' do
|
57
|
+
it 'should default to the name of the class if one is not supplied' do
|
58
|
+
section_class.stub(:name).and_return('PageSection')
|
59
|
+
page_elements.section section_class, selector
|
60
|
+
page_elements.elements(parent_page_element).first.name.should == :page_section
|
69
61
|
end
|
70
62
|
end
|
71
|
-
|
72
|
-
it 'does not require a block' do
|
73
|
-
expect { page_elements.section :page_section, :object }.not_to raise_exception
|
74
|
-
end
|
75
63
|
end
|
64
|
+
end
|
76
65
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
it 'should be assigned when selector is passed to section method' do
|
88
|
-
element = @element
|
66
|
+
context 'using a block' do
|
67
|
+
context 'browser_element' do
|
68
|
+
before :each do
|
69
|
+
@browser = double('browser')
|
70
|
+
@element = double('element')
|
71
|
+
@parent_page_element = double('parent_page_element')
|
72
|
+
@parent_page_element.stub(:browser_element).and_return(@browser)
|
73
|
+
@browser.should_receive(:find).with(:css, :selector).and_return(@element)
|
74
|
+
end
|
89
75
|
|
90
|
-
|
91
|
-
|
92
|
-
end
|
76
|
+
it 'should be assigned when selector is passed to section method' do
|
77
|
+
element = @element
|
93
78
|
|
94
|
-
|
79
|
+
page_elements.section :page_section, css: :selector do
|
80
|
+
browser_element.should == element
|
95
81
|
end
|
96
82
|
|
97
|
-
|
98
|
-
element = @element
|
99
|
-
|
100
|
-
page_elements.section :page_section do
|
101
|
-
selector css: :selector
|
102
|
-
browser_element.should == element
|
103
|
-
end
|
104
|
-
|
105
|
-
page_elements.elements(@parent_page_element, nil)
|
106
|
-
end
|
83
|
+
page_elements.element_definitions[:page_section].call(@parent_page_element)
|
107
84
|
end
|
108
85
|
|
109
|
-
it 'should
|
110
|
-
|
111
|
-
|
86
|
+
it 'should be assigned when selector is defined in the block passed to the section method' do
|
87
|
+
element = @element
|
88
|
+
|
89
|
+
page_elements.section :page_section do
|
90
|
+
selector css: :selector
|
91
|
+
browser_element.should == element
|
112
92
|
end
|
113
93
|
|
114
|
-
|
115
|
-
browser = double('browser', find: :browser_element)
|
116
|
-
parent_page_element = double('parent_browser_element', browser_element: browser)
|
117
|
-
page_elements.elements(parent_page_element, arg)
|
118
|
-
arg[:passed_through].should be_true
|
94
|
+
page_elements.elements(@parent_page_element, nil)
|
119
95
|
end
|
96
|
+
end
|
120
97
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
second = page_elements.element_definitions[:page_section].call(parent_page_element)
|
125
|
-
first.should_not equal(second)
|
98
|
+
it 'should pass args through to the block' do
|
99
|
+
page_elements.section :page_section, css: '.blah' do |arg|
|
100
|
+
arg[:passed_through] = true
|
126
101
|
end
|
102
|
+
|
103
|
+
arg = {}
|
104
|
+
browser = double('browser', find: :browser_element)
|
105
|
+
parent_page_element = double('parent_browser_element', browser_element: browser)
|
106
|
+
page_elements.elements(parent_page_element, arg)
|
107
|
+
arg[:passed_through].should be_true
|
127
108
|
end
|
128
109
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
expected_section.should == page_elements.elements(parent_page_element).first
|
135
|
-
end
|
136
|
-
end
|
110
|
+
it 'should return your a copy of the core definition' do
|
111
|
+
page_elements.element :page_section, selector
|
112
|
+
first = page_elements.element_definitions[:page_section].call(parent_page_element)
|
113
|
+
second = page_elements.element_definitions[:page_section].call(parent_page_element)
|
114
|
+
first.should_not equal(second)
|
137
115
|
end
|
116
|
+
end
|
138
117
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
page_elements.
|
118
|
+
describe 'location' do
|
119
|
+
context 'a prefetched object' do
|
120
|
+
it 'should add a section' do
|
121
|
+
expected_section = PageMagic::Element.new(:element, parent_page_element, type: :section, browser_element: :object)
|
122
|
+
page_elements.element :page_section, :object
|
123
|
+
expected_section.should == page_elements.elements(parent_page_element).first
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
144
127
|
|
145
|
-
|
128
|
+
describe 'session handle' do
|
129
|
+
it 'should be on instances created from a class' do
|
130
|
+
browser_element = double(:browser_element, find: :browser_element)
|
131
|
+
parent = double('parent', session: :current_session, browser_element: browser_element)
|
132
|
+
page_elements.element :page_section, selector
|
146
133
|
|
147
|
-
|
148
|
-
end
|
134
|
+
section = page_elements.element_definitions[:page_section].call(parent)
|
149
135
|
|
150
|
-
|
151
|
-
|
152
|
-
browser_element.stub(:find)
|
153
|
-
parent = double('parent', session: :current_session, browser_element: browser_element)
|
136
|
+
section.session.should == :current_session
|
137
|
+
end
|
154
138
|
|
155
|
-
|
156
|
-
|
139
|
+
it 'should be on instances created dynamically using the section method' do
|
140
|
+
browser_element = double('browser_element')
|
141
|
+
browser_element.stub(:find)
|
142
|
+
parent = double('parent', session: :current_session, browser_element: browser_element)
|
157
143
|
|
158
|
-
|
159
|
-
section.session.should == :current_session
|
144
|
+
page_elements.section :page_section, css: :selector do
|
160
145
|
end
|
146
|
+
|
147
|
+
section = page_elements.element_definitions[:page_section].call(parent)
|
148
|
+
section.session.should == :current_session
|
161
149
|
end
|
162
150
|
end
|
163
151
|
end
|