Lock in $30 Savings on PRO—Offer Ends Soon! ⏳
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
100
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
180
git - the stupid content tracker
seenmyfate
2
130
Give
seenmyfate
1
130
4 Steps to Faster Rails Tests
seenmyfate
5
630
Other Decks in Programming
See All in Programming
Developing static sites with Ruby
okuramasafumi
0
310
TUIライブラリつくってみた / i-just-make-TUI-library
kazto
1
410
AIエージェントの設計で注意するべきポイント6選
har1101
5
1.6k
JETLS.jl ─ A New Language Server for Julia
abap34
2
430
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
220
C-Shared Buildで突破するAI Agent バックテストの壁
po3rin
0
410
マスタデータ問題、マイクロサービスでどう解くか
kts
0
110
Jetpack XR SDKから紐解くAndroid XR開発と技術選定のヒント / about-androidxr-and-jetpack-xr-sdk
drumath2237
1
160
Denoのセキュリティに関する仕組みの紹介 (toranoana.deno #23)
uki00a
0
120
まだ間に合う!Claude Code元年をふりかえる
nogu66
5
870
AIの誤りが許されない業務システムにおいて“信頼されるAI” を目指す / building-trusted-ai-systems
yuya4
6
3.8k
ローターアクトEクラブ アメリカンナイト:川端 柚菜 氏(Japan O.K. ローターアクトEクラブ 会長):2720 Japan O.K. ロータリーEクラブ2025年12月1日卓話
2720japanoke
0
740
Featured
See All Featured
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
23
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
170
Joys of Absence: A Defence of Solitary Play
codingconduct
1
250
Art, The Web, and Tiny UX
lynnandtonic
304
21k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
710
Mind Mapping
helmedeiros
PRO
0
36
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
9
1k
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
29
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
The browser strikes back
jonoalderson
0
66
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
GitHub's CSS Performance
jonrohan
1032
470k
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