Skip to content
Browse files

Add some tests

  • Loading branch information...
1 parent 4c30639 commit b97b9a403b5c27a88b4edbe97ed8ece01cdcb8bd @titanous titanous committed Aug 12, 2012
Showing with 21 additions and 5 deletions.
  1. +1 −1 Guardfile
  2. +6 −0 lib/sp-server/api.rb
  3. +4 −4 spec/sp-server/api_spec.rb
  4. +3 −0 spec/spec_helper.rb
  5. +7 −0 spec/support/json_request.rb
View
2 Guardfile
@@ -2,5 +2,5 @@ guard 'rspec', :version => 2 do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^lib/[^/]+\.rb$}) { "spec" }
- watch('spec/spec_helper.rb') { "spec" }
+ watch(%r{spec/(spec_helper|support/).*\.rb}) { "spec" }
end
View
6 lib/sp-server/api.rb
@@ -3,7 +3,13 @@
module SP
module Server
class API < Grape::API
+ version 'v1', using: :header
+ resource :subscriptions do
+ post do
+ puts params[:foo]
+ end
+ end
end
end
end
View
8 spec/sp-server/api_spec.rb
@@ -5,10 +5,10 @@ def app
SP::Server::API
end
- describe "GET /foo" do
- it "works" do
- get "/foo"
- last_response.status.should == 404
+ describe "POST /subscriptions" do
+ it "creates a new subscription" do
+ json_post '/subscriptions', :foo => 'bar'
+ last_response.status.should == 201
end
end
end
View
3 spec/spec_helper.rb
@@ -5,6 +5,9 @@
require 'rack/test'
require 'sp-server'
+Dir["#{File.dirname(__FILE__)}/support/*.rb"].each { |f| require f }
+
RSpec.configure do |config|
config.include Rack::Test::Methods
+ config.include JsonPostHelper
end
View
7 spec/support/json_request.rb
@@ -0,0 +1,7 @@
+require 'json'
+
+module JsonPostHelper
+ def json_post(path, data = {})
+ post path, data.to_json, 'CONTENT_TYPE' => 'application/json'
+ end
+end

0 comments on commit b97b9a4

Please sign in to comment.
Something went wrong with that request. Please try again.