# Rspec issues

**URL:** <https://www.ruby-forum.com/t/rspec-issues/152202>\
**Category:** Rails\
**Created:** [October 31, 2008, 8:41am UTC](https://www.ruby-forum.com/t/rspec-issues/152202 "2008-10-31T08:41:10Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [October 31, 2008, 8:41am UTC](https://www.ruby-forum.com/t/rspec-issues/152202/1 "2008-10-31T08:41:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [October 31, 2008, 10:06am UTC](https://www.ruby-forum.com/t/rspec-issues/152202/2 "2008-10-31T10:06:47Z")

</div>

Hi Elise,

2008/10/31 removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> - 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.

> **[James Mead](https://jamesmead.org/)**
>
> Ruby Developer, author of Mocha, and ex-Antarctic Hero.

[1] [http://groups.google.com/group/mocha-developer](http://groups.google.com/group/mocha-developer)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [October 31, 2008, 10:44am UTC](https://www.ruby-forum.com/t/rspec-issues/152202/3 "2008-10-31T10:44:59Z")

</div>

> - 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”)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 2, 2008, 2:20pm UTC](https://www.ruby-forum.com/t/rspec-issues/152202/4 "2008-11-02T14:20:06Z")

</div>

> > 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

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 2, 2008, 2:22pm UTC](https://www.ruby-forum.com/t/rspec-issues/152202/5 "2008-11-02T14:22:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 2, 2008, 2:37pm UTC](https://www.ruby-forum.com/t/rspec-issues/152202/6 "2008-11-02T14:37:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 2, 2008, 3:48pm UTC](https://www.ruby-forum.com/t/rspec-issues/152202/7 "2008-11-02T15:48:32Z")

</div>

2008/11/2 removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> 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.

> **[James Mead](https://jamesmead.org/)**
>
> Ruby Developer, author of Mocha, and ex-Antarctic Hero.
