1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
require 'support'
require 'mustermann/mapper'
describe Mustermann::Mapper do
describe :initialize do
context 'accepts a block with no arguments, using the return value' do
subject(:mapper) { Mustermann::Mapper.new(additional_values: :raise) {{ "/foo" => "/bar" }}}
its(:to_h) { should be == { Mustermann.new("/foo") => Mustermann::Expander.new("/bar") } }
example { mapper['/foo'].should be == '/bar' }
example { mapper['/fox'].should be == '/fox' }
end
context 'accepts a block with argument, passes instance to it' do
subject(:mapper) { Mustermann::Mapper.new(additional_values: :raise) { |m| m["/foo"] = "/bar" }}
its(:to_h) { should be == { Mustermann.new("/foo") => Mustermann::Expander.new("/bar") } }
example { mapper['/foo'].should be == '/bar' }
example { mapper['/fox'].should be == '/fox' }
end
context 'accepts mappings followed by options' do
subject(:mapper) { Mustermann::Mapper.new("/foo" => "/bar", additional_values: :raise) }
its(:to_h) { should be == { Mustermann.new("/foo") => Mustermann::Expander.new("/bar") } }
example { mapper['/foo'].should be == '/bar' }
example { mapper['/fox'].should be == '/fox' }
end
context 'accepts options followed by mappings' do
subject(:mapper) { Mustermann::Mapper.new(additional_values: :raise, "/foo" => "/bar") }
its(:to_h) { should be == { Mustermann.new("/foo") => Mustermann::Expander.new("/bar") } }
example { mapper['/foo'].should be == '/bar' }
example { mapper['/fox'].should be == '/fox' }
end
context 'allows specifying type' do
subject(:mapper) { Mustermann::Mapper.new(additional_values: :raise, type: :rails, "/foo" => "/bar") }
its(:to_h) { should be == { Mustermann.new("/foo", type: :rails) => Mustermann::Expander.new("/bar", type: :rails) } }
example { mapper['/foo'].should be == '/bar' }
example { mapper['/fox'].should be == '/fox' }
end
end
describe :convert do
subject(:mapper) { Mustermann::Mapper.new }
context 'it maps params' do
before { mapper["/:a"] = "/:a.html" }
example { mapper["/foo"] .should be == "/foo.html" }
example { mapper["/foo/bar"] .should be == "/foo/bar" }
end
context 'it supports named splats' do
before { mapper["/*a"] = "/*a.html" }
example { mapper["/foo"] .should be == "/foo.html" }
example { mapper["/foo/bar"] .should be == "/foo/bar.html" }
end
context 'can map from patterns' do
before { mapper[Mustermann.new("/:a")] = "/:a.html" }
example { mapper["/foo"] .should be == "/foo.html" }
example { mapper["/foo/bar"] .should be == "/foo/bar" }
end
context 'can map to patterns' do
before { mapper[Mustermann.new("/:a")] = Mustermann.new("/:a.html") }
example { mapper["/foo"] .should be == "/foo.html" }
example { mapper["/foo/bar"] .should be == "/foo/bar" }
end
context 'can map to expanders' do
before { mapper[Mustermann.new("/:a")] = Mustermann::Expander.new("/:a.html") }
example { mapper["/foo"] .should be == "/foo.html" }
example { mapper["/foo/bar"] .should be == "/foo/bar" }
end
context 'can map to array' do
before { mapper["/:a"] = ["/:a.html", "/:a.:f"] }
example { mapper["/foo"] .should be == "/foo.html" }
example { mapper["/foo", "f" => 'x'] .should be == "/foo.x" }
example { mapper["/foo", f: 'x'] .should be == "/foo.x" }
example { mapper["/foo/bar"] .should be == "/foo/bar" }
end
end
end
|