Skip to content

Instantly share code, notes, and snippets.

@tinomen
Created June 22, 2011 04:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tinomen/1039524 to your computer and use it in GitHub Desktop.
Save tinomen/1039524 to your computer and use it in GitHub Desktop.
example goliath app
source 'http://rubygems.org'
# gem 'goliath'
gem 'goliath', :git => 'https://github.com/postrank-labs/goliath.git'
gem 'em-http-request', '>= 1.0.0.beta.1'
# gem 'em-http-request', :git => 'https://github.com/igrigorik/em-http-request.git'
gem 'yajl-ruby'
group :development, :test do
gem 'rspec'
gem 'simplecov'
gem 'multipart_body'
end
require 'spec_helper'
require File.join(File.dirname(__FILE__), '../../', 'vindecoder')
require 'yajl'
describe Vindecoder do
let(:err) { Proc.new { fail "request failed" } }
it 'should respond with an error if vin is missing' do
with_api(Vindecoder) do
get_request({:vin => 's'}, err) do |c|
# puts c.inspect
r = Yajl::Parser.parse(c.response)
r['error'].should_not be_nil
r['error'].should == 'Vin identifier missing'
end
end
end
end
require 'bundler'
Bundler.setup
Bundler.require
require 'goliath/test_helper'
Goliath.env = :test
RSpec.configure do |c|
c.include Goliath::TestHelper, :example_group => {
:file_path => /spec\/integrations/
}
end
#!/usr/bin/env ruby
require 'goliath'
require 'yajl'
class Vindecoder < Goliath::API
use Goliath::Rack::Params
use Goliath::Rack::Formatters::JSON
use Goliath::Rack::Validation::RequestMethod, %w(GET POST)
use Goliath::Rack::Validation::RequiredParam, {:key => 'vin'}
# returning hash body will be formatted as JSON by middleware
def response(env)
puts env.inspect
[200, {}, {}]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment