page_magic 2.0.2 → 2.0.3

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
  SHA256:
3
- metadata.gz: 6da71e330b1c223cf3bae293c485653388c8e7db834f6c4fc3ac1de274763a46
4
- data.tar.gz: da53a97958f3a55557dfb23b0b67054d6375b0f7151777b24d0e7046d982f871
3
+ metadata.gz: c1a9811611ede317ffdd2a0bbc3a611f6eed20c8c23bd5bd7cbd355f0c66d660
4
+ data.tar.gz: 728d6cda028973338f615612b213f22c8954ea7e18322d6b4cdb078c7a9e8a9a
5
5
  SHA512:
6
- metadata.gz: 292d751ef686fad2d35b21c90c59b89b906ec1173a1d2c4ded593760e9890cd0152c535899a70fc6c887525e96b8a56b5c5708247caf8aa84fb2f768d10ebcf2
7
- data.tar.gz: b7e9e00a2c766aa9e6e98087e9e5d7bd0ac04498f256a5854667558d8e5f4bb21a22b1cdbcaa8b016ca18cc6c5521ca6169266226a89c93387228e2305f702b5
6
+ metadata.gz: 756ebdd5a0d88342fe934ef27abc8cf96bdb5ac2478dd89b421ff4d5343812d1aca9e5fde7b19bad993101f38c9ed44ecfa0a8d6d0eb8319ba87604d42da60f0
7
+ data.tar.gz: 44e72e003481db7ea23ec3716ce36f6fc8f767d805effef34c3f094c08f2ebbe3ace017bf080d56bb067653b46d4fa334d22bfdac4fe81ca98472f1a8fba9f61
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.2
1
+ 2.0.3
@@ -3,7 +3,6 @@
3
3
  require_relative '../active_support/core_ext/object/to_query'
4
4
  require_relative 'comparator'
5
5
 
6
-
7
6
  module PageMagic
8
7
  # models mapping used to relate pages to uris
9
8
  class Mapping
@@ -32,16 +32,6 @@ module PageMagic
32
32
  @current_page
33
33
  end
34
34
 
35
- # @return [String] path in the browser
36
- def current_path
37
- raw_session.current_path
38
- end
39
-
40
- # @return [String] full url in the browser
41
- def current_url
42
- raw_session.current_url
43
- end
44
-
45
35
  # Map paths to Page classes. The session will auto load page objects from these mapping when
46
36
  # the {Session#current_path}
47
37
  # is matched.
@@ -54,26 +44,22 @@ module PageMagic
54
44
  @transitions = Transitions.new(transitions)
55
45
  end
56
46
 
57
- # execute javascript on the browser
58
- # @param [String] script the script to be executed
59
- # @return [Object] object returned by the capybara execute_script method
60
- # @raise [NotSupportedException] if the capybara driver in use does not support execute script
61
- def execute_script(script)
62
- raw_session.execute_script(script)
63
- rescue Capybara::NotSupportedByDriverError
64
- raise NotSupportedException, UNSUPPORTED_OPERATION_MSG
65
- end
66
-
67
47
  # proxies unknown method calls to the currently loaded page object
68
48
  # @return [Object] returned object from the page object method call
69
49
  def method_missing(name, *args, &block)
50
+ return raw_session.send(name, *args, &block) if raw_session.respond_to?(name)
51
+
70
52
  current_page.send(name, *args, &block)
71
53
  end
72
54
 
55
+ def on?(page_class)
56
+ current_page.is_a?(page_class)
57
+ end
58
+
73
59
  # @param args see {::Object#respond_to?}
74
60
  # @return [Boolean] true if self or the current page object responds to the give method name
75
61
  def respond_to_missing?(*args)
76
- super || current_page.respond_to?(*args)
62
+ super || current_page.respond_to?(*args) || raw_session.respond_to?(*args)
77
63
  end
78
64
 
79
65
  # Direct the browser to the given page or url. {Session#current_page} will be set be an instance of the given/mapped
@@ -40,20 +40,6 @@ RSpec.describe PageMagic::Session do
40
40
  end
41
41
  end
42
42
 
43
- describe '#current_path' do
44
- it "returns the browser's current path" do
45
- browser.visit('/url')
46
- expect(session.current_path).to eq(browser.current_path)
47
- end
48
- end
49
-
50
- describe '#current_url' do
51
- it "returns the browser's current url" do
52
- browser.visit('/url')
53
- expect(session.current_url).to eq(session.current_url)
54
- end
55
- end
56
-
57
43
  describe '#define_page_mappings' do
58
44
  context 'when the mapping includes a literal' do
59
45
  it 'creates a matcher to contain the specification' do
@@ -71,22 +57,6 @@ RSpec.describe PageMagic::Session do
71
57
  end
72
58
  end
73
59
 
74
- describe '#execute_script' do
75
- it 'calls the execute script method on the capybara session' do
76
- allow(browser).to receive(:execute_script).with(:script).and_return(:result)
77
- expect(session.execute_script(:script)).to be(:result)
78
- end
79
-
80
- context 'when the Capybara session does not support #execute_script' do
81
- let(:browser) { Capybara::Driver::Base.new }
82
-
83
- it 'raises an error' do
84
- expected_message = described_class::UNSUPPORTED_OPERATION_MSG
85
- expect { session.execute_script(:script) }.to raise_error(PageMagic::NotSupportedException, expected_message)
86
- end
87
- end
88
- end
89
-
90
60
  describe '#method_missing' do
91
61
  before do
92
62
  page.class_eval do
@@ -100,6 +70,13 @@ RSpec.describe PageMagic::Session do
100
70
  session = described_class.new(browser).visit(page, url: 'http://base.url')
101
71
  expect(session.my_method).to be(:called)
102
72
  end
73
+
74
+ context 'when method not on current page' do
75
+ it 'delegates to the capybara session' do
76
+ session = described_class.new(browser).visit(page, url: 'http://base.url')
77
+ expect(session).to have_text('ok')
78
+ end
79
+ end
103
80
  end
104
81
 
105
82
  describe '#respond_to?' do
@@ -123,6 +100,13 @@ RSpec.describe PageMagic::Session do
123
100
  expect(session.respond_to?(:my_method)).to eq(true)
124
101
  end
125
102
  end
103
+
104
+ context 'when method not on self or the current page' do
105
+ it 'checks the capybara session' do
106
+ session = described_class.new(browser)
107
+ expect(session).to respond_to(:has_text?)
108
+ end
109
+ end
126
110
  end
127
111
 
128
112
  describe '#visit' do
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: 2.0.2
4
+ version: 2.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leon Davis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-02 00:00:00.000000000 Z
11
+ date: 2021-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport