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.
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.
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.
With that one sentence, you have summed up all the painful bits of
my first five weeks on rails. Bring on merb
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 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).