42
35

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

SpringでRSpecを高速化する

Last updated at Posted at 2015-09-16

1. Gemfileにspring-commands-rspecを追加する

gem 'spring-commands-rspec'

2. bin/rspecを作成する

spring-commands-rspecの場合

$ bundle exec spring binstub rspec

bin/rspec

#!/usr/bin/env ruby
begin
  load File.expand_path("../spring", __FILE__)
rescue LoadError
end
require 'bundler/setup'
load Gem.bin_path('rspec-core', 'rspec')

注意:すでにbundleのbinstubsを使ってbin/rspecがある場合は、一度削除する

$ bundle binstubs rspec-core

binstubsで生成したbin/rspec

#!/usr/bin/env ruby
#
# This file was generated by Bundler.
#
# The application 'rspec' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require 'pathname'
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
  Pathname.new(__FILE__).realpath)

require 'rubygems'
require 'bundler/setup'

load Gem.bin_path('rspec-core', 'rspec')

このbin/rspecはspringが使われない

3. 測定

Springなし

実行

$ bundle exec spring status
Spring is not running.

出力結果

bundle exec rspec  3.83s user 0.94s system 97% cpu 4.887 total

Springあり

実行

$ time bundle exec bin/rspec

出力結果

bundle exec bin/rspec  0.53s user 0.10s system 45% cpu 1.379 total
42
35
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
42
35

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?