Permalink
Browse files

adding specs

  • Loading branch information...
1 parent 1d28361 commit 7268251a073ba94953ef0576ee8f1cc16b7f6fee @steelThread committed Jan 10, 2012
Showing with 83 additions and 13 deletions.
  1. +2 −0 .rspec
  2. +1 −1 Gemfile
  3. +2 −4 Gemfile.lock
  4. +17 −1 Rakefile
  5. +0 −4 lib/redmon.rb
  6. +10 −3 lib/redmon/app.rb
  7. +38 −0 spec/app_spec.rb
  8. +13 −0 spec/spec_helper.rb
View
2 .rspec
@@ -0,0 +1,2 @@
+--color
+--format <%= true ? 'documentation' : 'progress' %>
View
@@ -15,7 +15,7 @@ gem "thin"
gem "activesupport"
group :development do
- gem "delorean", ">= 0"
+ gem "rake"
gem "rspec", "~> 2.6.0"
gem "shoulda", ">= 0"
gem "bundler", "~> 1.0.0"
View
@@ -12,10 +12,7 @@ GEM
bson (1.5.2)
bson_ext (1.5.2)
bson (= 1.5.2)
- chronic (0.6.6)
daemons (1.1.5)
- delorean (1.2.0)
- chronic
diff-lcs (1.1.3)
em-hiredis (0.1.0)
hiredis (~> 0.3.0)
@@ -30,6 +27,7 @@ GEM
rack
rack-test (0.6.1)
rack (>= 1.0)
+ rake (0.9.2.2)
redis (2.2.2)
rspec (2.6.0)
rspec-core (~> 2.6.0)
@@ -57,14 +55,14 @@ DEPENDENCIES
activesupport
bson_ext (>= 1.4.0)
bundler (~> 1.0.0)
- delorean
em-hiredis
eventmachine
haml
i18n
json
rack
rack-test
+ rake
redis (>= 2.2.2)
rspec (~> 2.6.0)
shoulda
View
@@ -1 +1,17 @@
-require "bundler/gem_tasks"
+require 'rubygems'
+require 'bundler'
+begin
+ Bundler.setup(:default, :development)
+rescue Bundler::BundlerError => e
+ $stderr.puts e.message
+ $stderr.puts "Run `bundle install` to install missing gems"
+ exit e.status_code
+end
+require 'rake'
+
+require 'rspec'
+require 'rspec/core/rake_task'
+desc "Run all examples"
+task RSpec::Core::RakeTask.new('spec')
+
+task :default => "spec"
View
@@ -55,10 +55,6 @@ def self.shutdown
EM.stop
end
- def self.key
- "#{@opts[:namespace]}:redis.info"
- end
-
def self.log(msg)
puts "[#{Time.now.strftime("%y-%m-%d %H:%M:%S")}] #{msg}"
end
View
@@ -11,8 +11,8 @@ def opts
@opts
end
- def count
- -params[:count].to_i
+ def count()
+ -(params[:count] ? params[:count].to_i : 1)
end
end
@@ -28,7 +28,7 @@ def initialize(opts)
get '/info' do
content_type :json
- @redis.zrange(Redmon.key, count, -1).to_json
+ @redis.zrange(key, count, -1).to_json
end
get '/cli' do
@@ -42,4 +42,11 @@ def initialize(opts)
"(error) ERR wrong number of arguments for '#{cmd.to_s}' command"
end
end
+
+ private
+
+ def key
+ "#{@opts[:namespace]}:redis.info"
+ end
+
end
View
@@ -0,0 +1,38 @@
+require ::File.expand_path('../spec_helper.rb', __FILE__)
+
+include Rack::Test::Methods
+
+describe "app" do
+
+ def app
+ Redmon::App.new(Redmon::DEFAULT_OPTS)
+ end
+
+ context "/" do
+ it "should render the app" do
+ get "/"
+ last_response.should be_ok
+ last_response.body.include?('Redmon')
+ end
+ end
+
+ context "/info" do
+ it "should render json" do
+ get "/info"
+ last_response.should be_ok
+ last_response.headers["Content-Type"].should == "application/json;charset=utf-8"
+ end
+
+ it "should render the correct # of results" do
+ get "/info?count=1"
+ JSON.parse(last_response.body).length.should == 1
+
+ get "/info?count=2"
+ JSON.parse(last_response.body).length.should == 2
+ end
+ end
+
+ context "/cli" do
+
+ end
+end
View
@@ -0,0 +1,13 @@
+require 'rubygems'
+require 'json'
+require 'rspec'
+require 'redis'
+require 'rack'
+require 'rack/test'
+
+ENV['RACK_ENV'] = "test"
+
+$: << ::File.expand_path('../../lib', __FILE__)
+require "redmon"
+require "eventmachine"
+require 'em-hiredis'

0 comments on commit 7268251

Please sign in to comment.