How do you run a single test/spec file in RSpec?

前端 未结 14 1659
-上瘾入骨i
-上瘾入骨i 2020-12-12 08:45

I want to be able to run a single spec file\'s tests — for the one file I\'m editing, for example. rake spec executes all the specs. My project is not a

相关标签:
14条回答
  • 2020-12-12 09:13

    Alternatively, have a look at autotest.

    Running autotest in a command window will mean that the spec file will be executed whenever you save it. Also, it will be run whenever the file you are speccing is run.

    For instance, if you have a model spec file called person_spec.rb, and a model file that it is speccing called person.rb, then whenever you save either of these files from your editor, the spec file will be executed.

    0 讨论(0)
  • 2020-12-12 09:14

    The raw invocation:

    rake spec SPEC=spec/controllers/sessions_controller_spec.rb \
              SPEC_OPTS="-e \"should log in with cookie\""
    

    Now figure out how to embed this into your editor.

    0 讨论(0)
  • 2020-12-12 09:15

    To run all of your rspec files: rspec

    note: you must be in the root of your project

    To run one rspec file: rspec 'path_to/spec.rb'

    note: replace 'path_to/spec.rb' with your path. Quotation marks optional.

    To run one rspec test from one file: rspec 'path_to/spec.rb:7'

    note: :7 is the line number where the test starts

    0 讨论(0)
  • 2020-12-12 09:17

    http://github.com/grosser/single_test lets you do stuff like..

    rake spec:user          #run spec/model/user_spec.rb (searches for user*_spec.rb)
    rake test:users_c       #run test/functional/users_controller_test.rb
    rake spec:user:token    #run the first spec in user_spec.rb that matches /token/
    rake test:user:token    #run all tests in user_test.rb that match /token/
    rake test:last
    rake spec:last
    
    0 讨论(0)
  • 2020-12-12 09:21

    You can also use the actual text of the *e*xample test case with -e !

    So for:

    it "shows the plane arrival time"
    

    you can use

    rspec path/to/spec/file.rb -e 'shows the plane arrival time'
    ./scripts/spec path/to/spec/file.rb -e 'shows the plane arrival time'
    

    no need for rake here.

    0 讨论(0)
  • 2020-12-12 09:23

    Or you can skip rake and use the 'rspec' command:

    rspec path/to/spec/file.rb
    

    In your case I think as long as your ./spec/db_spec.rb file includes the appropriate helpers, it should work fine.

    If you're using an older version of rspec it is:

    spec path/to/spec/file.rb
    
    0 讨论(0)
提交回复
热议问题