Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥
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
99
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
610
Other Decks in Programming
See All in Programming
WebRTC と Rust と8K 60fps
tnoho
2
1.9k
AIと協働し、イベントソーシングとアクターモデルで作る後悔しないアーキテクチャ Regret-Free Architecture with AI, Event Sourcing, and Actors
tomohisa
5
18k
tparseでgo testの出力を見やすくする
utgwkk
1
140
Why Kotlin? 電子カルテを Kotlin で開発する理由 / Why Kotlin? at Henry
agatan
2
6.3k
スタートアップを支える技術戦略と組織づくり
pospome
8
15k
ゲームの物理 剛体編
fadis
0
160
Evolving NEWT’s TypeScript Backend for the AI-Driven Era
xpromx
0
270
Querying Design System デザインシステムの意思決定を支える構造検索
ikumatadokoro
1
1.2k
ハイパーメディア駆動アプリケーションとIslandアーキテクチャ: htmxによるWebアプリケーション開発と動的UIの局所的適用
nowaki28
0
340
All(?) About Point Sets
hole
0
270
NUMA環境とコンテナランタイム ― youki における Linux Memory Policy 実装
n4mlz
1
110
251126 TestState APIってなんだっけ?Step Functionsテストどう変わる?
east_takumi
0
300
Featured
See All Featured
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
Making Projects Easy
brettharned
120
6.5k
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
Why You Should Never Use an ORM
jnunemaker
PRO
60
9.6k
Side Projects
sachag
455
43k
Imperfection Machines: The Place of Print at Facebook
scottboms
269
13k
How GitHub (no longer) Works
holman
316
140k
Practical Orchestrator
shlominoach
190
11k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
22k
Embracing the Ebb and Flow
colly
88
4.9k
Thoughts on Productivity
jonyablonski
73
5k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
54k
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