page_magic 2.0.0.alpha1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +5 -2
  3. data/.zsh_config +5 -5
  4. data/Dockerfile +2 -1
  5. data/Gemfile +2 -1
  6. data/Gemfile.lock +9 -5
  7. data/Makefile +7 -3
  8. data/README.md +16 -4
  9. data/VERSION +1 -1
  10. data/lib/active_support/core_ext/object/to_query.rb +6 -6
  11. data/lib/page_magic.rb +15 -16
  12. data/lib/page_magic/class_methods.rb +1 -1
  13. data/lib/page_magic/comparator.rb +37 -0
  14. data/lib/page_magic/comparator/fuzzy.rb +23 -0
  15. data/lib/page_magic/comparator/literal.rb +22 -0
  16. data/lib/page_magic/comparator/null.rb +26 -0
  17. data/lib/page_magic/comparator/parameter_map.rb +52 -0
  18. data/lib/page_magic/drivers.rb +2 -2
  19. data/lib/page_magic/element.rb +19 -8
  20. data/lib/page_magic/element/locators.rb +4 -4
  21. data/lib/page_magic/element/not_found.rb +38 -0
  22. data/lib/page_magic/element/query.rb +19 -27
  23. data/lib/page_magic/element/query/multiple_results.rb +21 -0
  24. data/lib/page_magic/element/query/prefetched_result.rb +26 -0
  25. data/lib/page_magic/element/query/single_result.rb +20 -0
  26. data/lib/page_magic/element/selector.rb +38 -16
  27. data/lib/page_magic/element/selector/methods.rb +18 -0
  28. data/lib/page_magic/element/selector/model.rb +21 -0
  29. data/lib/page_magic/element_context.rb +5 -21
  30. data/lib/page_magic/element_definition_builder.rb +17 -24
  31. data/lib/page_magic/elements.rb +62 -102
  32. data/lib/page_magic/elements/config.rb +103 -0
  33. data/lib/page_magic/elements/inheritance_hooks.rb +15 -0
  34. data/lib/page_magic/elements/types.rb +25 -0
  35. data/lib/page_magic/exceptions.rb +3 -0
  36. data/lib/page_magic/instance_methods.rb +2 -2
  37. data/lib/page_magic/mapping.rb +79 -0
  38. data/lib/page_magic/session.rb +10 -32
  39. data/lib/page_magic/session_methods.rb +1 -1
  40. data/lib/page_magic/transitions.rb +49 -0
  41. data/lib/page_magic/utils/string.rb +4 -0
  42. data/lib/page_magic/utils/url.rb +20 -0
  43. data/lib/page_magic/watcher.rb +10 -17
  44. data/lib/page_magic/watchers.rb +28 -15
  45. data/spec/page_magic/class_methods_spec.rb +64 -37
  46. data/spec/page_magic/comparator/fuzzy_spec.rb +44 -0
  47. data/spec/page_magic/comparator/literal_spec.rb +41 -0
  48. data/spec/page_magic/comparator/null_spec.rb +35 -0
  49. data/spec/page_magic/comparator/parameter_map_spec.rb +75 -0
  50. data/spec/page_magic/driver_spec.rb +25 -29
  51. data/spec/page_magic/drivers/poltergeist_spec.rb +4 -7
  52. data/spec/page_magic/drivers/rack_test_spec.rb +4 -9
  53. data/spec/page_magic/drivers/selenium_spec.rb +9 -12
  54. data/spec/page_magic/drivers_spec.rb +36 -29
  55. data/spec/page_magic/element/locators_spec.rb +26 -25
  56. data/spec/page_magic/element/not_found_spec.rb +24 -0
  57. data/spec/page_magic/element/query/multiple_results_spec.rb +14 -0
  58. data/spec/page_magic/element/query/single_result_spec.rb +21 -0
  59. data/spec/page_magic/element/query_spec.rb +26 -47
  60. data/spec/page_magic/element/selector_spec.rb +118 -110
  61. data/spec/page_magic/element_context_spec.rb +46 -88
  62. data/spec/page_magic/element_definition_builder_spec.rb +12 -71
  63. data/spec/page_magic/element_spec.rb +256 -0
  64. data/spec/page_magic/elements/config_spec.rb +200 -0
  65. data/spec/page_magic/elements_spec.rb +87 -138
  66. data/spec/page_magic/instance_methods_spec.rb +63 -63
  67. data/spec/page_magic/mapping_spec.rb +181 -0
  68. data/spec/page_magic/session_methods_spec.rb +27 -25
  69. data/spec/page_magic/session_spec.rb +109 -198
  70. data/spec/page_magic/transitions_spec.rb +43 -0
  71. data/spec/page_magic/utils/string_spec.rb +20 -27
  72. data/spec/page_magic/utils/url_spec.rb +9 -0
  73. data/spec/page_magic/wait_methods_spec.rb +14 -22
  74. data/spec/page_magic/watcher_spec.rb +22 -0
  75. data/spec/page_magic/watchers_spec.rb +56 -62
  76. data/spec/page_magic_spec.rb +27 -24
  77. data/spec/spec_helper.rb +7 -3
  78. data/spec/support/shared_examples.rb +15 -17
  79. metadata +48 -15
  80. data/lib/page_magic/element/query_builder.rb +0 -61
  81. data/lib/page_magic/element/selector_methods.rb +0 -16
  82. data/lib/page_magic/matcher.rb +0 -130
  83. data/spec/element_spec.rb +0 -251
  84. data/spec/page_magic/element/query_builder_spec.rb +0 -110
  85. data/spec/page_magic/matcher_spec.rb +0 -338
  86. data/spec/support/shared_contexts/files_context.rb +0 -9
  87. data/spec/support/shared_contexts/nested_elements_html_context.rb +0 -18
  88. data/spec/support/shared_contexts/rack_application_context.rb +0 -11
  89. data/spec/support/shared_contexts/webapp_fixture_context.rb +0 -41
  90. data/spec/watcher_spec.rb +0 -64
