require File.expand_path('../../../spec_helper', __FILE__) shared_examples 'converter that can forward to given block' do |klass| klass ||= describes context 'given block through #config' do let(:converter) { klass.new.config { 'it works' } } describe '#run' do subject { converter.method(:run) } it 'forwards to the block' do subject.should convert(name: 'Home', path: 'Home').to('it works') end end end context 'given block accessing options in constructor through #config' do let(:converter) { klass.new(fake_result: 'fake').config { options[:fake_result] } } describe '#run' do subject { converter.method(:run) } it 'forwards to the block and allows options access' do subject.should convert(name: 'Home', path: 'Home').to('fake') end end end end describe Wikilink::Converter::Namespace do let(:converter) { Wikilink::Converter::Namespace.new } describe '#run' do subject { converter.method(:run) } it 'does nothing' do subject.should convert(name: 'Home', path: 'Home').to(nil) end end it_behaves_like 'converter that can forward to given block' end describe Wikilink::Converter::Namespace::Default do let(:run_options) { { name: 'Name', path: 'Home' } } shared_examples 'converter that keeps query fragment only path untouched' do it { should convert(path: '#toc-1', name: 'Header 1'). to('Header 1') } it { should convert(path: '?q=keyword', name: 'Search keyword'). to('Search keyword') } it { should convert(path: '?q=keyword#page-10', name: 'Search keyword (page 10)'). to('Search keyword (page 10)') } end let(:converter) { self.class.describes.new } describe '#run' do subject { converter.method(:run) } it { should convert(run_options). to('Name') } it_behaves_like 'converter that keeps query fragment only path untouched' end context 'given option :prefix "/wiki/"' do let(:converter) { self.class.describes.new prefix: '/wiki/' } describe '#run' do subject { converter.method(:run) } it_behaves_like 'converter that keeps query fragment only path untouched' end end context 'given option :suffix "/index.html"' do let(:converter) { self.class.describes.new suffix: '/index.html' } describe '#run' do subject { converter.method(:run) } it { should convert(run_options). to('Name') } it_behaves_like 'converter that keeps query fragment only path untouched' end end context 'given option :external true' do let(:converter) { self.class.describes.new external: true } describe '#run' do subject { converter.method(:run) } it { should convert(run_options). to('Name') } end end context 'given option :class "fancy"' do let(:converter) { self.class.describes.new class: 'fancy' } describe '#run' do subject { converter.method(:run) } it { should convert(run_options). to('Name') } end end context 'given option :external true and :class "fancy"' do let(:converter) { self.class.describes.new external: true, class: 'fancy' } describe '#run' do subject { converter.method(:run) } it { should convert(run_options). to('Name') } end end it_behaves_like 'converter that can forward to given block' end