page_magic 1.0.0.alpha20 → 1.0.0.alpha21

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 49ba851eb365dd26d8f8a4f31d5d9a00edd453a5
4
- data.tar.gz: dddb7d4942c3a1957e2ace92af5cfe9420cb4b56
3
+ metadata.gz: 115f37789b407f0f922654cec028ab74268132c4
4
+ data.tar.gz: ad52bf172b7e0ebd649f738c86e418c47c57a70f
5
5
  SHA512:
6
- metadata.gz: 3034f818fb008d3c2efb696be112f0c1fc5f69c33618ad148ae98a2ab5fc728d5c30ea40835428dcf3164b37cc9e23de548c556b5f484e16b003faf1c828c547
7
- data.tar.gz: 91090c400e40cbbee6cb9e6c3b0c2b1bc28c810da8c8fd492d80c867dbf15bb4fedd29326f9b917ceb2c497aef0bb78eeb37108ff04d30f58b92a27dc9501a57
6
+ metadata.gz: 1a3d128c9dbf70e10c7aae8ddef2c48603714b625634639b8b559af1870655a114c9f706447add67e906ed4cd087e905dc827492798b8b71166455e1cade255b
7
+ data.tar.gz: 6428d9dc270bc4768556e102a68bf0014817c05e3c947e467fc7cad3868b3cf7ad0007cf34a16cab24fc9cb8d23502192509103d6ca9799efe4f8c514c352337
data/README.md CHANGED
@@ -7,7 +7,7 @@ It has a simple but powerful DSL which makes modelling and interacting with your
7
7
  Wouldn't it be great if there was a framework that could:
