page_magic 2.0.6 → 2.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/lib/page_magic/session.rb +0 -6
  4. metadata +55 -90
  5. data/.codeclimate.yml +0 -4
  6. data/.pullreview.yml +0 -14
  7. data/.rspec +0 -1
  8. data/.rubocop.yml +0 -39
  9. data/.simplecov +0 -10
  10. data/.zsh_config +0 -6
  11. data/Dockerfile +0 -11
  12. data/Gemfile +0 -24
  13. data/Gemfile.lock +0 -175
  14. data/Makefile +0 -17
  15. data/Rakefile +0 -32
  16. data/circle.yml +0 -8
  17. data/page_magic.gemspec +0 -128
  18. data/spec/lib/active_support/core_ext/object/to_query_test.rb +0 -78
  19. data/spec/page_magic/class_methods_spec.rb +0 -92
  20. data/spec/page_magic/comparator/fuzzy_spec.rb +0 -44
  21. data/spec/page_magic/comparator/literal_spec.rb +0 -41
  22. data/spec/page_magic/comparator/null_spec.rb +0 -35
  23. data/spec/page_magic/comparator/parameter_map_spec.rb +0 -75
  24. data/spec/page_magic/driver_spec.rb +0 -40
  25. data/spec/page_magic/drivers/poltergeist_spec.rb +0 -8
  26. data/spec/page_magic/drivers/rack_test_spec.rb +0 -8
  27. data/spec/page_magic/drivers/selenium_spec.rb +0 -15
  28. data/spec/page_magic/drivers_spec.rb +0 -48
  29. data/spec/page_magic/element/locators_spec.rb +0 -36
  30. data/spec/page_magic/element/not_found_spec.rb +0 -24
  31. data/spec/page_magic/element/query/multiple_results_spec.rb +0 -14
  32. data/spec/page_magic/element/query/single_result_spec.rb +0 -21
  33. data/spec/page_magic/element/query_spec.rb +0 -38
  34. data/spec/page_magic/element/selector_spec.rb +0 -166
  35. data/spec/page_magic/element_context_spec.rb +0 -72
  36. data/spec/page_magic/element_definition_builder_spec.rb +0 -19
  37. data/spec/page_magic/element_spec.rb +0 -256
  38. data/spec/page_magic/elements/config_spec.rb +0 -203
  39. data/spec/page_magic/elements_spec.rb +0 -125
  40. data/spec/page_magic/instance_methods_spec.rb +0 -90
  41. data/spec/page_magic/mapping_spec.rb +0 -181
  42. data/spec/page_magic/session_methods_spec.rb +0 -40
  43. data/spec/page_magic/session_spec.rb +0 -164
  44. data/spec/page_magic/transitions_spec.rb +0 -43
  45. data/spec/page_magic/utils/string_spec.rb +0 -29
  46. data/spec/page_magic/utils/url_spec.rb +0 -9
  47. data/spec/page_magic/wait_methods_spec.rb +0 -35
  48. data/spec/page_magic/watcher_spec.rb +0 -22
  49. data/spec/page_magic/watchers_spec.rb +0 -80
  50. data/spec/page_magic_spec.rb +0 -115
  51. data/spec/spec_helper.rb +0 -15
  52. data/spec/support/shared_contexts.rb +0 -5
  53. data/spec/support/shared_examples.rb +0 -25
