RSpec in Rails -- HTTP methods

It seems that RSpec-Rails isn’t restricted to the HTTP methods
correctly.

For example doing:

http://foo.local/session/destroy

in the browser doesn’t work, because the destroy action is only
recognised with the HTTP ‘delete’ verb.

But in Rspec specs if you do:

get :destroy

It works.

Is this intended behaviour or a bug?

Many Thanks,

~ Mark

On Wed, Sep 10, 2008 at 12:24 PM, Mark D. [email protected]
wrote:

But in Rspec specs if you do:

get :destroy

It works.

Is this intended behaviour or a bug?

RSpec controller examples and scenarios each wrap testing services
provided by Rails. You’ll get the same results from rails functional
tests as you do in rspec controller examples, and you’ll get the same
results from rails integration tests as you do from rspec scenarios
(using RailsStory).

In controller examples (wrapping rails functional tests), routing is
bypassed, so I think you’ll find that you can get, post, put, delete
any action that aren’t restricted from the controller.

In RailsStory, the RSpec wrapper for rails integration tests, requests
DO go through routing, so, similarly, I think you’ll find that you can
get, post, put, delete any action that aren’t restricted from routing.

That all make sense? Let us know if you have any additional questions.

Cheers,
David

On Wed, Sep 10, 2008 at 1:24 PM, Mark D. [email protected]
wrote:

But in Rspec specs if you do:

get :destroy

It works.

Is this intended behaviour or a bug?

Rails uses routing to map DELETE /session to
SessionController#destroy. Controller specs don’t use routing.
Whenever you do get/put/post/delete in your spec, you’re effectively
doing

SessionController.new.destroy

except you can’t simply do that, because ActionPack is a rat’s nest of
dependencies.

Pat

On 10 Sep 2008, at 19:49, Pat M. wrote:

except you can’t simply do that, because ActionPack is a rat’s nest of
dependencies.

With that one sentence, you have summed up all the painful bits of my
first five weeks on rails. Bring on merb :slight_smile:

cheers,
Matt

http://blog.mattwynne.net

In case you wondered: The opinions expressed in this email are my own
and do not necessarily reflect the views of any former, current or
future employers of mine.

On 10 Sep 2008, at 23:21, Matt W. wrote:

With that one sentence, you have summed up all the painful bits of
my first five weeks on rails. Bring on merb :slight_smile:

If you’re doing something simple, try Ramaze[1] (although I will
investigate Merb in depth soon for a more significant project). I’ve
started using it to build mockup versions of web APIs I need to code
against*, and I’ve been amazed how simple, elegant and flexible it
is. I have yet to write any specs against its controllers (although
they do specifically enable that), but specs against models are ORM-
dependent, and stories can be done in something implementation
independent (I’m currently favouring Celerity[2]).

Rails has grown from a snazzy little framework into an untestable
behemoth, and I’m doing my best to avoid it. There’s a lot of
frameworks and libraries now that give RSpec and BDD processes the
respect they deserve, rather than forcing anyone that wants to do BDD
to make ugly workarounds.

The work the RSpec team has done to make Rails testable is fantastic
and should be applauded. But I can’t help feel it’s an unfortunate
sink on everyone’s time, a bit like maintaining Windows compatibility
in ports of software.

But that’s just me grumbling as usual… I’ve got a very low tolerance
for kludgy software. What can’t everything be perfect, goddammit!!!

Ashley

  • including Twitter - let me know if anyone here would benefit from a
    simple Twitter implementation (like Laconica) that plays nice with the
    Twitter gem, and I’ll see if we can open source it…

[1] http://ramaze.net/
[2] http://celerity.rubyforge.org/


http://www.patchspace.co.uk/

+1 for ramaze. The gem also installs some lovely example apps and they
use rspec for their development, so there are plenty of example specs
both at the code and integration (web) level.

I’ve not been writing ruby web apps in anger but for all the little
example apps I write I’ve been using ramaze.

It is also view-agnostic (any combination of erb, haml, cass, etc) and
persistence-agnostic (sequel, og, cough activerecord, datamapper).

It’s a breath of fresh air!

Cheers, Dan

Many thanks for the info, that certainly clarifies things!

~ Mark