Fix slow rspec on macOS – 10x speedup

For some reason rspec was running horribly slow on my macOS laptop, with a simple test suite taking over 30 seconds to run. This made TDD almost unbearable:


>rspec spec/features
...
Finished in 27.29 seconds (files took 33.71 seconds to load)
8 examples, 2 failures

After some googling, the recommended approach is to compile spring binstubs for rspec. For good hygiene, we’ll use bundler to do this, and use guard so we can leave a terminal window open on a second monitor and see test results automatically after saving code changes.


# edit /Gemfile
group :development do
gem 'guard'
gem 'guard-rspec'
gem 'spring'
gem 'spring-commands-rspec'
gem 'spring-watcher-listen'
end

>bundle install --path vendor/bundle --without=production --binstubs # install gems into vendor/bundle
>echo 'vendor/bundle' >> .gitignore # don't track installed gemfiles

Now replace the bundler rails binstubs with updated rails gem versions and insert spring:


>bundle exec rails app:update:bin # now regenerate standard rails binstubs
>bin/rails app:update:bin # norly plox use teh rail binstubs
>bundle exec spring binstub --all # use spring versions of binstubs
>bundle exec guard init # create guard config file /Guardfile

Note: bin/rails can get overwritten by bundler and stop accepting commands eg “bin/rails server” will show the default output of “rails” instead of launching the server. This can be fixed by running “bundle binstubs railties” then updating the binstubs again as per the instructions above.

Running “bundle config –delete bin” will stop bundler from blatting bin/rails but this also means you will need to manually generate binstubs using eg “bundle binstubs cucumber”.

Note also that bundler pulls in config from $APP/.bundle/config and ~/.bundle.config, so disabling binstubs in your app folder can be overridden by your home directory config.


# edit /Guardfile
guard :rspec, cmd: “bundle exec bin/rspec”, failed_mode: :keep do

>bundle exec guard


Finished in 1.72 seconds (files took 3.17 seconds to load)
5 examples, 2 failures

From 33 seconds to 3 seconds. Nice!

Note: now instead of using “bundle exec” rails or rake, use bin/$GEMNAME eg “bin/rails console”. The spring server running in the background will respond much faster than booting rails each time.

simple MagicCloud example

Simple demo of the MagicCloud gem, as the docs are not explicit about how to output an image:

require "magic_cloud"

words = [
 ['test', 50],
 ['me', 40],
 ['tenderly', 30]
]

cloud = MagicCloud::Cloud.new(words, rotate: :free, scale: :log)
img = cloud.draw(800, 600)
img.write("magic_cloud.png")

Vim is not TextMate

When I first discovered Vim I wasted a lot of time trying to bend it backwards into a traditional editor. The below quote sums it up perfectly:

Vim is not TextMate or whatever other editor you have used before. There is no way to transfer all your old habits seamlessly, point blank.

Instead of wasting your time trying to make Vim and your terminal into something that it’s not and can’t be you should learn how to use and customize Vim wisely. All your Cmd+Shift+Ctrl+Alt combos won’t lead you anywhere. Especially in a terminal where Alt is often problematic and Cmd unusable.

Consider using leader(:help leader):

  • it’s portable on every platform
  • it’s less prone to conflicts with your OS or terminal emulator
  • it opens a lot of easy to remember possibilities

— romainl

Adding gobs of plugins instead of learning Vim’s native functionality is another common trap, so I maintain a secondary lightweight Vim config called Ninjarc with minimal plugins to keep me sharp.

Finally, Tim Pope’s philosophy of favouring commands over leader key combos yields a more cohesive configuration. I’m experimenting with Spacemacs-style command mnemonics in my Aetherwolf Vim config. For example, instead of binding Leader+T to open NerdTree, :tn is used (Toggle NerdTree). This allows :tt for Toggle Tagbar and so on – a nice memorable taxonomy rather than a flat multitude of somewhat arbitrary leader combos.

I might eventually move this into Denite menus à la SpaceVim, but for now I’m digging the simplicity of using :ex commands.