# Rspec: routing test di controller nested

**URL:** <https://www.ruby-forum.com/t/rspec-routing-test-di-controller-nested/205833>\
**Category:** IT\
**Created:** [April 16, 2011, 6:41pm UTC](https://www.ruby-forum.com/t/rspec-routing-test-di-controller-nested/205833 "2011-04-16T18:41:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [April 16, 2011, 6:41pm UTC](https://www.ruby-forum.com/t/rspec-routing-test-di-controller-nested/205833/1 "2011-04-16T18:41:32Z")

</div>

Ciao,

nel file routes.rb ho

resources :thoughts do  
resources :statements, :only =\> [:create, :destroy]  
end

se eseguo rake routes | grep statements ottengo

```
  thought_statements POST

```

/thoughts/:thought\_id/statements(.:format) {:action=\>“create”,  
:controller=\>“statements”}  
thought\_statement DELETE  
/thoughts/:thought\_id/statements/:id(.:format) {:action=\>“destroy”,  
:controller=\>“statements”}

ma non riesco a capire perch il test di queste rotte con rspec fallisce

require “spec\_helper”

describe StatementsController do  
describe “routing” do

```
it "recognizes and generates #create" do
  { :post => "/thoughts/1/statements" }.should

```

route\_to(:controller =\> “statements”, :action =\> “create”)  
end

```
it "recognizes and generates #destroy" do
  { :delete => "/thoughts/1/statements/1" }.should

```

route\_to(:controller =\> “statements”, :action =\> “destroy”, :id =\>  
“1”)  
end

end  
end

con

rake spec:routing  
FF…

Failures:

Failures:

1. StatementsController routing recognizes and generates #create  
Failure/Error: { :post =\> “/thoughts/1/statements” }.should  
route\_to(:controller =\> “statements”, :action =\> “create”)  
Expected block to return true value.
# ./spec/routing/statements\_routing\_spec.rb:7:in `block (3

levels) in \<top (required)\>’

1. StatementsController routing recognizes and generates #destroy  
Failure/Error: { :delete =\> “/thoughts/1/statements/1” }.should  
route\_to(:controller =\> “statements”, :action =\> “destroy”, :id =\>  
“1”)  
Expected block to return true value.
# ./spec/routing/statements\_routing\_spec.rb:11:in `block (3

levels) in \<top (required)\>’

Qualche suggerimento ?  
Grazie mille.  
Claudio

---

<div class="post-metadata">

**Author:** ![maxer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e47774/32.png) [@maxer](https://www.ruby-forum.com/u/maxer)\
**Post date:** [April 16, 2011, 6:53pm UTC](https://www.ruby-forum.com/t/rspec-routing-test-di-controller-nested/205833/2 "2011-04-16T18:53:14Z")

</div>

Ciao Claudio,  
Credo che le spec falliscano rispettivamente a causa dell’id che non  
viene passato e della mancanza del thought\_id nel secondo caso.

Ti consiglio di eseguire `rake routes` per verificare i parametri  
mancanti.

Luca

---

<div class="post-metadata">

**Author:** ![maxer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e47774/32.png) [@maxer](https://www.ruby-forum.com/u/maxer)\
**Post date:** [April 18, 2011, 9:00am UTC](https://www.ruby-forum.com/t/rspec-routing-test-di-controller-nested/205833/3 "2011-04-18T09:00:23Z")

</div>

Ciao Luca,

grazie della tua risposta  
se eseguo rake routes | grep statements ottengo

```
 thought_statements POST

```

/thoughts/:thought\_id/statements(.:format) {:action=\>“create”,  
:controller=\>“statements”}  
thought\_statement DELETE  
/thoughts/:thought\_id/statements/:id(.:format)  
{:action=\>“destroy”, :controller=\>“statements”}

e mi sembra tutto ok ?

2011/4/16 Luca G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [http://lists.ruby-it.org/mailman/listinfo/ml](http://lists.ruby-it.org/mailman/listinfo/ml)

–  
Claudio M.

---

<div class="post-metadata">

**Author:** ![maxer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e47774/32.png) [@maxer](https://www.ruby-forum.com/u/maxer)\
**Post date:** [April 18, 2011, 10:37am UTC](https://www.ruby-forum.com/t/rspec-routing-test-di-controller-nested/205833/4 "2011-04-18T10:37:24Z")

</div>

Perfetto!  
Grazie mille

On Mon, Apr 18, 2011 at 10:05 AM, Luca G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > thought\_statements POST
> > 
> > > Credo che le spec falliscano rispettivamente a causa dell’id che non viene  
> > > passato e della mancanza del thought\_id nel secondo caso.
> > 
> > [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> > [http://lists.ruby-it.org/mailman/listinfo/ml](http://lists.ruby-it.org/mailman/listinfo/ml)
> 
> * * *
> 
> Ml mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [http://lists.ruby-it.org/mailman/listinfo/ml](http://lists.ruby-it.org/mailman/listinfo/ml)

–  
Claudio M.

---

<div class="post-metadata">

**Author:** ![maxer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e47774/32.png) [@maxer](https://www.ruby-forum.com/u/maxer)\
**Post date:** [April 18, 2011, 10:06am UTC](https://www.ruby-forum.com/t/rspec-routing-test-di-controller-nested/205833/5 "2011-04-18T10:06:30Z")

</div>

Prova con:

it “recognizes and generates #create” do  
{ :post =\> “/thoughts/1/statements” }.should route\_to(:controller =\>  
“statements”, :action =\> “create”, :thought\_id =\> “1”)  
end

it “recognizes and generates #destroy” do  
{ :delete =\> “/thoughts/1/statements/1” }.should route\_to(:controller =\>  
“statements”, :action =\> “destroy”, :thought\_id =\> “1”, :id =\>  
“1”)  
end

## Luca

> **[Luca Guidi on about.me](https://about.me/jodosha)**
>
> I use about.me to show people what matters most to me.
