How can i test an individual controller in rails 5

suppose you want to test a test/controllers/static_pages_controller_test.rb

rails test test/controllers/static_pages_controller_test.rb

the results will be

(static-pages) $ rails test test/controllers/static_pages_controller_test.rb Running via Spring preloader in process 2430 Run options: --seed 45024

Running:

..

Finished in 0.900028s, 2.2222 runs/s, 2.2222 assertions/s.

2 runs, 2 assertions, 0 failures, 0 errors, 0 skips

Upvotes: 0

Views: 1158

Answers (1)

Tyesh
Tyesh

Reputation: 380

rails test method you have used run all unit, functional and integration tests. To run only a single test you can use invitation test as follows

 ruby -Itest test/controllers/static_pages_controller_test.rb 

You can also run a particular test method from the static_pages_controller_test by using the -n switch with the test method name as follows.

 ruby -Itest test/controllers/static_pages_controller_test.rb -n test_method_name

Hope this link will help you to get a better idea

Upvotes: 2

Related Questions