spec/leadlight/tint_helper_spec.rb in leadlight-0.0.5 vs spec/leadlight/tint_helper_spec.rb in leadlight-0.0.6
- old
+ new
@@ -3,12 +3,13 @@
module Leadlight
describe TintHelper do
subject{ TintHelper.new(object, tint) }
let(:object) {
- stub(__location__: stub(path: '/the/path'),
- __response__: response)
+ stub(__location__: Addressable::URI.parse('/the/path'),
+ __response__: response,
+ __captures__: captures)
}
let(:response) {
stub(:response,
env: env,
status: 200)
@@ -16,10 +17,11 @@
let(:env) { {response_headers: headers} }
let(:headers) {
{ 'Content-Type' => 'text/html; charset=UTF-8'}
}
let(:tint) { Module.new }
+ let(:captures) { {} }
it 'forwards unknown calls to the wrapped object' do
object.should_receive(:foo).with('bar')
subject.foo('bar')
end
@@ -39,15 +41,47 @@
match_path(/path/)
baz
end
end
+ it 'adds regex captures to representation captures' do
+ subject.exec_tint do
+ match_path(%r{/(?<x>\w+)/(?<y>\w+)})
+ end
+ captures.should eq('x' => 'the', 'y' => 'path')
+ end
+
it 'does not allow execution to proceed on no match' do
object.should_not_receive(:baz)
subject.exec_tint do
match_path('/the/wrong/path')
baz
end
+ end
+ end
+
+ describe '#match_template' do
+ it 'allows execution to proceed on match' do
+ object.should_receive(:baz)
+ subject.exec_tint do
+ match_template('/{a}/{b}')
+ baz
+ end
+ end
+
+ it 'halts execution on no match' do
+ object.should_not_receive(:baz)
+ subject.exec_tint do
+ match_template('/{a}/{b}/{c}')
+ baz
+ end
+ end
+
+ it 'adds mappings to representation captures' do
+ subject.exec_tint do
+ match_template('/{a}/{b}')
+ end
+ captures.should eq('a' => 'the', 'b' => 'path')
end
end
describe '#match_content_type' do
it 'allows execution to proceed on match' do