[opensuse-ruby] active_resource_test_helper
Sometimes ago I tried to figure out how to tests ActiveResouce. Unfortunately there are two possible choices around: use mocha or use the ActiveResource::HttpMock.responds_to method. Stubbing ActiveResource objects/calls with mocha is really annoying and produces ugly and unmaintainable code (especially when you have big/complex objects). Using ActiveResource::HttpMock is slightly better, but unfortunately you have to write manually all the request/response pairs that are going to be used by your test. You have also to write all the objects that are going to be transformed into ActiveResource instances by HttpMock. This really annoying and there's no way to avoid that (you cannot for example use fixtures). Hence I decided to create the active_resource_test_helper. Below you can find an explanation about how it works and how it can be used. You can find the code on github: http://github.com/flavio/active_resource_test_helper You can install the gem from gemcutter or using the package from devel:languages:ruby:extensions (it's called rubygem- active_resource_test_helper and I've just submitted it). Feedback is really appreciated. Happy hacking Flavio -- To unsubscribe, e-mail: opensuse-ruby+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-ruby+help@opensuse.org
Flavio Castelli write:
Sometimes ago I tried to figure out how to tests ActiveResouce. Unfortunately there are two possible choices around: use mocha or use the ActiveResource::HttpMock.responds_to method.
Stubbing ActiveResource objects/calls with mocha is really annoying and produces ugly and unmaintainable code (especially when you have big/complex objects).
Using ActiveResource::HttpMock is slightly better, but unfortunately you have to write manually all the request/response pairs that are going to be used by your test. You have also to write all the objects that are going to be transformed into ActiveResource instances by HttpMock. This really annoying and there's no way to avoid that (you cannot for example use fixtures).
Hi, we use "fixtures" in webyast for httpmock. We just save example xml response from server and use it as input for http mock. Also we have own extension of httpmock which mock authentification header (quite annoying), introspection on our backend and permission setup on backend. Maybe you find something useful in our testsuite (especially how we test that request is really sent correct) - example test: http://gitorious.org/opensuse/yast-web-client/blobs/master/plugins/time/test... our extension: http://gitorious.org/opensuse/yast-web-client/blobs/master/webclient/lib/yas... Josef
Hence I decided to create the active_resource_test_helper. Below you can find an explanation about how it works and how it can be used.
You can find the code on github: http://github.com/flavio/active_resource_test_helper
You can install the gem from gemcutter or using the package from devel:languages:ruby:extensions (it's called rubygem- active_resource_test_helper and I've just submitted it).
Feedback is really appreciated.
Happy hacking Flavio
-- Josef Reidinger YaST team maintainer of perl-Bootloader, YaST2-Repair, parts of webyast -- To unsubscribe, e-mail: opensuse-ruby+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-ruby+help@opensuse.org
participants (2)
-
Flavio Castelli
-
Josef Reidinger