page_magic 0.11.0.alpha5 → 0.11.0.alpha6

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: cd7f970881ca342aebac6a622629e2256c7b3772
4
- data.tar.gz: c1a87cb1706b7d2bc40fc521a9cc5af55fea6c40
3
+ metadata.gz: 56f774d5606a8b3fbe8f0e8ea337bd54bd360d70
4
+ data.tar.gz: 318201438260f08156d1afa43a5baa2479143eb5
5
5
  SHA512:
6
- metadata.gz: 00119f1eacd5c3d0001a020fe938b1dfd3fa1340b21800f7a7087ecc43e375d3ffae769c4f3eca2b96404e7c19d605a448e4b35b2f2202bb43e58bfa11ffdf43
7
- data.tar.gz: 243f27af8b0adfd0c58a9e254b128d0c60e4da10eff2d1e421435b1d65b22e30324adba474d92499df6bd0b2f008e203389e45510aa0dd24e82c1e0ffce1165f
6
+ metadata.gz: ce887cd3a1b4e3d8fbd6cd0c82b9d78036d46f075c821d213049ef60ff6ec453c601bb55f79359dae1bfab91d4aa1443dfbd8e4aef10b6ea873aee5c618c5a0f
7
+ data.tar.gz: 5b0b401f94a6d9fb856efc935157fb3a9754fb98d004c1fdb1590e440b79353ad97ba923970fe8c968bf0b0b686bb0f88b7e88812d46f8a61dc320d82c4b0531
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.11.0.alpha5
1
+ 1.0.0.alpha2
@@ -18,15 +18,8 @@ module PageMagic
18
18
  return @caller.send(method, *args) if @executing_hooks
19
19
  return @page_element.send(method, *args) if @page_element.methods.include?(method)
20
20
 
21
-
22
21
  element_locator_factory = @page_element.element_definitions[method]
23
22
 
24
- action = nil
25
- unless element_locator_factory
26
- action = resolve_action(method)
27
- element_locator_factory = @page_element.element_definitions[method.to_s.gsub("#{action}_", '').to_sym]
28
- end
29
-
30
23
  raise ElementMissingException, "Could not find: #{method}" unless element_locator_factory
31
24
 
32
25
  if args.empty?
@@ -37,7 +30,7 @@ module PageMagic
37
30
 
38
31
  result = element_locator.browser_element
39
32
 
40
- return element_locator if element_locator.section? && action.nil?
33
+ return element_locator if element_locator.section?
41
34
 
42
35
  [:set, :select_option, :unselect_option, :click].each do |action_method|
43
36
  apply_hooks(page_element: result,
@@ -47,13 +40,7 @@ module PageMagic
47
40
  )
48
41
  end
49
42
 
50
- action ? result.send(action) : result
51
- end
52
-
53
- def resolve_action(field)
54
- {/^click_/ => :click}.each do |prefix, action|
55
- return action if field.to_s =~ prefix
56
- end
43
+ result
57
44
  end
58
45
 
59
46
  def apply_hooks(options)
@@ -1,30 +1,53 @@
1
1
  require 'wait'
2
2
  module PageMagic
3
3
  class Session
4
- attr_accessor :current_page, :raw_session
4
+ attr_accessor :current_page, :raw_session, :transitions
5
5
 
6
6
  def initialize browser
7
7
  @raw_session = browser
8
8
  end
9
9
 
10
+ def define_page_mappings transitions
11
+ @transitions = transitions
12
+ end
13
+
14
+ def current_page
15
+ if transitions
16
+ mapping = find_mapped_page(current_path)
17
+ @current_page = mapping.new(self) if mapping
18
+ end
19
+ @current_page
20
+ end
21
+
22
+ def find_mapped_page path
23
+ mapping = transitions.keys.find do |key|
24
+ string_matches?(path, key)
25
+ end
26
+ transitions[mapping]
27
+ end
28
+
29
+ def string_matches?(string, matcher)
30
+ if matcher.is_a?(Regexp)
31
+ string =~ matcher
32
+ elsif matcher.is_a?(String)
33
+ string == matcher
34
+ else
35
+ false
36
+ end
37
+ end
38
+
10
39
  def visit page
11
- @raw_session.visit page.url
40
+ raw_session.visit page.url
12
41
  @current_page = page.new self
13
42
  self
14
43
  end
15
44
 
16
45
  def current_path
17
- @raw_session.current_path
46
+ raw_session.current_path
18
47
  end
19
48
 
20
49
  def current_url
21
- @raw_session.current_url
22
- end
23
-
24
- def move_to page_class
25
- page_class = eval(page_class) if page_class.is_a?(String)
26
- @current_page = page_class.new self
27
- wait_until { raw_session.current_url == page_class.url }
50
+ raw_session.current_url
28
51
  end
29
52
 
30
53
  def wait_until &block
@@ -33,7 +56,7 @@ module PageMagic
33
56
  end
34
57
 
35
58
  def method_missing name, *args, &block
36
- @current_page.send(name, *args, &block)
59
+ current_page.send(name, *args, &block)
37
60
  end
38
61
 
39
62
  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.11.0.alpha3"
8
+ s.version = "0.11.0.alpha6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Leon Davis"]
12
- s.date = "2014-04-05"
12
+ s.date = "2015-07-03"
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 = [
@@ -22,12 +22,12 @@ Gem::Specification.new do |s|
22
22
  ".travis.yml",
23
23
  "Gemfile",
24
24
  "Gemfile.lock",
25
+ "Guardfile",
25
26
  "README.md",
26
27
  "Rakefile",
27
28
  "VERSION",
28
29
  "lib/ext/string.rb",
29
30
  "lib/page_magic.rb",
30
- "lib/page_magic/ajax_support.rb",
31
31
  "lib/page_magic/browser.rb",
32
32
  "lib/page_magic/element.rb",
33
33
  "lib/page_magic/element_context.rb",
@@ -36,18 +36,18 @@ Gem::Specification.new do |s|
36
36
  "lib/page_magic/page_magic.rb",
37
37
  "lib/page_magic/session.rb",
38
38
  "page_magic.gemspec",
39
- "spec/browser_spec.rb",
40
- "spec/element_context_spec.rb",
41
39
  "spec/element_spec.rb",
42
40
  "spec/helpers/capybara.rb",
43
41
  "spec/member_methods_spec.rb",
42
+ "spec/page_magic/browser_spec.rb",
43
+ "spec/page_magic/element_context_spec.rb",
44
44
  "spec/page_magic/elements_spec.rb",
45
+ "spec/page_magic/session_spec.rb",
45
46
  "spec/page_magic/usage/defining_page_elements_spec.rb",
46
47
  "spec/page_magic/usage/defining_pages_spec.rb",
47
48
  "spec/page_magic/usage/include_page_magic_spec.rb",
48
49
  "spec/page_magic/usage/interacting_with_pages_spec.rb",
49
50
  "spec/page_magic/usage/starting_a_session_spec.rb",
50
- "spec/session_spec.rb",
51
51
  "spec/spec_helper.rb"
52
52
  ]
53
53
  s.homepage = "https://github.com/ladtech/page_magic"
@@ -61,18 +61,6 @@ describe PageMagic::ElementContext do
61
61
  end
62
62
  end
63
63
 
64
- describe 'actions' do
65
- it 'should click the element' do
66
- page = page1.new
67
- page.visit
68
-
69
- described_class.new(page, page.browser, self).click_next
70
- page.session.current_path.should == '/page2'
71
- page.text.should == 'page 2 content'
72
- end
73
- end
74
-
75
-
76
64
  describe 'accessing page sections' do
77
65
  it 'should go through page sections' do
78
66
 
@@ -89,20 +77,6 @@ describe PageMagic::ElementContext do
89
77
  described_class.new(page, page.browser, self).form
90
78
  end
91
79
 
92
- it 'they are clickable too' do
93
- elements_page.class_eval do
94
- section :section do
95
- selector id: 'form_link'
96
- end
97
- end
98
-
99
- page = elements_page.new
100
- page.visit
101
-
102
-
103
- described_class.new(page, page.browser, self).click_section
104
- page.session.current_path.should == '/page2'
105
- end
106
80
 
107
81
  it 'should delegate to page element if method not found' do
108
82
  #TODO call page method, look for subelement, delagate to capybara object
@@ -3,7 +3,7 @@ describe PageMagic::Session do
3
3
  let(:page) do
4
4
  Class.new do
5
5
  include PageMagic
6
- url :url
6
+ url '/page1'
7
7
 
8
8
  def my_method
9
9
  :called
@@ -20,6 +20,56 @@ describe PageMagic::Session do
20
20
 
21
21
  let(:browser) { double('browser', current_url: 'url') }
