Hi, i''ve started using rspec for this project (latest versions: rspec 1.1.9 and rspec-rails 1.1.9), and i stumbled upon the following problems: - render_template: response.should render_template(''new'') i get the following fail expected "new", got "/Users/elise/Rails/myapp/app/views/user/profiles/ new.html.erb" So it expects the full path. That can''t be right ? - should be: doesn''t give me the result i expect for two strings that are equal. assigns[''page''].menu.should be("home alone") gives me expected "home alone", got "home alone" - mocking (ok, i''m using mocha, so maybe it isn''t rspec): i make a mailer raise an error like this: DummyMailer.stubs(:deliver_invitation).raises(Exception) and in my code, surround this with begin ... rescue, the exception is not caught ! Any tips ? Thanks ! Elise --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi Elise, 2008/10/31 huard.elise-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <huard.elise-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>> - mocking (ok, i''m using mocha, so maybe it isn''t rspec): i make a > mailer raise an error like this: > DummyMailer.stubs(:deliver_invitation).raises(Exception) > and in my code, surround this with begin ... rescue, the exception is > not caught ! >a) Are you sure deliver_invitation is being called? b) Are you using just a default rescue clause? This will only rescue StandardError''s and descendants of StandardError. Exception is not a descendant of StandardError. I think Mocha raises a StandardError by default, so if you change your stubbing as follows, a default rescue clause will work... DummyMailer.stubs(:deliver_invitation).raises If you are still seeing unexpected behaviour, come over to the Mocha mailing list [1] and we''ll see if we can help. -- James. http://blog.floehopper.org [1] http://groups.google.com/group/mocha-developer --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> - render_template: > response.should render_template(''new'') > i get the following fail > expected "new", got "/Users/elise/Rails/myapp/app/views/user/profiles/ > new.html.erb" > So it expects the full path. That can''t be right ?nope, it expects new and gets the full path instead. what''s your render command?> - should be: doesn''t give me the result i expect for two strings that > are equal. > assigns[''page''].menu.should be("home alone") > gives me > expected "home alone", got "home alone" >Typical ruby thing. "should be" tests for the two strings are an identical string object (one and the same thingy in memory) use: assigns[''page''].menu.should eql("home alone") --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
huard.elise-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Nov-02 13:19 UTC
Re: rspec issues
> > expected "new", got "/Users/elise/Rails/myapp/app/views/user/profiles/ > > new.html.erb" > > So it expects the full path. That can''t be right ? > > nope, it expects new and gets the full path instead. > what''s your render command?render :action => :new> Typical ruby thing. "should be" tests for the two > strings are an identical string object (one and the same thingy in > memory) > use: > assigns[''page''].menu.should eql("home alone")OK, thanks Elise --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
huard.elise-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Nov-02 13:21 UTC
Re: rspec issues
b) makes sense, though it is surprising: I mean developer-defined errors are usually Exceptions, and should be caught too, no ? I need to pick up my ruby book again. Elise On Oct 31, 10:05 am, "James Mead" <jamesmea...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi Elise, > > 2008/10/31 huard.el...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <huard.el...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > > - mocking (ok, i''m using mocha, so maybe it isn''t rspec): i make a > > mailer raise an error like this: > > DummyMailer.stubs(:deliver_invitation).raises(Exception) > > and in my code, surround this with begin ... rescue, the exception is > > not caught ! > > a) Are you sure deliver_invitation is being called? > b) Are you using just a default rescue clause? This will only rescue > StandardError''s and descendants of StandardError. Exception is not a > descendant of StandardError. I think Mocha raises a StandardError by > default, so if you change your stubbing as follows, a default rescue clause > will work... > > DummyMailer.stubs(:deliver_invitation).raises > > If you are still seeing unexpected behaviour, come over to the Mocha mailing > list [1] and we''ll see if we can help. > > -- > James.http://blog.floehopper.org > > [1]http://groups.google.com/group/mocha-developer--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
huard.elise-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Nov-02 13:35 UTC
Re: rspec issues
b) makes sense, though it is surprising: I mean developer-defined errors are usually Exceptions, and should be caught too, no ? I need to pick up my ruby book again. Elise On Oct 31, 10:05 am, "James Mead" <jamesmea...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi Elise, > > 2008/10/31 huard.el...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <huard.el...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > > - mocking (ok, i''m using mocha, so maybe it isn''t rspec): i make a > > mailer raise an error like this: > > DummyMailer.stubs(:deliver_invitation).raises(Exception) > > and in my code, surround this with begin ... rescue, the exception is > > not caught ! > > a) Are you sure deliver_invitation is being called? > b) Are you using just a default rescue clause? This will only rescue > StandardError''s and descendants of StandardError. Exception is not a > descendant of StandardError. I think Mocha raises a StandardError by > default, so if you change your stubbing as follows, a default rescue clause > will work... > > DummyMailer.stubs(:deliver_invitation).raises > > If you are still seeing unexpected behaviour, come over to the Mocha mailing > list [1] and we''ll see if we can help. > > -- > James.http://blog.floehopper.org > > [1]http://groups.google.com/group/mocha-developer--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
2008/11/2 huard.elise-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <huard.elise-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>> > b) makes sense, though it is surprising: I mean developer-defined > errors are usually Exceptions, and should be caught too, no ? I need > to pick up my ruby book again. >It''s a common developer mistake to derive new exception classes from Exception, rather than StandardError. Such exception classes will not be rescued by a default rescue clause. -- James. http://blog.floehopper.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---