8
8
  - [Model your pages](#modelling-pages)
9
9
  - [Fluently define interaction hooks / waiters on page elements](#interaction-hooks)
10
- - [Provide urls to pages to avoid awkward page object switching](#page-mapping)
10
+ - [Map paths to pages so that the correct page object is loaded as you navigate](#page-mapping)
11
11
  - [Be super dynamic](#dynamic-selectors)
12
12
 
13
13
  Well PageMagic might just be the answer!
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0.alpha20
1
+ 1.0.0.alpha21
data/circle.yml CHANGED
@@ -1,3 +1,6 @@
1
+ machine:
2
+ ruby:
3
+ version: '2.1'
1
4
  test:
2
5
  override:
3
6
  - bundle exec rake
@@ -16,5 +16,19 @@ module PageMagic
16
16
  return @on_load || DEFAULT_ON_LOAD unless block
17
17
  @on_load = block
18
18
  end
19
+
20
+ # Visit this page based on the class level registered url
21
+ # @param [Object] application rack application (optional)
22
+ # @param [Symbol] browser name of browser
23
+ # @param [Hash] options browser driver specific options
24
+ # @return [Session] active session configured to be using an instance of the page object modeled by this class
25
+ def visit(application: nil, browser: :rack_test, options: {})
26
+ session_options = { browser: browser, options: options, url: url }
27
+ session_options[:application] = application if application
28
+
29
+ PageMagic.session(session_options).tap do |session|
30
+ session.visit(self, url: url)
31
+ end
32
+ end
19
33
  end
20
34
  end
@@ -24,12 +24,6 @@ module PageMagic
24
24
  text.downcase.include?(string.downcase)
25
25
  end
26
26
 
27
- # Visit this page based on the class level registered url
28
- def visit
29
- browser.visit self.class.url
30
- execute_on_load
31
- end
32
-
33
27
  # @return the page text
34
28
  def text
35
29
  browser.text
data/lib/page_magic.rb CHANGED
@@ -16,6 +16,12 @@ module PageMagic
16
16
  @drivers ||= Drivers.new.tap(&:load)
17
17
  end
18
18
 
19
+ # Visit this page based on the class level registered url
20
+ # @param [Object] application rack application (optional)
21
+ # @param [Symbol] browser name of browser
22
+ # @param [String] url url to start the session on
23
+ # @param [Hash] options browser driver specific options
24
+ # @return [Session] configured sessoin
19
25
  def session(application: nil, browser: :rack_test, url:, options: {})
20
26
  driver = drivers.find(browser)
21
27
  fail UnspportedBrowserException unless driver
data/spec/element_spec.rb CHANGED
@@ -10,9 +10,9 @@ module PageMagic
10
10
  end
11
11
  end
12
12
 
13
- let(:page) do
14
- page_class.new.tap(&:visit)
15
- end
13
+ let(:session) { page_class.visit(application: rack_app) }
14
+
15
+ let(:page) { session.current_page }
16
16
 
17
17
  describe 'inheriting' do
18
18
  it 'lets you create custom elements' do
@@ -62,14 +62,11 @@ module PageMagic
62
62
  describe '#browser_element' do
63
63
  let!(:browser) { double('browser') }
64
64
 
65
- it 'calls the on_load hook' do
66
- end
67
-
68
65
  context 'options supplied to selector' do
69
66
  it 'passes them on to the cappybara finder method' do
70
67
  options = { count: 1 }
71
68
  xpath_selector = '//div/input'
72
- expect(Capybara.current_session).to receive(:find).with(:xpath, xpath_selector, options)
69
+ expect(page.session.raw_session).to receive(:find).with(:xpath, xpath_selector, options)
73
70
  described_class.new(:my_input,
74
71
  page,
75
72
  type: :text_field,
@@ -1,7 +1,10 @@
1
1
  module PageMagic
2
2
  describe ClassMethods do
3
3
  subject do
4
- Object.new.tap { |o| o.extend(described_class) }
4
+ Class.new.tap do |clazz|
5
+ clazz.extend(described_class)
6
+ clazz.include(InstanceMethods)
7
+ end
5
8
  end
6
9
  describe '#url' do
7
10
  it 'get/sets a value' do
@@ -25,5 +28,20 @@ module PageMagic
25
28
  end
26
29
  end
27
30
  end
31
+
32
+ describe '#visit' do
33
+ include_context :webapp_fixture
34
+ it 'passes all options to create an active session on the registered url' do
35
+ subject.url '/page1'
36
+ expect(PageMagic).to receive(:session).with(application: rack_app,
37
+ options: {},
38
+ browser: :rack_test,
39
+ url: subject.url).and_call_original
40
+
41
+ session = subject.visit(application: rack_app, options: {}, browser: :rack_test)
42
+
43
+ expect(session.title).to eq('page1')
44
+ end
45
+ end
28
46
  end
29
47
  end
@@ -16,7 +16,7 @@ module PageMagic
16
16
 
17
17
  describe '#method_missing' do
18
18
  let(:page) do
19
- elements_page.new.tap(&:visit)
19
+ elements_page.visit(application: rack_app).current_page
20
20
  end
21
21
 
22
22
  context 'neither a method or page element are defined' do
@@ -11,12 +11,12 @@ module PageMagic
11
11
  end
12
12
 
13
13
  subject do
14
- page_class.new.tap(&:visit)
14
+ page_class.visit(application: rack_app)
15
15
  end
16
16
 
17
17
  describe 'execute_on_load' do
18
18
  it 'runs the on_load_hook in the context of self' do
19
- instance = subject
19
+ instance = subject.current_page
20
20
  page_class.on_load do
21
21
  extend RSpec::Matchers
22
22
  expect(self).to be(instance)
@@ -26,7 +26,7 @@ module PageMagic
26
26
  end
27
27
 
28
28
  it 'returns self' do
29
- expect(subject.execute_on_load).to be(subject)
29
+ expect(subject.execute_on_load).to be(subject.current_page)
30
30
  end
31
31
  end
32
32
 
@@ -44,16 +44,11 @@ module PageMagic
44
44
  it 'goes to the class define url' do
45
45
  expect(subject.session.current_path).to eq('/page1')
46
46
  end
47
-
48
- it 'runs the on load handler' do
49
- expect(subject).to receive(:execute_on_load).and_call_original
50
- subject.visit
51
- end
52
47
  end
53
48
 
54
49
  describe 'session' do
55
50
  it 'gives access to the page magic object wrapping the user session' do
56
- expect(subject.session.raw_session).to be(Capybara.current_session)
51
+ expect(subject.session.raw_session).to be_a(Capybara::Session)
57
52
  end
58
53
  end
59
54
 
@@ -1,17 +1,18 @@
1
1
  shared_context :webapp_fixture do
2
2
  require 'sinatra/base'
3
3
 
4
- rack_app = Class.new(Sinatra::Base) do
5
- get '/page1' do
6
- "<html><head><title>page1</title></head><body><a href='/page2'>next page</a></body></html>"
7
- end
8
-
9
- get '/page2' do
10
- 'page 2 content'
11
- end
12
-
13
- get '/elements' do
14
- <<-ELEMENTS
4
+ let(:rack_app) do
5
+ Class.new(Sinatra::Base) do
6
+ get '/page1' do
7
+ "<html><head><title>page1</title></head><body><a href='/page2'>next page</a></body></html>"
8
+ end
9
+
10
+ get '/page2' do
11
+ 'page 2 content'
12
+ end
13
+
14
+ get '/elements' do
15
+ <<-ELEMENTS
15
16
  <a href='#'>a link</a>
16
17
 
17
18
 
@@ -23,7 +24,8 @@ shared_context :webapp_fixture do
23
24
  <input id='form_button' type='submit' value='a button'/>
24
25
  </form>
25
26
 
26
- ELEMENTS
27
+ ELEMENTS
28
+ end
27
29
  end
28
30
  end
29
31
 
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: 1.0.0.alpha20
4
+ version: 1.0.0.alpha21
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leon Davis
@@ -133,8 +133,6 @@ files:
133
133
  - ".pullreview.yml"
134
134
  - ".rspec"
135
135
  - ".rubocop.yml"
136
- - ".ruby-gemset"
137
- - ".ruby-version"
138
136
  - ".simplecov"
139
137
  - ".yardopts"
140
138
  - Gemfile
@@ -160,7 +158,6 @@ files:
160
158
  - lib/page_magic/exceptions.rb
161
159
  - lib/page_magic/instance_methods.rb
162
160
  - lib/page_magic/session.rb
163
- - page_magic.gemspec
164
161
  - spec/element_spec.rb
165
162
  - spec/member_methods_spec.rb
166
163
  - spec/page_magic/class_methods_spec.rb
data/.ruby-gemset DELETED
@@ -1 +0,0 @@
1
- page_magic
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- 2.1
data/page_magic.gemspec DELETED
@@ -1,76 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
5
-
6
- Gem::Specification.new do |s|
7
- s.name = 'page_magic'
8
- s.version = '0.11.0.alpha3'
9
-
10
- s.required_rubygems_version = Gem::Requirement.new('> 1.3.1') if s.respond_to? :required_rubygems_version=
11
- s.authors = ['Leon Davis']
12
- s.date = '2014-04-05'
13
- s.description = 'Framework for modeling and interacting with webpages which wraps capybara'
14
- s.email = 'info@lad-tech.com'
15
- s.extra_rdoc_files = [
16
- 'README.md'
17
- ]
18
- s.files = [
19
- '.rspec',
20
- '.ruby-gemset',
21
- '.ruby-version',
22
- '.travis.yml',
23
- 'Gemfile',
24
- 'Gemfile.lock',
25
- 'README.md',
26
- 'Rakefile',
27
- 'VERSION',
28
- 'lib/ext/string.rb',
29
- 'lib/page_magic.rb',
30
- 'lib/page_magic/ajax_support.rb',
31
- 'lib/page_magic/browser.rb',
32
- 'lib/page_magic/element.rb',
33
- 'lib/page_magic/element_context.rb',
34
- 'lib/page_magic/elements.rb',
35
- 'lib/page_magic/exceptions.rb',
36
- 'lib/page_magic/page_magic.rb',
37
- 'lib/page_magic/session.rb',
38
- 'page_magic.gemspec',
39
- 'spec/browser_spec.rb',
40
- 'spec/element_context_spec.rb',
41
- 'spec/element_spec.rb',
42
- 'spec/helpers/capybara.rb',
43
- 'spec/member_methods_spec.rb',
44
- 'spec/page_magic/elements_spec.rb',
45
- 'spec/page_magic/usage/defining_page_elements_spec.rb',
46
- 'spec/page_magic/usage/defining_pages_spec.rb',
47
- 'spec/page_magic/usage/include_page_magic_spec.rb',
48
- 'spec/page_magic/usage/interacting_with_pages_spec.rb',
49
- 'spec/page_magic/usage/starting_a_session_spec.rb',
50
- 'spec/session_spec.rb',
51
- 'spec/spec_helper.rb'
52
- ]
53
- s.homepage = 'https://github.com/ladtech/page_magic'
54
- s.licenses = ['ruby']
55
- s.require_paths = ['lib']
56
- s.rubygems_version = '2.0.3'
57
- s.summary = 'Framework for modeling and interacting with webpages'
58
-
59
- if s.respond_to? :specification_version
60
- s.specification_version = 4
61
-
62
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0')
63
- s.add_runtime_dependency('capybara', ['>= 0'])
64
- s.add_runtime_dependency('wait', ['>= 0'])
65
- s.add_development_dependency('jeweler', ['>= 0'])
66
- else
67
- s.add_dependency('capybara', ['>= 0'])
68
- s.add_dependency('wait', ['>= 0'])
69
- s.add_dependency('jeweler', ['>= 0'])
70
- end
71
- else
72
- s.add_dependency('capybara', ['>= 0'])
73
- s.add_dependency('wait', ['>= 0'])
74
- s.add_dependency('jeweler', ['>= 0'])
75
- end
76
- end