22
22
 
23
+ describe '#current_page' do
24
+ subject do
25
+ PageMagic::Session.new(browser).tap do |session|
26
+ session.define_page_mappings '/another_page1' => another_page_class
27
+ end
28
+ end
29
+ context 'page url has not changed' do
30
+ it 'returns the original page' do
31
+ browser.should_receive(:visit).with(page.url)
32
+ allow(browser).to receive(:current_path).and_return('/page1')
33
+ subject.visit(page)
34
+ expect(subject.current_page).to be_an_instance_of(page)
35
+ end
36
+ end
37
+
38
+ context 'page url has changed' do
39
+ it 'returns the mapped page object' do
40
+ browser.should_receive(:visit).with(page.url)
41
+ subject.visit(page)
42
+ allow(browser).to receive(:current_path).and_return('/another_page1')
43
+ expect(subject.current_page).to be_an_instance_of(another_page_class)
44
+ end
45
+ end
46
+ end
47
+
48
+ describe '#find_mapped_page' do
49
+ subject do
50
+ described_class.new(nil).tap do |session|
51
+ session.define_page_mappings '/page' => :mapped_page_using_string, /page\d/ => :mapped_page_using_regex
52
+ end
53
+ end
54
+
55
+ context 'mapping is string' do
56
+ it 'returns the page class' do
57
+ expect(subject.find_mapped_page('/page')).to be(:mapped_page_using_string)
58
+ end
59
+ end
60
+ context 'mapping is regex' do
61
+ it 'returns the page class' do
62
+ expect(subject.find_mapped_page('/page2')).to be(:mapped_page_using_regex)
63
+ end
64
+ end
65
+
66
+ context 'mapping is not found' do
67
+ it 'returns nil' do
68
+ expect(subject.find_mapped_page('/fake_page')).to be(nil)
69
+ end
70
+ end
71
+ end
72
+
23
73
  it 'should visit the given url' do
24
74
  browser.should_receive(:visit).with(page.url)
25
75
  session = PageMagic::Session.new(browser).visit(page)
@@ -38,30 +88,4 @@ describe PageMagic::Session do
38
88
  session.my_method.should be(:called)
39
89
  end
40
90
  end
41
-
42
- context 'move_to moves the session object to another page' do
43
- it 'can take a class' do
44
- page_magic_session = PageMagic::Session.new(double(:browser, current_url: '/another_page1'))
45
- page_magic_session.move_to(another_page_class)
46
- page_magic_session.current_page.should be_a(another_page_class)
47
- end
48
-
49
- it 'can take the name of the class as a string' do
50
- class ThePage
51
- include PageMagic
52
- url '/the_page'
53
- end
54
-
55
- page_magic_session = PageMagic::Session.new(double(:browser, current_url: '/the_page'))
56
- page_magic_session.move_to("ThePage")
57
- page_magic_session.current_page.should be_a(ThePage)
58
- end
59
-
60
- it 'should wait until the browser url has changed' do
61
- mock_browser = double(:browser, current_url: 'a')
62
- page_magic_session = PageMagic::Session.new(mock_browser)
63
-
64
- expect { page_magic_session.move_to(another_page_class) }.to raise_error(Wait::ResultInvalid)
65
- end
66
- end
67
91
  end
@@ -43,7 +43,7 @@ describe 'The Elements of a Page' do
43
43
 
44
44
  it 'should access a field' do
45
45
  @page.visit
46
- @page.click_next
46
+ @page.next.click
47
47
  @page.text.should == 'page 2 content'
48
48
  end
49
49
 
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: 0.11.0.alpha5
4
+ version: 0.11.0.alpha6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leon Davis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-23 00:00:00.000000000 Z
11
+ date: 2015-07-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capybara
@@ -52,34 +52,6 @@ dependencies:
52
52
  - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: guard
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - '>='
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - '>='
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: guard-ctags-bundler
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - '>='
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - '>='
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
55
  description: Framework for modeling and interacting with webpages which wraps capybara
84
56
  email: info@lad-tech.com
85
57
  executables: []
@@ -140,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
140
112
  version: 1.3.1
141
113
  requirements: []
142
114
  rubyforge_project:
143
- rubygems_version: 2.2.2
115
+ rubygems_version: 2.4.3
144
116
  signing_key:
145
117
  specification_version: 4
146
118
  summary: Framework for modeling and interacting with webpages