@@ -1,125 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe PageMagic::Elements do
4
- subject do
5
- Class.new do
6
- extend PageMagic::Elements
7
- include PageMagic::Element::Locators
8
- end
9
- end
10
-
11
- let(:instance) do
12
- subject.new
13
- end
14
- let(:child_selector) { { id: 'child' } }
15
-
16
- context 'element types' do
17
- it 'provides all of the type provided by capybara' do
18
- capybara_elements = Capybara::Selector.all.except(*%i[element datalist_input datalist_option id xpath css]).keys
19
- expect(described_class::TYPES).to include(*capybara_elements)
20
- end
21
- end
22
-
23
- describe '#element' do
24
- it 'converts arguments in to options' do
25
- allow(PageMagic::Elements::Config)
26
- .to receive(:build)
27
- .with([:alias, child_selector, { visible: true }], :text_field)
28
- .and_call_original
29
- subject.text_fields :alias, child_selector, visible: true
30
- end
31
-
32
- context 'complex elements' do
33
- let!(:section_class) do
34
- Class.new(PageMagic::Element) do
35
- def self.name
36
- 'PageSection'
37
- end
38
- end
39
- end
40
-
41
- context 'using a predefined class' do
42
- it 'adds an element using that class section' do
43
- subject.element section_class, :page_section, child_selector
44
- element_definition_builder = instance.element_by_name(:page_section)
45
- expect(element_definition_builder.send(:definition_class)).to be < section_class
46
- end
47
- end
48
- end
49
-
50
- context 'using a block' do
51
- it 'passes the parent element in as the last argument' do
52
- expected_element = instance
53
- subject.element :page_section, child_selector do |_arg1|
54
- extend RSpec::Matchers
55
- expect(parent_element).to eq(expected_element)
56
- end
57
- instance.element_by_name(:page_section, :arg1)
58
- end
59
-
60
- it 'passes args through to the block' do
61
- subject.element :page_section, child_selector do |arg|
62
- extend RSpec::Matchers
63
- expect(arg).to eq(:arg1)
64
- end
65
-
66
- instance.element_by_name(:page_section, :arg1)
67
- end
68
- end
69
-
70
- describe 'restrictions' do
71
- subject do
72
- Class.new.tap do |clazz|
73
- clazz.extend(described_class)
74
- end
75
- end
76
-
77
- it 'does not allow method names that match element names' do
78
- expect do
79
- subject.class_eval do
80
- link(:hello, text: 'world')
81
-
82
- def hello; end
83
- end
84
- end.to raise_error(PageMagic::InvalidMethodNameException)
85
- end
86
-
87
- it 'does not allow element names that match method names' do
88
- expect do
89
- subject.class_eval do
90
- def hello; end
91
-
92
- link(:hello, text: 'world')
93
- end
94
- end.to raise_error(PageMagic::InvalidElementNameException)
95
- end
96
-
97
- it 'does not allow duplicate element names' do
98
- expect do
99
- subject.class_eval do
100
- link(:hello, text: 'world')
101
- link(:hello, text: 'world')
102
- end
103
- end.to raise_error(PageMagic::InvalidElementNameException)
104
- end
105
-
106
- it 'does not evaluate the elements when applying naming checks' do
107
- subject.class_eval do
108
- link(:link1, :selector) do
109
- raise('should not have been evaluated')
110
- end
111
- link(:link2, :selector)
112
- end
113
- end
114
- end
115
- end
116
-
117
- describe '#element_definitions' do
118
- it 'returns your a copy of the core definition' do
119
- subject.text_field :alias, child_selector
120
- first = instance.element_by_name(:alias)
121
- second = instance.element_by_name(:alias)
122
- expect(first).not_to equal(second)
123
- end
124
- end
125
- end
@@ -1,90 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe PageMagic::InstanceMethods do
4
- let(:page_class) do
5
- Class.new.tap do |klass|
6
- klass.include(described_class)
7
- end
8
- end
9
-
10
- it_behaves_like 'session accessor'
11
- it_behaves_like 'element watcher'
12
- it_behaves_like 'waiter'
13
- it_behaves_like 'element locator'
14
-
15
- describe 'execute_on_load' do
16
- let(:page_class) do
17
- Class.new.tap do |klass|
18
- klass.extend(PageMagic::ClassMethods)
19
- klass.include(described_class)
20
- klass.include RSpec::Matchers
21
- end
22
- end
23
-
24
- it 'runs the on_load_hook in the context of self' do
25
- instance = page_class.new
26
- page_class.on_load do
27
- expect(self).to be(instance)
28
- end
29
-
30
- instance.execute_on_load
31
- end
32
-
33
- it 'returns self' do
34
- instance = page_class.new
35
- expect(instance.execute_on_load).to be(instance)
36
- end
37
- end
38
-
39
- describe '#respond_to?' do
40
- it 'checks element definitions' do
41
- instance = page_class.new
42
- allow(instance).to receive(:contains_element?).and_return(true)
43
- expect(instance).to respond_to(:next_page)
44
- end
45
- end
46
-
47
- describe '#text' do
48
- it 'returns the text on the page' do
49
- session = PageMagic::Session.new(instance_double(Capybara::Session, text: 'text'))
50
- instance = page_class.new(session)
51
- expect(instance.text).to eq('text')
52
- end
53
- end
54
-
55
- describe '#text_on_page?' do
56
- it 'returns true if the text is present' do
57
- session = PageMagic::Session.new(instance_double(Capybara::Session, text: 'text'))
58
- instance = page_class.new(session)
59
-
60
- expect(instance.text_on_page?('text')).to eq(true)
61
- end
62
-
63
- it 'returns false if the text is not present' do
64
- session = PageMagic::Session.new(instance_double(Capybara::Session, text: 'text'))
65
- instance = page_class.new(session)
66
-
67
- expect(instance.text_on_page?('not on page')).to eq(false)
68
- end
69
- end
70
-
71
- describe 'title' do
72
- it 'returns the title' do
73
- session = PageMagic::Session.new(instance_double(Capybara::Session, title: 'page1'))
74
- instance = page_class.new(session)
75
-
76
- expect(instance.title).to eq('page1')
77
- end
78
- end
79
-
80
- describe 'method_missing' do
81
- let(:spy_element_context) { spy }
82
-
83
- it 'gives access to element definitions' do
84
- instance = page_class.new
85
- allow(PageMagic::ElementContext).to receive(:new).with(instance).and_return(spy_element_context)
86
- instance.next_page(:arg1, :arg2)
87
- expect(spy_element_context).to have_received(:next_page).with(:arg1, :arg2)
88
- end
89
- end
90
- end
@@ -1,181 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe PageMagic::Mapping do
4
- describe '#can_compute_uri?' do
5
- context 'when there is a regex in the path' do
6
- it 'returns false' do
7
- expect(described_class.new(//).can_compute_uri?).to eq(false)
8
- end
9
- end
10
-
11
- context 'when there is a regex in `parameters`' do
12
- it 'returns false' do
13
- expect(described_class.new(parameters: { param: // }).can_compute_uri?).to eq(false)
14
- end
15
- end
16
-
17
- context 'when there is a regexp in `fragment`' do
18
- it 'returns false' do
19
- expect(described_class.new(fragment: //).can_compute_uri?).to eq(false)
20
- end
21
- end
22
-
23
- context 'when matching element is a regexp' do
24
- it 'returns true' do
25
- expect(described_class.new('/').can_compute_uri?).to eq(true)
26
- end
27
- end
28
- end
29
-
30
- describe '<=>' do
31
- context 'when other does not have a `path`' do
32
- it 'is greater' do
33
- expect(described_class.new('/') <=> described_class.new(parameters: {})).to be 1
34
- end
35
- end
36
-
37
- context 'other has a `path`' do
38
- it 'compares them' do
39
- expect(described_class.new('/', parameters: { param: 1 }) <=> described_class.new('/')).to be 1
40
- end
41
-
42
- context 'other has does not have a fragment' do
43
- it 'is lesser' do
44
- expect(described_class.new('/', parameters: { param: 1 },
45
- fragment: '') <=> described_class.new('/', parameters: { param: 1 })).to be 1
46
- end
47
- end
48
-
49
- context 'other has a fragment' do
50
- it 'is compares them' do
51
- expect(described_class.new('/', parameters: { param: 1 },
52
- fragment: '') <=> described_class.new('/', parameters: { param: 1 },
53
- fragment: //)).to be 1
54
- end
55
- end
56
- end
57
- end
58
-
59
- describe 'compute_uri' do
60
- context 'when path present' do
61
- it 'returns a uri' do
62
- expect(described_class.new('/').compute_uri).to eq('/')
63
- end
64
- end
65
-
66
- context 'when matching on parameters' do
67
- context 'when matching on 1 parameter' do
68
- it 'returns a uri' do
69
- expect(described_class.new(parameters: { a: 1 }).compute_uri).to eq('?a=1')
70
- end
71
- end
72
-
73
- context 'when matching on more than 1 parameter' do
74
- it 'returns a uri' do
75
- expect(described_class.new(parameters: { a: 1, b: 2 }).compute_uri).to eq('?a=1&b=2')
76
- end
77
- end
78
- end
79
-
80
- context 'when matching on a fragment' do
81
- it 'returns a uri' do
82
- expect(described_class.new(fragment: 'fragment').compute_uri).to eq('#fragment')
83
- end
84
- end
85
- end
86
-
87
- describe '#matches?' do
88
- let(:matching_url) { 'http://www.example.com/path?foo=bar#fragment' }
89
- let(:incompatible_url) { 'http://www.example.com/mismatch?miss=match#mismatch' }
90
-
91
- context 'when matching on path' do
92
- context 'when using a literal' do
93
- subject do
94
- described_class.new('/path')
95
- end
96
-
97
- it 'returns true for an exact match' do
98
- expect(subject.match?(matching_url)).to eq(true)
99
- end
100
-
101
- it 'returns false when not an exact match' do
102
- expect(subject.match?(incompatible_url)).to eq(false)
103
- end
104
- end
105
-
106
- context 'when using a regexp' do
107
- subject do
108
- described_class.new(/\d/)
109
- end
110
-
111
- it 'returns true for a match on the regexp' do
112
- expect(subject.match?('3')).to eq(true)
113
- end
114
-
115
- it 'returns false when regexp is not a match' do
116
- expect(subject.match?('/mismatch')).to eq(false)
117
- end
118
- end
119
- end
120
-
121
- context 'when matching on the query string' do
122
- context 'parameter requirement is a literal' do
123
- subject do
124
- described_class.new(parameters: { foo: 'bar' })
125
- end
126
-
127
- it 'returns true for a match' do
128
- expect(subject.match?(matching_url)).to eq(true)
129
- end
130
-
131
- it 'returns false when regexp is not a match' do
132
- expect(subject.match?(incompatible_url)).to eq(false)
133
- end
134
- end
135
-
136
- context 'when matching on parameters' do
137
- subject do
138
- described_class.new(parameters: { foo: /bar/ })
139
- end
140
-
141
- it 'returns true for a match on the regexp' do
142
- expect(subject.match?(matching_url)).to eq(true)
143
- end
144
-
145
- it 'returns false when regexp is not a match' do
146
- expect(subject.match?(incompatible_url)).to eq(false)
147
- end
148
- end
149
- end
150
-
151
- context 'when matching on the fragment' do
152
- context 'when the fragment requirement is a literal' do
153
- subject do
154
- described_class.new(fragment: 'fragment')
155
- end
156
-
157
- it 'returns true for a match' do
158
- expect(subject.match?(matching_url)).to eq(true)
159
- end
160
-
161
- it 'returns false when regexp is not a match' do
162
- expect(subject.match?(incompatible_url)).to eq(false)
163
- end
164
- end
165
-
166
- context 'when the fragment requirement is a regexp' do
167
- subject do
168
- described_class.new(fragment: /fragment/)
169
- end
170
-
171
- it 'returns true for a match on the regexp' do
172
- expect(subject.match?(matching_url)).to eq(true)
173
- end
174
-
175
- it 'returns false when regexp is not a match' do
176
- expect(subject.match?(incompatible_url)).to eq(false)
177
- end
178
- end
179
- end
180
- end
181
- end
@@ -1,40 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'ostruct'
4
- RSpec.describe PageMagic::SessionMethods do
5
- subject(:session_methods) do
6
- OpenStruct.new(session: session).tap do |o|
7
- o.extend(described_class)
8
- end
9
- end
10
-
11
- let(:session) do
12
- rack_app = instance_double(Proc, call: [200, {}, ['<html><head><title>page1</title></head></html>']])
13
- PageMagic.session(application: rack_app, url: '/page1')
14
- end
15
-
16
- describe '#execute_script' do
17
- it 'returns the output of Session#execute_script' do
18
- allow(session.raw_session).to receive(:execute_script).with(:script).and_return(:result)
19
- expect(session_methods.execute_script(:script)).to eq(:result)
20
- end
21
- end
22
-
23
- describe '#page' do
24
- it 'returns the current page of the session' do
25
- expect(session_methods.page).to eq(session.current_page)
26
- end
27
- end
28
-
29
- describe '#path' do
30
- it 'returns the path of the session' do
31
- expect(session_methods.path).to eq(session.current_path)
32
- end
33
- end
34
-
35
- describe '#url' do
36
- it 'returns the url of the session' do
37
- expect(session_methods.url).to eq(session.current_url)
38
- end
39
- end
40
- end
@@ -1,164 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe PageMagic::Session do
4
- subject(:session) { described_class.new(browser, 'http://base.url') }
5
-
6
- let(:page) do
7
- Class.new do
8
- include PageMagic
9
- end
10
- end
11
-
12
- let(:browser) do
13
- rack_application = Class.new do
14
- def self.call(_env)
15
- [200, {}, ['ok']]
16
- end
17
- end
18
-
19
- Capybara::Session.new(:rack_test, rack_application)
20
- end
21
-
22
- describe '#current_page' do
23
- let(:another_page_class) do
24
- Class.new do
25
- include PageMagic
26
- end
27
- end
28
-
29
- it 'returns the current page' do
30
- session.visit(page, url: 'http://base.url')
31
- expect(session.current_page).to be_an_instance_of(page)
32
- end
33
-
34
- context 'when the page url has changed' do
35
- it 'returns the mapped page object' do
36
- session.define_page_mappings '/another_page1' => another_page_class
37
- browser.visit('/another_page1')
38
- expect(session.current_page).to be_an_instance_of(another_page_class)
39
- end
40
- end
41
- end
42
-
43
- describe '#define_page_mappings' do
44
- context 'when the mapping includes a literal' do
45
- it 'creates a matcher to contain the specification' do
46
- session.define_page_mappings path: :page
47
- expect(session.transitions.to_h).to include(PageMagic::Mapping.new(:path) => :page)
48
- end
49
- end
50
-
51
- context 'when the mapping is a matcher' do
52
- it 'leaves it intact' do
53
- expected_matcher = PageMagic::Mapping.new(:page)
54
- session.define_page_mappings expected_matcher => :page
55
- expect(session.transitions.key(:page)).to be(expected_matcher)
56
- end
57
- end
58
- end
59
-
60
- describe '#method_missing' do
61
- before do
62
- page.class_eval do
63
- def my_method
64
- :called
65
- end
66
- end
67
- end
68
-
69
- it 'delegates to current page' do
70
- session = described_class.new(browser).visit(page, url: 'http://base.url')
71
- expect(session.my_method).to be(:called)
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
80
- end
81
-
82
- describe '#is_a?' do
83
- context 'when other is a `Capybara::Session`' do
84
- it 'returns true' do
85
- expect(described_class.new(browser).is_a?(Capybara::Session)).to eq(true)
86
- end
87
- end
88
- end
89
-
90
- describe '#respond_to?' do
91
- it 'checks self' do
92
- session = described_class.new(browser)
93
- expect(session.respond_to?(:current_url)).to eq(true)
94
- end
95
-
96
- context 'when method is not on self' do
97
- before do
98
- page.class_eval do
99
- def my_method
100
- :called
101
- end
102
- end
103
- end
104
-
105
- it 'checks the current page' do
106
- session = described_class.new(browser)
107
- session.visit(page, url: '/')
108
- expect(session.respond_to?(:my_method)).to eq(true)
109
- end
110
- end
111
-
112
- context 'when method not on self or the current page' do
113
- it 'checks the capybara session' do
114
- session = described_class.new(browser)
115
- expect(session).to respond_to(:has_text?)
116
- end
117
- end
118
- end
119
-
120
- describe '#visit' do
121
- context 'when a page is supplied' do
122
- it 'sets the current page' do
123
- session.define_page_mappings '/page' => page
124
- session.visit(page)
125
- expect(session.current_page).to be_a(page)
126
- end
127
-
128
- it 'uses the base url and the path in the page mappings' do
129
- session = described_class.new(browser, 'http://base.url')
130
- session.define_page_mappings '/page' => page
131
- session.visit(page)
132
- expect(session.current_url).to eq('http://base.url/page')
133
- end
134
-
135
- it 'raises an error when page no page mappings are found' do
136
- expect do
137
- session.visit(page)
138
- end.to raise_exception PageMagic::InvalidURLException, described_class::URL_MISSING_MSG
139
- end
140
-
141
- it 'calls the onload hook' do
142
- on_load_hook_called = false
143
- page.on_load { on_load_hook_called = true }
144
- session.visit(page, url: 'http://base.url')
145
- expect(on_load_hook_called).to eq(true)
146
- end
147
- end
148
-
149
- context 'when a page and `:url` supplied' do
150
- it 'uses the url' do
151
- session.visit(page, url: 'http://other.url/')
152
- expect(session.current_url).to eq('http://other.url/')
153
- end
154
- end
155
-
156
- context 'when `url` is supplied' do
157
- it 'visits that url' do
158
- expected_url = 'http://base.url/page'
159
- session.visit(expected_url)
160
- expect(browser.current_url).to eq(expected_url)
161
- end
162
- end
163
- end
164
- end