나는 순간적으로 나를 혼란에 빠뜨린 ActionMailer :: Base 테스트가 깨졌습니다. 아마도 나는 오류가 무엇인지 모르지만 전자 메일의 : 필드가 올바르게 표시되는지 확인하는 나의 주장에 도달하면 문제의 오류가 나타납니다. 다음은 내 코드 스 니펫입니다. MiniTest :: Spec :: Factory Girl과 테스트하지 않았습니다. 아래는 나의 Factory Girl 코드와 테스트 조건입니다. 나는 문제 영역에 대해 설명하고 콘솔에서 어떤 조건이 출력되는지 설명했다.조치 메일러가 어설 션에 실패했습니다. 누군가 내 전자 메일과 어설 션이 일치하지 않는 이유를 이해할 수 있습니까?
describe PostsController do
let(:forum) { create(:forum) }
let(:user) { create(:account) }
let(:admin) { create(:admin) }
let(:topic) { create(:topic) }
let(:post_object) { create(:post) }
before { ActionMailer::Base.deliveries.clear }
#code ------------
it 'create action: user2 replying to user1 receives
a creation email while user1 receives a reply email' do
login_as user
assert_difference('ActionMailer::Base.deliveries.size', 2) do
post :create, topic_id: post_object.topic.id, post: { body:
'Post reply gets sent to User 1. Post creation gets sent to User 2' }
end
email = ActionMailer::Base.deliveries
# -----debugging area ----------
puts email.first.to '[email protected]'
puts email.last.to '[email protected]'
puts email.map(&:to) '[email protected], [email protected]'
# ------debugging area --------
#-------failing test ----------
email.first.to.must_equal post_object.topic.account.email
Expected '[email protected], Actual: [email protected]'
#------failing test -----------
email.first.subject.must_equal 'Someone has responded to your post'
email.last.to.must_equal user.email
email.last.subject.must_equal 'Post successfully created'
must_redirect_to topic_path(post_object.topic.id)
end
왜 [email protected]이 필요한지 알 수 없습니다. assert_difference 블록 이후에 변경 사항이 있는지 궁금하네요.하지만 블록에서 puts 및 debugger 문을 실행 해봤는데 동일한 결과가 나옵니다. assert_difference에서 나오는 변경 사항은 없습니다. 도움을 주시면 감사하겠습니다. 감사.
안녕하세요. 답장을 보내 주셔서 감사합니다. 저를 망가뜨 렸던 테스트는 전자 메일이었습니다. 나는 당신에게 email.first.to.must_include post_object.topic.account.email을 제안했지만 그 이메일은 완전히 다른 것입니다. 아직도 ... 그 일을 아직도 멍 들었다. –
나는 문제 영역이 email.first.last 이메일이 아니라는 것을 의미했다. last.to. 이걸 영원히 바라 보았습니다. –