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
Capybara & AJAX: die ultimative Lösung?
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Taktsoft
September 02, 2013
Programming
1
69
Capybara & AJAX: die ultimative Lösung?
Präsentation:
http://bit.ly/15v0ynO
Code:
http://bit.ly/1cBdZ4M
Taktsoft
September 02, 2013
Tweet
Share
Other Decks in Programming
See All in Programming
CSC307 Lecture 04
javiergs
PRO
0
660
AI Schema Enrichment for your Oracle AI Database
thatjeffsmith
0
330
OCaml 5でモダンな並列プログラミングを Enjoyしよう!
haochenx
0
150
[KNOTS 2026登壇資料]AIで拡張‧交差する プロダクト開発のプロセス および携わるメンバーの役割
hisatake
0
300
AgentCoreとHuman in the Loop
har1101
5
250
なぜSQLはAIぽく見えるのか/why does SQL look AI like
florets1
0
480
16年目のピクシブ百科事典を支える最新の技術基盤 / The Modern Tech Stack Powering Pixiv Encyclopedia in its 16th Year
ahuglajbclajep
5
1k
izumin5210のプロポーザルのネタ探し #tskaigi_msup
izumin5210
1
140
フロントエンド開発の勘所 -複数事業を経験して見えた判断軸の違い-
heimusu
7
2.8k
Apache Iceberg V3 and migration to V3
tomtanaka
0
180
Rust 製のコードエディタ “Zed” を使ってみた
nearme_tech
PRO
0
210
MDN Web Docs に日本語翻訳でコントリビュート
ohmori_yusuke
0
660
Featured
See All Featured
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
2.8k
[SF Ruby Conf 2025] Rails X
palkan
1
760
Principles of Awesome APIs and How to Build Them.
keavy
128
17k
Odyssey Design
rkendrick25
PRO
1
500
Speed Design
sergeychernyshev
33
1.5k
Rebuilding a faster, lazier Slack
samanthasiow
85
9.4k
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.1k
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
0
440
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
55k
Docker and Python
trallard
47
3.7k
How to make the Groovebox
asonas
2
1.9k
My Coaching Mixtape
mlcsv
0
52
Transcript
Taktsoft Wissensaustausch Capybara & AJAX: die ultimative Lösung?
einfaches Beispiel • Rails 3 Application ◦ PostgreSQL ◦ Poltergeist
/ PhantomJS • Post (Title & Body) ◦ Create & Destroy via AJAX
Feature-Spec it "creates a new post on submit" do visit
posts_path page.click_on "New Post" page.fill_in 'Title', with: "Foo" page.fill_in 'Body', with: "Bar" expect { page.click_on "Create Post" }.to change(Post, :count).from(0).to(1) end
1 example, 1 failure
Probleme • ID des neuen Datensatzes nicht bekannt! ◦ kein:
page.should have_css “#model_#{id}” • Class nur für den Test setzen? ◦ Kein App-Code damit Test funktioniert • sleep(Capybara.default_wait_time) ◦ Nicht die feine Art
Vorschlag • jQuery.ajaxStart & jQuery.ajaxStop ◦ globale AJAX-Event-Handler • AJAX-Status
an Attribut setzen / erkennen ◦ z.B. am immer verfügbaren body-Tag
Implementierung (1) page.execute_script <<-EOS $(document).ready(function() { $('body').attr('data-ajax-status', 'stop'); }); $(document).ajaxStart(function()
{ $('body').attr('data-ajax-status', 'start'); }); $(document).ajaxStop(function() { $('body').attr('data-ajax-status', 'stop'); }); EOS
page.should have_css "body[data-ajax-status=stop]" • Jeweils über eine Helper-Methode aufrufbar ◦
wait_for_ajax_install (1) ◦ wait_for_ajax_stop (2) • install nach visit • stop vor assert Implementierung (2)
1 example, 0 failures
Ausblick • Berücksichtigung von Nebenläufigkeit ◦ Mehrere AJAX-Requests überschneiden sich
• Verankerung in RSpec ◦ kein expliziter Aufruf der Helper • Erweiterung als Gem ◦ nächster Wissensaustausch … ;)
Vielen Dank Präsentation: http://bit.ly/15v0ynO Code: http://bit.ly/1cBdZ4M
Hidden Page • using_wait_time(seconds) { … } ◦ führt einen
Block mit der angegebenen wait time aus • page.should have_css “#foo”, wait: 5 ◦ führt die expectation mit der angegebenen wait time aus