page_magic 0.9.6 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.6
1
+ 0.10.0
@@ -60,8 +60,15 @@ module PageMagic
60
60
  end
61
61
 
62
62
  page_section.parent_browser_element = parent_browser_element.browser_element
63
- page_section.selector selector if selector
64
63
 
64
+ case selector
65
+ when Hash
66
+ page_section.selector selector
67
+ else
68
+ page_section.browser_element = selector
69
+ end
70
+
71
+ block = block || Proc.new{}
65
72
  page_section.class_exec *args_for_section, &block
66
73
  page_section.new(parent_browser_element, name, selector)
67
74
  end
@@ -86,4 +93,4 @@ module PageMagic
86
93
  @element_definitions ||= {}
87
94
  end
88
95
  end
89
- end
96
+ end
@@ -5,13 +5,15 @@ module PageMagic
5
5
  def locate_in browser_element, selector
6
6
  method, selector = selector.to_a.flatten
7
7
  case method
8
- when :id
9
- browser_element.find("##{selector}")
10
- when :css
11
- browser_element.find(:css, selector)
12
- else
13
- raise UnsupportedSelectorException
14
- end
8
+ when :id
9
+ browser_element.find("##{selector}")
10
+ when :css
11
+ browser_element.find(:css, selector)
12
+ when :xpath
13
+ browser_element.find(:xpath, selector)
14
+ else
15
+ raise UnsupportedSelectorException
16
+ end
15
17
  end
16
18
  end
17
19
  class UndefinedSelectorException < Exception
@@ -45,10 +47,12 @@ module PageMagic
45
47
  @selector = selector
46
48
  @parent_page_element = parent_page_element
47
49
 
48
- @selector = selector ? selector : self.class.selector
50
+ @selector = selector.is_a?(Hash) ? selector : self.class.selector
51
+
52
+ @browser_element = self.class.browser_element
53
+ raise UndefinedSelectorException, "Pass a selector to the constructor/define one the class" unless @selector || @browser_element
49
54
 
50
- raise UndefinedSelectorException, "Pass a selector to the constructor/define one the class" unless @selector
51
- @browser_element = locate_in(@parent_page_element.browser_element, @selector)
55
+ @browser_element = locate_in(@parent_page_element.browser_element, @selector) unless @browser_element
52
56
  if name
53
57
  @name = name
54
58
  else
@@ -98,4 +102,4 @@ module PageMagic
98
102
 
99
103
 
100
104
  end
101
- end
105
+ end
data/page_magic.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "page_magic"
8
- s.version = "0.9.6"
8
+ s.version = "0.10.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Leon Davis"]
12
- s.date = "2013-11-17"
12
+ s.date = "2013-12-16"
13
13
  s.description = "Framework for modeling and interacting with webpages which wraps capybara"
14
14
  s.email = "info@lad-tech.com"
