“...I've been working since 2008 with Ruby / Ruby on Rails, love a bit of Elixir / Phoenix and learning Rust. I also poke through other people's code and make PRs for OpenSource Ruby projects that sometimes make it. Currently working for InPay...”

Rob Lacey
Senior Software Engineer, UK

RSpec 1.2.7 and Spork

I just updated the RSpec gem today since seeing from The RSpec book update that there is a new release.

rl@bloodandguts:~/project$ ./script/spec_server 
Loading Rails environment

*****************************************************************
DEPRECATION WARNING: you are using deprecated behaviour that will
be removed from a future version of RSpec.

/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'

* spec_server is deprecated.
* please use spork (gem install spork) instead.
*****************************************************************

So…here we go.

rl@bloodandguts:~/project$ sudo gem install spork
Successfully installed spork-0.5.7
1 gem installed
Installing ri documentation for spork-0.5.7...
Updating ri class cache with 7915 classes...
Installing RDoc documentation for spork-0.5.7...

Update the spec helper with the bootstrap command

rl@bloodandguts:~/project$ spork --bootstrap
Using RSpec
Bootstrapping /home/rl/project/spec/spec_helper.rb.
Done. Edit /home/rl/project/spec/spec_helper.rb now with your favorite text editor and follow the instructions.

The spec_helper will have instructions on how to edit the file although I mostly took the previous contents of the file and placed it in the ‘Spork.prefork’ block.

require 'rubygems'
require 'spork'

Spork.prefork do
  # Loading more in this block will cause your tests to run faster. However, 
  # if you change any configuration or code from libraries loaded here, you'll
  # need to restart spork for it take effect.
end

Spork.each_run do
  # This code will be run each time you run your specs.

end

# --- Instructions ---
# - Sort through your spec_helper file. Place as much environment loading 
#   code that you don't normally modify during development in the 
#   Spork.prefork block.
# - Place the rest under Spork.each_run block
# - Any code that is left outside of the blocks will be ran during preforking
#   and during each_run!
# - These instructions should self-destruct in 10 seconds.  If they don't,
#   feel free to delete them.
#

# This file is copied to ~/spec when you run 'ruby script/generate rspec'
# from the project root directory.

Starting the server with just ‘spork’

rl@bloodandguts:~/project$ spork
Using RSpec
Preloading Rails environment
Loading Spork.prefork block...
Spork is ready and listening on 8989!

And run your spec for good measure.

rl@bloodandguts:~/project$ spec --drb spec/models/user_spec.rb 
.....

Finished in 6.806868 seconds

5 examples, 0 failures, 0 pending
GPK of the Day Mad DONNA