page_magic 1.2.8 → 2.0.2

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