15
15
  s.extra_rdoc_files = [
@@ -51,7 +51,8 @@ describe PageMagic::Elements do
51
51
 
52
52
  def == object
53
53
  object.class.is_a?(PageMagic::Section) &&
54
- object.name == self.name
54
+ object.name == self.name &&
55
+ object.browser_element == self.browser_element
55
56
  end
56
57
  end
57
58
  end
@@ -84,80 +85,98 @@ describe PageMagic::Elements do
84
85
  end
85
86
  end
86
87
 
87
- context 'using a class as a definition' do
88
- it 'should add a section' do
89
- page_elements.section section_class, :page_section, selector
90
- page_elements.elements(parent_page_element).first.should == section_class.new(parent_page_element, :page_section, selector)
88
+ describe 'definition' do
89
+
90
+
91
+ context 'using a class as a definition' do
92
+ it 'should add a section' do
93
+ page_elements.section section_class, :page_section, selector
94
+ page_elements.elements(parent_page_element).first.should == section_class.new(parent_page_element, :page_section, selector)
95
+ end
91
96
  end
92
- end
93
97
 
94
- context 'using a block to define a section inline' do
98
+ it 'should not require a block' do
99
+ expect { page_elements.section :page_section, :object }.not_to raise_exception
100
+ end
95
101
 
96
- context 'browser_element' do
97
- before :each do
102
+ context 'an object that has already been found' do
103
+ it 'should add a section' do
104
+ page_elements.section :page_section, :object
98
105
 
99
- @browser, @element, @parent_page_element = double('browser'), double('element'), double('parent_page_element')
100
- @parent_page_element.stub(:browser_element).and_return(@browser)
101
- @browser.should_receive(:find).with(:css, :selector).twice.and_return(@element)
106
+ section_class.browser_element = :object
107
+ expected_section = section_class.new(parent_page_element, :page_section, nil)
108
+ expected_section.should == page_elements.elements(parent_page_element).first
102
109
  end
110
+ end
103
111
 
104
- it 'should be assigned when selector is passed to section method' do
105
- element = @element
106
112
 
107
- page_elements.section :page_section, css: :selector do
108
- browser_element.should == element
113
+ context 'using a block to define a section inline' do
114
+
115
+ context 'browser_element' do
116
+ before :each do
117
+
118
+ @browser, @element, @parent_page_element = double('browser'), double('element'), double('parent_page_element')
119
+ @parent_page_element.stub(:browser_element).and_return(@browser)
120
+ @browser.should_receive(:find).with(:css, :selector).and_return(@element)
109
121
  end
110
122
 
111
- page_elements.element_definitions[:page_section].call(@parent_page_element)
112
- end
123
+ it 'should be assigned when selector is passed to section method' do
124
+ element = @element
113
125
 
114
- it 'should be assigned when selector is defined in the block passed to the section method' do
115
- element = @element
126
+ page_elements.section :page_section, css: :selector do
127
+ browser_element.should == element
128
+ end
116
129
 
117
- page_elements.section :page_section do
118
- browser_element.should == nil
119
- selector css: :selector
120
- browser_element.should == element
130
+ page_elements.element_definitions[:page_section].call(@parent_page_element)
121
131
  end
122
132
 
123
- page_elements.elements(@parent_page_element, nil)
133
+ it 'should be assigned when selector is defined in the block passed to the section method' do
134
+ element = @element
135
+
136
+ page_elements.section :page_section do
137
+ browser_element.should == nil
138
+ selector css: :selector
139
+ browser_element.should == element
140
+ end
141
+
142
+ page_elements.elements(@parent_page_element, nil)
143
+ end
124
144
  end
125
- end
126
145
 
127
- it 'should raise an exception if the selector is not passed' do
146
+ it 'should raise an exception if the selector is not passed' do
128
147
 
129
- arg, browser, element = {}, double('browser'), double('element')
130
- parent_page_element = double('parent_browser_element', browser_element: browser)
148
+ arg, browser, element = {}, double('browser'), double('element')
149
+ parent_page_element = double('parent_browser_element', browser_element: browser)
131
150
 
132
- page_elements.section :page_section, nil do
133
- end
151
+ page_elements.section :page_section, nil
134
152
 
135
- expect { page_elements.elements(parent_page_element, arg) }.to raise_error(PageMagic::Section::UndefinedSelectorException)
136
- end
153
+ expect { page_elements.elements(parent_page_element, arg) }.to raise_error(PageMagic::Section::UndefinedSelectorException)
154
+ end
137
155
 
138
156
 
157
+ it 'should pass args through to the block' do
158
+ page_elements.section :page_section, css: '.blah' do |arg|
159
+ arg[:passed_through] = true
160
+ end
139
161
 
140
- it 'should pass args through to the block' do
141
- page_elements.section :page_section, css: '.blah' do |arg|
142
- arg[:passed_through] = true
162
+ arg, browser = {}, double('browser', find: :browser_element)
163
+ parent_page_element = double('parent_browser_element', browser_element: browser)
164
+ page_elements.elements(parent_page_element, arg)
165
+ arg[:passed_through].should be_true
143
166
  end
144
167
 
145
- arg, browser = {}, double('browser', find: :browser_element)
146
- parent_page_element = double('parent_browser_element', browser_element: browser)
147
- page_elements.elements(parent_page_element, arg)
148
- arg[:passed_through].should be_true
149
168
  end
150
169
 
151
- end
152
-
153
- it 'should return your a copy of the core definition' do
154
- page_elements.section section_class, :page_section, selector
155
- first = page_elements.element_definitions[:page_section].call(parent_page_element)
156
- second = page_elements.element_definitions[:page_section].call(parent_page_element)
157
- first.should_not equal(second)
170
+ it 'should return your a copy of the core definition' do
171
+ page_elements.section section_class, :page_section, selector
172
+ first = page_elements.element_definitions[:page_section].call(parent_page_element)
173
+ second = page_elements.element_definitions[:page_section].call(parent_page_element)
174
+ first.should_not equal(second)
175
+ end
158
176
  end
159
177
  end
160
178
 
179
+
161
180
  describe 'restrictions' do
162
181
  it 'should not allow method names that match element names' do
163
182
  expect do
data/spec/section_spec.rb CHANGED
@@ -47,6 +47,11 @@ describe PageMagic::Section do
47
47
  section.selector css: '.form'
48
48
  section.browser_element[:id].should == 'form'
49
49
  end
50
+
51
+ it 'should find by xpath' do
52
+ section.selector xpath: '//div'
53
+ section.browser_element[:id].should == 'form'
54
+ end
50
55
  end
51
56
  end
52
57
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: page_magic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.6
4
+ version: 0.10.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-11-17 00:00:00.000000000 Z
12
+ date: 2013-12-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capybara
@@ -125,7 +125,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
125
125
  version: '0'
126
126
  segments:
127
127
  - 0
128
- hash: -3173894650534542993
128
+ hash: 537336402356197264
129
129
  required_rubygems_version: !ruby/object:Gem::Requirement
130
130
  none: false
131
131
  requirements: