Try only one of them or describe with RSpec

In TestUnit, you can run one test in a file with the -n option

eg

require 'test_helper' class UserTest < ActiveSupport::TestCase test "the truth" do assert true end test "the truth 2" do assert true end end 

You can only do a truth check

 ruby -Itest test/unit/user_test.rb -n test_the_truth 

Output

 1 tests, 1 assertions, 0 failures, 0 errors, 0 skip 

How to do it with rspec?

The team seems not working

 rspec spec/models/user_spec.rb -e "User the truth" 
+4
source share
3 answers

You did not specify the source of your specification, so it’s hard to say where the problem is, but in general you can use the -e option to run one example. Given this specification:

 # spec/models/user_spec.rb require 'spec_helper' describe User do it "is true" do true.should be_true end describe "validation" do it "is also true" do true.should be_true end end end 

This command line:

 rspec spec/models/user_spec.rb -e "User is true" 

Will produce this result:

 Run filtered including {:full_description=>/(?-mix:User\ is\ true)/} . Finished in 0.2088 seconds 1 example, 0 failures 

And if you want to call another example, one that is nested in a validation group, you should use this:

 rspec spec/models/user_spec.rb -e "User validation is also true" 

Or to run all the examples in a validation group:

 rspec spec/models/user_spec.rb -e "User validation" 
+7
source

You can also choose which line contains the test case that you want to run.

 rspec spec/models/user_spec.rb:8 

By skipping any line within the scope of the test case, only this test case will be executed. You can also use this to execute the entire context inside your test.

+2
source

At least in Rspec 2.11.1 you can use all of the following options:

** Filtering / tags **

 In addition to the following options for selecting specific files, groups, or examples, you can select a single example by appending the line number to the filename: rspec path/to/a_spec.rb:37 -P, --pattern PATTERN Load files matching pattern (default: "spec/**/*_spec.rb"). -e, --example STRING Run examples whose full nested names include STRING (may be used more than once) -l, --line_number LINE Specify line number of an example or group (may be used more than once). -t, --tag TAG[:VALUE] Run examples with the specified tag, or exclude examples by adding ~ before the tag. - eg ~slow - TAG is always converted to a symbol 
+1
source

All Articles