2015-08-25 29 views
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中?我發現第一種方式更容易,更快速。

+0

不公平的downvote這個問題。是的,它是一個ruby noob錯誤,但這不是一個壞問題。 – Daiku

回答

4

路線插值只能用雙引號工程紅寶石:

it 'renders the subject' do 
    expect(mail.subject).to eq("#{order.firstname} <#{order.email}> has made an order.") 
end 

這應該工作。

+0

當然。我一直使用紅寶石几乎專有的雙引號,所以我從來沒有碰到過這個。 – rorykoehler