å æ¥æ¸ãã SeleniumRC spec ã®ä¸ã§ä½¿ã£ã¦ããã¯ããã¯ãæè¿ãä¼ç¤¾ã§æµè¡ã£ã¦ãã
2007-12-04追è¨: ãã®ãã¯ããã¯ã¯RSpec 0.8以åã®ããã«éçºãã¾ãããRSpec 1.0以éã§ã¯shared behaviourã使ãã¾ãããããã ãRSpecãããããææ³ã®åºç¤ã¨ãã¦åèã«ã¯ãªãããããã¾ããã
ã³ã³ããã¹ãã«ãããå ±éã®åæåå¦çã¯å¿è«ãsetupãcontext_setupã«æ¸ãã°ãããã ãã©ãåé¡ã¯è¤æ°ã®ã³ã³ããã¹ãã«ã¾ãããå ±éã®åæåå¦çããããã¯ãmodelã®specã§fixtureãè¨å®ããããcontrollerã®specã«ããã¦ã³ã³ããã¼ã©ã¼åãæå®ãããã
ãããã£ã¦ããã¡ãã¡æ¸ãã®ããªããDRYãããªãæ°ããããç¹ã«ã1ã¤ã®modelã«å¯¾ããspecãcontextããæ§æãããã¨ã(諸æ©ããæ¹å¼ãcontextã¨ããè¨èã®æå³åãããè¨ãã°ãç¡çã«1ã¤ã®ã³ã³ããã¹ãã«ãããããã®æ¹ãèªç¶ãªã¯ã)ãã§ãfixtureã®èªã¿è¾¼ã¿ã¯æ¯ååãã ã£ãããã³ã³ããã¼ã©ã¼æå®ã¯ããæ¸ãå¿ãããã©ãæ¸ãå¿ããã¨ããåãããªãã¨ã©ã¼ãåºããã
ã§ãããããããã ãmodel Hogeã«å¯¾ããspecã§ããã¨ããã°ããã®specãã¡ã¤ã«ã®é ã§ãããªã¡ã½ãããå®ç¾©ããã
def hoge_context(*args, &block) context(*args) do fixtures :hoge, :huga, :hugu context_setup do # ãªããå ±éã®åæå end instance_eval(&block) end end
ã§ã以éã¯contextã®ä»£ããã«hoge_contextã使ç¨ãããDRYã§å®å ¨ããæ軽簡åã