While working with Rails 4.1, I realized that the default unit test framework and minitest work very well together. So, I decided to look at several different scenarios in this context. We will start with creating a blank controller.
In order to test the index response,the method generated is as follows.
According to our specification, we need to make our welcome as route. We will first write a test for it. We need to create a test under the integration tests for the routes.
We will now try to run this test, but it will fail.
We will edit our routes to make the test pass.
Let’s run the tests and see how it goes.
Alright, now we need to write a test for getting last 5 meals, sorted by available date.
In order to create this test, we need to create a fixture.
We have not created associations yet, so we can keep chef_id, meal_type_id and food_preference_id as ids. Also assert_equal will match the expected results and actual results. The test now looks like the following:
In order to pass this test, we need to write the code.
Great! So we have tested the descending order and limit.