require 'spec_helper' describe Sinatra::LinkHeader do before do mock_app do helpers Sinatra::LinkHeader before('/') { link 'something', :rel => 'from-filter', :foo => :bar } get '/' do link :something, 'booyah' end get '/style' do stylesheet '/style.css' end get '/prefetch' do prefetch '/foo' end get '/link_headers' do response['Link'] = " ;bar=\"baz\"" stylesheet '/style.css' prefetch '/foo' link_headers end end end describe :link do it "sets link headers" do get '/' expect(headers['Link'].lines).to include('; rel="something"') end it "returns link html tags" do get '/' expect(body).to eq('') end it "takes an options hash" do get '/' elements = ["", "foo=\"bar\"", "rel=\"from-filter\""] expect(headers['Link'].lines.first.strip.split('; ').sort).to eq(elements) end end describe :stylesheet do it 'sets link headers' do get '/style' expect(headers['Link']).to match(%r{^;}) end it 'sets type to text/css' do get '/style' expect(headers['Link']).to include('type="text/css"') end it 'sets rel to stylesheet' do get '/style' expect(headers['Link']).to include('rel="stylesheet"') end it 'returns html tag' do get '/style' expect(body).to match(%r{^;}) end it 'sets rel to prefetch' do get '/prefetch' expect(headers['Link']).to include('rel="prefetch"') end it 'returns html tag' do get '/prefetch' expect(body).to eq('') end end describe :link_headers do it 'generates html for all link headers' do get '/link_headers' expect(body).to include('') expect(body).to include('') end end end