Vasspilka
Vasspilka

Reputation: 1163

Rake test fail assert_match

I am following Agile Web Developement with rails4 and at the rake test I get this failure. I cant figure out what's wrong... I know this causes the problem
assert_match /<td>1&times;<\/td>\s*<td>Programming Ruby 1.9<\/td>/, mail.body.encoded
My order_notifier_test, my shipped.text.erb is under app/views/order_notifier

The failure
OrderNotifierTest#test_shipped [Work/depot/test/mailers/order_notifier_test.rb:17]:
Expected /<td>1&times;<\/td>\s*<td>Programming Ruby 1.9<\/td>/ to match "<h3>Pragmatic Order Shipped</h3>\r\n<p>\r\n This is just to let you know that we've shipped your recent order:\r\n</p>\r\n \r\n<table>\r\n <tr><th colspan=\"2\">Qty</th><th>Description</th></tr>\r\n 1 x Programming Ruby 1.9\r\n\r\n</table>\r\n".

Feel free to browse the repository for more info (My system is there also under the README.md)

Upvotes: 3

Views: 1096

Answers (2)

Vardmev
Vardmev

Reputation: 21

i added

.gsub("\r\n", "")

to assert string:

assert_match /<td>1&times;<\/td>\s*<td>Programming Ruby 1\.9<\/td>/, mail.body.encoded.gsub("\r\n", "")

Upvotes: 0

Domon
Domon

Reputation: 6823

The failed assertion:

assert_match /<td>1&times;<\/td>\s*<td>Programming Ruby 1.9<\/td>/, mail.body.encoded

is expecting the rendered view in HTML format (line_items/_line_item.html.erb).

However, since the mailer view is in text format (order_notifier/shipped.text.erb), the partial in it is also rendered in text format (line_items/_line_item.text.erb).

Therefore, you might want to change the assertion to:

assert_match /1 x Programming Ruby 1.9/, mail.body.encoded

(Just like the one in the previous received order notifier test.)

Upvotes: 3

Related Questions