How to run unit tests on rspec?

Asked

Viewed 1,260 times

0

When I execute rake spec it runs all tests. How do I run only unit tests.

  • And how will he know which are unit tests and which are not? How about using rspec instead of the rake? You can pass the path of the unit tests (if that is the way that distinguishes your unit tests), thus: rspec --pattern spec/unit/*_spec.rb

2 answers

1


You can specify specific files so that Rspec only runs tests of these files, for example

$ rspec spec/models/*

It will run only model tests. You can also run only one test by specifying the line, for example.

$ rspec spec/models/user_spec.rb:31

Which will only run the test of line 31 of the user_spec.Rb file

1

Rspec tests behavior, while Unit Test (assuming this is the tool you are using for unit testing) tests the units of your application. You cannot run unit tests with a tool that runs behavior tests.

If you want to run only unit tests you can run the following command:

ruby -I test test/unit/
  • My Rspec must be defective because I use it to specify and run my unit tests.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.