0
我正在Rspec中測試一個郵件程序,並且遇到了帶有字符串連接的怪癖。當我做如下:如何正確地在Rspec中進行字符串連接?
it 'renders the subject' do
expect(mail.subject).to eq('#{order.firstname} <#{order.email}> has made an order.')
end
我得到以下信息:
OrderMailer instructions renders the subject
Failure/Error: expect(mail.subject).to eq('#{order.firstname} <#{order.email}> has made an order.')
expected: "\#{order.firstname} <\#{order.email}> has made an order."
got: "Joe <[email protected]> has made an order."
(compared using ==)
然而,當我這樣做它通過:
it 'renders the subject' do
expect(mail.subject).to eq(order.firstname + " <" + order.email + "> has made an order.")
end
什麼是連接的正確方法在rspec中?我發現第一種方式更容易,更快速。
不公平的downvote這個問題。是的,它是一個ruby noob錯誤,但這不是一個壞問題。 – Daiku