# encoding: utf-8
require 'spec_helper'
require 'sinatra/classy_assets'
class ClassySinatraApp < Sinatra::Base
use Rack::ClassyAssets
register Sinatra::ClassyAssets
get "/stylesheet_tag" do
slim :stylesheet_tag
end
get "/stylesheet_tag_media" do
slim :stylesheet_tag_media
end
get "/javascript_tag" do
slim :javascript_tag
end
template :index do
"| Classy Assets"
end
template :layout do
"html\n\tbody\n\t\t==yield\n"
end
template :stylesheet_tag do
"==stylesheet_tag('application')"
end
template :stylesheet_tag_media do
"==stylesheet_tag('application', media: 'print')"
end
template :javascript_tag do
"==javascript_tag('application')"
end
end
def app
ClassySinatraApp.new
end
describe Sinatra::ClassyAssets do
before do
ClassyAssets.config do |config|
config.asset_root = File.expand_path('../../support', __FILE__)
config.asset_debug = false
config.asset_digest = false
config.asset_host = nil
config.asset_paths = Dir.glob(File.join(config.asset_root, config.asset_prefix, '*'))
end
end
context "sprockets.context_class" do
it "resolves the url to the asset" do
get "/assets/application.css"
last_response.body.must_match(/background-url: "\/assets\/image.png";/)
end
end
context "Helpers" do
it "outputs a stylesheet link tag" do
get "/stylesheet_tag"
last_response.body.must_match(//)
end
it "outputs the stylesheet tag with the correct media attribute" do
get "/stylesheet_tag_media"
last_response.body.must_match(//)
end
it "outputs a javascript tag" do
get "/javascript_tag"
last_response.body.must_match(/