Created
June 22, 2011 04:51
-
-
Save tinomen/1039524 to your computer and use it in GitHub Desktop.
example goliath app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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