SporkからSpringに乗り換えた結果wwwwwwwwwwww
今までrspec + guard + sporkでやってきましたけど、sporkのテストにしか効かないあたりとかはイマイチだなぁ、と思ったので噂のSpringに乗り換えてみることにした。
Gemfile
group :development, :test do gem "rspec-rails", "~> 2.13.0" gem "guard-rspec", "~> 2.5.2" ~snip~ gem 'spring' end
$ bundle install $ spring binstub rspec $ spring rspec Coverage report Rcov style generated for RSpec to /Users/ria10/IdeaProjects/hoge-web/coverage/rcov /usr/local/opt/rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/spring-0.0.9/lib/spring/watcher/listen.rb:36:in `subjects_changed': undefined method `directories' for #<Listen::Listener:0x007f9a5ac5ac78> (NoMethodError) from /usr/local/opt/rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/spring-0.0.9/lib/spring/watcher/abstract.rb:47:in `add' from /usr/local/opt/rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/spring-0.0.9/lib/spring/application.rb:100:in `setup' from /usr/local/opt/rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/spring-0.0.9/lib/spring/application.rb:61:in `serve' from /usr/local/opt/rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/spring-0.0.9/lib/spring/application.rb:49:in `block in run' from /usr/local/opt/rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/spring-0.0.9/lib/spring/application.rb:43:in `loop' from /usr/local/opt/rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/spring-0.0.9/lib/spring/application.rb:43:in `run' from /usr/local/opt/rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/spring-0.0.9/lib/spring/application.rb:37:in `start' from /usr/local/opt/rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/spring-0.0.9/lib/spring/application_manager.rb:96:in `block in start_child' from /usr/local/opt/rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/spring-0.0.9/lib/spring/application_manager.rb:83:in `fork' from /usr/local/opt/rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/spring-0.0.9/lib/spring/application_manager.rb:83:in `start_child' from /usr/local/opt/rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/spring-0.0.9/lib/spring/application_manager.rb:26:in `start' from /usr/local/opt/rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/spring-0.0.9/lib/spring/application_manager.rb:53:in `block in with_child' from /usr/local/opt/rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/spring-0.0.9/lib/spring/application_manager.rb:20:in `synchronize' from /usr/local/opt/rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/spring-0.0.9/lib/spring/application_manager.rb:42:in `with_child' from /usr/local/opt/rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/spring-0.0.9/lib/spring/application_manager.rb:61:in `run' from /usr/local/opt/rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/spring-0.0.9/lib/spring/server.rb:52:in `serve' from /usr/local/opt/rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/spring-0.0.9/lib/spring/server.rb:40:in `block in boot' from /usr/local/opt/rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/spring-0.0.9/lib/spring/server.rb:40:in `loop' from /usr/local/opt/rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/spring-0.0.9/lib/spring/server.rb:40:in `boot' from /usr/local/opt/rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/spring-0.0.9/lib/spring/server.rb:18:in `boot' from /usr/local/opt/rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/spring-0.0.9/lib/spring/client/start.rb:13:in `call' from /usr/local/opt/rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/spring-0.0.9/lib/spring/client/command.rb:7:in `call' ~snip~
エラった。
調べてみるとこのエラーはlisten gemが< 1.0のときに起きるらしい。
https://github.com/jonleighton/spring/issues/161
listen gemがなんの絡みで入ったのかわからないけど、とにかくupdateする。
$ bundle exec gem update listen Updating installed gems Updating listen Successfully installed rb-inotify-0.9.0 Successfully installed rb-kqueue-0.2.0 Successfully installed listen-1.2.2 Gems updated: rb-inotify rb-kqueue listen
よし、と思ってリトライしたらまた同じエラーがでた。どうもguardのバージョンが低いと、低いlistenがインストールされちゃうみたいでguardもupdateしてやったらうまくいった。
リトライ
$ spring rspec No DRb server is running. Running in local process instead ... /usr/local/opt/rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require': cannot load such file -- spork (LoadError)
エラった。
spec/spec_helper.rbにsporkをrequireしているためだった。
それとSpork絡みの記述を削除してリトライ。
$ spring rspec No DRb server is running. Running in local process instead ... ..................................................................................................................................................................................................................................................................................................................
うまくいった。
guardと組み合わせてみる。guard-springというgemがある。
https://github.com/mknapik/guard-spring
Gemfile
group :development, :test do gem "rspec-rails", "~> 2.13.2" gem "guard-rspec", "~> 3.0.2" gem 'spring' gem 'guard-spring' end >|| $ bundle install $ guard init spring WARN: Unresolved specs during Gem::Specification.reset: thor (>= 0.14.6) ffi (>= 0.5.0) lumberjack (>= 1.0.2) WARN: Clearing out unresolved specs. Please report a bug if this causes problems. 20:49:44 - INFO - Guard here! It looks like your project has a Gemfile, yet you are running 20:49:45 - INFO - spring guard added to Guardfile, feel free to edit it
なんやらキモいワーニングがでた。複数バージョンのgemが入っているとこういうことになるらしい。bundle exec gem cleanupで掃除しよう。あと、この状態でもGuardfileにコンフィグが追記はされている。
追記されたコンフィグを消してリトライ。
$ bundle exec guard init spring 21:00:16 - INFO - spring guard added to Guardfile, feel free to edit it
うまくいったようだ。
Guradフィアルからは追加されたコンフィグ以外は全部消してしまった。
$ bundle exec guard 21:32:02 - WARN - Failed to create all required binstubs 21:32:02 - INFO - Guard::Spring Initialized 21:32:02 - INFO - Guard uses Growl to send notifications. 21:32:02 - INFO - Guard uses TerminalTitle to send notifications. Spring is not running 21:32:02 - INFO - Stopping Spring 21:32:02 - INFO - Starting Spring 21:32:02 - INFO - Guard is now watching at '/Users/ria10/IdeaProjects/hoge-web'
ちゃんとファイルが変更されると動く。2回も動く。えっ。
spec_helper.rbから以下の記述を消さないとサービスでもう1回動いてしまうらしい。
require 'rspec/autorun'
手作業でテストを走らせる時も待たずに済む
$ spring rspec spec/routing/ ...................................................... Finished in 0.61229 seconds 54 examples, 0 failures Randomized with seed 20789
はえぇ・・・。
よく使うrails console
$ spring rails c Loading development environment (Rails 3.2.13)
これも2度めから爆速!
うーん。狙ったとおり、いまんとここっちのほうがいいかな。