3

I am testing a mailer in Rspec and have run into a quirk with string concatenation. When I do it as follows:

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

I get the following message:

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 <joe@mctester.com> has made an order."

   (compared using ==)

However when I do the following it passes:

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

What is the correct way to concatenate in rspec? I find the first way far easier on the eye and quicker to work with.

rorykoehler
  • 1,642
  • 2
  • 15
  • 20
  • Unfair to downvote this question. Yes, its a ruby noob mistake, but it was not a bad question. – Daiku Aug 25 '15 at 16:12

1 Answers1

6

String interpolation only works with double quotes in ruby:

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

That should work.

tlehman
  • 5,125
  • 2
  • 33
  • 51