Irrespective request type controller tests passes

9 views
Skip to first unread message

siva

unread,
Feb 9, 2014, 9:52:27 AM2/9/14
to rs...@googlegroups.com


  Hi all

  I might found issue or it couldn't be. In my routes file I have RESTful routes for movies as follows:

  ```
    resource :movies

 ```

 When I write test for movies controller#index action

   ```
      it "assigns to @movies" do
         post :index
         expect(assigns[:movies]).to eq([@movie])
     end
   ```

  I defined a route for movies#index with request type as `get` but when I use `post :index` in my test controller it passes the test. Ideally it should raise routing error but it didn't.   What's happening behind the covers? Is rails doing magic or rspec doing magic? Could you clarify me?
 


 

Myron Marston

unread,
Feb 16, 2014, 10:17:17 AM2/16/14
to rs...@googlegroups.com
 For the most part, rspec's rails' support is a very thin wrapper around rails' built-in testing support and I believe that's the case there.  If you are writing a controller spec bear in mind that it bypasses the router.  You could see if it has the same behavior if you write a rails functional test -- I suspect it does.

HTH,
Myron
Reply all
Reply to author
Forward
0 new messages