page_magic 1.2.7 → 2.0.0
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 +5 -5
- data/.rubocop.yml +23 -4
- data/.simplecov +5 -3
- data/.zsh_config +6 -0
- data/Dockerfile +11 -0
- data/Gemfile +13 -13
- data/Gemfile.lock +135 -144
- data/Makefile +17 -0
- data/README.md +48 -4
- data/Rakefile +12 -2
- data/VERSION +1 -1
- data/circle.yml +4 -2
- data/lib/active_support/core_ext/object/to_query.rb +84 -0
- data/lib/page_magic.rb +22 -20
- data/lib/page_magic/class_methods.rb +5 -2
- data/lib/page_magic/comparator.rb +37 -0
- data/lib/page_magic/comparator/fuzzy.rb +23 -0
- data/lib/page_magic/comparator/literal.rb +22 -0
- data/lib/page_magic/comparator/null.rb +26 -0
- data/lib/page_magic/comparator/parameter_map.rb +52 -0
- data/lib/page_magic/driver.rb +3 -0
- data/lib/page_magic/drivers.rb +6 -5
- data/lib/page_magic/drivers/poltergeist.rb +2 -0
- data/lib/page_magic/drivers/rack_test.rb +3 -1
- data/lib/page_magic/drivers/selenium.rb +4 -2
- data/lib/page_magic/element.rb +35 -15
- data/lib/page_magic/element/locators.rb +8 -5
- data/lib/page_magic/element/not_found.rb +38 -0
- data/lib/page_magic/element/query.rb +21 -20
- data/lib/page_magic/element/query/multiple_results.rb +21 -0
- data/lib/page_magic/element/query/prefetched_result.rb +26 -0
- data/lib/page_magic/element/query/single_result.rb +20 -0
- data/lib/page_magic/element/selector.rb +41 -16
- data/lib/page_magic/element/selector/methods.rb +18 -0
- data/lib/page_magic/element/selector/model.rb +21 -0
- data/lib/page_magic/element_context.rb +7 -21
- data/lib/page_magic/element_definition_builder.rb +20 -24
- data/lib/page_magic/elements.rb +65 -68
- data/lib/page_magic/elements/config.rb +103 -0
- data/lib/page_magic/elements/inheritance_hooks.rb +15 -0
- data/lib/page_magic/elements/types.rb +25 -0
- data/lib/page_magic/exceptions.rb +6 -1
- data/lib/page_magic/instance_methods.rb +8 -3
- data/lib/page_magic/mapping.rb +79 -0
- data/lib/page_magic/session.rb +15 -35
- data/lib/page_magic/session_methods.rb +3 -1
- data/lib/page_magic/transitions.rb +49 -0
- data/lib/page_magic/utils/string.rb +18 -0
- data/lib/page_magic/utils/url.rb +20 -0
- data/lib/page_magic/wait_methods.rb +3 -0
- data/lib/page_magic/watcher.rb +12 -17
- data/lib/page_magic/watchers.rb +31 -15
- data/page_magic.gemspec +17 -13
- data/spec/lib/active_support/core_ext/object/to_query_test.rb +78 -0
- data/spec/page_magic/class_methods_spec.rb +66 -37
- data/spec/page_magic/comparator/fuzzy_spec.rb +44 -0
- data/spec/page_magic/comparator/literal_spec.rb +41 -0
- data/spec/page_magic/comparator/null_spec.rb +35 -0
- data/spec/page_magic/comparator/parameter_map_spec.rb +75 -0
- data/spec/page_magic/driver_spec.rb +26 -28
- data/spec/page_magic/drivers/poltergeist_spec.rb +6 -7
- data/spec/page_magic/drivers/rack_test_spec.rb +6 -9
- data/spec/page_magic/drivers/selenium_spec.rb +11 -12
- data/spec/page_magic/drivers_spec.rb +38 -29
- data/spec/page_magic/element/locators_spec.rb +28 -25
- data/spec/page_magic/element/not_found_spec.rb +24 -0
- data/spec/page_magic/element/query/multiple_results_spec.rb +14 -0
- data/spec/page_magic/element/query/single_result_spec.rb +21 -0
- data/spec/page_magic/element/query_spec.rb +26 -45
- data/spec/page_magic/element/selector_spec.rb +120 -110
- data/spec/page_magic/element_context_spec.rb +47 -87
- data/spec/page_magic/element_definition_builder_spec.rb +14 -71
- data/spec/page_magic/element_spec.rb +256 -0
- data/spec/page_magic/elements/config_spec.rb +200 -0
- data/spec/page_magic/elements_spec.rb +90 -127
- data/spec/page_magic/instance_methods_spec.rb +65 -63
- data/spec/page_magic/mapping_spec.rb +181 -0
- data/spec/page_magic/session_methods_spec.rb +29 -25
- data/spec/page_magic/session_spec.rb +109 -199
- data/spec/page_magic/transitions_spec.rb +43 -0
- data/spec/page_magic/utils/string_spec.rb +29 -0
- data/spec/page_magic/utils/url_spec.rb +9 -0
- data/spec/page_magic/wait_methods_spec.rb +16 -22
- data/spec/page_magic/watcher_spec.rb +22 -0
- data/spec/page_magic/watchers_spec.rb +58 -62
- data/spec/page_magic_spec.rb +31 -30
- data/spec/spec_helper.rb +9 -2
- data/spec/support/shared_contexts.rb +3 -1
- data/spec/support/shared_examples.rb +17 -17
- metadata +101 -48
- data/lib/page_magic/element/query_builder.rb +0 -48
- data/lib/page_magic/element/selector_methods.rb +0 -13
- data/lib/page_magic/matcher.rb +0 -121
- data/spec/element_spec.rb +0 -249
- data/spec/page_magic/element/query_builder_spec.rb +0 -108
- data/spec/page_magic/matcher_spec.rb +0 -336
- data/spec/support/shared_contexts/files_context.rb +0 -7
- data/spec/support/shared_contexts/nested_elements_html_context.rb +0 -16
- data/spec/support/shared_contexts/rack_application_context.rb +0 -9
- data/spec/support/shared_contexts/webapp_fixture_context.rb +0 -39
- data/spec/watcher_spec.rb +0 -61
|
@@ -1,162 +1,125 @@
|
|
|
1
|
-
#
|
|
2
|
-
module PageMagic
|
|
3
|
-
describe Elements do
|
|
4
|
-
include_context :nested_elements_html
|
|
1
|
+
# frozen_string_literal: true
|
|
5
2
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
include Element::Locators
|
|
12
|
-
end
|
|
3
|
+
RSpec.describe PageMagic::Elements do
|
|
4
|
+
subject do
|
|
5
|
+
Class.new do
|
|
6
|
+
extend PageMagic::Elements
|
|
7
|
+
include PageMagic::Element::Locators
|
|
13
8
|
end
|
|
14
|
-
|
|
15
|
-
|
|
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)
|
|
16
20
|
end
|
|
21
|
+
end
|
|
17
22
|
|
|
18
|
-
|
|
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
|
|
19
31
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
expect(instance.element_by_name(:alias)).to eq(expected_definition)
|
|
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
|
|
28
39
|
end
|
|
29
40
|
|
|
30
|
-
context '
|
|
31
|
-
it '
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
expect(
|
|
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
|
|
35
46
|
end
|
|
36
47
|
end
|
|
48
|
+
end
|
|
37
49
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
end
|
|
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)
|
|
45
56
|
end
|
|
57
|
+
instance.element_by_name(:page_section, :arg1)
|
|
58
|
+
end
|
|
46
59
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
end
|
|
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
|
|
53
65
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
subject.element section_class, :alias
|
|
58
|
-
element_definition_builder = instance.element_by_name(:alias)
|
|
59
|
-
expect(element_definition_builder.selector).to eq(child_selector)
|
|
60
|
-
end
|
|
61
|
-
end
|
|
66
|
+
instance.element_by_name(:page_section, :arg1)
|
|
67
|
+
end
|
|
68
|
+
end
|
|
62
69
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
expect(element_definition_builder.definition_class).to be < section_class
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
+
describe 'restrictions' do
|
|
71
|
+
subject do
|
|
72
|
+
Class.new.tap do |clazz|
|
|
73
|
+
clazz.extend(described_class)
|
|
70
74
|
end
|
|
71
75
|
end
|
|
72
76
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
extend RSpec::Matchers
|
|
78
|
-
expect(parent_element).to eq(expected_element)
|
|
79
|
-
end
|
|
80
|
-
instance.element_by_name(:page_section, :arg1)
|
|
81
|
-
end
|
|
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')
|
|
82
81
|
|
|
83
|
-
|
|
84
|
-
subject.element :page_section, child_selector do |arg|
|
|
85
|
-
extend RSpec::Matchers
|
|
86
|
-
expect(arg).to eq(:arg1)
|
|
82
|
+
def hello; end
|
|
87
83
|
end
|
|
88
|
-
|
|
89
|
-
instance.element_by_name(:page_section, :arg1)
|
|
90
|
-
end
|
|
84
|
+
end.to raise_error(PageMagic::InvalidMethodNameException)
|
|
91
85
|
end
|
|
92
86
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
87
|
+
it 'does not allow element names that match method names' do
|
|
88
|
+
expect do
|
|
89
|
+
subject.class_eval do
|
|
90
|
+
def hello; end
|
|
97
91
|
|
|
98
|
-
|
|
99
|
-
expect(element_defintion_builder.element).to eq(:object)
|
|
92
|
+
link(:hello, text: 'world')
|
|
100
93
|
end
|
|
101
|
-
end
|
|
94
|
+
end.to raise_error(PageMagic::InvalidElementNameException)
|
|
102
95
|
end
|
|
103
96
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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')
|
|
108
102
|
end
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
it 'should not allow method names that match element names' do
|
|
112
|
-
expect do
|
|
113
|
-
subject.class_eval do
|
|
114
|
-
link(:hello, text: 'world')
|
|
115
|
-
|
|
116
|
-
def hello
|
|
117
|
-
end
|
|
118
|
-
end
|
|
119
|
-
end.to raise_error(InvalidMethodNameException)
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
it 'should not allow element names that match method names' do
|
|
123
|
-
expect do
|
|
124
|
-
subject.class_eval do
|
|
125
|
-
def hello
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
link(:hello, text: 'world')
|
|
129
|
-
end
|
|
130
|
-
end.to raise_error(InvalidElementNameException)
|
|
131
|
-
end
|
|
132
|
-
|
|
133
|
-
it 'should not allow duplicate element names' do
|
|
134
|
-
expect do
|
|
135
|
-
subject.class_eval do
|
|
136
|
-
link(:hello, text: 'world')
|
|
137
|
-
link(:hello, text: 'world')
|
|
138
|
-
end
|
|
139
|
-
end.to raise_error(InvalidElementNameException)
|
|
140
|
-
end
|
|
103
|
+
end.to raise_error(PageMagic::InvalidElementNameException)
|
|
104
|
+
end
|
|
141
105
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
end
|
|
147
|
-
link(:link2, :selector)
|
|
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')
|
|
148
110
|
end
|
|
111
|
+
link(:link2, :selector)
|
|
149
112
|
end
|
|
150
113
|
end
|
|
151
114
|
end
|
|
115
|
+
end
|
|
152
116
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
end
|
|
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)
|
|
160
123
|
end
|
|
161
124
|
end
|
|
162
125
|
end
|
|
@@ -1,88 +1,90 @@
|
|
|
1
|
-
|
|
2
|
-
describe InstanceMethods do
|
|
3
|
-
include_context :webapp_fixture
|
|
1
|
+
# frozen_string_literal: true
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
link(:next_page, text: 'next page')
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
subject do
|
|
14
|
-
page_class.visit(application: rack_app)
|
|
3
|
+
RSpec.describe PageMagic::InstanceMethods do
|
|
4
|
+
let(:page_class) do
|
|
5
|
+
Class.new.tap do |klass|
|
|
6
|
+
klass.include(described_class)
|
|
15
7
|
end
|
|
8
|
+
end
|
|
16
9
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
describe 'execute_on_load' do
|
|
23
|
-
it 'runs the on_load_hook in the context of self' do
|
|
24
|
-
instance = subject.current_page
|
|
25
|
-
page_class.on_load do
|
|
26
|
-
extend RSpec::Matchers
|
|
27
|
-
expect(self).to be(instance)
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
subject.execute_on_load
|
|
31
|
-
end
|
|
10
|
+
it_behaves_like 'session accessor'
|
|
11
|
+
it_behaves_like 'element watcher'
|
|
12
|
+
it_behaves_like 'waiter'
|
|
13
|
+
it_behaves_like 'element locator'
|
|
32
14
|
|
|
33
|
-
|
|
34
|
-
|
|
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
|
|
35
21
|
end
|
|
36
22
|
end
|
|
37
23
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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)
|
|
41
28
|
end
|
|
42
29
|
|
|
43
|
-
|
|
44
|
-
expect(subject.respond_to?(:next_page)).to eq(true)
|
|
45
|
-
end
|
|
30
|
+
instance.execute_on_load
|
|
46
31
|
end
|
|
47
32
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
end
|
|
33
|
+
it 'returns self' do
|
|
34
|
+
instance = page_class.new
|
|
35
|
+
expect(instance.execute_on_load).to be(instance)
|
|
52
36
|
end
|
|
37
|
+
end
|
|
53
38
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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)
|
|
58
44
|
end
|
|
45
|
+
end
|
|
59
46
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
|
64
54
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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)
|
|
68
61
|
end
|
|
69
62
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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)
|
|
74
68
|
end
|
|
69
|
+
end
|
|
75
70
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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')
|
|
80
77
|
end
|
|
78
|
+
end
|
|
81
79
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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)
|
|
86
88
|
end
|
|
87
89
|
end
|
|
88
90
|
end
|
|
@@ -0,0 +1,181 @@
|
|
|
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
|