page_magic 2.0.0 → 2.0.1

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
  SHA256:
3
- metadata.gz: 92b6df866c2bbcae9351e24417bf141c50101f96b74ce6a1225318998c30da9b
4
- data.tar.gz: 2a605e1c74eda006717474066d6824806a20f35ca05ddeef75d684951ebea257
3
+ metadata.gz: a818b71ddcc138a95601f724bcae9b6631bf87431a9bbd7edb0816f1bdac5fb8
4
+ data.tar.gz: 2d6a165aec8c854e49496c6375154c90aa714b97e28f00fa5cefc5d954fe8dd0
5
5
  SHA512:
6
- metadata.gz: 773b643dcf348bd77718e53e924754dd47d23e2edc1bbc1c904a82d332a66b00f9d7285c409a91be37d7ecca27cdbb11f62d6b938ea47e7a9396a2dd97a724d3
7
- data.tar.gz: 7864c97e2e3b196809835ad8a9d4ede8fd44a7ad84276a3bd06d72fb706b2400437ded32301f5e5bb299d13cbfbe2314d606c57fc1de809dfa396e3d8070de85
6
+ metadata.gz: 6145762ea0b3ddc8cea37e04957a95873b6d892798efe051d1f3e3937ebc9c6487e1ab9123dc02544190cf77ac3957197dcd0eaf14e87ce5b104c682aee21696
7
+ data.tar.gz: d5fc4d9729c2a68bab771e0f4538ed4346daa91a23a53b65cacbe8b75fff02e1ee83e68eef87f77bc5925852a2b1fbd0520e0f3bff2b85f5a2653f408c231faf
data/README.md CHANGED
@@ -56,6 +56,8 @@ Check it out :)
56
56
  - [Helper Methods](#helper-methods)
57
57
  - [Dynamic Selectors](#dynamic-selectors)
58
58
  - [Starting a session](#starting-a-session)
59
+ - [Using an existing session](#using-an-existing-session)
60
+ - [Rack applications and Rack::Test](#rack-applications-and-racktest)
59
61
  - [Page mapping](#page-mapping)
60
62
  - [Mapping against query string parameters](#mapping-against-query-string-parameters)
61
63
  - [Mapping against fragment identifiers](#mapping-against-fragment-identifiers)
@@ -325,9 +327,16 @@ session = PageMagic.session(browser: :chrome, url: 'https://www.github.com')
325
327
  ```
326
328
 
327
329
  Your session won't do much besides navigating to the given url until you have [mapped pages](#page-mapping) to it, so
328
- take a look at this next!
330
+ take a look at this next!
329
331
 
330
332
  **Note** PageMagic supports having multiple sessions using different browsers at the same time :)
333
+
334
+ ## Using an existing session
335
+ If you are introducing PageMagic in to a test suite that already makes use of Capybara, PageMagic can be configured to
336
+ make use of the session that is already configure like this:
337
+ ```ruby
338
+ session = PageMagic.session(session: Capybara.current_session)
339
+ ```
331
340
 
332
341
  ## Rack applications and Rack::Test
333
342
  To run a session against a rack application instead of a live site, simply supply the rack application when creating
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.0
1
+ 2.0.1
data/lib/page_magic.rb CHANGED
@@ -50,16 +50,21 @@ module PageMagic
50
50
  # @param [Symbol] browser name of browser
51
51
  # @param [String] url url to start the session on
52
52
  # @param [Hash] options browser driver specific options
53
+ # @param [Capybara::Session] session - use you own already configure capybara session e.g. Capybara.current_session
53
54
  # @return [Session] configured session
54
- def session(url: nil, application: nil, browser: :rack_test, options: {})
55
- driver = drivers.find(browser)
56
- raise UnsupportedBrowserException unless driver
55
+ def session(session: nil, url: nil, application: nil, browser: :rack_test, options: {})
56
+ session ||= begin
57
+ driver = drivers.find(browser)
58
+ raise UnsupportedBrowserException unless driver
57
59
 
58
- Capybara.register_driver browser do |app|
59
- driver.build(app, browser: browser, options: options)
60
+ Capybara.register_driver browser do |app|
61
+ driver.build(app, browser: browser, options: options)
62
+ end
63
+
64
+ Capybara::Session.new(browser, application)
60
65
  end
61
66
 
62
- Session.new(Capybara::Session.new(browser, application), url)
67
+ Session.new(session, url)
63
68
  end
64
69
  end
65
70
  end
@@ -89,6 +89,13 @@ RSpec.describe PageMagic do
89
89
  end
90
90
  end
91
91
 
92
+ context 'when `session` is specified' do
93
+ it 'uses it' do
94
+ session = described_class.session(session: :custom_session)
95
+ expect(session.raw_session).to be(:custom_session)
96
+ end
97
+ end
98
+
92
99
  context 'when `:options` is specified' do
93
100
  it 'passes the options to the browser driver' do
94
101
  options = { option: :config }
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: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leon Davis