PhantomJSã¨Poltergeistã§HeadlessãªJavascriptãã¹ãç°å¢ãä½ã
RailsでJavascript/CoffeeScriptをテストするときの決定版(にしたい)!Konachaã®ç¶ãã
æåã¯ãã©ã¦ã¶ãªãã¼ãããã°ãããã ããããããããããªãã¦ããããã¨æã£ããã©ãå½è©²ç°å¢ããã¡ã³ãã ã¨ããã«ã¿ã¼ã¬ã¤ã¹ãã¨ãä¸äºç ã®è«¸çç¶ãæªåãããç´æ°ã«ã¾ã¿ãã¦ããããããããããå¾ãªããªãã¾ããã
ã¨ããã§ãããã¬ã¹ã¨ã¯ããã åã«GUIãããªãããã¨ããã ãã§ããã£ãã¤ãã¦ããããã¼ãã¨ãæåã¯æã£ããã©å·éã«ãªã£ã¦ã¿ãã¨ãå¥ã«ãããªãã£ãããããã¼ããã¨ãããã¨ã§ã¨ã«ãããããããã¨ã§ã
Railsåæã®è©±ã§ãã
PhantomJSã®ã¤ã³ã¹ãã¼ã«
http://phantomjs.org/
PhantomJSãããã®ãããã¬ã¹ãã©ã¦ã¶ã®æ¬ä½ã
macã ã¨homebrewã§å
¥ãã
brew install phantomjs
ã¦ã£ã³ãã¦ãºã®ããã¯ã²ã¤ãã¨ãã«ã¤ã³ã¹ãã¼ã«æ¹æ³ãèãã¦ãã ããã
poltergeistã®ã¤ã³ã¹ãã¼ã«
poltergeistã¯PhantomJSã¨é£æºãã¦ãããcapybaraã®ãã©ã¤ãã
gemã§ã¤ã³ã¹ã³ã
group :development, :test do ~snip~ gem 'konacha' gem "poltergeist" end
è¨å®ãã¡ã¤ã«ãå°ã
poltergeistã使ãããã«config/initializersã«è¨å®ãã¡ã¤ã«ãç½®ãã
# config/initializers/konacha.rb if defined?(Konacha) require 'capybara/poltergeist' Konacha.configure do |config| config.driver = :poltergeist end end
ãããã¬ã¹ã£ã·ããæãã
以ä¸ã®ã³ãã³ããå®è¡ãã¦ããã©ã¦ã¶ãç«ã¡ä¸ãããã«ãã¹ããéããã¨ã確èªããã
â»ãã®ã¸ãã¯RailsでJavascript/CoffeeScriptをテストするときの決定版(にしたい)!Konachaãåç
§
bundle exec rake konacha:run
guard-konachaã§ãã¹ããèªåå®è¡
https://github.com/alexgb/guard-konacha
ããã¾ã§æ¥ãã¨ãã³ãã³ããå©ãã®ãããã©ããããªã£ã¦ãããã²ã¤ã©ã®æ°æã¡ããããããã¾ãã
- gemã§ã¤ã³ã¹ãã¼ã«
group :development, :test do ~snip~ gem 'konacha' gem "poltergeist" gem 'guard-konacha' end
- Guardfileã«è¨å®è¿½å
~snip~ guard :konacha do watch(%r{^app/assets/javascripts/(.*)\.js(\.coffee)?$}) { |m| "#{m[1]}_spec.js" } watch(%r{^spec/javascripts/.+_spec(\.js|\.js\.coffee)$}) end
ãªããGuardèªä½ã®ã¤ã³ã¹ãã¼ã«ã¯Guard+Spork+GrowlでRspecを自動実行する設定ãããã§ã
- Guardå®è¡
bundle exec guard start
ãããã¾ãã ãã©ãGuardfileãä¸ç·ã ããRspecã®ã»ããåãã¡ãããã ããªããã¦ã©ã¼ã¯ã¹ã«ã¼ãã¹ãããã¨ãã£ããæéãããã£ã¡ãããã¾ããRSpecã¨konachaã®ã©ã¡ããã®è¨å®ãã³ã¡ã³ãã¢ã¦ããã¤ã¤ãããªã
ãããJenkinsã¨ãã§ããPhantomJSã ãå¥ã®æ¹æ³ã§ã¤ã³ã¹ãã¼ã«ããã°ã»ã¼æ¸ãããããªãããªã
ãã ããããããã¹ã²ã¼ããããã ãããguardãã©ãããã£ã¦ããããkonacha:runãé ãã®ããªãèªåçã«ãã¹ããèµ°ã£ã¦ãããã®ã¯ãããã ãã©ãç´°ããçµæã確èªãããã ã£ãããã©ã¦ã¶ãªãã¼ãã®ã»ããç¾å®çã ãã
ã¨ãããããã¡ã³ãã ãã¡ã³ãã ï¼