@@ -1,176 +1,125 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # rubocop:disable Metrics/ModuleLength
4
- module PageMagic
5
- describe Elements do
6
- include_context :nested_elements_html
7
-
8
- let(:page) { double(init: nested_elements_node) }
9
-
10
- subject do
11
- Class.new do
12
- extend Elements
13
- include Element::Locators
14
- end
15
- end
16
- let(:instance) do
17
- subject.new
3
+ RSpec.describe PageMagic::Elements do
4
+ subject do
5
+ Class.new do
6
+ extend PageMagic::Elements
7
+ include PageMagic::Element::Locators
18
8
  end
9
+ end
19
10
 
20
- let(:child_selector) { { id: 'child' } }
11
+ let(:instance) do
12
+ subject.new
13
+ end
14
+ let(:child_selector) { { id: 'child' } }
21
15
 
22
- context 'element types' do
23
- it 'provides all of the type provided by capybara' do
24
- capybara_elements = Capybara::Selector.all.except(*%i[element datalist_input datalist_option id xpath css]).keys
25
- expect(described_class::TYPES).to include(*capybara_elements)
26
- end
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)
27
20
  end
21
+ end
28
22
 
29
- describe '#element' do
30
- it 'sets the selector and type' do
31
- expected_definition = ElementDefinitionBuilder.new(definition_class: Element,
32
- type: :text_field,
33
- selector: child_selector,
34
- options: { multiple_results: false })
35
- subject.text_field :alias, child_selector
36
- expect(instance.element_by_name(:alias)).to eq(expected_definition)
37
- end
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
38
31
 
39
- context 'options' do
40
- it 'puts them on the builder' do
41
- options = { my: :options }
42
- subject.text_field :alias, child_selector, options
43
- expect(instance.element_by_name(:alias).options).to eq(options)
32
+ context 'complex elements' do
33
+ let!(:section_class) do
34
+ Class.new(PageMagic::Element) do
35
+ def self.name
36
+ 'PageSection'
37
+ end
44
38
  end
45
39
  end
46
40
 
