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
|
require 'support'
require 'mustermann/to_pattern'
require 'delegate'
describe Mustermann::ToPattern do
context String do
example { "".to_pattern .should be_a(Mustermann::Sinatra) }
example { "".to_pattern(type: :rails) .should be_a(Mustermann::Rails) }
end
context Regexp do
example { //.to_pattern .should be_a(Mustermann::Regular) }
example { //.to_pattern(type: :rails) .should be_a(Mustermann::Regular) }
end
context Symbol do
example { :foo.to_pattern .should be_a(Mustermann::Sinatra) }
example { :foo.to_pattern(type: :rails) .should be_a(Mustermann::Sinatra) }
end
context Array do
example { [:foo, :bar].to_pattern .should be_a(Mustermann::Composite) }
example { [:foo, :bar].to_pattern(type: :rails) .should be_a(Mustermann::Composite) }
end
context Mustermann::Pattern do
subject(:pattern) { Mustermann.new('') }
example { pattern.to_pattern.should be == pattern }
example { pattern.to_pattern(type: :rails).should be_a(Mustermann::Sinatra) }
end
context 'custom class' do
let(:example_class) do
Class.new do
include Mustermann::ToPattern
def to_s
":foo/:bar"
end
end
end
example { example_class.new.to_pattern .should be_a(Mustermann::Sinatra) }
example { example_class.new.to_pattern(type: :rails) .should be_a(Mustermann::Rails) }
example { Mustermann.new(example_class.new) .should be_a(Mustermann::Sinatra) }
example { Mustermann.new(example_class.new, type: :rails) .should be_a(Mustermann::Rails) }
end
context 'primitive delegate' do
let(:example_class) do
Class.new(DelegateClass(Array)) do
include Mustermann::ToPattern
end
end
example { example_class.new([:foo, :bar]).to_pattern .should be_a(Mustermann::Composite) }
example { example_class.new([:foo, :bar]).to_pattern(type: :rails) .should be_a(Mustermann::Composite) }
end
context 'primitive subclass' do
let(:example_class) do
Class.new(Array) do
include Mustermann::ToPattern
end
end
example { example_class.new([:foo, :bar]).to_pattern .should be_a(Mustermann::Composite) }
example { example_class.new([:foo, :bar]).to_pattern(type: :rails) .should be_a(Mustermann::Composite) }
end
end
|