Request Spec, Steakã§ä½¿ã Capybara DSL ã®æ å ±ããµã³ãã«
å æ¥ãªãªã¼ã¹ãã 萌えトーク ã§ã¯End-to-Endãã¹ãã«ã¯ Request Spec ã使ã£ã¦ãã¾ããããã¹ã(RSpec)ãæ¸ãã«ã¯ Capybara DSL (API) ã®ç¥èãå¿ è¦ã«ãªãã¾ãã 萌えトーク ã® Request Spec ãæ¸ãéã«åç §ããæ å ±ããµã³ãã«ãã¾ã¨ãã¦ããã¾ãã
Capybara DSL æ å ±
- Capybara本家 ä¸ç¨ããã® The DSL ã«åºæ¬çãªä½¿ãæ¹ã®ä¾ã並ãã§ãã¾ãã®ã§ãCapybara ã使ãéã«ã¯ã¾ããããèªã¿ã¾ããã
- Richard Conroy's Personal Blog: Capybara Reference DSLä¸è¦§ãã¾ã¨ã¾ã¨ãããã¦ãã¦ãã³ã¼ããæ¸ãã®ã«ä¾¿å©ã§ãã
- Module: Capybara Capybaraã®RDocã§ããDSLã«ã¯æç¨ãªãªãã·ã§ã³ãç¨æããã¦ã¾ãããã®ãªãã·ã§ã³ã解ãã¾ãã ãã ããæ £ããªãã¨èª¿ã¹ã¥ããããããã¾ããã
ãµã³ãã«
萌えトーク ã® Request Spec ã§ä½¿ã£ãã³ã¼ãã®ãµã³ãã«ãæ¸ãã¾ããå¿
ãããæé©ã§ã¯ãªããã®ãããããç¥ãã¾ãããé©åã§ãªããã®ããã£ãããææä¸ããã
page.should have_content "ä¸è¦§"
ä¸çª è¯ã使ããã¼ã¸å ã«æå®ããæåããããã¨ãæ¤è¨¼
page.find("table.attendances tr:eq(2) td:eq(2)").text.should =~ /å±±ãã.*å·ãã/
ãã¼ãã«ã®ç¹å®ã®ã«ã©ã å ã®æååãæ¤è¨¼
page.all("table.db_list tr:eq(2) td")[1..2].map{|e| e.text}.should == ["10,000", "2011-01-20"]
ãã¼ãã«ã®è¤æ°ã®ã«ã©ã å ã®æååãæ¤è¨¼
within "table.db_list tr:eq(5)" do click_link "å ¥é" end
ãã¼ãã«ã®ç¹å®ã®è¡ã«ãããªã³ã¯ãã¯ãªãã¯
find("div.op_buttons a:eq(3)").click
æå®ãã div å
ã®ãªã³ã¯ãå·¦ããã®åæ°(é çª)ã§æå®ãã¦ãã¯ãªãã¯ã
æ¬æ¥ã¯ãªã³ã¯ã«idãä»ãã¦ãããæ¹ãè¯ãã¨æãã¾ãã
find("a", :text => "åç°").click
ãªã³ã¯ã®æååãæå®ãã¦ãã¯ãªãã¯
page.should have_css("div.char_detail img", :alt => "No19")
ç»åã®altå±æ§ãæå®ãã¦æ¤è¨¼ã ãã®ããã« CSSã»ã¬ã¯ã¿ã¼ã ãã§ã¯ãªããã¿ã°ã®æã¤å±æ§ãªã©ãæå®ã§ãã¾ãã