mustermann 3.0.4 → 3.1.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.
data/spec/concat_spec.rb DELETED
@@ -1,127 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'support'
3
- require 'mustermann'
4
-
5
- describe Mustermann::Concat do
6
- describe Mustermann::Concat::Native do
7
- context "sinatra + sinatra" do
8
- subject(:pattern) { Mustermann.new("/:foo") + Mustermann.new("/:bar") }
9
- its(:class) { should be == Mustermann::Sinatra }
10
- its(:to_s) { should be == "/{foo}/{bar}" }
11
- end
12
-
13
- context "sinatra + string" do
14
- subject(:pattern) { Mustermann.new("/:foo") + "/:bar" }
15
- its(:class) { should be == Mustermann::Sinatra }
16
- its(:to_s) { should be == "/{foo}/\\:bar" }
17
- end
18
-
19
- context "regular + regular" do
20
- subject(:pattern) { Mustermann.new(/foo/) + Mustermann.new(/bar/) }
21
- its(:class) { should be == Mustermann::Regular }
22
- its(:to_s) { should be == "foobar" }
23
- end
24
-
25
- context "sinatra + rails" do
26
- subject(:pattern) { Mustermann.new("/:foo") + Mustermann.new("/:bar", type: :rails) }
27
- its(:class) { should be == Mustermann::Sinatra }
28
- its(:to_s) { should be == "/{foo}/{bar}" }
29
- end
30
-
31
- context "sinatra + flask" do
32
- subject(:pattern) { Mustermann.new("/:foo") + Mustermann.new("/<bar>", type: :flask) }
33
- its(:class) { should be == Mustermann::Sinatra }
34
- its(:to_s) { should be == "/{foo}/{bar}" }
35
- end
36
-
37
- context "sinatra + flask (typed)" do
38
- subject(:pattern) { Mustermann.new("/:foo") + Mustermann.new("/<int:bar>", type: :flask) }
39
- its(:class) { should be == Mustermann::Concat }
40
- its(:to_s) { should be == '(sinatra:"/:foo" + flask:"/<int:bar>")' }
41
- end
42
-
43
- context "sinatra + sinatra (different options)" do
44
- subject(:pattern) { Mustermann.new("/:foo") + Mustermann.new("/:bar", uri_decode: false) }
45
- its(:class) { should be == Mustermann::Concat }
46
- its(:to_s) { should be == '(sinatra:"/:foo" + sinatra:"/:bar")' }
47
- end
48
-
49
- context "sinatra + rails (different options)" do
50
- subject(:pattern) { Mustermann.new("/:foo") + Mustermann.new("/:bar", type: :rails, uri_decode: false) }
51
- its(:class) { should be == Mustermann::Concat }
52
- its(:to_s) { should be == '(sinatra:"/:foo" + rails:"/:bar")' }
53
- end
54
-
55
- context "sinatra + rails (different options) + sinatra" do
56
- subject(:pattern) { Mustermann.new("/:foo") + Mustermann.new("/:bar", type: :rails, uri_decode: false) + Mustermann.new("/:baz") }
57
- its(:class) { should be == Mustermann::Concat }
58
- its(:to_s) { should be == '(sinatra:"/:foo" + rails:"/:bar" + sinatra:"/:baz")' }
59
- end
60
-
61
- context "sinatra + (sinatra + regular)" do
62
- subject(:pattern) { Mustermann.new("/foo") + (Mustermann.new("/bar") + Mustermann.new(/baz/)) }
63
- its(:class) { should be == Mustermann::Concat }
64
- its(:to_s) { should be == '(sinatra:"/foo/bar" + regular:"baz")' }
65
- end
66
-
67
- context "sinatra + (sinatra + rails (different options) + sinatra)" do
68
- subject(:pattern) { Mustermann.new("/foo") + (Mustermann.new("/bar") + Mustermann.new("/baz", type: :rails, uri_decode: false) + Mustermann.new("/boo")) }
69
- its(:class) { should be == Mustermann::Concat }
70
- its(:to_s) { should be == '(sinatra:"/foo/bar" + rails:"/baz" + sinatra:"/boo")' }
71
- end
72
- end
73
-
74
- subject(:pattern) { Mustermann::Concat.new("/:foo", "/:bar") }
75
-
76
- describe :=== do
77
- example { (pattern === "/foo/bar") .should be true }
78
- example { (pattern === "/foo/bar/") .should be false }
79
- example { (pattern === "/foo") .should be false }
80
- end
81
-
82
- describe :match do
83
- it { should match("/foo/bar").capturing(foo: "foo", bar: "bar") }
84
- it { should_not match("/foo/bar/") }
85
- it { should_not match("/foo/") }
86
- end
87
-
88
- describe :params do
89
- example { pattern.params("/foo/bar") .should be == { "foo" => "foo", "bar" => "bar" }}
90
- example { pattern.params("/foo/bar/") .should be_nil }
91
- example { pattern.params("/foo") .should be_nil }
92
- end
93
-
94
- describe :peek do
95
- example { pattern.peek("/foo/bar/baz") .should be == "/foo/bar" }
96
- example { pattern.peek("/foo") .should be_nil }
97
- end
98
-
99
- describe :peek_params do
100
- example { pattern.peek_params("/foo/bar/baz") .should be == [{ "foo" => "foo", "bar" => "bar" }, 8]}
101
- example { pattern.peek_params("/foo") .should be_nil }
102
- end
103
-
104
- describe :peek_match do
105
- example { pattern.peek_match("/foo/bar/baz").to_s .should be == "/foo/bar" }
106
- example { pattern.peek_match("/foo") .should be_nil }
107
- end
108
-
109
- describe :peek_size do
110
- example { pattern.peek_size("/foo/bar/baz") .should be == 8 }
111
- example { pattern.peek_size("/foo") .should be_nil }
112
- end
113
-
114
- describe :expand do
115
- it { should expand(foo: :bar, bar: :foo) .to('/bar/foo') }
116
- it { should expand(:append, foo: :bar, bar: :foo, baz: 42) .to('/bar/foo?baz=42') }
117
- it { should_not expand(foo: :bar) }
118
- end
119
-
120
- describe :to_templates do
121
- subject(:pattern) { Mustermann::Concat.new("/:foo|:bar", "(/:baz)?") }
122
- it { should generate_template("/{foo}/{baz}") }
123
- it { should generate_template("{bar}/{baz}") }
124
- it { should generate_template("/{foo}") }
125
- it { should generate_template("{bar}") }
126
- end
127
- end
@@ -1,42 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'support'
3
- require 'mustermann/equality_map'
4
-
5
- RSpec.describe Mustermann::EqualityMap do
6
- before { GC.disable }
7
- after { GC.enable }
8
-
9
- describe :fetch do
10
- subject { Mustermann::EqualityMap.new }
11
- specify 'with existing entry' do
12
- next if subject.is_a? Hash
13
- subject.fetch("foo") { "foo" }
14
- result = subject.fetch("foo") { "bar" }
15
- expect(result).to be == "foo"
16
- end
17
-
18
- specify 'with GC-removed entry' do
19
- next if subject.is_a? Hash
20
- subject.fetch(String.new('foo')) { "foo" }
21
- expect(subject.map).to receive(:[]).and_return(nil)
22
- result = subject.fetch(String.new('foo')) { "bar" }
23
- expect(result).to be == "bar"
24
- end
25
-
26
- specify 'allows a frozen key and value' do
27
- next if subject.is_a? Hash
28
- key = "foo".freeze
29
- value = "bar".freeze
30
- subject.fetch(key) { value }
31
- result = subject.fetch("foo".dup) { raise "not executed" }
32
- expect(result).to be == value
33
- expect(result).not_to equal value
34
- end
35
-
36
- specify 'allows only a single argument to be compatible with Hash#fetch' do
37
- expect {
38
- subject.fetch("foo", "bar", "baz") { "value" }
39
- }.to raise_error(ArgumentError)
40
- end
41
- end
42
- end
@@ -1,123 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'support'
3
- require 'mustermann/expander'
4
-
5
- describe Mustermann::Expander do
6
- it 'expands a pattern' do
7
- expander = Mustermann::Expander.new("/:foo.jpg")
8
- expander.expand(foo: 42).should be == "/42.jpg"
9
- end
10
-
11
- it 'expands multiple patterns' do
12
- expander = Mustermann::Expander.new << "/:foo.:ext" << "/:foo"
13
- expander.expand(foo: 42, ext: 'jpg').should be == "/42.jpg"
14
- expander.expand(foo: 23).should be == "/23"
15
- end
16
-
17
- it 'supports setting pattern options' do
18
- expander = Mustermann::Expander.new(type: :rails) << "/:foo(.:ext)" << "/:bar"
19
- expander.expand(foo: 42, ext: 'jpg').should be == "/42.jpg"
20
- expander.expand(foo: 42).should be == "/42"
21
- end
22
-
23
- it 'supports combining different pattern styles' do
24
- expander = Mustermann::Expander.new << Mustermann.new("/:foo(.:ext)", type: :rails) << Mustermann.new("/:bar", type: :sinatra)
25
- expander.expand(foo: 'pony', ext: 'jpg').should be == '/pony.jpg'
26
- expander.expand(bar: 23).should be == "/23"
27
- end
28
-
29
- it 'ignores nil values' do
30
- expander = Mustermann::Expander.new << Mustermann.new("/:foo(.:ext)?")
31
- expander.expand(foo: 'pony', ext: nil).should be == '/pony'
32
- end
33
-
34
- it 'supports splat' do
35
- expander = Mustermann::Expander.new << Mustermann.new("/foo/*/baz")
36
- expander.expand(splat: 'bar').should be == '/foo/bar/baz'
37
- end
38
-
39
- it 'supports multiple splats' do
40
- expander = Mustermann::Expander.new << Mustermann.new("/foo/*/bar/*")
41
- expander.expand(splat: [123, 456]).should be == '/foo/123/bar/456'
42
- end
43
-
44
- it 'supports identity patterns' do
45
- expander = Mustermann::Expander.new('/:foo', type: :identity)
46
- expander.expand.should be == '/:foo'
47
- end
48
-
49
- describe :additional_values do
50
- context "illegal value" do
51
- example { expect { Mustermann::Expander.new(additional_values: :foo) }.to raise_error(ArgumentError) }
52
- example { expect { Mustermann::Expander.new('/').expand(:foo, a: 10) }.to raise_error(ArgumentError) }
53
- end
54
-
55
- context :raise do
56
- subject(:expander) { Mustermann::Expander.new('/:a', additional_values: :raise) }
57
- example { expander.expand(a: ?a).should be == '/a' }
58
- example { expect { expander.expand(a: ?a, b: ?b) }.to raise_error(Mustermann::ExpandError) }
59
- example { expect { expander.expand(b: ?b) }.to raise_error(Mustermann::ExpandError) }
60
- end
61
-
62
- context :ignore do
63
- subject(:expander) { Mustermann::Expander.new('/:a', additional_values: :ignore) }
64
- example { expander.expand(a: ?a).should be == '/a' }
65
- example { expander.expand(a: ?a, b: ?b).should be == '/a' }
66
- example { expect { expander.expand(b: ?b) }.to raise_error(Mustermann::ExpandError) }
67
- example { expect { expander.expand(b: ?b, c: []) }.to raise_error(Mustermann::ExpandError) }
68
- example { expect { expander.expand(b: ?b, c: [], d: ?d) }.to raise_error(Mustermann::ExpandError) }
69
- end
70
-
71
- context :append do
72
- subject(:expander) { Mustermann::Expander.new('/:a', additional_values: :append) }
73
- example { expander.expand(a: ?a).should be == '/a' }
74
- example { expander.expand(a: ?a, b: ?b).should be == '/a?b=b' }
75
- example { expect { expander.expand(b: ?b) }.to raise_error(Mustermann::ExpandError) }
76
- end
77
- end
78
-
79
- describe :cast do
80
- subject(:expander) { Mustermann::Expander.new('/:a(/:b)?') }
81
-
82
- example { expander.cast { "FOOBAR" }.expand(a: "foo") .should be == "/FOOBAR" }
83
- example { expander.cast { |v| v.upcase }.expand(a: "foo") .should be == "/FOO" }
84
- example { expander.cast { |v| v.upcase }.expand(a: "foo", b: "bar") .should be == "/FOO/BAR" }
85
- example { expander.cast(:a) { |v| v.upcase }.expand(a: "foo", b: "bar") .should be == "/FOO/bar" }
86
- example { expander.cast(:a, :b) { |v| v.upcase }.expand(a: "foo", b: "bar") .should be == "/FOO/BAR" }
87
- example { expander.cast(Integer) { |k,v| "#{k}_#{v}" }.expand(a: "foo", b: 42) .should be == "/foo/b_42" }
88
-
89
- example do
90
- expander.cast(:a) { |v| v.upcase }
91
- expander.cast(:b) { |v| v.downcase }
92
- expander.expand(a: "fOo", b: "bAr").should be == "/FOO/bar"
93
- end
94
- end
95
-
96
- describe :== do
97
- example { Mustermann::Expander.new('/foo') .should be == Mustermann::Expander.new('/foo') }
98
- example { Mustermann::Expander.new('/foo') .should_not be == Mustermann::Expander.new('/bar') }
99
- example { Mustermann::Expander.new('/foo', type: :rails) .should be == Mustermann::Expander.new('/foo', type: :rails) }
100
- example { Mustermann::Expander.new('/foo', type: :rails) .should_not be == Mustermann::Expander.new('/foo', type: :sinatra) }
101
- end
102
-
103
- describe :hash do
104
- example { Mustermann::Expander.new('/foo') .hash.should be == Mustermann::Expander.new('/foo').hash }
105
- example { Mustermann::Expander.new('/foo') .hash.should_not be == Mustermann::Expander.new('/bar').hash }
106
- example { Mustermann::Expander.new('/foo', type: :rails) .hash.should be == Mustermann::Expander.new('/foo', type: :rails).hash }
107
- example { Mustermann::Expander.new('/foo', type: :rails) .hash.should_not be == Mustermann::Expander.new('/foo', type: :sinatra).hash }
108
- end
109
-
110
- describe :eql? do
111
- example { Mustermann::Expander.new('/foo') .should be_eql Mustermann::Expander.new('/foo') }
112
- example { Mustermann::Expander.new('/foo') .should_not be_eql Mustermann::Expander.new('/bar') }
113
- example { Mustermann::Expander.new('/foo', type: :rails) .should be_eql Mustermann::Expander.new('/foo', type: :rails) }
114
- example { Mustermann::Expander.new('/foo', type: :rails) .should_not be_eql Mustermann::Expander.new('/foo', type: :sinatra) }
115
- end
116
-
117
- describe :equal? do
118
- example { Mustermann::Expander.new('/foo') .should_not be_equal Mustermann::Expander.new('/foo') }
119
- example { Mustermann::Expander.new('/foo') .should_not be_equal Mustermann::Expander.new('/bar') }
120
- example { Mustermann::Expander.new('/foo', type: :rails) .should_not be_equal Mustermann::Expander.new('/foo', type: :rails) }
121
- example { Mustermann::Expander.new('/foo', type: :rails) .should_not be_equal Mustermann::Expander.new('/foo', type: :sinatra) }
122
- end
123
- end
@@ -1,127 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'support'
3
- require 'mustermann/identity'
4
-
5
- describe Mustermann::Identity do
6
- extend Support::Pattern
7
-
8
- pattern '' do
9
- it { should match('') }
10
- it { should_not match('/') }
11
-
12
- it { should respond_to(:expand) }
13
- it { should respond_to(:to_templates) }
14
-
15
-
16
- it { should generate_template('') }
17
- it { should expand.to('') }
18
- it { should expand(:ignore, a: 10).to('') }
19
- it { should expand(:append, a: 10).to('?a=10') }
20
- it { should_not expand(:raise, a: 10) }
21
- it { should_not expand(a: 10) }
22
-
23
- example do
24
- pattern.match('').inspect.should be == '#<Mustermann::SimpleMatch "">'
25
- end
26
- end
27
-
28
- pattern '/' do
29
- it { should match('/') }
30
- it { should_not match('/foo') }
31
-
32
- example { pattern.params('/').should be == {} }
33
- example { pattern.params('').should be_nil }
34
-
35
- it { should generate_template('/') }
36
- it { should expand.to('/') }
37
- end
38
-
39
- pattern '/foo' do
40
- it { should match('/foo') }
41
- it { should_not match('/bar') }
42
- it { should_not match('/foo.bar') }
43
- end
44
-
45
- pattern '/foo/bar' do
46
- it { should match('/foo/bar') }
47
- it { should match('/foo%2Fbar') }
48
- it { should match('/foo%2fbar') }
49
- end
50
-
51
- pattern '/:foo' do
52
- it { should match('/:foo') }
53
- it { should match('/%3Afoo') }
54
- it { should_not match('/foo') }
55
- it { should_not match('/foo?') }
56
- it { should_not match('/foo/bar') }
57
- it { should_not match('/') }
58
- it { should_not match('/foo/') }
59
-
60
- it { should generate_template('/:foo') }
61
- it { should expand.to('/:foo') }
62
- end
63
-
64
- pattern '/föö' do
65
- it { should match("/f%C3%B6%C3%B6") }
66
- end
67
-
68
- pattern '/test$/' do
69
- it { should match('/test$/') }
70
- end
71
-
72
- pattern '/te+st/' do
73
- it { should match('/te+st/') }
74
- it { should_not match('/test/') }
75
- it { should_not match('/teest/') }
76
- end
77
-
78
- pattern "/path with spaces" do
79
- it { should match('/path%20with%20spaces') }
80
- it { should_not match('/path%2Bwith%2Bspaces') }
81
- it { should_not match('/path+with+spaces') }
82
- it { should generate_template('/path%20with%20spaces') }
83
- end
84
-
85
- pattern '/foo&bar' do
86
- it { should match('/foo&bar') }
87
- end
88
-
89
- pattern '/test.bar' do
90
- it { should match('/test.bar') }
91
- it { should_not match('/test0bar') }
92
- end
93
-
94
- pattern '/foo/bar', uri_decode: false do
95
- it { should match('/foo/bar') }
96
- it { should_not match('/foo%2Fbar') }
97
- it { should_not match('/foo%2fbar') }
98
- end
99
-
100
- pattern "/path with spaces", uri_decode: false do
101
- it { should_not match('/path%20with%20spaces') }
102
- it { should_not match('/path%2Bwith%2Bspaces') }
103
- it { should_not match('/path+with+spaces') }
104
- end
105
-
106
- context "peeking" do
107
- subject(:pattern) { Mustermann::Identity.new("foo bar") }
108
-
109
- describe :peek_size do
110
- example { pattern.peek_size("foo bar blah") .should be == "foo bar".size }
111
- example { pattern.peek_size("foo%20bar blah") .should be == "foo%20bar".size }
112
- example { pattern.peek_size("foobar") .should be_nil }
113
- end
114
-
115
- describe :peek_match do
116
- example { pattern.peek_match("foo bar blah").to_s .should be == "foo bar" }
117
- example { pattern.peek_match("foo%20bar blah").to_s .should be == "foo%20bar" }
118
- example { pattern.peek_match("foobar") .should be_nil }
119
- end
120
-
121
- describe :peek_params do
122
- example { pattern.peek_params("foo bar blah") .should be == [{}, "foo bar".size] }
123
- example { pattern.peek_params("foo%20bar blah") .should be == [{}, "foo%20bar".size] }
124
- example { pattern.peek_params("foobar") .should be_nil }
125
- end
126
- end
127
- end
data/spec/mapper_spec.rb DELETED
@@ -1,77 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'support'
3
- require 'mustermann/mapper'
4
-
5
- describe Mustermann::Mapper do
6
- describe :initialize do
7
- context 'accepts a block with no arguments, using the return value' do
8
- subject(:mapper) { Mustermann::Mapper.new(additional_values: :raise) {{ "/foo" => "/bar" }}}
9
- its(:to_h) { should be == { Mustermann.new("/foo") => Mustermann::Expander.new("/bar") } }
10
- example { mapper['/foo'].should be == '/bar' }
11
- example { mapper['/fox'].should be == '/fox' }
12
- end
13
-
14
- context 'accepts a block with argument, passes instance to it' do
15
- subject(:mapper) { Mustermann::Mapper.new(additional_values: :raise) { |m| m["/foo"] = "/bar" }}
16
- its(:to_h) { should be == { Mustermann.new("/foo") => Mustermann::Expander.new("/bar") } }
17
- example { mapper['/foo'].should be == '/bar' }
18
- example { mapper['/fox'].should be == '/fox' }
19
- end
20
-
21
- context 'accepts mappings followed by options' do
22
- subject(:mapper) { Mustermann::Mapper.new({ "/foo" => "/bar" }, additional_values: :raise) }
23
- its(:to_h) { should be == { Mustermann.new("/foo") => Mustermann::Expander.new("/bar") } }
24
- example { mapper['/foo'].should be == '/bar' }
25
- example { mapper['/fox'].should be == '/fox' }
26
- end
27
-
28
- context 'allows specifying type' do
29
- subject(:mapper) { Mustermann::Mapper.new({ "/foo" => "/bar" }, additional_values: :raise, type: :rails) }
30
- its(:to_h) { should be == { Mustermann.new("/foo", type: :rails) => Mustermann::Expander.new("/bar", type: :rails) } }
31
- example { mapper['/foo'].should be == '/bar' }
32
- example { mapper['/fox'].should be == '/fox' }
33
- end
34
- end
35
-
36
- describe :convert do
37
- subject(:mapper) { Mustermann::Mapper.new }
38
-
39
- context 'it maps params' do
40
- before { mapper["/:a"] = "/:a.html" }
41
- example { mapper["/foo"] .should be == "/foo.html" }
42
- example { mapper["/foo/bar"] .should be == "/foo/bar" }
43
- end
44
-
45
- context 'it supports named splats' do
46
- before { mapper["/*a"] = "/*a.html" }
47
- example { mapper["/foo"] .should be == "/foo.html" }
48
- example { mapper["/foo/bar"] .should be == "/foo/bar.html" }
49
- end
50
-
51
- context 'can map from patterns' do
52
- before { mapper[Mustermann.new("/:a")] = "/:a.html" }
53
- example { mapper["/foo"] .should be == "/foo.html" }
54
- example { mapper["/foo/bar"] .should be == "/foo/bar" }
55
- end
56
-
57
- context 'can map to patterns' do
58
- before { mapper[Mustermann.new("/:a")] = Mustermann.new("/:a.html") }
59
- example { mapper["/foo"] .should be == "/foo.html" }
60
- example { mapper["/foo/bar"] .should be == "/foo/bar" }
61
- end
62
-
63
- context 'can map to expanders' do
64
- before { mapper[Mustermann.new("/:a")] = Mustermann::Expander.new("/:a.html") }
65
- example { mapper["/foo"] .should be == "/foo.html" }
66
- example { mapper["/foo/bar"] .should be == "/foo/bar" }
67
- end
68
-
69
- context 'can map to array' do
70
- before { mapper["/:a"] = ["/:a.html", "/:a.:f"] }
71
- example { mapper["/foo"] .should be == "/foo.html" }
72
- example { mapper["/foo", "f" => 'x'] .should be == "/foo.x" }
73
- example { mapper["/foo", f: 'x'] .should be == "/foo.x" }
74
- example { mapper["/foo/bar"] .should be == "/foo/bar" }
75
- end
76
- end
77
- end
@@ -1,81 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'support'
3
- require 'mustermann'
4
- require 'sinatra/base'
5
-
6
- describe Mustermann do
7
- describe :new do
8
- context "string argument" do
9
- example { Mustermann.new('') .should be_a(Mustermann::Sinatra) }
10
- example { Mustermann.new('', type: :identity) .should be_a(Mustermann::Identity) }
11
- example { Mustermann.new('', type: :rails) .should be_a(Mustermann::Rails) }
12
- example { Mustermann.new('', type: :shell) .should be_a(Mustermann::Shell) }
13
- example { Mustermann.new('', type: :sinatra) .should be_a(Mustermann::Sinatra) }
14
- example { Mustermann.new('', type: :simple) .should be_a(Mustermann::Simple) }
15
- example { Mustermann.new('', type: :template) .should be_a(Mustermann::Template) }
16
-
17
- example { expect { Mustermann.new('', foo: :bar) }.to raise_error(ArgumentError, "unsupported option :foo for Mustermann::Sinatra") }
18
- example { expect { Mustermann.new('', type: :ast) }.to raise_error(ArgumentError, "unsupported type :ast (cannot load such file -- mustermann/ast)") }
19
- end
20
-
21
- context "pattern argument" do
22
- subject(:pattern) { Mustermann.new('') }
23
- example { Mustermann.new(pattern).should be == pattern }
24
- example { Mustermann.new(pattern, type: :rails).should be_a(Mustermann::Sinatra) }
25
- end
26
-
27
- context "regexp argument" do
28
- example { Mustermann.new(//) .should be_a(Mustermann::Regular) }
29
- example { Mustermann.new(//, type: :rails) .should be_a(Mustermann::Regular) }
30
- end
31
-
32
- context "argument implementing #to_pattern" do
33
- subject(:pattern) { Class.new { def to_pattern(**o) Mustermann.new('foo', **o) end }.new }
34
- example { Mustermann.new(pattern) .should be_a(Mustermann::Sinatra) }
35
- example { Mustermann.new(pattern, type: :rails) .should be_a(Mustermann::Rails) }
36
- example { Mustermann.new(pattern).to_s.should be == 'foo' }
37
- end
38
-
39
- context "multiple arguments" do
40
- example { Mustermann.new(':a', ':b/:a') .should be_a(Mustermann::Composite) }
41
- example { Mustermann.new(':a', ':b/:a').patterns.first .should be_a(Mustermann::Sinatra) }
42
- example { Mustermann.new(':a', ':b/:a').operator .should be == :| }
43
- example { Mustermann.new(':a', ':b/:a', operator: :&).operator .should be == :& }
44
- example { Mustermann.new(':a', ':b/:a', greedy: true) .should be_a(Mustermann::Composite) }
45
-
46
- example { Mustermann.new('/foo', ':bar') .should be_a(Mustermann::Sinatra) }
47
- example { Mustermann.new('/foo', ':bar').to_s .should be == "/foo|{bar}" }
48
- end
49
-
50
- context "invalid arguments" do
51
- it "raise a TypeError for unsupported types" do
52
- expect { Mustermann.new(10) }.to raise_error(TypeError, /(Integer|Fixnum) can't be coerced into Mustermann::Pattern/)
53
- end
54
- end
55
- end
56
-
57
- describe :[] do
58
- example { Mustermann[:identity] .should be == Mustermann::Identity }
59
- example { Mustermann[:rails] .should be == Mustermann::Rails }
60
- example { Mustermann[:shell] .should be == Mustermann::Shell }
61
- example { Mustermann[:sinatra] .should be == Mustermann::Sinatra }
62
- example { Mustermann[:simple] .should be == Mustermann::Simple }
63
- example { Mustermann[:template] .should be == Mustermann::Template }
64
-
65
- example { expect { Mustermann[:ast] }.to raise_error(ArgumentError, "unsupported type :ast (cannot load such file -- mustermann/ast)") }
66
- example { expect { Mustermann[:expander] }.to raise_error(ArgumentError, "unsupported type :expander") }
67
- end
68
-
69
- describe :extend_object do
70
- context 'special behavior for Sinatra only' do
71
- example { Object .new.extend(Mustermann).should be_a(Mustermann) }
72
- example { Class .new.extend(Mustermann).should be_a(Mustermann) }
73
-
74
- example { expect { Sinatra.new.extend(Mustermann) }.to raise_error(RuntimeError, "Mustermann extension for Sinatra has been extracted into its own gem. More information at https://github.com/sinatra/mustermann-sinatra-extension") }
75
- end
76
- end
77
-
78
- describe :=== do
79
- example { Mustermann.should be === Mustermann.new("") }
80
- end
81
- end
data/spec/pattern_spec.rb DELETED
@@ -1,54 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'support'
3
- require 'mustermann/pattern'
4
- require 'mustermann/sinatra'
5
- require 'mustermann/rails'
6
-
7
- describe Mustermann::Pattern do
8
- describe :=== do
9
- it 'raises a NotImplementedError when used directly' do
10
- expect { Mustermann::Pattern.new("") === "" }.to raise_error(NotImplementedError)
11
- end
12
- end
13
-
14
- describe :initialize do
15
- it 'raises an ArgumentError for unknown options' do
16
- expect { Mustermann::Pattern.new("", foo: :bar) }.to raise_error(ArgumentError)
17
- end
18
-
19
- it 'does not complain about unknown options if ignore_unknown_options is enabled' do
20
- expect { Mustermann::Pattern.new("", foo: :bar, ignore_unknown_options: true) }.not_to raise_error
21
- end
22
- end
23
-
24
- describe :respond_to? do
25
- subject(:pattern) { Mustermann::Pattern.new("") }
26
-
27
- it { should_not respond_to(:expand) }
28
- it { should_not respond_to(:to_templates) }
29
-
30
- it { expect { pattern.expand } .to raise_error(NotImplementedError) }
31
- it { expect { pattern.to_templates } .to raise_error(NotImplementedError) }
32
- end
33
-
34
- describe :== do
35
- example { Mustermann::Pattern.new('/foo') .should be == Mustermann::Pattern.new('/foo') }
36
- example { Mustermann::Pattern.new('/foo') .should_not be == Mustermann::Pattern.new('/bar') }
37
- example { Mustermann::Sinatra.new('/foo') .should be == Mustermann::Sinatra.new('/foo') }
38
- example { Mustermann::Rails.new('/foo') .should_not be == Mustermann::Sinatra.new('/foo') }
39
- end
40
-
41
- describe :eql? do
42
- example { Mustermann::Pattern.new('/foo') .should be_eql Mustermann::Pattern.new('/foo') }
43
- example { Mustermann::Pattern.new('/foo') .should_not be_eql Mustermann::Pattern.new('/bar') }
44
- example { Mustermann::Sinatra.new('/foo') .should be_eql Mustermann::Sinatra.new('/foo') }
45
- example { Mustermann::Rails.new('/foo') .should_not be_eql Mustermann::Sinatra.new('/foo') }
46
- end
47
-
48
- describe :equal? do
49
- example { Mustermann::Pattern.new('/foo') .should be_equal Mustermann::Pattern.new('/foo') }
50
- example { Mustermann::Pattern.new('/foo') .should_not be_equal Mustermann::Pattern.new('/bar') }
51
- example { Mustermann::Sinatra.new('/foo') .should be_equal Mustermann::Sinatra.new('/foo') }
52
- example { Mustermann::Rails.new('/foo') .should_not be_equal Mustermann::Sinatra.new('/foo') }
53
- end
54
- end
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'support'
3
- require 'mustermann/regexp_based'
4
-
5
- describe Mustermann::RegexpBased do
6
- it 'raises a NotImplementedError when used directly' do
7
- expect { Mustermann::RegexpBased.new("") === "" }.to raise_error(NotImplementedError)
8
- end
9
- end