schrodingersbox/spec_cat
This gem contains trivial matchers to make RSpecs a bit more effective and less annoying.
- eql_file
- have_a_spec
- include_module
It also provides rake commands
- rake spec_cat:accept
- spec_cat:coverage
NOTE: This gem does not depend on Rails. All paths are relative to cwd, which may be Rails.root or anywhere else.
Getting Started
Add this to your gemfile...
gem 'spec_cat'
Matchers
eql_file
eql_file will compare method output to a ground truth file and fail if they
are different.
It also writes a .tmp file to replace the old ground truth if it's gone stale.
e.g. #foo produces a gnarly string too nasty to copy and paste into spec code.
foo.should eql_file( 'spec/data/foo.json' )
... if it fails for a valid change, you can just....
cp spec/truth/foo.json.tmp spec/truth/foo.json
... and all will be good again.
This mechanism is a bit brittle, but great for big blobs of data.
If you use this, you should add *.tmp to your .gitignore.
have_a_spec
have_a_spec will ensure that any given path has a corresponding spec file to
help ensure that you have good coverage.
'app/controllers/application_controller.rb'.should have_a_spec
... is a good thing to write right after you integrate RSpec.
Here's an example coverage spec...
https://github.com/schrodingersbox/spec_cat/blob/master/spec/coverage_spec.rb
include_module
include_module makes it easy to spec concern inclusion.
it( 'is Taggable' ) { should include_module( Taggable ) }
Rake Tasks
spec_cat:accept
rake spec_cat:accept runs all specs and causes the eql_file matcher to overwrite
the ground truth files, rather than output .tmp files.
This is convenient when a code change impacts a large number of ground truth files, but is also risky, as it may allow an incorrect change to become ground truth.
spec_cat:coverage
rake spec_cat:coverage runs all specs and then opens the coverage report if all the
specs pass.
Reference
- RSpec
- Testing Rake Tasks with RSpec
- Nathan Humbert's Blog: Rails 3: Loading rake tasks from a gem
- Add Achievement Badges to Your Gem README
- Publishing your gem
- Better Specs
Version History
- 3.0.0 - RSpec 3 supported
- 1.0.3 - Last version with RSpec 2.x support
TODO
- Fix include_module - only get class if arg is not already a class
- Add more matchers



