Skip to content

Instantly share code, notes, and snippets.

@yknd
Created February 2, 2012 14:53
Show Gist options
  • Save yknd/1723816 to your computer and use it in GitHub Desktop.
Save yknd/1723816 to your computer and use it in GitHub Desktop.
sample sinatra application with haml, sass and rspec.
Autotest.add_hook(:initialize) {|at|
at.add_exception %r{^\.git}
at.add_exception %r{^./tmp}
at.add_mapping(%r{^lib/.*\.rb$}) {|f, _|
Dir['spec/**/*_spec.rb']
}
nil
}
.sass-cache/
Test
$ autotest
Run
$ rackup -s thin
require 'bundler/setup'
Bundler.require(:default)
class MyApp < Sinatra::Base
set :root, File.expand_path('../../', __FILE__)
set :haml, format: :html5
set :haml, escape_html: true
configure :development do
register Sinatra::Reloader
end
get '/' do
haml :index
end
end
require 'spec_helper'
describe MyApp do
context "when get '/'" do
before do
get '/'
end
subject { last_response }
its(:status) { should == 200}
its(:body) { should include('Hello World!!')}
end
end
$:.unshift File.join(File.dirname(__FILE__), 'lib')
require 'bundler'
Bundler.require
require 'app'
run MyApp
source :rubygems
gem 'sinatra', require: 'sinatra/base'
gem 'sinatra-reloader', require: 'sinatra/reloader'
gem 'thin'
gem 'haml'
gem 'sass'
group :test do
gem 'rspec'
gem 'rack-test', require: 'rack/test'
end
GEM
remote: http://rubygems.org/
specs:
backports (2.3.0)
daemons (1.1.6)
diff-lcs (1.1.3)
eventmachine (0.12.10)
haml (3.1.4)
rack (1.4.1)
rack-protection (1.2.0)
rack
rack-test (0.6.1)
rack (>= 1.0)
rspec (2.8.0)
rspec-core (~> 2.8.0)
rspec-expectations (~> 2.8.0)
rspec-mocks (~> 2.8.0)
rspec-core (2.8.0)
rspec-expectations (2.8.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.8.0)
sass (3.1.12)
sinatra (1.3.2)
rack (~> 1.3, >= 1.3.6)
rack-protection (~> 1.2)
tilt (~> 1.3, >= 1.3.3)
sinatra-contrib (1.3.1)
backports (>= 2.0)
eventmachine
rack-protection
rack-test
sinatra (~> 1.3.0)
tilt (~> 1.3)
sinatra-reloader (1.0)
sinatra-contrib
thin (1.3.1)
daemons (>= 1.0.9)
eventmachine (>= 0.12.6)
rack (>= 1.0.0)
tilt (1.3.3)
PLATFORMS
ruby
DEPENDENCIES
haml
rack-test
rspec
sass
sinatra
sinatra-reloader
thin
%h1 Hello World!!
!!!
%html
%head
%title My App
%link{rel: 'stylesheet', media: 'screen', href: '/css/myapp.css'}
%script{type: 'text/javascript', src: '/js/myapp.js'}
%body!= yield
h1 {
margin: 0;
color: #000;
text-shadow: 1px 1px 2px #555; }
// MyApp's javascript file
h1 {
margin: 0;
color: #000;
text-shadow: 1px 1px 2px #555;
}
require 'bundler/setup'
Bundler.require(:default, :test)
require 'app'
module MyTestModule
def app
MyApp
end
end
RSpec.configure do |config|
config.include Rack::Test::Methods
config.include MyTestModule
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment