no longer run api

This commit is contained in:
Konstantin Haase 2012-10-16 18:28:49 +02:00
parent e278f007a7
commit ab866b4fe2
24 changed files with 1724 additions and 2431 deletions

26
Gemfile
View File

@ -3,10 +3,6 @@ ruby '1.9.3' rescue nil
source :rubygems
gem 'unicorn'
gem 'sinatra'
gem 'sinatra-contrib'
gem 'yard-sinatra', github: 'rkh/yard-sinatra'
gem 'rack-contrib', github: 'rack/rack-contrib'
gem 'rack-ssl', '~> 1.3'
gem 'rack-cache'
@ -15,35 +11,13 @@ group :development, :test do
end
group :development do
gem 'travis-api', github: 'travis-ci/travis-api'
gem 'travis-core', github: 'travis-ci/travis-core', branch: 'sf-travis-api'
gem 'travis-support', github: 'travis-ci/travis-support'
gem 'gh', github: 'rkh/gh'
gem 'bunny'
gem 'pg', '~> 0.13.2'
gem 'newrelic_rpm', '~> 3.3.0'
gem 'hubble', github: 'roidrage/hubble'
gem 'rake-pipeline', github: 'livingsocial/rake-pipeline', ref: '3465e0e3e1'
gem 'rake-pipeline-web-filters', github: 'wycats/rake-pipeline-web-filters'
gem 'coffee-script'
gem 'compass'
gem 'tilt'
gem 'uglifier'
gem 'debugger'
gem 'foreman'
gem 'rerun'
gem 'rb-fsevent', '~> 0.9.1'
gem 'guard'
end
group :test do
gem 'rspec', '~> 2.11'
gem 'factory_girl', '~> 2.4.0'
gem 'mocha', '~> 0.12'
end

View File

