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

前端 未结 14 1726
-上瘾入骨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:03

    Although many great answers were written to this question, none of them uses the Rspec tags approach.

    I use tags to run one or more specs in different files -- only those related to my current development task.

    For example, I add the tag "dev" with the value "current":

    it "creates an user", dev: :current do
      user = create(:user)
      expect(user.persisted?).to be_truthy
    end
    

    then I run

    bundle exec rspec . --tag dev:current
    

    Different tags/values can be set in individual specs or groups.

提交回复
热议问题