autotest ãã«ã¹ã¿ãã¤ãºãã
- clear_mappings ã¨äºéå®ç¾©ã«ã¤ãã¦è¿½è¨ @2008/04/12
ããã®ãã¡ã¤ã«ãã»ã¼ãããããã£ã¡ã® spec èµ°ããããï¼ãã¨æã£ãã®ã§èª¿ã¹ãã
ã½ã¼ã¹ã¯ãã®è¾º
- ZenTest: http://zentest.rubyforge.org/ZenTest/
- autodiscovery(): http://zentest.rubyforge.org/ZenTest/classes/Autotest.html#M000010
çµè«
autotest ã®ã«ã¹ã¿ãã¤ãºã«ã¯ãå®è¡ãã£ã¬ã¯ããªï¼ã¾ãã¯~/ï¼ã« .autotest ãç½®ãæ¹æ³ãå®ãããããã£ã¬ã¯ããªã« autotest/ ãä½ãæ¹æ³ã®ï¼ç¨®é¡ãããã
.autotest ããæ軽
Autotest.add_discovery do "rspec" # use Autotest::Rspec end Autotest.add_hook :initialize do |at| # 好ãã«æ¸ãã¹ã # at.add_mapping(%r%^config/routes\.rb$%) { # at.files_matching %r%^spec/(controllers|views|helpers)/.*_spec\.rb$% # } end
å ·ä½ä¾ã
Autotest.add_hook :initialize do |at| at.add_mapping(/([\w\0-9]+)\.rb$/) { |f, matched| "spec/#{matched[1]}_spec.rb" } end
ã¨ãã㨠./foo.rb ãæ´æ°ããã㨠./spec/foo_spec.rb ãèµ°ãã
autotest/ ãä½ãå ´åã
ä¾ãã° MyRspec ã¨ãã¦æ°ãã autotest å®è¡ç°å¢ãä½æã追å ããã«ã¯ autotest ã®æ¢ç´¢å¯¾è±¡ï¼loadpath, rubygems, vendor/pluginsï¼ã« autotest/discover.rb, autotest/my_rspec.rb ãä½æããã
discover.rb ã¯
Autotest.add_discovery do style if (cond) end
å ·ä½çã«ã¯ãã
Autotest.add_discovery do ['my', 'rspec'] if File.exist?('spec') end
my_rspec.rb ã®ä¸èº«ã¯
class Autotest::MyRspec < Autotest def initialize super .. snipped .. end ..snipped .. end
ãããªæãã
æ¤è¨¼ãã¡ãã£ã¨ãµãã£ã¦ããã®ã§ééããæ¸ã足ããªãç®æãããã°ããã³ããããã¨å¬ããã§ãã
clear_mappings ã¨äºéå®ç¾©
rails ç°å¢ã§ .autotest ã« add_hook æ¸ã㦠lib 以ä¸ã® spec ã lib/spec ã« add_mapping ãããã¨ããã失æããã
Autotest.add_hook :initialize do |at| # at.clear_mappings at.add_mapping(%r%^lib/foo.rb$%) {|f, m| puts "lib/foo.rb was pikced" } at.add_mapping(%r%^foo.rb$%) {|f, m| puts "./foo.rb was pikced" } end
foo.rb ã®ã¿æ¾ãããlib/foo.rb ã¯æ¾ã£ã¦ãããªãã
ãã㯠rails_rspec.rb 㧠lib 以ä¸ã®ãããã³ã°ãé©ç¨ããã¦ããããã§ï¼rspec_on_railsã.autotest ã®é ã«èªã¿è¾¼ã¾ããï¼ãclear_mappings ãå®è¡ãã㨠lib 以ä¸ãèªãã§ãããããã«ãªãï¼å¿è«ãä»ã®å¿
è¦ãªè¨å®ãå·»ãæ·»ãã«å
¨é¨æ¶ãå»ãï¼ã
解決æ¹æ³ã¨ãã¦ã¯ Autotest ã®ãµãã¯ã©ã¹ãæ¸ãããªã®ã ããããã¾ã 試ãã¦ããªãã
調æ»è¨é²
autodiscovery ããã
Strategy:
1. Find all files and associate them from impl <-> test.
2. Run all tests.
3. Scan for failures.
4. Detect changes in ANY (ruby?. file, rerun all failures + changed files.
5. Until 0 defects, goto 3.
6. When 0 defects, goto 2.
ã£ã¦äºãããã
autodiscovery() ãã
Automatically find all potential autotest runner styles by searching your loadpath, vendor/plugins, and rubygems for "autotest/discover.rb".
ãµããµãã
(discovery.rb) should register discovery procs with autotest using add_discovery.
autotest/discover.rb 㧠discovery proc ãã»ãããããã¨ã
That proc should return one or more strings describing the userâs current environment.
Those styles are then combined to dynamically invoke an autotest plugin to suite your environment.
ããã runner-styles ã£ã¦ã¤ãã§ãããã
Autotest.add_discovery do styles if (cond) end
ããããäºãã
That plugin should define a subclass of Autotest with a corresponding name.
ã§ãã¨ããã®ä¸ãè¦ãã
Process:
1. All autotest/discover.rb files loaded.
2. Those procs determine your styles (eg ["rails", "rspec"]).
3. Require file by sorting styles and joining (eg âautotest/rails_rspecâ).
4. Invoke run method on appropriate class (eg Autotest::RailsRspec.run).
ç解ã
Style ã®æ¢åã®ç¨®é¡ã¨ä¸èº«ãæ¢ãã
ZenTest ã®ãã¡ã¤ã«ç¾¤ãè¦ã㨠camping.rb 㨠rails.rb ãè¦ã¤ããã
ä½ã¨ãªãåãã£ã¦ãããrails rspec ãã©ã°ã¤ã³ãåèã«ãã¤ã¤ãå¾ã¯è©¦ãã
autotest/ ã®ä¸ã¯ dicover.rb 㨠stylename.rb ãã¡ã¤ã«ã«ãªãã
stylename ã¯æåéããrspec.rb ã¨ãããã¡ã¤ã«åã«ããã¨ã¹ã¿ã¤ã«å㯠rspec ã«ãªããAutotest::Rspec ã¯ã©ã¹ãããäºãæå¾
ãããã
ã¤ã¾ã MyRspec ã¹ã¿ã¤ã«ãä½ãããã£ãããã¡ã¤ã«å㯠autotest/my_rspec.rb ã¨ããã
ãã㧠vendor/plugins/(rspec|rspec_on_rails)/autotest ã®åå¨çç±ãåãã£ãã