RSpec Tutorial
RSpec Resources
Selected Reading
- RSpec - Expectations
- RSpec - Filtering
- RSpec - Metadata
- RSpec - Helpers
- RSpec - Subjects
- RSpec - Tags
- RSpec - Hooks
- RSpec - Stubs
- RSpec - Test Doubles
- RSpec - Matchers
- RSpec - Writing Specs
- RSpec - Basic Syntax
- RSpec - Introduction
- RSpec - Home
RSpec Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
RSpec - Tags
RSpec - Tags
RSpec Tags provide an easy way to run specific tests in your spec files. By default, RSpec will run all tests in the spec files that it runs, but you might only need to run a subset of them. Let’s say that you have some tests that run very quickly and that you’ve just made a change to your apppcation code and you want to just run the quick tests, this code will demonstrate how to do that with RSpec Tags.
describe "How to run specific Examples with Tags" do it is a slow test , :slow = > true do sleep 10 puts This test is slow! end it is a fast test , :fast = > true do puts This test is fast! end end
Now, save the above code in a new file called tag_spec.rb. From the command pne, run this command: rspec --tag slow tag_spec.rb
You will see this output −
Run options: include {: slow = >true}
This test is slow! . Finished in 10 seconds (files took 0.11601 seconds to load) 1 example, 0 failures
Then, run this command: rspec --tag fast tag_spec.rb
You will see this output −
Run options: include {:fast = >true} This test is fast! . Finished in 0.001 seconds (files took 0.11201 seconds to load) 1 example, 0 failures
As you can see, RSpec Tags makes it very easy to a subset of tests!
Advertisements