Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Test Driving Goliath
Search
Tom Clements
April 20, 2012
Programming
1
77
Test Driving Goliath
Introduction to testing Goliath, demo code available here
https://github.com/seenmyfate/read_later
Tom Clements
April 20, 2012
Tweet
Share
More Decks by Tom Clements
See All by Tom Clements
Cucumber - Doing it Right
seenmyfate
3
160
git - the stupid content tracker
seenmyfate
2
120
Give
seenmyfate
1
110
4 Steps to Faster Rails Tests
seenmyfate
5
500
Other Decks in Programming
See All in Programming
雑に思考を整理する技術と効能
konifar
55
25k
Micro Frontends for Java Microservices - Devnexus 2024
mraible
PRO
0
420
Git Rebase
bkuhlmann
11
1.6k
"config" ってなんだ? / What is "config"?
okashoi
0
210
OpenTelemetry のサービスという概念について
azukiazusa1
2
1.1k
Elm 0.19.0 Changes
bkuhlmann
0
480
Java 22 Overview
kishida
1
170
Site Reliability Engineering for GMO
pyama86
6
910
What We Can Learn From OSS
inouehi
0
400
甘い香りに誘われてVanilla Extractを1年間運用してみた
miyahkun
1
110
[技育CAMPアカデミア]アイディアを形に!【超入門】スマホアプリ開発〜リリースまでの流れをご紹介
teamlab
PRO
0
340
Hanami and htmx
bkuhlmann
0
190
Featured
See All Featured
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
154
14k
StorybookのUI Testing Handbookを読んだ
zakiyama
11
4.6k
Designing with Data
zakiwarfel
95
4.8k
Navigating Team Friction
lara
177
13k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
273
13k
Put a Button on it: Removing Barriers to Going Fast.
kastner
58
3k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
18
6.9k
The Cost Of JavaScript in 2023
addyosmani
14
3.8k
Raft: Consensus for Rubyists
vanstee
132
6.2k
Testing 201, or: Great Expectations
jmmastey
27
6.3k
The Cult of Friendly URLs
andyhume
74
5.7k
A designer walks into a library…
pauljervisheath
199
23k
Transcript
Test Driving Goliath Tom Clements Senior Developer, On The Beach
tom-clements.com | github.com/seenmyfate @Seenmyfate
Goliath is an open source non-blocking asynchronous Ruby web server
framework
powered by an EventMachine reactor a high-performance HTTP parser Rack
Ruby 1.9 runtime (MRI, JRuby Rubinius)
High fibers Each HTTP request within Goliath is executed in
its own Ruby fiber all asynchronous I/O operations can suspend and resume without additional code
Hello, world $ gem install goliath
class HelloWorld < Goliath::API def response(env) [200, {}, "Hello, world"]
end end
Start the server $ ruby hello_world.rb -sv
Read Later A demo Single Endpoint Fire and forget Validate
params are correct Store a url
Tree $ . ├── Gemfile ├── config │ └── read_later.rb
├── read_later.rb └── spec ├── read_later_spec.rb └── spec_helper.rb
spec_helper.rb Goliath.env = :test RSpec.configure do |c| c.include Goliath::TestHelper, example_group:
{ file_path: /spec/ } end
spec/read_later_spec.rb it 'returns OK' do with_api ReadLater do get_request(query: {url:
'/test'}) do |request| response = Yajl::Parser.parse(request.response) response.should eq 'OK' end end end
config/read_later.rb config['db'] = EM::Synchrony::ConnectionPool.new(size: 20) do Mysql2::EM::Client.new(ENV['DB_CONFIG']) end
read_later.rb class ReadLater < Goliath::API use Goliath::Rack::Params use Goliath::Rack::DefaultMimeType use
Goliath::Rack::Render, 'json' def response(env) db.aquery("INSERT INTO `articles`(`url`) VALUES ('#{params[:url]}")) [200, {}, 'OK'] end end
spec/read_later.rb it "returns an error" do with_api ReadLater do get_request(query:
{}) do |request| response = Yajl::Parser.parse(request.response) response['error'].should eq 'Url identifier missing' end end end
read_later.rb use Goliath::Rack::Validation::RequiredParam, {key: 'url', type: 'Url'}
and that's it! github.com/postrank-labs/goliath igvita.com/ github.com/seenmyfate/read_later
gem install goliath tom-clements.com | github.com/seenmyfate @Seenmyfate