Skip to content

Commit

Permalink
Add codes for simplecov and coveralls to analyze code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ishida committed Jun 18, 2013
1 parent b3d1f5a commit b2c4c83
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 32 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ vendor/bundle
spec/reports
log
run_*
Procfile.*
Procfile.*
coverage
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ group :test do
gem 'rake'
gem 'rspec'
gem 'rack-test'
gem 'simplecov', require: false
gem 'coveralls', require: false
end
18 changes: 18 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ GEM
remote: https://rubygems.org/
specs:
backports (3.3.0)
colorize (0.5.8)
coveralls (0.6.7)
colorize
multi_json (~> 1.3)
rest-client
simplecov (>= 0.7)
thor
dalli (2.6.4)
diff-lcs (1.2.4)
eventmachine (1.0.3)
Expand All @@ -16,6 +23,8 @@ GEM
excon (~> 0.22.1)
json (1.7.7)
memcachier (0.0.2)
mime-types (1.23)
multi_json (1.7.7)
multipart-post (1.2.0)
newrelic_rpm (3.6.2.96)
nokogiri (1.5.9)
Expand All @@ -28,6 +37,8 @@ GEM
rack-test (0.6.2)
rack (>= 1.0)
rake (10.0.4)
rest-client (1.6.7)
mime-types (>= 1.16)
rspec (2.13.0)
rspec-core (~> 2.13.0)
rspec-expectations (~> 2.13.0)
Expand All @@ -39,6 +50,10 @@ GEM
sanitize (2.0.3)
nokogiri (>= 1.4.4, < 1.6)
nokogiri (>= 1.4.4, < 1.6)
simplecov (0.7.1)
multi_json (~> 1.0)
simplecov-html (~> 0.7.1)
simplecov-html (0.7.1)
sinatra (1.4.2)
rack (~> 1.5, >= 1.5.2)
rack-protection (~> 1.4)
Expand All @@ -50,6 +65,7 @@ GEM
rack-test
sinatra (~> 1.4.2)
tilt (~> 1.3)
thor (0.18.1)
tilt (1.3.7)
tumblr_client (0.7.1)
faraday (>= 0.8)
Expand All @@ -61,6 +77,7 @@ PLATFORMS
ruby

DEPENDENCIES
coveralls
dalli
haml
heroku-api
Expand All @@ -71,6 +88,7 @@ DEPENDENCIES
rake
rspec
sanitize
simplecov
sinatra
sinatra-contrib
tumblr_client
46 changes: 17 additions & 29 deletions app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ class App < Sinatra::Base
@@is_restarting = false

configure do
require 'newrelic_rpm' if production?
require 'heroku-api' if production?
register Sinatra::Reloader if development?
use Rack::Deflater

set :haml, { :format => :html5 }
set :worker_max, (ENV['WORKER_MAX'] || 10).to_i
set :memory_kbyte_max, (ENV['MEMORY_KBYTE_MAX'] || 480000).to_i
Expand All @@ -24,31 +28,23 @@ class App < Sinatra::Base
set :tumblr_consumer_key, (ENV['TUMBLR_CONSUMER_KEY'] ||
open(File.dirname(__FILE__) + '/.tumblr') { |f|
YAML.load(f) }['consumer_key'])
set :heroku_app_name, (ENV['HEROKU_APP_NAME'] || 'simblr')
cache_sec = (ENV['DEFAULT_CACHE_MAX_AGE_SEC'] || 86400).to_i
set :cache_max_age_sec, cache_sec
set :static_cache_control, [:public, :max_age => cache_sec]
end

configure :test do
enable :raise_errors
disable :run, :logging
set :cache_max_age_sec, 0
set :static_cache_control, 0
@@dc_test = {}
end

configure :development do
register Sinatra::Reloader
configure :test, :development do
set :cache_max_age_sec, 0
set :static_cache_control, 0
end

configure :production do
require 'newrelic_rpm'
require 'heroku-api'
cache_max_age_sec = (ENV['DEFAULT_CACHE_MAX_AGE_SEC'] || 86400).to_i
set :cache_max_age_sec, cache_max_age_sec
set :static_cache_control, [:public, :max_age => cache_max_age_sec]
set :heroku_app_name, ENV['HEROKU_APP_NAME']
end

configure :development, :production do
enable :logging
set :dc, Dalli::Client.new(nil, :compress => true,
Expand All @@ -61,14 +57,11 @@ class App < Sinatra::Base
cache_control :public, :max_age => settings.cache_max_age_sec

@app_name = 'Simblr'
if development?
@host_name = request.host
@host_name << ":#{request.port}" unless request.port == 80
@host_name_enc = request.host
@host_name_enc << "%3a#{request.port}" unless request.port == 80
else
@host_name = request.host
@host_name_enc = request.host
@host_name = request.host
@host_name_enc = request.host
if !production? && request.port != 80
@host_name << ":#{request.port}"
@host_name_enc << "%3a#{request.port}"
end
end

Expand All @@ -82,12 +75,11 @@ class App < Sinatra::Base
get '/' do
q = params[:q]

if development?
@newrelic_header = ''
@newrelic_footer = ''
else
if production?
@newrelic_header = ::NewRelic::Agent.browser_timing_header rescue ''
@newrelic_footer = ::NewRelic::Agent.browser_timing_footer rescue ''
else
@newrelic_header = @newrelic_footer = ''
end

return haml :index if q.nil?
Expand Down Expand Up @@ -193,10 +185,6 @@ def logger
request.logger
end

def h(html)
Rack::Utils.escape_html(html)
end

def s(html)
Sanitize.clean(html,
:elements => %w{br p a img blockquote},
Expand Down
15 changes: 13 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# coding: utf-8
ENV['RACK_ENV'] = 'test'

require 'simplecov'
require 'coveralls'
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
SimpleCov::Formatter::HTMLFormatter,
Coveralls::SimpleCov::Formatter
]
SimpleCov.start do
add_filter '/spec/'
add_filter '/vendor/'
end

require 'rack/test'
require 'rspec'

ENV['RACK_ENV'] = 'test'

0 comments on commit b2c4c83

Please sign in to comment.