have_selector style test with html emails

32 views
Skip to first unread message

Karl Baum

unread,
Aug 13, 2009, 6:29:01 PM8/13/09
to cu...@googlegroups.com
I love the webrat have_selector css selector methods for cuke tests.
Was wondering if it's possible to use this style for asserting the
content of html emails?

thx.

-karl

aslak hellesoy

unread,
Aug 13, 2009, 7:23:36 PM8/13/09
to cu...@googlegroups.com

I love the webrat have_selector css selector methods for cuke tests.
Was wondering if it's possible to use this style for asserting the
content of html emails?

I don't think there is any such thing available, but I have an idea how it could be implemented.
Forl bmabey's email_spec and modify EmailSpec#have_body_text to take an optional Proc argument so that you could do something like:

email.should have_body_text do |html|
  doc = ... # hand it to webrat and invoke webrat methods...
  doc.field(#my_check).should be_checked
end

Ok, maybe a checked checkbox in a HTML mail isn't the best example, but you get the idea.

I would love to see email_spec wed to Webrat.

Aslak


thx.

-karl



Karl Baum

unread,
Aug 13, 2009, 7:37:12 PM8/13/09
to cu...@googlegroups.com
I would like to see this too. Not sure exactly how the "hand it to
webrat" is implemented , but I'll have a look at it.

thx.

-karl

thx!

Karl Baum

unread,
Aug 20, 2009, 9:12:23 AM8/20/09
to cu...@googlegroups.com
It's not the prettiest solution, but i was able to get this done by
extracting the html body from the email into a new response object.

response = ActionController::Response.new
response.body=current_email.body_html
response.extend(ActionController::TestResponseBehavior)
...
response.should have_selector("#order-email-
count", :content=>order_count.to_s) unless order_count==0
response.should_not have_selector("#order-email-count") if
order_count==0

thx.

-karl


On Aug 13, 2009, at 7:23 PM, aslak hellesoy wrote:

>
>
Reply all
Reply to author
Forward
0 new messages