apneadiving
2012-Jan-14 14:40 UTC
[rspec-users] Testing an API I''m creating, need test server to be running
Hi, As I am writing a brand new API, I''d like to test it''s response. Obviously, controller tests are great and work like a charm but as I expose data which are not really resources, I''ve to make some DIY to provide responses that ActiveResource can handle properly. 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. 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. Thanks in advance, Ben
David Chelimsky
2012-Jan-14 16:32 UTC
[rspec-users] Testing an API I''m creating, need test server to be running
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. HTH, David -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20120114/28bbd2a7/attachment.html>
David Chelimsky
2012-Jan-14 16:36 UTC
[rspec-users] Testing an API I''m creating, need test server to be running
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). http://rubydoc.info/gems/rspec-rails/file/README.md#Request_Specs http://guides.rubyonrails.org/testing.html#integration-testing -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20120114/4ee7dba3/attachment.html>
Hedge Hog
2012-Jan-15 01:25 UTC
[rspec-users] Testing an API I''m creating, need test server to be running
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 this. 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 time.>From someone who years ago wasted too many days trying to isolateissues that rack-test happily passed. Now at least you can''t say your weren''t forewarned ;) HTH> > 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) http://hedgehogshiatus.com
Sidu Ponnappa
2012-Jan-15 03:00 UTC
[rspec-users] Testing an API I''m creating, need test server to be running
Agreed. This is even more a bullet to bite early if your app orchestrates over more than one service, or if services talk to other services or both. Testing this kind of setup is pretty difficult and the tests are typically very brittle. Best, Sidu. http://c42.in http://rubymonk.com Sent from my phone On Jan 15, 2012 7:20 AM, "Hedge Hog" <hedgehogshiatus at gmail.com> wrote:> 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 > this. > 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 > time. > > 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 ;) > > HTH > > > > > 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) > http://hedgehogshiatus.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20120115/6789f9b5/attachment.html>
apneadiving
2012-Jan-17 20:10 UTC
[rspec-users] Testing an API I''m creating, need test server to be running
Thanks for all your answers, I should have said I''m very used to the workflow of integration specs and capybara. My question is really oriented towards API testing and particularly on the use of Active Resource. Basically, I''d like to: a- create ActiveResource classes in rspec/support b- run my tests for a, I don''t really know what URL I should provide for b, according to what you said, this kind of tests should live in rspec/requests Any more enlightenment? :) Ben On Jan 14, 5:36?pm, David Chelimsky <dchelim... 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 outhttps://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). > > http://rubydoc.info/gems/rspec-rails/file/README.md#Request_Specshttp://guides.rubyonrails.org/testing.html#integration-testing > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users
Anil Wadghule
2012-Apr-21 20:16 UTC
[rspec-users] Testing an API I''m creating, need test server to be running
How one should test an API which depends on other web services (SOAP etc). e.g. Login to my API internally calls to another webservice API for authentication. Also all the data sent back by my API is actually data retrieved from another web service. Also should we verify the data or just responses are 200 or something else. Any thoughts? Sidu Ponnappa wrote in post #1040936:> Agreed. This is even more a bullet to bite early if your app > orchestrates > over more than one service, or if services talk to other services or > both. > > Testing this kind of setup is pretty difficult and the tests are > typically > very brittle. > > Best, > Sidu. > http://c42.in > http://rubymonk.com > > Sent from my phone-- Posted via http://www.ruby-forum.com/.