47
- context 'complex elements' do
48
- let!(:section_class) do
49
- Class.new(Element) do
50
- def self.name
51
- 'PageSection'
52
- end
53
- end
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
54
46
  end
47
+ end
48
+ end
55
49
 
56
- context 'using a predefined class' do
57
- it 'should add an element using that class section' do
58
- subject.element section_class, :page_section, child_selector
59
- element_definition_builder = instance.element_by_name(:page_section)
60
- expect(element_definition_builder.definition_class).to be < section_class
61
- end
62
-
63
- context 'with no selector supplied' do
64
- it 'defaults the selector to the one on the class' do
65
- section_class.selector child_selector
66
- subject.element section_class, :alias
67
- element_definition_builder = instance.element_by_name(:alias)
68
- expect(element_definition_builder.selector).to eq(child_selector)
69
- end
70
- end
71
-
72
- context 'with no name supplied' do
73
- it 'should default to the name of the class if one is not supplied' do
74
- subject.element section_class, child_selector
75
- element_definition_builder = instance.element_by_name(:page_section)
76
- expect(element_definition_builder.definition_class).to be < section_class
77
- end
78
- 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)
79
56
  end
57
+ instance.element_by_name(:page_section, :arg1)
80
58
  end
81
59
 
82
- context 'using a block' do
83
- it 'passes the parent element in as the last argument' do
84
- expected_element = instance
85
- subject.element :page_section, child_selector do |_arg1|
86
- extend RSpec::Matchers
87
- expect(parent_element).to eq(expected_element)
88
- end
89
- instance.element_by_name(:page_section, :arg1)
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)
90
64
  end
91
65
 
92
- it 'should pass args through to the block' do
93
- subject.element :page_section, child_selector do |arg|
94
- extend RSpec::Matchers
95
- expect(arg).to eq(:arg1)
96
- end
66
+ instance.element_by_name(:page_section, :arg1)
67
+ end
68
+ end
97
69
 
98
- instance.element_by_name(:page_section, :arg1)
70
+ describe 'restrictions' do
71
+ subject do
72
+ Class.new.tap do |clazz|
73
+ clazz.extend(described_class)
99
74
  end
100
75
  end
101
76
 
102
- describe 'location' do
103
- context 'a prefetched object' do
104
- it 'should add a section' do
105
- subject.element :page_section, :object
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')
106
81
 
107
- element_defintion_builder = instance.element_by_name(:page_section)
108
- expect(element_defintion_builder.element).to eq(:object)
82
+ def hello; end
109
83
  end
110
- end
84
+ end.to raise_error(PageMagic::InvalidMethodNameException)
111
85
  end
112
86
 
113
- describe 'restrictions' do
114
- subject do
115
- Class.new.tap do |clazz|
116
- clazz.extend(described_class)
117
- end
118
- end
119
-
120
- it 'should not allow method names that match element names' do
121
- expect do
122
- subject.class_eval do
123
- link(:hello, text: 'world')
124
-
125
- def hello; end
126
- end
127
- end.to raise_error(InvalidMethodNameException)
128
- end
129
-
130
- it 'should not allow element names that match method names' do
131
- expect do
132
- subject.class_eval do
133
- def hello; end
134
-
135
- link(:hello, text: 'world')
136
- end
137
- end.to raise_error(InvalidElementNameException)
138
- end
87
+ it 'does not allow element names that match method names' do
88
+ expect do
89
+ subject.class_eval do
90
+ def hello; end
139
91
 
140
- it 'should not allow duplicate element names' do
141
- expect do
142
- subject.class_eval do
143
- link(:hello, text: 'world')
144
- link(:hello, text: 'world')
145
- end
146
- end.to raise_error(InvalidElementNameException)
147
- end
92
+ link(:hello, text: 'world')
93
+ end
94
+ end.to raise_error(PageMagic::InvalidElementNameException)
95
+ end
148
96
 
149
- it 'should not evaluate the elements when applying naming checks' do
97
+ it 'does not allow duplicate element names' do
98
+ expect do
150
99
  subject.class_eval do
