0

I'm trying to set up an email to notify me of errors that occur in my Rails app. I'm encountering a small error in my tests that are more or less an inability to properly state what I'm wanting. Let's just say my errors include the following two lines

2013-04-23 02:06:06 ERROR -- Errors for OUT6984-20130422-111427-1366647266.5769058.mp3:
2013-04-23 02:06:06 ERROR -- {:phone=>['is invalid']}

When I'm writing this to my email, I'm writing my expectation as follows:

it "contains the right content" do
  @email.should have_body_text("2013-04-23 02:04:56 ERROR -- Errors for OUT6984-20130422-101157-1366643517.5758441.mp3:")
  @email.should have_body_text("2013-04-23 02:04:56 ERROR -- {:phone=>['is invalid']}")
end

but my tests are failing due to...

expected the body to contain "2013-04-23 02:04:56 ERROR -- {:phone=>['is invalid']}" but was 
"<!DOCTYPE html> <html> <head> <meta content='text/html; charset=UTF-8' http-equiv='Content-Type'> </head> <body> <h1>Errors for 20130423</h1> <br> <p>2013-04-23 02:04:56 ERROR -- Errors for OUT6984-20130422-101157-1366643517.5758441.mp3: 2013-04-23 02:04:56 ERROR -- {:phone=&gt;['is invalid']} </p> </body> </html> "

Where the > char in the final hash is being replaced with &gt;. How can I fix this, or rewrite the test in such a way that it passes? The test is doing exactly what I want it to, as is the code. I just don't know how to tell it that this is what I want.

4

1 に答える 1

0

@email インスタンス変数が何として定義されているかわかりませんが、代わりに

@email.should have_body_text

使ってみて

mail.body.encoded.should match

出力を確認します。

于 2013-05-01T12:03:48.947 に答える