RSpec - thuy-econsys/rails_app GitHub Wiki
Resources for test automation with RSpec
Run your tests
Run specific tests by appending the line number of where the example group starts to spec file path preceded by a :
. The following runs tests for example groups located in a_spec.rb
file inside the /spec
directory that start at line 37 and line 87.
rspec ./spec/a_spec.rb:37:87
If you have followed the best practices of describing your methods with brief, clear descriptions, organize your tests with context
, and follow the "one expectation" tip, it's possible to use the -e
option to search for specific strings or even Regex patterns with -E
to run all the example groups for a method:
rspec ./spec/a_spec.rb -e "GET #edit"
Or run all the example groups for a particular expectation:
rspec ./spec/a_spec.rb -e "200 OK status"
References
- RSpec - Relish, official documentation site for RSpec
rspec-rails
library documentation- rspec/rspec-rails GitHub
- Rails Testing - Nov 9, 2015 - extensive notes
- How We Test Rails Applications | thoughtbot
- Testing Rails: How expert developers write maintainable tests PDF from thoughtbot
- Setting up Rails testing with rspec, devise, and the gang | Will Schenk
- RSpec cheatsheet in the form of a Rails app | eliotsykes/rspec-rails-examples GitHub
- RSpec Cheatsheet | eliotsykes GitHub Gist