Module 5 notes (ru) - Evanto/qna GitHub Wiki

1

Для методов-предикатов в rspec есть фича использовать их сразу как мэтчеры: ставим метод после .to/to_not, добавляем be_ и убираем вопросительный знак. Поэтому в юнит-тестах модели для проверки авторства вместо такой формы записи:

   it 'should return true if user owns the question' do
      expect(user.author_of?(question)).to eq true

пишем так:

expect(user).to be_author_of(question)

2

Slim завязан на отступах, любой косяк отступа - ошибка. Например, из-за того, что здесь в нижней строке не хватает отступа (она не под условием), форма будет выводиться всегда, без учета условия:

- if user_signed_in?
= render 'answers/form'

Slim docs

3

Дебагинг

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

Ошибки

1

1) AnswersController DELETE #destroy 1) user deletes his answer redirects to question
     Failure/Error: expect(response).to redirect_to question_path(question)

       Expected response to be a redirect to <http://test.host/questions/2033> but was a redirect to <http://test.host/questions/2034>.
       Expected "http://test.host/questions/2033" to be === "http://test.host/questions/2034".
     # ./spec/controllers/answers_controller_spec.rb:21:in `block (4 levels) in <top (required)>'

лечение: поменяла expect(response).to redirect_to question_path(question) expect(response).to redirect_to question_path(answer.question)