Skip to content

Commit

Permalink
Added some basic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jamtur01 committed Jul 16, 2012
1 parent ab2162c commit a237559
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .rspec
@@ -0,0 +1,2 @@
--colour
--format progress
5 changes: 4 additions & 1 deletion psigner.gemspec
Expand Up @@ -16,5 +16,8 @@ Gem::Specification.new do |s|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"] s.require_paths = ["lib"]


s.add_dependency "sinatra" s.add_development_dependency "sinatra"
s.add_development_dependency "mocha"
s.add_development_dependency "rspec"
s.add_development_dependency "rack-test"
end end
33 changes: 33 additions & 0 deletions spec/psigner_spec.rb
@@ -0,0 +1,33 @@
require 'spec_helper'

describe Psigner::Application do

describe "GET '/api/sign'" do
it "should fail" do
get '/'
last_response.should_not be_ok
end
end

describe "POST '/api/sign'" do
it "should fail to get the API signing page without parameters" do
post '/api/sign'
last_response.status.should == 400
end

it "should fail to get the API signing page with only one parameter" do
post '/api/sign', params = { "secret" => "SHAREDSECRET" }
last_response.status.should == 400
end

it "should get the API signing page" do
post '/api/sign', params = { "secret" => "SHAREDSECRET", "certname" => "bob" }
last_response.status.should == 200
end

it "should fail with incorrect shared secret" do
post '/api/sign', params = { "secret" => "NOSHAREDSECRET", "certname" => "bob" }
last_response.status.should == 401
end
end
end
28 changes: 28 additions & 0 deletions spec/spec_helper.rb
@@ -0,0 +1,28 @@
$LOAD_PATH.unshift(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))

require 'psigner'
require 'rspec'
require 'rack/test'

set :environment, :test
set :run, false
set :raise_errors, true
set :logging, false

RSpec.configure do |config|
config.include Rack::Test::Methods
config.mock_framework = :mocha
end

ENV['RACK_ENV'] = "test"

def app
@app ||= Psigner::Application
end

# quick convenience methods..

def fixtures_path
"#{File.dirname(File.expand_path(__FILE__))}/fixtures"
end

0 comments on commit a237559

Please sign in to comment.