@ -7,86 +7,6 @@ GIT
rake (~> 0.9.0)
thor
GIT
remote: git://github.com/rack/rack-contrib.git
revision: b7e7c38fd02c3b5da91aa57af78b3f571c6ebcd0
specs:
rack-contrib (1.1.0)
rack (>= 0.9.1)
GIT
remote: git://github.com/rkh/gh.git
revision: affde20a4fecb1023f2e7031734b9386a76d22c2
specs:
gh (0.8.0)
addressable
backports (~> 2.3)
faraday (~> 0.8)
multi_json (~> 1.0)
net-http-persistent (>= 2.7)
net-http-pipeline
GIT
remote: git://github.com/rkh/yard-sinatra.git
revision: 3b1064eef407d2d288a5b96d258178a1e67b3b80
specs:
yard-sinatra (1.0.0)
yard (~> 0.7)
GIT
remote: git://github.com/roidrage/hubble.git
revision: f5e6301ac24eabeebaf8f4485d71cdcf93b2f3f8
specs:
hubble (0.1.2)
faraday
json (~> 1.6)
GIT
remote: git://github.com/travis-ci/travis-api.git
revision: 558847f6555202adb7da4f7d31a7b2b80ab4bac2
specs:
travis-api (0.0.1)
backports (~> 2.5)
hubble (~> 0.1)
newrelic_rpm (~> 3.3.0)
pg (~> 0.13.2)
rack-contrib (~> 1.1)
rack-ssl (~> 1.3)
redcarpet (~> 2.1)
sinatra (~> 1.3)
sinatra-contrib (~> 1.3)
thin (~> 1.4)
travis-core
travis-support
GIT
remote: git://github.com/travis-ci/travis-core.git
revision: abac97114a36f3a6715e118cc1f90c05a08004f6
branch: sf-travis-api
specs:
travis-core (0.0.1)
actionmailer (~> 3.2.3)
activerecord (~> 3.2.3)
data_migrations (~> 0.0.1)
gh
hashr (~> 0.0.19)
metriks (~> 0.9.7)
multi_json
postmark-rails (~> 0.4.1)
pusher (~> 0.9.2)
railties (~> 3.2.3)
rake (~> 0.9.2.2)
redis (~> 3.0)
rollout (~> 1.1.0)
simple_states (~> 0.1.1)
thor (~> 0.14.6)
GIT
remote: git://github.com/travis-ci/travis-support.git
revision: 7fb3660e0d5705305aa59b30fa74cbcc6248bbad
specs:
travis-support (0.0.1)
GIT
remote: git://github.com/wycats/rake-pipeline-web-filters.git
revision: f28f5809d6a3e580401a0c589d54e6ad28f34a26
@ -98,37 +18,6 @@ GIT
GEM
remote: http://rubygems.org/
specs:
actionmailer (3.2.8)
actionpack (= 3.2.8)
mail (~> 2.4.4)
actionpack (3.2.8)
activemodel (= 3.2.8)
activesupport (= 3.2.8)
builder (~> 3.0.0)
erubis (~> 2.7.0)
journey (~> 1.0.4)
rack (~> 1.4.0)
rack-cache (~> 1.2)
rack-test (~> 0.6.1)
sprockets (~> 2.1.3)
activemodel (3.2.8)
activesupport (= 3.2.8)
builder (~> 3.0.0)
activerecord (3.2.8)
activemodel (= 3.2.8)
activesupport (= 3.2.8)
arel (~> 3.0.2)
tzinfo (~> 0.3.29)
activesupport (3.2.8)
i18n (~> 0.6)
multi_json (~> 1.0)
addressable (2.3.2)
arel (3.0.2)
atomic (1.0.1)
avl_tree (1.1.3)
backports (2.6.4)
builder (3.0.3)
bunny (0.8.0)
chunky_png (1.2.6)
coffee-script (2.2.0)
coffee-script-source
@ -139,10 +28,6 @@ GEM
chunky_png (~> 1.2)
fssm (>= 0.2.7)
sass (~> 3.1)
daemons (1.1.9)
data_migrations (0.0.1)
activerecord
rake
debugger (1.2.1)
columnize (>= 0.3.1)
debugger-linecache (~> 1.1.1)
@ -150,122 +35,26 @@ GEM
debugger-linecache (1.1.2)
debugger-ruby_core_source (>= 1.1.1)
debugger-ruby_core_source (1.1.4)
diff-lcs (1.1.3)
erubis (2.7.0)
eventmachine (1.0.0)
execjs (1.4.0)
multi_json (~> 1.0)
factory_girl (2.4.2)
activesupport
faraday (0.8.4)
multipart-post (~> 1.1)
foreman (0.60.2)
thor (>= 0.13.6)
fssm (0.2.9)
guard (1.4.0)
listen (>= 0.4.2)
thor (>= 0.14.6)
hashr (0.0.22)
hike (1.2.1)
hitimes (1.1.1)
i18n (0.6.1)
journey (1.0.4)
json (1.7.5)
kgio (2.7.4)
listen (0.5.3)
mail (2.4.4)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
metaclass (0.0.1)
metriks (0.9.9.1)
atomic (~> 1.0)
avl_tree (~> 1.1.2)
hitimes (~> 1.1)
mime-types (1.19)
mocha (0.12.7)
metaclass (~> 0.0.1)
multi_json (1.3.6)
multipart-post (1.1.5)
net-http-persistent (2.7)
net-http-pipeline (1.0.1)
newrelic_rpm (3.3.5)
pg (0.13.2)
polyglot (0.3.3)
postmark (0.9.13)
json
rake
postmark-rails (0.4.1)
actionmailer
postmark (>= 0.9.0)
rake
pusher (0.9.4)
multi_json (~> 1.0)
signature (~> 0.1.2)
rack (1.4.1)
rack-cache (1.2)
rack (>= 0.4)
rack-protection (1.2.0)
rack
rack-ssl (1.3.2)
rack
rack-test (0.6.2)
rack (>= 1.0)
railties (3.2.8)
actionpack (= 3.2.8)
activesupport (= 3.2.8)
rack-ssl (~> 1.3.2)
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (>= 0.14.6, < 2.0)
raindrops (0.10.0)
rake (0.9.2.2)
rb-fsevent (0.9.2)
rdoc (3.12)
json (~> 1.4)
redcarpet (2.2.1)
redis (3.0.2)
rerun (0.7.1)
listen
rollout (1.1.0)
rspec (2.11.0)
rspec-core (~> 2.11.0)
rspec-expectations (~> 2.11.0)
rspec-mocks (~> 2.11.0)
rspec-core (2.11.1)
rspec-expectations (2.11.3)
diff-lcs (~> 1.1.3)
rspec-mocks (2.11.3)
sass (3.2.1)
signature (0.1.4)
simple_states (0.1.1)
activesupport
hashr (~> 0.0.10)
sinatra (1.3.3)
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)
sprockets (2.1.3)
hike (~> 1.2)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
thin (1.5.0)
daemons (>= 1.0.9)
eventmachine (>= 0.12.6)
rack (>= 1.0.0)
thor (0.14.6)
tilt (1.3.3)
treetop (1.4.11)
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.33)
uglifier (1.3.0)
execjs (>= 0.3.0)
multi_json (~> 1.0, >= 1.0.2)
@ -273,39 +62,21 @@ GEM
kgio (~> 2.6)
rack
raindrops (~> 0.7)
yard (0.8.3)
PLATFORMS
ruby
DEPENDENCIES
bunny
coffee-script
compass
debugger
factory_girl (~> 2.4.0)
foreman
gh!
guard
hubble!
mocha (~> 0.12)
newrelic_rpm (~> 3.3.0)
pg (~> 0.13.2)
rack-cache
rack-contrib!
rack-ssl (~> 1.3)
rake (~> 0.9.2)
rake-pipeline!
rake-pipeline-web-filters!
rb-fsevent (~> 0.9.1)
rerun
rspec (~> 2.11)
sinatra
sinatra-contrib
tilt
travis-api!
travis-core!
travis-support!
uglifier
unicorn
yard-sinatra!

