Migration to rspec2

gmarik 2 min

RSpec 2 just came out (as a bonus for 10/10/10 date?).

So before going to bed I decided to switch my small non rails project to new RSpec 2 mostly for the new [:focused] feature borrowed from Micronaut.

After bumping gem version in Gemfile

gem 'rspec', '~> 2.0.0'

and running bundle install

Installing rspec-core (2.0.0) 
Installing rspec-expectations (2.0.0) 
Installing rspec-mocks (2.0.0) 
Installing rspec (2.0.0)

got it installed (wow, it’s modular now!)

So I fired autotest to watch my specs passed. But instead I got it stuck doing nothing! WTF?!

Ok, lets try test spec:

$ echo "describe('rspec') { it }" > test_spec.rb
$ rspec test_spec.rb

passed with:

    # Not Yet Implemented
    # ./test_spec.rb:1
Finished in 0.00024 seconds
1 example, 0 failures, 1 pending

Good. Problem must be somewhere in my code then.

So I tried to run single spec

$ rspec spec/source_spec.rb

and got error:

in require: no such file to load -- spec (MissingSourceFile)

well, turns out that

require 'spec'

is deprecated and now we have to

require 'rspec'

instead! But I can get rid of that require at all now, as


takes care about all necessary requires.

Tried to run specs and got another error:

uninitialized constant RSpec::Runner (NameError)

with nice banner:

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

* Spec is deprecated.
* RSpec is the new top-level module in RSpec-2

So I had to change

Spec::Runner.configure do |config|


RSpec.configure do |config|

in spec_helper.rb

And now I got my single spec running.

But autotest still doing nothing!

Ok time to configure autotest for rspec:

$ rspec --configure autotest
autotest/discover.rb has been added

But attept to run specs this time errored out with:

undefined method `context' for main:Object (NoMethodError)

That’s because i’m using context along with describe to define examples.

Adding quick workaround to spec_helper.rb

alias :context :describe

solves the issue for now(but i’ll refactor it out later, promise!)

and finally autotest is back to work!

$ autotest
Finished in 2.43 seconds
69 examples, 1 failure, 4 pending



Few days ago I tried to colorize autotest output with redgreen gem, but it didn’t work out.

Now it’s easy to colorize autotest output with rspec2:

$ echo '--color' > .rspec # run in project or $HOME dir



Read More
Ctags on OSX
Scraping ASP.Net site with Mechanize
read or add one↓