[rspec-users] Testing an API I'm creating, need test server to be running

Hedge Hog hedgehogshiatus at gmail.com
Sat Jan 14 20:25:34 EST 2012

On Sun, Jan 15, 2012 at 3:36 AM, David Chelimsky <dchelimsky at gmail.com> wrote:
> On Jan 14, 2012, at 10:32 AM, David Chelimsky wrote:
> On Jan 14, 2012, at 8:40 AM, apneadiving wrote:
> As I am writing a brand new API, I'd like to test it's response.
> <snip/>
> Basically, it would be great in my case to test if ActiveResource gets
> the expected data but it means I have to launch a test server in
> background for the whole suite.
> <snip/>
> Is there a convenient to handle this? Currently, I launch the test
> server in console but it would be much better to have this handled
> programmatically.
> I'd recommend you check out https://github.com/brynary/rack-test.
> It provides access to attributes of the request and the response object, and
> obviates the need for running a server. Take a look at its
> specs: https://github.com/brynary/rack-test/blob/master/spec/rack/test_spec.rb.
> Of course, you get rack-test for free if you use request specs (which wrap
> Rails integration tests, which use rack-test).

This could be considered to be off topic, but rack-test was advised....

Some think this issue is a trap for young players, others that it is
just a different test philosophy. Nonetheless:

 After a while you will eventually face the fact that you _have_ to
test responses from your whole 'stack', specifically all the
interactions of the different components, and rack-test does _not_ do
Better to bite this bullet early.
FWIW I have unit tests that are just that, and integration tests that
are, well, integration tests - which precludes (by definition) using
rack-test :)
To get interagtion tests running (quickly) you'll likely need to use
Vagrant+Chef+VCR, or some such toolbox, to launch your test stack
(locally, AWS, Rackspace etc.)

Again, this is inevitable, so better to bite integration testing early
while things are simple - build the complexity incrementally over

>From someone who years ago wasted too many days trying to isolate
issues that rack-test happily passed.

Now at least you can't say your weren't forewarned ;)


> http://rubydoc.info/gems/rspec-rails/file/README.md#Request_Specs
> http://guides.rubyonrails.org/testing.html#integration-testing
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users

πόλλ' οἶδ ἀλώπηξ, ἀλλ' ἐχῖνος ἓν μέγα
[The fox knows many things, but the hedgehog knows one big thing.]
  Archilochus, Greek poet (c. 680 BC – c. 645 BC)

More information about the rspec-users mailing list