- specifying the directory
- using an rspec tag option
For example, if you want to run model specs that you've tagged as work in progress (wip) do the following:
Add tag to spec
require 'spec_helper'
describe HomeController do
render_views
it "Logs in Person with non-blank name", :lex_tag => 'wip' do
person = Factory(:Person, name: "non-blank name")
get :login
response.should redirect_to(people_path)
end
it "does not log in Person with blank name" do
person = Factory(:Person, name: "") # blank name
get :login
response.should redirect_to(root_path)
end
end
Run spec like so
$ be rspec --pattern spec/models/*_spec.rb --tag lex_tag:wip
Summary
By specifying the directory, you limit the number of specs to run to a logical grouping.By using rspec tags, you can be very specific about which individual tests you run.
Notes
- You can negate a tag using the "~" character
- To be compatible with the Cucumber syntax, tags can optionally start with a @, that will be ignored. Example: @lex_tag
- There is nothing special about "lex_tag", you can name your tag nearly anything, but using a name allows multiple developers to annotate without confusion.
- You would not want to check specs into your source code repository that had tag names that referenced individuals
- You might want to use tags to group specs according to other user acceptance testing criteria or perhaps tag tests for particular server deployment environments
- So, tags can be used to group specs, not by static folder directories but by any criteria you wish
No comments:
Post a Comment