page_magic 0.11.0.alpha8 → 1.0.0.alpha

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: 3b3b5bae4a08579ffe198524fb160791d40c75d0
4
- data.tar.gz: cfbcade44965019d6614dbd8a397cb717d0d608b
3
+ metadata.gz: dd89ee316817755f4b899d4e09dc5c985c34e97f
4
+ data.tar.gz: 24d259f187207b3ad600ab807c19f6202d2988af
5
5
  SHA512:
6
- metadata.gz: 9802999ea9cafdbe9c1104784047ae65734cfc5bef00f6da87b0da30c4b143c3add0e5cd0be4fd1e1655ce39290ce3884d53816e61c2c3f979fdad9a47312bc2
7
- data.tar.gz: 1382773ba5e71d48604da93565ff477eaf3bdc901a1735ad6eca8859bb968bcc9b67704c81c53a7398cc28794200786c63714222bfd9282ec6603131e934d9d6
6
+ metadata.gz: 060f54874232cb6447596a75ee5c7251185bc1b1d93f2c0e265999d321c9de4c512354cf14e55e5f6e19f86c619d874d34ae86a71f795be70d17700b2b1abd32
7
+ data.tar.gz: 9347c6789a93e2e4854763dea8ca8fe5ffd0b45f25873fdab51acd733f3b368402ecdc590b3ee3b0a355903d1589ad7304daf964260233bfc97b5a41b37be19e
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.1
1
+ 2.0.0
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ rvm:
2
+ - '1.9.3'
3
+ - '2.0.0'
4
+
data/Gemfile CHANGED
@@ -1,7 +1,6 @@
1
1
  source "http://rubygems.org"
2
2
 
3
3
  gem 'capybara'
4
- gem 'activesupport'
5
4
  gem 'wait'
6
5
 
7
6
  group :test do
data/Gemfile.lock CHANGED
@@ -1,12 +1,6 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- activesupport (4.2.3)
5
- i18n (~> 0.7)
6
- json (~> 1.7, >= 1.7.7)
7
- minitest (~> 5.1)
8
- thread_safe (~> 0.3, >= 0.3.4)
9
- tzinfo (~> 1.1)
10
4
  addressable (2.3.6)
11
5
  builder (3.2.2)
12
6
  capybara (2.1.0)
@@ -44,7 +38,6 @@ GEM
44
38
  guard (~> 2.0)
45
39
  hashie (2.0.5)
46
40
  highline (1.6.21)
47
- i18n (0.7.0)
48
41
  jeweler (2.0.1)
49
42
  builder
50
43
  bundler (>= 1.0)
@@ -65,7 +58,6 @@ GEM
65
58
  method_source (0.8.2)
66
59
  mime-types (1.25)
67
60
  mini_portile (0.5.1)
68
- minitest (5.7.0)
69
61
  multi_json (1.7.3)
70
62
  multi_xml (0.5.5)
71
63
  multipart-post (1.2.0)
@@ -121,11 +113,8 @@ GEM
121
113
  tilt (~> 1.3, >= 1.3.4)
122
114
  slop (3.5.0)
123
115
  thor (0.19.1)
124
- thread_safe (0.3.5)
125
116
  tilt (1.4.1)
126
117
  timers (1.1.0)
127
- tzinfo (1.2.2)
128
- thread_safe (~> 0.1)
129
118
  wait (0.5.1)
130
119
  watir-webdriver (0.6.4)
131
120
  selenium-webdriver (>= 2.18.0)
@@ -138,7 +127,6 @@ PLATFORMS
138
127
  ruby
139
128
 
140
129
  DEPENDENCIES
141
- activesupport
142
130
  capybara
143
131
  guard
