I have a problem where a project is using an older version of RSpec (currently the lastest version is RSpec 1.3.0). Therefore running
spec spec/model/some_model_spec.rbgives me an error
/spec/models/../spec_helper.rb:23: undefined method `use_transactional_fixtures=’The solution would be to use the older, vendored spec. Now, the spec binary that is installed as part of the gem installation should do this (some gems do checked for vendor’ed binaries) and my rspec is installed under vendor/plugins, not vendor/gems. Therefore, I use some bash trickery to dynamically redefine the “spec” command. Put the code below in .bashrc :
if [ -x vendor/plugins/rspec/bin/spec ];
alias spec=‘$(vendored_or_path_spec) [email protected]’
Some explanations. The hardest thing to figure out was how to dynamically alias something. After such scrumbling and asking on vark.com, I managed to find command substitutions, which is the $(command) part. Combining that with [email protected] for all arguments meant that I can run any command in the alias.
Because I’m aliasing spec, I use *spec to refer to the original un-aliased spec.