This repository has been archived by the owner on Jul 22, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
The RSpec Toolbox
jamesgary edited this page Sep 10, 2012
·
46 revisions
From WindyCityRails 2012
Presenter: David Chelimsky
Lots of tips and tricks for using RSpec, including some lesser known ones (like tags/filters) and easier command line usage.
From @benjaminoakes:
- DRW Trading Group (hiring)
- Rspec2
- Micronaut: Each example has its own metadata
- New basis for Rspec
Basically the Command pattern:
example_group = describe Something { }
example = it 'does something' { }
- Used in output at command line, etc.
- rspec has formatter methods (there's an protocol with an interface)
- Example formatters:
- Documentation
- HTML
- 3rd party
-
Instafail
: shows you error messages early Fuubar
- NyanCat
-
- Example formatters:
- Focusing tools
-
autotest
,guard
-- monitor changes to files and re-run specs - Sometimes you don't want it to rerun everything again (e.g., if you TDD)... so, focus!
-
config.filter_run_including :focus => true
it 'something', :focus => true do
end
Or exclude stuff:
config.filter_run_excluding :slow => true
it 'something', :slow => true do
end
Shorthand:
# Will be default in the future...
config.treat_symbols_as_metadata_keys_with_true_values = true
it 'something', :slow do
end
it 'something', :focus do
end
conditional filters
describe Thing, :if => RUBY_VERSON >= "1.9" do
end
describe Thing, :if => ENV['GENERATE'] do
end
Can have specialized groups (what they do in rspec-rails
-- look at it for examples):
RSpec::configure do |c|
# Gist: if in this path, include this behavior
end
Or just always use, say, FakeFS
:
RSpec.configure do |config|
config.include FakeFS::SpecHelpers, :fakefs
end
describe 'something that writes files', :fakefs => true edo
# ...
# Or: `include FakeFS::SpecHelpers`
# TODO: can you have it output something too? Like in the `documentation` formatter?
end
Can also alias example
(as it
, xit
, pending
, etc.)
c.default_path = "./behavior" # normally "./spec"
c.fail_fast = true
rspec
can be much faster than rake
because of how rake
loads (with a sub shell)
--tag
is for filters
rspec --tag focus:true
rspec --tag ~slow:true
rspec --tag ~slow:true --tag issue:123 # Might have been written down incorrectly
--color
--order random
--format progress
--profile
Works the same way
With --options
at the command line, you can point to a file that has:
--tag issue:123
(pro tip about how to organize; see slides)
A crowd-sourced conference wiki!
Working together is better. :)
- Speakers, for example:
- Recent Conferences
- Software
- Offline Access
- Contributors (More than 50!)
- Code Frequency