When writing RSpec tests with rails, what should go in the spec / requests or spec / controllers folder?

I am new to rails and try to make something “right” by running tests from the start. Yesterday I used a forest generator to create my first model / view / controller configuration. Although I was told that you really shouldn't use scaffolding, it was useful so that I could find out how the Rails code is structured.

The only thing I noticed was that the automatically created RSpec was basically placed in the specifications / controllers folder . However, when I watched this episode of Railscasts , I noticed that it used

rails generate integration_test [test_name]

which placed one test file in the spec / requests folder . However, all of his tests he wrote interacted with controllers. What I'm trying to determine is the best practice for storing these tests.

When do I need to store tests in the spec / requests folder and when do I need to store tests in the spec / controllers folder? Any feedback would be greatly appreciated!

+5
source share
2 answers

These are actually two types of tests. In the controller folder, you must create tests to verify the actions of the controller, in the request folder you must place tests to interact with views that will actually check all of your parts of the application, and why he called the integration test.

.

http://everydayrails.com/2012/04/07/testing-series-rspec-controllers.html

http://everydayrails.com/2012/04/24/testing-series-rspec-requests.html

+6

. , ( ), , . , , - . .

, , (, , , ..). , , , : , , . /. , , , .

capybara ( , webrat), , . capybara javascript , , , , javascript json, ( javascript-, )

0

All Articles