Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Capybara & AJAX: die ultimative Lösung?
Search
Taktsoft
September 02, 2013
Programming
79
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Capybara & AJAX: die ultimative Lösung?
Präsentation:
http://bit.ly/15v0ynO
Code:
http://bit.ly/1cBdZ4M
Taktsoft
September 02, 2013
Transcript
12 slides
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
Other Decks in Programming
See All in Programming
Growing PicoRuby's Ecosystem on ESP32
yuuu
2
130
クラウドエージェントは、 何がそんなに便利なのか / what makes cloud agents so useful
rkaga
5
870
Materialが消えた日 〜真っ白なFlutterキャンバスにRenderObjectで絵を描く〜
umigishiaoi
0
160
Engineering Biometric UX Across Android Versions | DroidKnights 2026
ryunen344
1
210
AI Augmentation Techniques with Liberty
ivargrimstad
1
480
Rails初心者がパスキーを実装してみて大変だったこと
ktombow
0
190
3回つくってわかった、 定期実行ジョブ基盤の本質情報
takai
4
3.9k
Snowflake Openflow Connector利用の勘所 / 20261024developersio2026tokyo-snowflake-openflow
kasacchiful
PRO
0
340
学びを記事・スライド・Xへ高速展開する― AI-assisted Learning Loopで回すコンテンツ生成術
ochtum
0
210
どうしても Eloquent でリポジトリパターンをやりたいんだ #phpcon_niigata / phpcon-niigata-2026
shogogg
0
250
止まらない比較を止める — 余帰納法で無限ストリームを比べる
tarao
0
150
AIが実装を担う時代の「技術設計」と「チームマネジメント」
kamina_zzz
2
260
Featured
See All Featured
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
580
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.4k
Building the Perfect Custom Keyboard
takai
2
960
Prompt Engineering for Job Search
mfonobong
0
580
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.4k
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
590
Music & Morning Musume
bryan
48
7.5k
Tell your own story through comics
letsgokoyo
1
1.1k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.9k
Amusing Abliteration
ianozsvald
1
390
Google's AI Overviews - The New Search
badams
0
1.7k
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.4k