View File

@ -1,7 +0,0 @@
$: << 'lib'
guard 'assets' do
watch(%r(^Assetfile))
watch(%r(^assets))
end

View File

@ -1,6 +0,0 @@
$: << 'lib'
guard 'specs' do
watch(%r(^public))
end

View File

@ -1,3 +1,3 @@
web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
guard: bundle exec guard
rerun: rerun -p 'assets/**/*' 'bundle exec rakep'
web: script/server
assets: rerun -x -p 'assets/**/*' 'bundle exec rakep'
#specs: rerun -x -p 'public/**/*' './run_jasmine.coffee public/spec.html'

View File

@ -4,4 +4,9 @@ ENV['RAILS_ENV'] = ENV['RACK_ENV']
$: << 'lib'
require 'travis/web'
run Travis::Web::App.new
run Travis::Web::App.new(
environment: ENV['RACK_ENV'] || 'development',
api_endpoint: ENV['API_ENDPOINT'],
pusher_key: ENV['PUSHER_KEY'],
root: File.expand_path('../public', __FILE__)
)

View File

@ -1,3 +0,0 @@
[ $PORT ] || export PORT=9292
export API_ENDPOINT="http://api.dev:$PORT/"
export CLIENT_ENDPOINT="http://ci.dev:$PORT/"

View File

@ -1,41 +0,0 @@
$stdout.sync = true
require 'guard'
require 'guard/guard'
require 'rake-pipeline'
module Guard
class Assets < Guard
def start
UI.info "Guard::Assets is running."
run
end
def run_all
run
end
def reload
run
end
def run_on_change(paths)
puts "change: #{paths.inspect}"
run
end
private
def run
started = Time.now
print 'Compiling ... '
project.invoke_clean
puts "done (#{(Time.now - started).round(2)}s)."
end
def project
@project ||= Rake::Pipeline::Project.new('./Assetfile')
end
end
end

View File

@ -1,35 +0,0 @@
$stdout.sync = true
require 'guard'
require 'guard/guard'
module Guard
class Specs < Guard
def start
UI.info "Guard::Specs is running."
run
end
def run_all
run
end
def reload
run
end
def run_on_change(paths)
puts "change: #{paths.inspect}"
run
end
private
def run
system './run_jasmine.coffee public/spec.html'
end
end
end

View File

