How can I tell Rails to use RSpec instead of test-unit when creating a new Rails app?

后端 未结 5 663
遥遥无期
遥遥无期 2021-01-29 20:51

I have test-unit installed and rspec installed (along with -core, -expectations, -mocks and -rails

5条回答
  •  南笙
    南笙 (楼主)
    2021-01-29 21:34

    Once you created your rails application with:

    rails new  -T  # to exclude Test::Unit
    

    Add the RSpec gem to your Gemfile in the following way:

    group :development, :test do
      gem "rspec-rails"
    end
    

    In Command line write:

    bundle install  # this will install the missing gems
    

    Now you need to install RSpec by running:

    rails generate rspec:install
    

    This will generate the following files:

    create  .rspec
    create  spec
    create  spec/spec_helper.rb
    create  spec/rails_helper.rb
    

    I strongly recommended to read through all spec_helper and rails_helper comments to get a good understanding of what each option does.

    Once everything is set you can run all your tests with:

    bundle exec rspec
    

    You can read more about the recommended spec_helper and rails_helper configurations on https://kolosek.com/rails-rspec-setup.

提交回复
热议问题