Skip to content

Commit

Permalink
Config specs
Browse files Browse the repository at this point in the history
  • Loading branch information
winton committed Dec 7, 2009
1 parent 6b17a8a commit 09fe1b3
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 10 deletions.
6 changes: 3 additions & 3 deletions lib/lilypad/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def api_key(api_key=nil, &block)

def deploy_url(url=nil)
@deploy_url = url unless url.nil?
@deploy_url || "http://hoptoadapp.com/deploys.txt"
@deploy_url || "http://hoptoadapp.com:80/deploys.txt"
end

def environments(environments=nil)
Expand All @@ -20,7 +20,7 @@ def environments(environments=nil)

def filters(filters=nil)
@filters = filters unless filters.nil?
@filters
@filters || []
end

def log(log=nil)
Expand All @@ -30,7 +30,7 @@ def log(log=nil)

def notify_url(url=nil)
@notify_url = url unless url.nil?
@url || "http://hoptoadapp.com:80/notify_url/v2/notices"
@notify_url || "http://hoptoadapp.com:80/notify_url/v2/notices"
end

def rails
Expand Down
7 changes: 4 additions & 3 deletions lib/lilypad/hoptoad/notify.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def backtrace
end

def filter(hash)
return hash unless Config.filters
return hash if Config.filters.empty?
hash.inject({}) do |acc, (key, val)|
match = Config.filters.any? { |f| key.to_s =~ Regexp.new(f) }
acc[key] = match ? "[FILTERED]" : val
Expand Down Expand Up @@ -65,13 +65,14 @@ def parse

if @env
request = Rack::Request.new @env
params = filter request.params
request_path = request.script_name + request.path_info
else
request = nil
params = {}
request_path = 'Internal'
end

[ backtrace, env, @exception, request, request_path ]
[ backtrace, env, @exception, params, request_path ]
end

def success?
Expand Down
6 changes: 3 additions & 3 deletions lib/lilypad/hoptoad/xml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class <<self

include Config::Methods

def build(backtrace, env, exception, request, request_path)
def build(backtrace, env, exception, params, request_path)
@@last_request = nil
xml = ::Builder::XmlMarkup.new
xml.instruct! :xml, :version => "1.0", :encoding => "UTF-8"
Expand All @@ -29,9 +29,9 @@ def build(backtrace, env, exception, request, request_path)
r.action Config::Request.action
r.component Config::Request.component || request_path
r.url request_path
if request && request.params.any?
if params.any?
r.params do |p|
request.params.each do |key, value|
params.each do |key, value|
p.var value.to_s, :key => key
end
end
Expand Down
2 changes: 2 additions & 0 deletions lib/rack/lilypad.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require File.expand_path("#{File.dirname __FILE__}/../lilypad")

module Rack
class Lilypad

Expand Down
27 changes: 27 additions & 0 deletions spec/lilypad/config/request_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require File.expand_path("#{File.dirname __FILE__}/../../spec_helper")

describe Lilypad::Config::Request do

before(:each) do
Lilypad::Config::Request.action 'action'
Lilypad::Config::Request.component 'component'
end

after(:each) do
Lilypad::Config::Request.class_eval do
@action = nil
@component = nil
end
end

it "should set options" do
Lilypad::Config::Request.action.should == 'action'
Lilypad::Config::Request.component.should == 'component'
end

it "should provide a method to reset all options" do
Lilypad::Config::Request.reset!
Lilypad::Config::Request.action.should == nil
Lilypad::Config::Request.component.should == nil
end
end
45 changes: 45 additions & 0 deletions spec/lilypad/config_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
require File.expand_path("#{File.dirname __FILE__}/../spec_helper")

describe Lilypad::Config do

before(:each) do
Lilypad::Config.api_key 'api_key'
Lilypad::Config.deploy_url 'deploy_url'
Lilypad::Config.environments 'environments'
Lilypad::Config.filters 'filters'
Lilypad::Config.log 'log'
Lilypad::Config.notify_url 'notify_url'
end

after(:each) do
Lilypad::Config.class_eval do
@api_key = nil
@deploy_url = nil
@environments = nil
@filters = nil
@log = nil
@notify_url = nil
end
end

it "should set options" do
Lilypad::Config.api_key.should == 'api_key'
Lilypad::Config.deploy_url.should == 'deploy_url'
Lilypad::Config.environments.should == 'environments'
Lilypad::Config.filters.should == 'filters'
Lilypad::Config.log.should == 'log'
Lilypad::Config.notify_url.should == 'notify_url'
end

it "should require the rails adapter when the rails method is called" do
adapter = File.expand_path "#{SPEC}/../lib/lilypad/adapters/rails"
Lilypad::Config.should_receive(:require).with(adapter)
Lilypad::Config.rails
end

it "should require the rails adapter when the sinatra method is called" do
adapter = File.expand_path "#{SPEC}/../lib/lilypad/adapters/sinatra"
Lilypad::Config.should_receive(:require).with(adapter)
Lilypad::Config.sinatra
end
end
1 change: 0 additions & 1 deletion spec/lilypad_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
rescue Exception => e
Lilypad.notify(e)
end
validate_xml
end

it "should provide a deploy method" do
Expand Down

0 comments on commit 09fe1b3

Please sign in to comment.