151
- link(:link1, :selector) do
152
- raise('should not have been evaluated')
153
- end
154
- link(:link2, :selector)
100
+ link(:hello, text: 'world')
101
+ link(:hello, text: 'world')
155
102
  end
156
- end
103
+ end.to raise_error(PageMagic::InvalidElementNameException)
157
104
  end
158
- end
159
105
 
160
- describe '#elements' do
161
- it 'is an alias of #element allowing page_magic to find multiple results' do
162
- expected = described_class.public_instance_method(:element)
163
- expect(described_class.public_instance_method(:elements)).to eq(expected)
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
164
113
  end
165
114
  end
115
+ end
166
116
 
167
- describe '#element_definitions' do
168
- it 'should return your a copy of the core definition' do
169
- subject.text_field :alias, child_selector
170
- first = instance.element_by_name(:alias)
171
- second = instance.element_by_name(:alias)
172
- expect(first).to_not equal(second)
173
- 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)
174
123
  end
175
124
  end
176
125
  end
@@ -1,90 +1,90 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module PageMagic
4
- describe InstanceMethods do
5
- include_context :webapp_fixture
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
6
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
7
16
  let(:page_class) do
8
- Class.new do
9
- include PageMagic
10
- url '/page1'
11
- link(:next_page, text: 'next page')
17
+ Class.new.tap do |klass|
18
+ klass.extend(PageMagic::ClassMethods)
19
+ klass.include(described_class)
20
+ klass.include RSpec::Matchers
12
21
  end
13
22
  end
14
23
 
15
- subject do
16
- page_class.visit(application: rack_app)
17
- end
18
-
19
- it_behaves_like 'session accessor'
20
- it_behaves_like 'element watcher'
21
- it_behaves_like 'waiter'
22
- it_behaves_like 'element locator'
23
-
24
- describe 'execute_on_load' do
25
- it 'runs the on_load_hook in the context of self' do
26
- instance = subject.current_page
27
- page_class.on_load do
28
- extend RSpec::Matchers
29
- expect(self).to be(instance)
30
- end
31
-
32
- subject.execute_on_load
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)
33
28
  end
34
29
 
35
- it 'returns self' do
36
- expect(subject.execute_on_load).to be(subject.current_page)
37
- end
30
+ instance.execute_on_load
38
31
  end
39
32
 
40
- describe '#respond_to?' do
41
- it 'checks self' do
42
- expect(subject.respond_to?(:visit)).to eq(true)
43
- end
44
-
45
- it 'checks element definitions' do
46
- expect(subject.respond_to?(:next_page)).to eq(true)
47
- end
33
+ it 'returns self' do
34
+ instance = page_class.new
35
+ expect(instance.execute_on_load).to be(instance)
48
36
  end
37
+ end
49
38
 
50
- describe 'session' do
51
- it 'gives access to the page magic object wrapping the user session' do
52
- expect(subject.session.raw_session).to be_a(Capybara::Session)
53
- end
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)
54
44
  end
45
+ end
55
46
 
56
- describe 'text' do
57
- it 'returns the text on the page' do
58
- expect(subject.text).to eq('next page')
59
- end
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')
60
52
  end
53
+ end
61
54
 
62
- describe 'text_on_page?' do
63
- it 'returns true if the text is present' do
64
- expect(subject.text_on_page?('next page')).to eq(true)
65
- end
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)
66
59
 
67
- it 'returns false if the text is not present' do
68
- expect(subject.text_on_page?('not on page')).to eq(false)
69
- end
60
+ expect(instance.text_on_page?('text')).to eq(true)
70
61
  end
71
62
 
72
- describe 'title' do
73
- it 'returns the title' do
74
- expect(subject.title).to eq('page1')
75
- end
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)
76
68
  end
69
+ end
77
70
 
78
- describe '#visit' do
79
- it 'goes to the class define url' do
80
- expect(subject.session.current_path).to eq('/page1')
81
- end
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')
82
77
  end
78
+ end
83
79
 
84
- describe 'method_missing' do
85
- it 'gives access to the elements defined on your page classes' do
86
- expect(subject.next_page.tag_name).to eq('a')
87
- end
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
88
  end
89
89
  end
90
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