In my current project I wanted to avoid running a few set of slow tests every time. Tagging feature in rspec allow us to filter the examples to be run by tag.
We can use the –tag (or -t) option to filter the examples by tags. The tag can be a simple name or a name:value pair. In the first case, examples with :name => true will be filtered. In the second case, examples with :name => value will be filtered, where value is always a string.
Tags can also be used to exclude examples by adding a ~ before the tag. For example ~tag will exclude all examples marked with :tag => true and ~tag:value will exclude all examples marked with :tag => value.
Given example show how to add tags to spec examples,
To run only examples with a simple tag, for examlple to run tests with a tag focus
run ”rspec spec/ –tag focus”
Then the output should contain all the tests with tag :focus=>true
To exclude examples with a name:value tag
run ”rspec spec/ –tag ~speed:slow”
Then the tests with tag speed:slow” will not be run.
Detailed documenation is given here
Thats it, Happy Testing….
We can use the –tag (or -t) option to filter the examples by tags. The tag can be a simple name or a name:value pair. In the first case, examples with :name => true will be filtered. In the second case, examples with :name => value will be filtered, where value is always a string.
Tags can also be used to exclude examples by adding a ~ before the tag. For example ~tag will exclude all examples marked with :tag => true and ~tag:value will exclude all examples marked with :tag => value.
Given example show how to add tags to spec examples,
1 2 3 4 5 6 7 8 |
|
run ”rspec spec/ –tag focus”
Then the output should contain all the tests with tag :focus=>true
To exclude examples with a name:value tag
run ”rspec spec/ –tag ~speed:slow”
Then the tests with tag speed:slow” will not be run.
Detailed documenation is given here
Thats it, Happy Testing….