I'm using Rails 4.2 with RSpec 3.4.0. If I want to run all examples in the order in which the appear in a file, I can run
bundle exec rspec --order defined spec/models/my_model_spec.rb
But what if I only want to run the examples in a specific describe block in a specific order? It there any way I can do that by adding some attributes or making annotations in the file itself (as opposed to having to add them in on the command line)?
If you just want to run the specs within a single describe
or context
, just add the line number of the describe
or context
statement to the end of the spec file name.
bundle exec rspec --order defined scec/models/my_model_spec.rb:123
You can also run a specific example group by name using the --example
option.
bundle exec rspec --example "context name" spec/models/my_model_spec.rb
Though, that second choice will use a regex to find the string. So, it will find all instances of that string in any describe
, context
, or it
statement.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.