Ruby-on-rails 带有 Rspec 测试的完整 rails json API 示例
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6885572/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Complete rails json API example with Rspec tests
提问by Christian Schlensker
I'm looking for a good example repository of a Rails 3 project that implements a JSON API and has included RSpec tests. A full tutorial would be great but I'd settle for just a well commented example.
我正在寻找实现 JSON API 并包含 RSpec 测试的 Rails 3 项目的一个很好的示例存储库。一个完整的教程会很棒,但我只接受一个评论良好的例子。
回答by Leo Cassarani
Yehuda Katz and Ryan Bigg's excellent upcoming book, Rails 3 in Action, has a chapter on building a test-driven JSON API on top of the example application that runs through the entire book.
Yehuda Katz 和 Ryan Bigg 即将出版的优秀书籍Rails 3 in Action有一章是关于在贯穿整本书的示例应用程序之上构建测试驱动的 JSON API 的。
While I strongly recommend buying a copy of the beta edition of the book, the code for the sample application, Ticketee, is open source and can be found on GitHub. In particular, everything API-related is namespaced under /app/controllers/apiand you can find plenty of RSpec tests in /spec/api.
虽然我强烈建议您购买本书测试版的副本,但示例应用程序 Ticketee 的代码是开源的,可以在GitHub上找到。特别是,与 API 相关的所有内容都在命名空间下/app/controllers/api,您可以在/spec/api.
I was in your same position a couple of months ago when I was having to write a JSON API for an iPhone app so I'm well aware of the lack of good, test-driven, relevant tutorials online. Lucky for me I found out about the book and it turned out to be an absolute life saver.
几个月前,当我不得不为 iPhone 应用程序编写 JSON API 时,我处于与您相同的位置,因此我很清楚在线缺乏良好的、测试驱动的相关教程。幸运的是我发现了这本书,结果证明它绝对是救命稻草。
回答by erickreutz
RubyGems.orgis open source and has a great example of an API
RubyGems.org是开源的,并且有一个很好的 API 示例
回答by Whitney Imura
Can't necessarily answer the api example, but I can definitely vouch for the API testing of a rails 3 app in processes.
不一定能回答 api 示例,但我绝对可以保证在进程中对 rails 3 应用程序进行 API 测试。
Here you go: whitneytaylorimura.wordpress.com
给你:whitneytaylorimura.wordpress.com
It has a full example using Cucumber, Rspec, & FactoryGirl to create your objects (with DatabaseCleaner to clean them up).
它有一个完整的示例,使用 Cucumber、Rspec 和 FactoryGirl 创建您的对象(使用 DatabaseCleaner 清理它们)。