144
132
  guard-ctags-bundler
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
- #PageMagic
1
+ [![Build Status](https://travis-ci.org/Ladtech/page_magic.png)](https://travis-ci.org/Ladtech/page_magic)
2
+ #PageMagic
2
3
  PageMagic is an API for testing web applications.
3
4
 
4
5
  It has a simple but powerful DSL which makes modelling and interacting with your pages easy.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.11.0.alpha8
1
+ 1.0.0.alpha
@@ -0,0 +1,19 @@
1
+ module PageMagic
2
+ module Browser
3
+
4
+ class << self
5
+ attr_writer :default
6
+ def session
7
+ @session ||= PageMagic.session(default)
8
+ end
9
+
10
+ def default
11
+ @default || :firefox
12
+ end
13
+ end
14
+
15
+ def browser
16
+ Browser.session
17
+ end
18
+ end
19
+ end
@@ -28,15 +28,19 @@ module PageMagic
28
28
  element_locator = element_locator_factory.call(@page_element, *args)
29
29
  end
30
30
 
31
+ result = element_locator.browser_element
32
+
33
+ return element_locator if element_locator.section?
34
+
31
35
  [:set, :select_option, :unselect_option, :click].each do |action_method|
32
- apply_hooks(page_element: element_locator.browser_element,
36
+ apply_hooks(page_element: result,
33
37
  capybara_method: action_method,
34
38
  before_hook: element_locator.before,
35
39
  after_hook: element_locator.after,
36
40
  )
37
41
  end
38
42
 
39
- element_locator.section? ? element_locator : element_locator.browser_element
43
+ result
40
44
  end
41
45
 
42
46
  def apply_hooks(options)
@@ -7,37 +7,22 @@ module PageMagic
7
7
  @raw_session = browser
8
8
  end
9
9
 
10
- def define_page_mappings transitions
10
+ def define_transitions transitions
11
11
  @transitions = transitions
12
12
  end
13
13
 
14
14
  def current_page
15
15
  if transitions
16
- mapping = find_mapped_page(current_path)
17
- @current_page = mapping.new(self) if mapping
16
+ mapping = transitions.keys.find do |key|
17
+ current_url.include?(key)
18
+ end
19
+ @current_page = transitions[mapping].new(self) if transitions[mapping]
18
20
  end
19
21
  @current_page
20
22
  end
21
23
 
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
-
39
- def visit(page, url: nil)
40
- raw_session.visit url || page.url
24
+ def visit page
25
+ raw_session.visit page.url
41
26
  @current_page = page.new self
42
27
  self
43
28
  end
data/lib/page_magic.rb CHANGED
@@ -1,33 +1,41 @@
1
1
  $LOAD_PATH.unshift("#{File.dirname(__FILE__)}")
2
2
  require 'capybara'
3
3
  require 'page_magic/exceptions'
4
+ require 'page_magic/browser'
4
5
  require 'page_magic/session'
5
6
  require 'page_magic/elements'
6
7
  require 'page_magic/element_context'
7
8
  require 'page_magic/element'
8
9
  require 'page_magic/page_magic'
9
- require 'page_magic/drivers'
10
10
 
11
11
  module PageMagic
12
- class UnspportedBrowserException < Exception;end
13
-
14
12
  class << self
13
+ def session browser=nil, options = {}
14
+ if browser.is_a?(Symbol)
15
+ application = options.delete(:application)
16
+
17
+ Capybara.register_driver browser do |app|
18
+ options[:browser] = browser
19
+ case browser
20
+ when :poltergeist
21
+ require 'capybara/poltergeist'
22
+ Capybara::Poltergeist::Driver.new(app)
23
+ when :rack_test
24
+ Capybara::RackTest::Driver.new(app, options)
25
+ else
26
+ require 'watir-webdriver'
27
+ Capybara::Selenium::Driver.new(app, options)
28
+ end
29
+
30
+ end
31
+
32
+ Session.new(Capybara::Session.new(browser, application))
33
+ else
34
+ Capybara.reset!
35
+ Capybara.app = browser[:application] if browser.is_a?(Hash) && browser[:application]
36
+ Session.new(Capybara.current_session)
37
+ end
15
38
 
16
- def drivers
17
- @drivers ||= Drivers.new.tap do |drivers|
18
- drivers.load
19
- end
20
- end
21
-
22
- def session(application: nil, browser: :rack_test, options: {})
23
- driver = drivers.find(browser)
24
- raise UnspportedBrowserException unless driver
25
-
26
- Capybara.register_driver browser do |app|
27
- driver.build(app, browser: browser, options: options)
28
- end
29
-
30
- Session.new(Capybara::Session.new(browser, application))
31
39
  end
32
40
 
33
41
  def included clazz
@@ -45,10 +53,11 @@ module PageMagic
45
53
  PageMagic.pages << clazz
46
54
  end
47
55
  end
56
+
48
57
  end
49
58
 
50
59
  def pages
51
60
  @pages||=[]
52
61
  end
53
62
  end
54
- end
63
+ end
@@ -0,0 +1,35 @@
1
+ describe PageMagic::Browser do
2
+ let(:app) { Object.new }
3
+
4
+ before do
5
+ PageMagic::Browser.instance_variable_set(:@session, nil)
6
+ app.extend PageMagic::Browser
7
+ end
8
+
9
+ describe 'default' do
10
+ it 'should be firefox' do
11
+ PageMagic::Browser.default.should == :firefox
12
+ end
13
+ end
14
+
15
+ describe 'browser' do
16
+ it 'should return the existing session' do
17
+ session_instance = app.browser
18
+ app.browser.should == session_instance
19
+ end
20
+
21
+ it 'should create a session if not already set' do
22
+ new_session = double(:new_session)
23
+
24
+ PageMagic.should_receive(:session).with(:firefox).and_return new_session
25
+ app.browser.should == new_session
26
+ end
27
+
28
+ it 'should use custom browser' do
29
+ PageMagic.should_receive(:session).with(:custom_browser)
30
+
31
+ PageMagic::Browser.default = :custom_browser
32
+ app.browser
33
+ end
34
+ end
35
+ end
@@ -87,40 +87,23 @@ describe PageMagic::ElementContext do
87
87
 
88
88
  describe 'hooks' do
89
89
 
90
- subject(:page) do
91
- elements_page.new.tap do|p|
92
- p.visit
93
- end
94
- end
95
-
96
- before do
97
- browser = page.browser
98
- browser.should_receive(:call_in_before_hook)
99
- browser.should_receive(:call_in_after_before_hook)
100
- end
101
90
 
91
+ #it 'only applies them if browser element supports event' do
92
+ # page = elements_page.new
93
+ #end
102
94
 
103
- context 'section' do
104
- it 'applies the hooks' do
105
-
106
- elements_page.section(:form, id: 'form') do
107
- link :form_link, id: 'form_link'
95
+ it 'should execute a before and after action that gives access to the browser' do
108
96
 
109
- before do |page_browser|
110
- page_browser.call_in_before_hook
111
- end
97
+ page = elements_page.new
98
+ page.visit
112
99
 
113
- after do |page_browser|
114
- page_browser.call_in_after_before_hook
115
- end
116
- end
100
+ selector = {text: 'a link'}
101
+ browser = page.browser
102
+ browser.should_receive(:call_in_before_hook)
103
+ browser.should_receive(:call_in_after_before_hook)
117
104
 
118
- described_class.new(page, page.browser, self).form.click
119
- end
120
- end
121
105
 
122
- it 'should execute a before and after action that gives access to the browser' do
123
- elements_page.link(:create, text: 'a link') do
106
+ elements_page.link(:create, selector) do
124
107
  before do |page_browser|
125
108
  page_browser.call_in_before_hook
126
109
  end
@@ -3,7 +3,7 @@ describe PageMagic::Session do
3
3
  let(:page) do
4
4
  Class.new do
5
5
  include PageMagic
6
- url '/page1'
6
+ url :url
7
7
 
8
8
  def my_method
9
9
  :called
@@ -23,67 +23,33 @@ describe PageMagic::Session do
23
23
  describe '#current_page' do
24
24
  subject do
25
25
  PageMagic::Session.new(browser).tap do |session|
26
- session.define_page_mappings '/another_page1' => another_page_class
26
+ session.define_transitions '/another_page1' => another_page_class
27
27
  end
28
28
  end
29
29
  context 'page url has not changed' do
30
30
  it 'returns the original page' do
31
31
  browser.should_receive(:visit).with(page.url)
32
- allow(browser).to receive(:current_path).and_return('/page1')
33
32
  subject.visit(page)
34
33
  expect(subject.current_page).to be_an_instance_of(page)
35
34
  end
36
35
  end
37
36
 
38
37
  context 'page url has changed' do
38
+
39
39
  it 'returns the mapped page object' do
40
40
  browser.should_receive(:visit).with(page.url)
41
41
  subject.visit(page)
42
- allow(browser).to receive(:current_path).and_return('/another_page1')
42
+ allow(browser).to receive(:current_url).and_return('http://example.com/another_page1')
43
43
  expect(subject.current_page).to be_an_instance_of(another_page_class)
44
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
45
 
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
46
  end
71
47
  end
72
48
 
73
- describe '#visit' do
74
- context 'url supplied' do
75
- it 'uses this url instead of the one defined on the page class' do
76
- expect(browser).to receive(:visit).with(:custom_url)
77
- session = PageMagic::Session.new(browser).visit(page, url: :custom_url)
78
- session.current_page.should be_a(page)
79
- end
80
- end
81
-
82
- it 'visits the url on defined on the page class' do
83
- browser.should_receive(:visit).with(page.url)
84
- session = PageMagic::Session.new(browser).visit(page)
85
- session.current_page.should be_a(page)
86
- end
49
+ it 'should visit the given url' do
50
+ browser.should_receive(:visit).with(page.url)
51
+ session = PageMagic::Session.new(browser).visit(page)
52
+ session.current_page.should be_a(page)
87
53
  end
88
54
 
89
55
  it 'should return the current url' do
@@ -1,5 +1,4 @@
1
1
  describe 'PageMagic.session' do
2
-
3
2
  let(:app_class) do
4
3
  Class.new do
5
4
  def call env
@@ -12,10 +11,35 @@ describe 'PageMagic.session' do
12
11
  Capybara.drivers[browser].call(nil)
13
12
  end
14
13
 
15
- context 'specificying a browser' do
16
- it 'loads the driver for the specified browser' do
17
- session = PageMagic.session(browser: :firefox)
18
- session.raw_session.driver.is_a?(Capybara::Selenium::Driver).should be_true
14
+ context 'using a symbol as a parameter' do
15
+ it 'sets up a session using the specified browser' do
16
+ Capybara::Session.should_receive(:new).with(:chrome, nil).and_return(:chrome_session)
17
+
18
+ session = PageMagic.session(:chrome)
19
+
20
+ registered_driver(:chrome).should == Capybara::Selenium::Driver.new(nil, browser: :chrome)
21
+
22
+ session.raw_session.should == :chrome_session
23
+ end
24
+
25
+ context 'browsers' do
26
+ it 'supports poltergeist' do
27
+ session = PageMagic.session(:poltergeist, application: app_class.new)
28
+ session.raw_session.driver.is_a?(Capybara::Poltergeist::Driver).should be_true
29
+ end
30
+
31
+ it 'supports selenium' do
32
+ session = PageMagic.session(:firefox, application: app_class.new)
33
+ session.raw_session.driver.is_a?(Capybara::Selenium::Driver).should be_true
34
+ end
35
+ end
36
+ end
37
+
38
+ context 'defaulting the browser used from PageMagic sessions' do
39
+ it "uses what ever Capybara's default_driver is set to" do
40
+ Capybara.default_driver = :rack_test
41
+ session = PageMagic.session
42
+ session.raw_session.mode.should == :rack_test
19
43
  end
20
44
  end
21
45
 
@@ -28,7 +52,7 @@ describe 'PageMagic.session' do
28
52
  end
29
53
 
30
54
  it 'can run against an rack application using a particular browser' do
31
- session = PageMagic.session(browser: :rack_test, application: app_class.new)
55
+ session = PageMagic.session(:rack_test, application: app_class.new)
32
56
  session.raw_session.mode.should == :rack_test
33
57
  session.raw_session.visit('/')
34
58
  session.raw_session.text.should == 'hello world!!'
data/spec/spec_helper.rb CHANGED
@@ -11,22 +11,7 @@ require 'page_magic'
11
11
  require 'capybara/rspec'
12
12
  require 'helpers/capybara'
13
13
 
14
- shared_context :files do
15
- require 'tmpdir'
16
- def scratch_dir
17
- @dir ||= Dir.mktmpdir
18
- end
19
- end
20
14
 
21
- shared_context :rack_application do
22
- let(:rack_application) do
23
- Class.new do
24
- def call env
25
- [200, {}, ["hello world!!"]]
26
- end
27
- end
28
- end
29
- end
30
15
 
31
16
  RSpec.configure do
32
17
 
metadata CHANGED
@@ -1,97 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: page_magic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0.alpha8
4
+ version: 1.0.0.alpha
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-07-09 00:00:00.000000000 Z
11
+ date: 2015-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capybara
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: activesupport
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
24
+ - - '>='
39
25
  - !ruby/object:Gem::Version
40
26
  version: '0'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: wait
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
- - - ">="
31
+ - - '>='
46
32
  - !ruby/object:Gem::Version
47
33
  version: '0'
48
34
  type: :runtime
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
- - - ">="
38
+ - - '>='
53
39
  - !ruby/object:Gem::Version
54
40
  version: '0'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: jeweler
57
43
  requirement: !ruby/object:Gem::Requirement
58
44
  requirements:
59
- - - ">="
45
+ - - '>='
60
46
  - !ruby/object:Gem::Version
61
47
  version: '0'
62
48
  type: :development
63
49
  prerelease: false
64
50
  version_requirements: !ruby/object:Gem::Requirement
65
51
  requirements:
66
- - - ">="
52
+ - - '>='
67
53
  - !ruby/object:Gem::Version
68
54
  version: '0'
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: guard
71
57
  requirement: !ruby/object:Gem::Requirement
72
58
  requirements:
73
- - - ">="
59
+ - - '>='
74
60
  - !ruby/object:Gem::Version
75
61
  version: '0'
76
62
  type: :development
77
63
  prerelease: false
78
64
  version_requirements: !ruby/object:Gem::Requirement
79
65
  requirements:
80
- - - ">="
66
+ - - '>='
81
67
  - !ruby/object:Gem::Version
82
68
  version: '0'
83
69
  - !ruby/object:Gem::Dependency
84
70
  name: guard-ctags-bundler
85
71
  requirement: !ruby/object:Gem::Requirement
86
72
  requirements:
87
- - - ">="
73
+ - - '>='
88
74
  - !ruby/object:Gem::Version
89
75
  version: '0'
90
76
  type: :development
91
77
  prerelease: false
92
78
  version_requirements: !ruby/object:Gem::Requirement
93
79
  requirements:
94
- - - ">="
80
+ - - '>='
95
81
  - !ruby/object:Gem::Version
96
82
  version: '0'
97
83
  description: Framework for modeling and interacting with webpages which wraps capybara
@@ -101,9 +87,10 @@ extensions: []
101
87
  extra_rdoc_files:
102
88
  - README.md
103
89
  files:
104
- - ".rspec"
105
- - ".ruby-gemset"
106
- - ".ruby-version"
90
+ - .rspec
91
+ - .ruby-gemset
92
+ - .ruby-version
93
+ - .travis.yml
107
94
  - Gemfile
108
95
  - Gemfile.lock
109
96
  - Guardfile
@@ -112,11 +99,7 @@ files:
112
99
  - VERSION
113
100
  - lib/ext/string.rb
114
101
  - lib/page_magic.rb
115
- - lib/page_magic/driver.rb
116
- - lib/page_magic/drivers.rb
117
- - lib/page_magic/drivers/poltergeist.rb
118
- - lib/page_magic/drivers/rack_test.rb
119
- - lib/page_magic/drivers/selenium.rb
102
+ - lib/page_magic/browser.rb
120
103
  - lib/page_magic/element.rb
121
104
  - lib/page_magic/element_context.rb
122
105
  - lib/page_magic/elements.rb
@@ -127,11 +110,7 @@ files:
127
110
  - spec/element_spec.rb
128
111
  - spec/helpers/capybara.rb
129
112
  - spec/member_methods_spec.rb
130
- - spec/page_magic/driver_spec.rb
131
- - spec/page_magic/drivers/poltergeist_spec.rb
132
- - spec/page_magic/drivers/rack_test_spec.rb
133
- - spec/page_magic/drivers/selenium_spec.rb
134
- - spec/page_magic/drivers_spec.rb
113
+ - spec/page_magic/browser_spec.rb
135
114
  - spec/page_magic/element_context_spec.rb
136
115
  - spec/page_magic/elements_spec.rb
137
116
  - spec/page_magic/session_spec.rb
@@ -140,7 +119,6 @@ files:
140
119
  - spec/page_magic/usage/include_page_magic_spec.rb
141
120
  - spec/page_magic/usage/interacting_with_pages_spec.rb
142
121
  - spec/page_magic/usage/starting_a_session_spec.rb
143
- - spec/page_magic_spec.rb
144
122
  - spec/spec_helper.rb
145
123
  homepage: https://github.com/ladtech/page_magic
146
124
  licenses:
@@ -152,12 +130,12 @@ require_paths:
152
130
  - lib
153
131
  required_ruby_version: !ruby/object:Gem::Requirement
154
132
  requirements:
155
- - - ">="
133
+ - - '>='
156
134
  - !ruby/object:Gem::Version
157
135
  version: '0'
158
136
  required_rubygems_version: !ruby/object:Gem::Requirement
159
137
  requirements:
160
- - - ">"
138
+ - - '>'
161
139
  - !ruby/object:Gem::Version
162
140
  version: 1.3.1
163
141
  requirements: []
@@ -1,19 +0,0 @@
1
- module PageMagic
2
- class Driver
3
- attr_reader :supported_browsers, :handler
4
- def initialize(*supported_browsers, &block)
5
- @handler = block
6
- @supported_browsers = supported_browsers
7
- end
8
-
9
- def support? browser
10
- supported_browsers.include?(browser)
11
- end
12
-
13
- def build(app, browser:, options:{})
14
- options[:browser] = browser
15
- driver_clazz = handler.call
16
- driver_clazz.new(app, options)
17
- end
18
- end
19
- end
@@ -1,9 +0,0 @@
1
- module PageMagic
2
- class Drivers
3
- Poltergeist = Driver.new(:poltergeist) do
4
- require 'capybara/poltergeist'
5
- Capybara::Poltergeist::Driver
6
- end
7
- end
8
-
9
- end
@@ -1,7 +0,0 @@
1
- module PageMagic
2
- class Drivers
3
- RackTest = Driver.new(:rack_test) do
4
- Capybara::RackTest::Driver
5
- end
6
- end
7
- end
@@ -1,8 +0,0 @@
1
- module PageMagic
2
- class Drivers
3
- Selenium = Driver.new(:chrome, :firefox) do
4
- require 'watir-webdriver'
5
- Capybara::Selenium::Driver
6
- end
7
- end
8
- end
@@ -1,31 +0,0 @@
1
- require 'page_magic/driver'
2
- module PageMagic
3
- class Drivers
4
- def all
5
- @all ||=[]
6
- end
7
-
8
- def register(driver)
9
- all << driver
10
- end
11
-
12
-
13
- def find browser
14
- all.find{|driver|driver.support?(browser)}
15
- end
16
-
17
- def load path="#{__dir__}/drivers"
18
- require 'active_support/inflector'
19
-
20
- Dir["#{path}/*.rb"].each do |driver_file|
21
- require driver_file
22
- driver_name = File.basename(driver_file)[/(.*)\.rb$/, 1]
23
- register eval(driver_name.classify)
24
- end
25
- end
26
-
27
- def == other
28
- other.is_a?(Drivers) && other.all == other.all
29
- end
30
- end
31
- end
@@ -1,47 +0,0 @@
1
- require 'page_magic/driver'
2
-
3
- module PageMagic
4
- describe Driver do
5
-
6
- let(:driver_class) do
7
- Class.new do
8
- attr_reader :rack_app, :options
9
- def initialize rack_app, options
10
- @rack_app = rack_app
11
- @options = options
12
- end
13
- def == driver
14
- driver.rack_app == rack_app && driver.options == options
15
- end
16
- end
17
- end
18
- subject do
19
- described_class.new :custom_browser do
20
- driver_class
21
- end
22
- end
23
-
24
- describe '#supports?' do
25
- context 'browser is in supported browsers' do
26
- it 'returns true' do
27
- expect(subject.support?(:custom_browser)).to eq(true)
28
- end
29
- end
30
-
31
- context 'browser is not in supported browsers' do
32
- it 'returns false' do
33
- expect(subject.support?(:unsupported_browser)).to eq(false)
34
- end
35
- end
36
- end
37
- describe '#build' do
38
- it 'adds the browser to the options supplied to the driver' do
39
- expect(subject.build(:rack_app, browser: :custom_browser, options: {}).options).to eq(browser: :custom_browser)
40
- end
41
-
42
- it 'creates an instance of the supplied driver' do
43
- expect(subject.build(:rack_app,browser: :custom_browser, options: {})).to eq(driver_class.new(:rack_app, {browser: :custom_browser}))
44
- end
45
- end
46
- end
47
- end
@@ -1,10 +0,0 @@
1
- require 'page_magic/drivers/poltergeist'
2
- module PageMagic
3
- class Drivers
4
- describe Poltergeist do
5
- it %q{is capybara's poltergeist driver} do
6
- expect(described_class.build(:app, browser: :poltergeist, options:{})).to be_a(Capybara::Poltergeist::Driver)
7
- end
8
- end
9
- end
10
- end
@@ -1,10 +0,0 @@
1
- require 'page_magic/drivers/rack_test'
2
- module PageMagic
3
- class Drivers
4
- describe RackTest do
5
- it %q{is capybara's rack test driver} do
6
- expect(described_class.build(:app, browser: :rack_test, options:{})).to be_a(Capybara::RackTest::Driver)
7
- end
8
- end
9
- end
10
- end
@@ -1,10 +0,0 @@
1
- require 'page_magic/drivers/selenium'
2
- module PageMagic
3
- class Drivers
4
- describe Selenium do
5
- it 'is selenium' do
6
- expect(described_class.build(:app, browser: :selenium, options:{})).to be_a(Capybara::Selenium::Driver)
7
- end
8
- end
9
- end
10
- end
@@ -1,41 +0,0 @@
1
- require 'page_magic/drivers'
2
-
3
- module PageMagic
4
-
5
- describe Drivers do
6
- subject { described_class.new }
7
- let(:expected_driver) { Driver.new(:browser_driver) }
8
- describe '#register' do
9
- it 'stores the driver' do
10
- subject.register expected_driver
11
- expect(subject.all).to eq([expected_driver])
12
- end
13
- end
14
-
15
- describe '#find' do
16
- it 'returns the registered driver' do
17
- subject.register expected_driver
18
- expect(subject.find(:browser_driver)).to eq(expected_driver)
19
- end
20
- end
21
-
22
- describe '#load' do
23
- include_context :files
24
- it 'loads the drivers in the specified path' do
25
-
26
- class_definition=<<-RUBY
27
- class CustomDriver;
28
- def self.support? browser
29
- true
30
- end
31
- end
32
- RUBY
33
-
34
- File.write("#{scratch_dir}/custom_driver.rb", class_definition )
35
-
36
- subject.load(scratch_dir)
37
- expect(subject.find(:custom_browser)).to be(::CustomDriver)
38
- end
39
- end
40
- end
41
- end
@@ -1,44 +0,0 @@
1
- require 'page_magic'
2
-
3
- describe PageMagic do
4
- describe '::drivers' do
5
- it 'returns loaded drivers' do
6
- expected_drivers = described_class::Drivers.new.tap do |drivers|
7
- drivers.load
8
- end
9
-
10
- expect(described_class.drivers).to eq(expected_drivers)
11
- end
12
- end
13
-
14
- describe '::session' do
15
- context 'specifying the browser' do
16
- it 'loads the correct driver' do
17
- session = described_class.session(browser: :firefox)
18
- session.raw_session.driver.is_a?(Capybara::Selenium::Driver).should be_true
19
- end
20
- end
21
-
22
- context 'specifying a rack application' do
23
- it 'configures capybara to run against the app' do
24
- session = described_class.session(application: :rack_application)
25
- expect(session.raw_session.app).to be(:rack_application)
26
- end
27
- end
28
-
29
- context 'specifying options' do
30
- it 'passes the options to the browser driver' do
31
- options = {option: :config}
32
- session = described_class.session(options: options, browser: :chrome)
33
-
34
- expect(session.raw_session.driver.options).to include(options)
35
- end
36
- end
37
-
38
- context 'driver for browser not found' do
39
- it 'raises an error' do
40
- expect{described_class.session(browser: :invalid)}.to raise_exception described_class::UnspportedBrowserException
41
- end
42
- end
43
- end
44
- end