On Thu, Jun 5, 2008 at 8:13 PM, Thomas Chik
<tshchik-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:>
> Hello,
>
> Testing newbie here. I have some AJAX code that would render an error
> message back to the host using page.alert. How would I test that?
> Personally I use RSpec, but Test::Unit is also fine. Thanks.
>
> # If some error arises
> render :update do |page|
> page.alert("Error message!")
> end
Here''s how you can do it with rspec:
describe "some action" do
it "should alert with Error message!" do
page = mock("page")
page.should_receive(:alert).with("Error message!")
controller.expect_render(:update).and_yield(page)
get :some_action
end
end
Here''s how I *think* (haven''t tried it, but should work) you
can do it
with test/unit and mocha:
def test_alert_with_error_messaged
page = mock()
page.expects(:alert).with("Error message!")
@controller.expects(:update).yields(page)
get :some_action
end
Cheers,
David
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---