开发者

Testing Rails application API client

We have Rails application with restful API and another Rails application with client(ActiveResource) for that API.

How we can create a test suite(Rspec preferred) for the API client with original web 开发者_开发问答server that runs this API without mocking it?


Have you considered if this is really what you want? The point of test suites is to test all of the components, and then their interactions. If you have good Unit tests, then mocking isn't much different from using prod data in your integration tests.

The reason I ask is because using real data can sometimes have unforeseen consequences. My team used to make all of our service calls because we were thinking like you, we wanted to test the real stuff. As our project grew, the amount of time it took to run tests became astronomical. A person on the team then had to devote a lot of time hunting down all of these calls and mocking them out so we could actually build our code in a timely manner. (This was in rails, but we had a bunch of build scripts that pulled all of our assets to our prod stacks, translated our strings in our translator service, made sure all tests passed, etc.)

My advice: Write solid unit and functional tests and then trust your mock data for integration tests.


I have built a test suite (using Cucumber, rspec for assertions, ruby, & FactoryGirl to create objects) that hits the API in processes and creates/deletes the objects in the database for a rails 3 app.

Checkout my blog for examples and code: automation blog


Try webmock to mount your Rails API app as a target for calls from client.

See http://robots.thoughtbot.com/how-to-test-sinatra-based-web-services

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