@ -1,49 +1,114 @@
require 'rack'
require 'rack/protection/path_traversal'
require 'rack/cache'
require 'rack/ssl'
require 'delegate'
require 'time'
class Travis::Web::App
ASSET_DIRS = %r(/(styles|scripts)/)
DEFAULT_ENDPOINT = 'https://api.travis-ci.org'
DEFAULT_PUSHER_KEY = '23ed642e81512118260e'
autoload :Api, 'travis/web/app/api'
autoload :Assets, 'travis/web/app/assets'
autoload :Config, 'travis/web/app/config'
autoload :Files, 'travis/web/app/files'
autoload :Helpers, 'travis/web/app/helpers'
autoload :Filter, 'travis/web/app/filter'
autoload :Terminal, 'travis/web/app/terminal'
Rack.autoload :SSL, 'rack/ssl'
Rack.autoload :Deflater, 'rack/deflater'
include Terminal
attr_accessor :app
def initialize
config = Config.new
announce(config)
@app = Rack::Builder.app do
use Rack::SSL if config.production?
use Rack::Protection::PathTraversal
use Travis::Web::App::Api, config if config.run_api?
# TODO breaks with wrong content length
# use Rack::Cache, verbose: true, metastore: 'heap:/', entitystore: 'heap:/' if config.production?
use Rack::Deflater if config.deflate?
use Travis::Web::App::Assets, config
use Travis::Web::App::Filter, config
run Travis::Web::App::Files.new
# Simple Rack router that behaves like a hash.
# Key is the path, value the response.
class Router < DelegateClass(Hash)
def initialize
super({})
end
def call(env)
self[env['PATH_INFO']]
end
end
attr_reader :app, :router, :environment, :version, :last_modified, :age, :options, :root
def initialize(options = {})
@options = options
@environment = options.fetch(:environment)
@root = options.fetch(:root)
@router = Router.new
@app = builder.to_app
@version = File.read File.expand_path('version', root)
@last_modified = Time.now
@age = 60 * 60 * 24 * 365
load_routes
end
def call(env)
app.call(env)
end
end
private
def load_routes
each_file { |f| router[route_for(f)] = response_for(f) }
router.default = router['/']
end
def response_for(file)
content = File.read(file)
set_config(content) if index? file
headers = {
'Content-Length' => content.bytesize,
'Content-Location' => route_for(file),
'Cache-Control' => cache_control(file),
'Content-Location' => route_for(file),
'Content-Type' => mime_type(file),
'ETag' => version,
'Last-Modified' => last_modified.httpdate,
'Expires' => (last_modified + age).httpdate,
'Vary' => 'If-None-Match'
}
[ 200, headers, [ content ] ]
end
def each_file
Dir.chdir(root) do
Dir.glob('**/*') { |f| yield f if File.file? f }
end
end
def prefix?(file)
file =~ /^(styles|scripts)\//
end
def index?(file)
file == "index.html"
end
def route_for(file)
file = File.join(version, file) if prefix? file
file = "" if index? file
"/#{file}"
end
def cache_control(file)
case file
when 'index.html' then "public, must-revalidate"
when 'version' then "no-cache"
else "public, max-age=#{age}"
end
end
def mime_type(file)
Rack::Mime.mime_type File.extname(file)
end
def set_config(string)
string.gsub! %r(<meta (rel|name)="(travis\.[^"]*)" (href|value)="([^"]*)"[^>]*>) do
%(<meta #{$1}="#{$2}" #{$3}="#{options[$2.to_sym] || $4}">)
end
string.gsub! %r{(src|href)="(\/?)((styles|scripts)\/[^"]*)"} do
%(#$1="#$2#{version}/#$3")
end
end
def builder
builder = Rack::Builder.new
builder.use Rack::SSL if environment == 'production'
builder.use Rack::Deflater
builder.use Rack::Head
builder.use Rack::ConditionalGet
builder.run router
builder
end
end

View File

@ -1,29 +0,0 @@
require 'travis/api/app'
class Travis::Web::App
class Api
include Helpers
attr_reader :app, :api, :config
def initialize(app, config)
@app = app
@api = Travis::Api::App.new
@config = config
end
def call(env)
if matches?(env['PATH_INFO'])
api.call(map_env(env, config.api_endpoint))
else
app.call(env)
end
end
private
def matches?(path)
path.starts_with?(config.api_endpoint)
end
end
end

View File

@ -1,24 +0,0 @@
class Travis::Web::App
class Assets
include Helpers
attr_reader :app, :config
def initialize(app, config)
@app = app
@config = config
end
def call(env)
path = env['PATH_INFO']
env = map_env(env, config.version) if asset?(path)
app.call(env)
end
private
def asset?(path)
path =~ Travis::Web::App::ASSET_DIRS
end
end
end

View File

@ -1,79 +0,0 @@
class Travis::Web::App
class Config
OPTIONS = %w(ENV API_ENDPOINT CLIENT_ENDPOINT PUSHER_KEY RUN_API WATCH DEFLATE)
def [](key)
send(key)
end
def keys
@keys ||= OPTIONS.map(&:downcase)
end
def each
keys.each do |key|
yield key, send(key)
end
end
def env
config.fetch(:env, 'development')
end
def production?
env == 'production'
end
def run_api?
!!config.fetch(:run_api, config[:api_endpoint].to_s.start_with?('/'))
end
def api_endpoint
config.fetch(:api_endpoint, run_api? ? '/api' : DEFAULT_ENDPOINT).gsub(/:\d+/, '')
end
def client_endpoint
config.fetch(:client_endpoint, '/')
end
def pusher_key
config.fetch(:pusher_key, run_api? ? '' : DEFAULT_PUSHER_KEY)
end
def deflate?
!!config.fetch(:deflate, production?)
end
def watch?
!!config.fetch(:watch, false)
end
alias run_api run_api?
alias deflate deflate?
alias watch watch?
def version
production? ? @version ||= read_version : read_version
end
private
def config
@config ||= Hash[*OPTIONS.map do |key|
[key.downcase.to_sym, cast(ENV[key])] if ENV.key?(key)
end.compact.flatten]
end
def cast(value)
case value
when '1', 'true' then true
when '0', 'false' then false
else value
end
end
def read_version
File.read('public/version').chomp
end
end
end

View File

@ -1,44 +0,0 @@
class Travis::Web::App
class Files < Rack::Cascade
MUST_REVALIDATE = %w(/ /index.html /version)
def self.last_modified
@last_modified ||= File.mtime("public/version").httpdate
end
def initialize
super([public_dir, index])
end
def call(env)
status, headers, body = super(env)
# TODO: temporary hack to make specs work, remove this later properly
headers.delete 'Last-Modified' if env['PATH_INFO'] == '/spec.html'
[status, headers, body]
end
def public_dir
Rack::File.new('public')
end
def index
proc do |env|
status, headers, body = Rack::File.new(nil).tap { |f| f.path = 'public/index.html' }.serving(env)
headers.merge!(cache_headers(env['PATH_INFO'])) # TODO unless development?
[status, headers, body]
end
end
def cache_headers(path)
{ 'Cache-Control' => cache_control(path), 'Last-Modified' => self.class.last_modified }
end
def cache_control(path)
must_revalidate?(path) ? 'public, must-revalidate' : 'public, max-age=31536000'
end
def must_revalidate?(path)
MUST_REVALIDATE.include?(path)
end
end
end

View File

@ -1,43 +0,0 @@
class Travis::Web::App
class Filter
autoload :Config, 'travis/web/app/filter/config'
autoload :Assets, 'travis/web/app/filter/assets'
attr_reader :app, :config
def initialize(app, config)
@app = app
@config = config
end
def call(env)
status, headers, body = app.call(env)
headers, body = filter(headers, body) if content_type?(headers, 'text/html')
[status, headers, body]
end
private
def filter(headers, body)
headers.delete 'Content-Length' # why don't we just set this to the new length?
filtered = []
body.each { |chunk| filtered << filter_chunk(chunk) }
body.close if body.respond_to?(:close)
[headers, filtered]
end
def filter_chunk(string)
filters.inject(string) do |string, filter|
filter.apply? ? filter.apply(string) : string
end
end
def filters
@filters ||= Filter.constants.map { |name| Filter.const_get(name).new(config) }
end
def content_type?(headers, type)
headers.any? { |key, value| key.downcase == 'content-type' and value.start_with?(type) }
end
end
end

View File

@ -1,35 +0,0 @@
class Travis::Web::App
class Filter
class Assets
attr_reader :config
def initialize(config)
@config = config
end
def apply?
true
end
def apply(string)
string = version(string)
string = minify(string) if config.production?
string
end
private
def version(string)
string.gsub(Travis::Web::App::ASSET_DIRS) do
"/#{config.version}/#{$1}/"
end
end
def minify(string)
string.gsub(%r((/javascripts/.*).js)) do
"#{$1}.min.js/"
end
end
end
end
end

View File

@ -1,24 +0,0 @@
class Travis::Web::App
class Filter
class Config
CONFIG_TAG = %r(<meta (rel|name)="([^"]*)" (href|value)="([^"]*)"[^>]*>)
attr_reader :config
def initialize(config)
@config = config
end
def apply?
config.api_endpoint != DEFAULT_ENDPOINT ||
config.pusher_key != DEFAULT_PUSHER_KEY
end
def apply(string)
string.gsub(CONFIG_TAG) do
%(<meta #{$1}="#{$2}" #{$3}="#{config[$2.split('.').last]}">)
end
end
end
end
end

View File

@ -1,11 +0,0 @@
class Travis::Web::App
module Helpers
# TODO what's a better name?
def map_env(env, segment)
segment = "/#{segment}" unless segment[0] == '/'
env['PATH_INFO'] = env['PATH_INFO'].gsub(%r(^#{segment}(?:/)), '')
env['SCRIPT_NAME'] = "#{env['SCRIPT_NAME']}#{segment}"
env
end
end
end

View File

@ -1,17 +0,0 @@
class Travis::Web::App
module Terminal
def announce(config)
config.each do |key, value|
$stderr.puts("#{key.upcase.rjust(15)} = #{colorize(config.send(key))}")
end
end
def colorize(value)
case value
when nil, false, '0' then "\e[31m0\e[0m"
when true, '1' then "\e[32m1\e[0m"
else "\e[33m#{value}\e[0m"
end
end
end
end

File diff suppressed because it is too large Load Diff

View File

@ -1 +1 @@
402ce94f
6b8605ca

8
script/server Executable file
View File

@ -0,0 +1,8 @@
#!/usr/bin/env bash
cd "$(dirname "$0")/.."
[ $PORT ] || PORT=9292
[ $RACK_ENV ] || RACK_ENV=development
cmd="ruby -I lib -S bundle exec ruby -I lib -S unicorn -p $PORT -c ./config/unicorn.rb"
[[ $RACK_ENV == "development" ]] && exec rerun "$cmd -o 127.0.0.1"
exec $cmd

View File

@ -1,113 +0,0 @@
require 'lib/spec_helper'
describe Travis::Web::App::Config do
let(:config) { Travis::Web::App::Config.new }
before :each do
@env = ENV.clone
ENV.clear
end
after :each do
ENV.replace(@env)
end
describe 'env' do
it 'given ENV=foo it returns foo' do
ENV['ENV'] = 'foo'
config.env.should == 'foo'
end
it 'defaults to development' do
config.env.should == 'development'
end
end
describe 'run_api?' do
it 'given RUN_API=1 it returns true' do
ENV['RUN_API'] = '1'
config.run_api?.should be_true
end
it 'given RUN_API=0 it returns false' do
ENV['RUN_API'] = '0'
config.run_api?.should be_false
end
it 'defaults to true if api_endpoint is local' do
ENV['API_ENDPOINT'] = '/api'
config.run_api?.should be_true
end
it 'defaults to false if api_endpoint is not local' do
ENV['API_ENDPOINT'] = 'https://api.travis-ci.com'
config.run_api?.should be_false
end
end
describe 'api_endpoint' do
it 'given API_ENDPOINT=https://api.travis-ci.com it returns the given url' do
ENV['API_ENDPOINT'] = 'https://api.travis-ci.com'
config.api_endpoint.should == 'https://api.travis-ci.com'
end
it 'defaults to /api if run_api? is true' do
config.stubs(:run_api?).returns(true)
config.api_endpoint.should == '/api'
end
it 'defaults to https://api.travis-ci.org if run_api? is false' do
config.stubs(:run_api?).returns(false)
config.api_endpoint.should == 'https://api.travis-ci.org'
end
end
describe 'client_endpoint' do
it 'given CLIENT_ENDPOINT=/client it returns the given url' do
ENV['CLIENT_ENDPOINT'] = '/client'
config.client_endpoint.should == '/client'
end
it 'defaults to /' do
config.client_endpoint.should == '/'
end
end
describe 'deflate?' do
it 'given DEFLATE=1 it returns true' do
ENV['DEFLATE'] = '1'
config.deflate.should be_true
end
it 'given DEFLATE=0 it returns false' do
ENV['DEFLATE'] = '0'
config.deflate.should be_false
end
it 'defaults to true if env is production' do
config.stubs(:env).returns('production')
config.deflate.should be_true
end
it 'defaults to false if env is not production' do
config.stubs(:env).returns('development')
config.deflate.should be_false
end
end
describe 'watch?' do
it 'given WATCH=1 it returns true' do
ENV['WATCH'] = '1'
config.watch?.should be_true
end
it 'given WATCH=0 it returns false' do
ENV['WATCH'] = '0'
config.watch?.should be_false
end
it 'defaults to false' do
config.watch?.should be_false
end
end
end

View File

@ -1,19 +0,0 @@
# ENV['RACK_ENV'] = ENV['RAILS_ENV'] = ENV['ENV'] = 'test'
require 'rspec'
require 'travis/web'
require 'sinatra/test_helpers'
# require 'logger'
# require 'gh'
# require 'multi_json'
RSpec.configure do |config|
config.mock_framework = :mocha
config.expect_with :rspec, :stdlib
# config.include TestHelpers
# config.before :each do
# set_app Travis::Web::App.new
# end
end