Home>

I tried to find out for myself, but I couldn't solve it.
In each error statement

I was making a portfolio by referring to the rails tutorial, but I got an error like this.

● The code of the related file is posted below. (Ascending order of error photos)

1st
The error says "" [email protected] "should be valid", but I don't know why it wasn't enabled because there is "[email protected]" in "valid_addresses" in the photo below.

2nd and 3rd
"Expecting<" users/edit ">but rendering with<[]>"
I mean, I was expecting<"users/edit">, but<[]>nothing. When,
I've confirmed that it was copied as it is, so I think I've forgotten to write it.

4th
"User.count" didn't change by 1./Expected: 5/Actual: 4
In other words, there is not enough users. I don't know who is missing one more person.
If i increase 1 of "'User.count', 1 do" below, "Expected:" will also increase.

5th and 6th
"Expected nil (NilClass) to respond to #empty ?." = "Nil is empty."
When logging in, @user remembers that if it is 1, it saves and logs in, but if it is 0, it deletes it and logs in.

I've included my recognition, but I think it's probably correct, so I thought it would be helpful.
Answer wants you to tell me the solution.
If i have any other information you need, I will send it to you.

Thank you.

Postscript
"App/models/user.rb" was added.

  • Answer # 1

    The correct answer cannot be reached because the way of thinking about the test is wrong.

    First,These are not error statements.They areTest failureAnd must be distinguishable from normal errors.

    Second, you must have a good understanding of what a test is, why you run it, and what its successes and failures mean.

    The test is to make sure the implementation works as expected. Test to make sure your implementation is as expected. Success or failure of a test has the following implications:

    [Test succeeds]

    The implementation is as expected.

    It's not the expected implementation, but it's a result of success due to incorrect testing.

    Regardless of the implementation, the test is wrong and it always succeeds.

    Successful testing does not mean that the implementation is perfect. This is because the tests that should be performed in almost all cases are missing.

    [Test fails]

    The implementation is incorrect and does not work as expected.

    The implementation is as expected, but the test is wrong, resulting in failure.

    It's not implemented, it's always failing because of wrong tests.

    In most cases, the test will fail if the implementation is incorrect. However, you should always be aware that the test itself may be wrong.

    All tests should be successful, but what to do if they fail needs to be viewed from two perspectives.

    (1) Is the test itself correct?

    It's pointless if you can't explain what the test does. Because you can't tell if the test is correct. Then, make sure that the content of the test itself is correct. The most common case is when you have made the opposite decision.

    (2) Is the implementation correct?

    It is wrong to say that the test is correct but fails. There is no choice but to take a closer look at the implementation. Sometimes you may need to debug or add a test to see the details.

    That way, we will try to make each test successful. It's not always okay to be successful, and you should always be aware that the test itself may be wrong.


    Well, based on the above. The question seems to look only at the test, but the view on the test is different. First, there should be the expected behavior. You need to look at the tests to see if they are designed to test their expected behavior. For exampleassert @ user.valid? "..."Whether this is correct or not is a test that does what it does, knows if it is normal or abnormal to be valid, and then considers whether the test itself is correct or incorrect. If you don't understand the meaning of the test, the test itself isn't worth it.

    Then, if the test is correct, it is the implementation that is wrong. It's like checking the validation of the User model, so it may be strange. You can't tell until you look at that implementation this time. In other words, even the first one is not clear from this alone, and at least the implementation part of User will be necessary. In some cases you may need to look more.

    Rails is often associated with multiple files, so even if you simply try to solve it, it often doesn't look like it's all there. In order to solve all at once, it will be impossible unless you publish them all. For the time being, I intend to write the perspective of what to do. After that, please solve each one based on this.