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
94
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
560
Other Decks in Programming
See All in Programming
DevinとCursorから学ぶAIエージェントメモリーの設計とMoatの考え方
itarutomy
1
670
プログラミング言語学習のススメ / why-do-i-learn-programming-language
yashi8484
0
130
CloudNativePGがCNCF Sandboxプロジェクトになったぞ! 〜CloudNativePGの仕組みの紹介〜
nnaka2992
0
220
SwiftUI Viewの責務分離
elmetal
PRO
1
220
AIの力でお手軽Chrome拡張機能作り
taiseiue
0
170
CI改善もDatadogとともに
taumu
0
110
[JAWS-UG横浜 #80] うわっ…今年のServerless アップデート、少なすぎ…?
maroon1st
1
180
Amazon ECS とマイクロサービスから考えるシステム構成
hiyanger
2
520
Pulsar2 を雰囲気で使ってみよう
anoken
0
230
密集、ドキュメントのコロケーション with AWS Lambda
satoshi256kbyte
0
190
知られざるDMMデータエンジニアの生態 〜かつてツチノコと呼ばれし者〜
takaha4k
4
1.3k
GoとPHPのインターフェイスの違い
shimabox
2
170
Featured
See All Featured
The Invisible Side of Design
smashingmag
299
50k
Adopting Sorbet at Scale
ufuk
74
9.2k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
6
550
Designing for Performance
lara
604
68k
Fantastic passwords and where to find them - at NoRuKo
philnash
51
3k
[RailsConf 2023] Rails as a piece of cake
palkan
53
5.2k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
27
1.5k
VelocityConf: Rendering Performance Case Studies
addyosmani
328
24k
What's in a price? How to price your products and services
michaelherold
244
12k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
10
1.3k
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