page_magic 2.0.3 → 2.0.9
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 +4 -4
- data/VERSION +1 -1
- data/lib/page_magic/drivers/selenium.rb +1 -1
- data/lib/page_magic/session.rb +12 -3
- metadata +55 -90
- data/.codeclimate.yml +0 -4
- data/.pullreview.yml +0 -14
- data/.rspec +0 -1
- data/.rubocop.yml +0 -39
- data/.simplecov +0 -10
- data/.zsh_config +0 -6
- data/Dockerfile +0 -11
- data/Gemfile +0 -24
- data/Gemfile.lock +0 -178
- data/Makefile +0 -17
- data/Rakefile +0 -32
- data/circle.yml +0 -8
- data/page_magic.gemspec +0 -128
- data/spec/lib/active_support/core_ext/object/to_query_test.rb +0 -78
- data/spec/page_magic/class_methods_spec.rb +0 -92
- data/spec/page_magic/comparator/fuzzy_spec.rb +0 -44
- data/spec/page_magic/comparator/literal_spec.rb +0 -41
- data/spec/page_magic/comparator/null_spec.rb +0 -35
- data/spec/page_magic/comparator/parameter_map_spec.rb +0 -75
- data/spec/page_magic/driver_spec.rb +0 -40
- data/spec/page_magic/drivers/poltergeist_spec.rb +0 -8
- data/spec/page_magic/drivers/rack_test_spec.rb +0 -8
- data/spec/page_magic/drivers/selenium_spec.rb +0 -15
- data/spec/page_magic/drivers_spec.rb +0 -48
- data/spec/page_magic/element/locators_spec.rb +0 -36
- data/spec/page_magic/element/not_found_spec.rb +0 -24
- data/spec/page_magic/element/query/multiple_results_spec.rb +0 -14
- data/spec/page_magic/element/query/single_result_spec.rb +0 -21
- data/spec/page_magic/element/query_spec.rb +0 -38
- data/spec/page_magic/element/selector_spec.rb +0 -166
- data/spec/page_magic/element_context_spec.rb +0 -72
- data/spec/page_magic/element_definition_builder_spec.rb +0 -19
- data/spec/page_magic/element_spec.rb +0 -256
- data/spec/page_magic/elements/config_spec.rb +0 -203
- data/spec/page_magic/elements_spec.rb +0 -125
- data/spec/page_magic/instance_methods_spec.rb +0 -90
- data/spec/page_magic/mapping_spec.rb +0 -181
- data/spec/page_magic/session_methods_spec.rb +0 -40
- data/spec/page_magic/session_spec.rb +0 -149
- data/spec/page_magic/transitions_spec.rb +0 -43
- data/spec/page_magic/utils/string_spec.rb +0 -29
- data/spec/page_magic/utils/url_spec.rb +0 -9
- data/spec/page_magic/wait_methods_spec.rb +0 -35
- data/spec/page_magic/watcher_spec.rb +0 -22
- data/spec/page_magic/watchers_spec.rb +0 -80
- data/spec/page_magic_spec.rb +0 -115
- data/spec/spec_helper.rb +0 -15
- data/spec/support/shared_contexts.rb +0 -5
- data/spec/support/shared_examples.rb +0 -25
@@ -1,203 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe PageMagic::Elements::Config do
|
4
|
-
describe '.build' do
|
5
|
-
it 'sets of the type' do
|
6
|
-
options = described_class.build([], :field)
|
7
|
-
expect(options.type).to eq(:field)
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'sets the options' do
|
11
|
-
user_options = { option: 1 }
|
12
|
-
options = described_class.build([{ id: 'child' }, user_options], :field)
|
13
|
-
expect(options.options).to eq(user_options)
|
14
|
-
end
|
15
|
-
|
16
|
-
describe 'name' do
|
17
|
-
context 'when supplied' do
|
18
|
-
it 'sets it' do
|
19
|
-
options = described_class.build([:name], :field)
|
20
|
-
expect(options.name).to eq(:name)
|
21
|
-
end
|
22
|
-
|
23
|
-
context 'when an element class supplied' do
|
24
|
-
it 'uses the supplied name' do
|
25
|
-
element_class = Class.new(PageMagic::Element) do
|
26
|
-
selector({ css: 'class' })
|
27
|
-
def self.name
|
28
|
-
'PageSection'
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
options = described_class.build([:supplied_name, element_class], :field)
|
33
|
-
expect(options.name).to eq(:supplied_name)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
context 'when not supplied' do
|
39
|
-
context 'when an element class supplied' do
|
40
|
-
it 'uses the name of the class' do
|
41
|
-
element_class = Class.new(PageMagic::Element) do
|
42
|
-
selector({ css: 'class' })
|
43
|
-
def self.name
|
44
|
-
'PageSection'
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
options = described_class.build([element_class], :field)
|
49
|
-
expect(options.name).to eq(:page_section)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
describe 'selector' do
|
56
|
-
context 'when selector supplied' do
|
57
|
-
it 'sets the selector' do
|
58
|
-
options = described_class.build([{ id: 'child' }], :field)
|
59
|
-
expect(options.selector).to eq(PageMagic::Element::Selector.find(:id).build(:field, 'child'))
|
60
|
-
end
|
61
|
-
|
62
|
-
context 'when is empty hash' do
|
63
|
-
it 'raises an error' do
|
64
|
-
options = described_class.build([{}], :field)
|
65
|
-
expect { options.selector }.to raise_exception(PageMagic::InvalidConfigurationException,
|
66
|
-
described_class::INVALID_SELECTOR_MSG)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
context 'when defined on both class and as parameter' do
|
71
|
-
it 'uses the supplied selector' do
|
72
|
-
options = described_class.build([{ css: 'supplied_selector' }], :field)
|
73
|
-
options.definition_class = Class.new(PageMagic::Element) do
|
74
|
-
selector css: 'class_selector'
|
75
|
-
end
|
76
|
-
expect(options.selector).to eq(PageMagic::Element::Selector.find(:css).build(:field, 'supplied_selector'))
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
context 'when page_element class supplied' do
|
81
|
-
it 'uses the selector on the class' do
|
82
|
-
expected_selector = { css: 'class' }
|
83
|
-
element_class = Class.new(PageMagic::Element) do
|
84
|
-
selector({ css: 'class' })
|
85
|
-
def self.name
|
86
|
-
'PageSection'
|
87
|
-
end
|
88
|
-
end
|
89
|
-
options = described_class.build([element_class, expected_selector], :field)
|
90
|
-
|
91
|
-
expect(options.selector).to eq(PageMagic::Element::Selector.find(:css).build(:field, 'class'))
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
context 'when no selector supplied' do
|
97
|
-
context 'when page_element class supplied' do
|
98
|
-
it 'uses the selector on the class' do
|
99
|
-
element_class = Class.new(PageMagic::Element) do
|
100
|
-
selector({ css: 'class' })
|
101
|
-
|
102
|
-
def self.name
|
103
|
-
'PageSection'
|
104
|
-
end
|
105
|
-
end
|
106
|
-
options = described_class.build([element_class], :field)
|
107
|
-
|
108
|
-
expect(options.selector).to eq(PageMagic::Element::Selector.find(:css).build(:field, 'class'))
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
context 'when no selector on class or page_element' do
|
114
|
-
context 'when dynamically assigned element definition block' do
|
115
|
-
it 'uses it' do
|
116
|
-
options = described_class.build([], :field)
|
117
|
-
|
118
|
-
options.definition_class = Class.new(PageMagic::Element) do
|
119
|
-
selector({ css: 'class' })
|
120
|
-
end
|
121
|
-
|
122
|
-
expect(options.selector).to eq(PageMagic::Element::Selector.find(:css).build(:field, 'class'))
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
context 'when not dynamically assigned' do
|
127
|
-
it 'raises and exception' do
|
128
|
-
options = described_class.build([], :field)
|
129
|
-
options.definition_class = Class.new(PageMagic::Element)
|
130
|
-
expect { options.selector }.to raise_exception(PageMagic::InvalidConfigurationException,
|
131
|
-
described_class::INVALID_SELECTOR_MSG)
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
it 'sets prefetched options' do
|
138
|
-
options = described_class.build(%i[page_section prefetched_element], :field)
|
139
|
-
expect(options.element).to eq(:prefetched_element)
|
140
|
-
end
|
141
|
-
|
142
|
-
context 'complex elements' do
|
143
|
-
let!(:element_class) do
|
144
|
-
Class.new(PageMagic::Element) do
|
145
|
-
def self.name
|
146
|
-
'PageSection'
|
147
|
-
end
|
148
|
-
end
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
describe '.validate!' do
|
154
|
-
let(:options) do
|
155
|
-
{
|
156
|
-
type: :type,
|
157
|
-
selector: { css: 'css' },
|
158
|
-
element: :object,
|
159
|
-
element_class: Class.new(PageMagic::Element)
|
160
|
-
}
|
161
|
-
end
|
162
|
-
|
163
|
-
context 'when type nil' do
|
164
|
-
it 'raise an error' do
|
165
|
-
subject = described_class.new(options.except(:type))
|
166
|
-
expect { subject.validate! }.to raise_exception(PageMagic::InvalidConfigurationException,
|
167
|
-
described_class::TYPE_REQUIRED_MESSAGE)
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
describe '`element_class`' do
|
172
|
-
context 'when nil' do
|
173
|
-
it 'raise and error' do
|
174
|
-
subject = described_class.new(options.except(:element_class))
|
175
|
-
expect { subject.validate! }.to raise_exception(PageMagic::InvalidConfigurationException,
|
176
|
-
described_class::INVALID_ELEMENT_CLASS_MSG)
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
context 'not a type of `PageMagic::Element`' do
|
181
|
-
it 'raise and error' do
|
182
|
-
subject = described_class.new(options.update(element_class: Object))
|
183
|
-
expect { subject.validate! }.to raise_exception(PageMagic::InvalidConfigurationException,
|
184
|
-
described_class::INVALID_ELEMENT_CLASS_MSG)
|
185
|
-
end
|
186
|
-
end
|
187
|
-
end
|
188
|
-
end
|
189
|
-
|
190
|
-
describe '#selector' do
|
191
|
-
it 'returns a selector' do
|
192
|
-
input_options = {
|
193
|
-
type: :type,
|
194
|
-
selector: { css: 'css' },
|
195
|
-
options: { a: :b },
|
196
|
-
element: :object,
|
197
|
-
element_class: Class.new(PageMagic::Element)
|
198
|
-
}
|
199
|
-
options = described_class.new(input_options)
|
200
|
-
expect(options.selector).to eq(PageMagic::Element::Selector.find(:css).build(:type, 'css', options: { a: :b }))
|
201
|
-
end
|
202
|
-
end
|
203
|
-
end
|
@@ -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
|