Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 469 lines (335 sloc) 19.833 kb
3f957e4 @Sutto Add Gemnasium status
authored
1 # RocketPants! [![Build Status](https://secure.travis-ci.org/filtersquad/rocket_pants.png?branch=master)](http://travis-ci.org/filtersquad/rocket_pants) [![Dependency Status](https://gemnasium.com/filtersquad/rocket_pants.png)](https://gemnasium.com/filtersquad/rocket_pants)
2
22b6142 @Sutto More readme tweaks.
authored
3 ## Introduction
4
45ed4af @fredwu Fixed some small typos and enhanced syntax highlighting in the README
fredwu authored
5 First thing's first, you're probably asking yourself - "Why the ridiculous name?". It's simple, really - RocketPants is memorable, and sounds completely bad ass. - everything a library needs.
98d2351 @Sutto README work and License tweaks
authored
6
5e788d8 @levibuzolic Fixed typo in README
levibuzolic authored
7 At its core, RocketPants is a set of tools (built around existing toolsets such as ActionPack) to make it easier to build well-designed APIs in Ruby and more importantly, along side Rails. You can think of it like [Grape](https://github.com/intridea/grape), a fantastic library which RocketPants was originally inspired by but with deeper Rails and ActionPack integration.
98d2351 @Sutto README work and License tweaks
authored
8
9 ## Key Features
10
45ed4af @fredwu Fixed some small typos and enhanced syntax highlighting in the README
fredwu authored
11 Why use RocketPants over alternatives like Grape or normal Rails? The reasons we built it come down to a couple of simple things:
98d2351 @Sutto README work and License tweaks
authored
12
13 1. **It's opinionated** (like Grape) - In this case, we dictate a certain JSON structure we've found nice to work with (after having worked with and investigated a large number of other apis), it makes it simple to add metadata along side requests and the like.
45ed4af @fredwu Fixed some small typos and enhanced syntax highlighting in the README
fredwu authored
14 2. **Simple and Often Automatic Response Metadata** - RocketPants automatically takes care of sending metadata about paginated responses and arrays where possible. This means as a user, you only need to worry about writing `expose object_or_presenter` in your controller and RocketPants will do it's best to send as much information back to the user.
15 3. **Extended Error Support** - RocketPants has a built in framework to manage errors it knows how to handle (in the forms of mapping exceptions to a well defined JSON structure) as well as tools to make it simple to hook up to Airbrake and do things such as including an error identifier in the response.
16 4. **It's built on ActionPack** - One of the key differentiators to Grape is that RocketPants embraces ActionPack and uses the modular components included from Rails 3.0 onwards to provide things you're familiar with already such as filters.
17 5. **Semi-efficient Caching Support** - Thanks to a combination of Rails middleware and collection vs. resource distinctions, RocketPants makes it relatively easy to implement "Efficient Validation" (See [here](http://rtomayko.github.com/rack-cache/faq)). As a developer, this means you get even more benefits of http caching where possible, without the need to generate full requests when etags are present.
0222651 @Sutto Add client examples
authored
18 6. **Simple tools to consume RocketPants apis** - RocketPants includes the `RocketPants::Client` class which builds upon [APISmith](https://github.com/filtersquad/api_smith) to make it easier to build clients e.g. automatically converting paginated responses back.
98d2351 @Sutto README work and License tweaks
authored
19
22b6142 @Sutto More readme tweaks.
authored
20 ## Examples
21
22 ### A full example application
74b4567 @Sutto Add link to example app (not yet there)
authored
23
45ed4af @fredwu Fixed some small typos and enhanced syntax highlighting in the README
fredwu authored
24 Learn better by reading code? There is also have an example app mixing models and api clients over at [Sutto/transperth-api](https://github.com/Sutto/transperth-api) that is built using RocketPants.
74b4567 @Sutto Add link to example app (not yet there)
authored
25
0222651 @Sutto Add client examples
authored
26 ### Example Server Code
22b6142 @Sutto More readme tweaks.
authored
27
7a362ce @Sutto More tweaks! Namely to the README
authored
28 Say, for example, you have a basic Food model:
22b6142 @Sutto More readme tweaks.
authored
29
30 ```ruby
7a362ce @Sutto More tweaks! Namely to the README
authored
31 class Food < ActiveRecord::Base
32 include RocketPants::Cacheable
33 end
34 ```
35
36 ```ruby
37 class FoodsController < RocketPants::Base
38
39 version 1
40
41 # The list of foods is paginated for 5 minutes, the food itself is cached
42 # until it's modified (using Efficient Validation)
43 caches :index, :show, :caches_for => 5.minutes
22b6142 @Sutto More readme tweaks.
authored
44
45 def index
7a362ce @Sutto More tweaks! Namely to the README
authored
46 expose Food.paginate(:page => params[:page])
22b6142 @Sutto More readme tweaks.
authored
47 end
48
49 def show
7a362ce @Sutto More tweaks! Namely to the README
authored
50 expose Food.find(params[:id])
22b6142 @Sutto More readme tweaks.
authored
51 end
52
53 end
54 ```
55
56 And in the router we'd just use the normal REST-like routes in Rails:
57
58 ```ruby
7a362ce @Sutto More tweaks! Namely to the README
authored
59 api :version => 1 do
60 resources :foods, :only => [:index, :show]
61 end
62 ```
63
d6092e9 @Sutto We need the version in the URL
authored
64 And then, using this example, hitting `GET http://localhost:3000/1/foods` would result in:
7a362ce @Sutto More tweaks! Namely to the README
authored
65
66 ```json
67 {
68 "response": [{
69 "id": 1,
70 "name": "Delicious Food"
71 }, {
72 "id": 2,
73 "name": "More Delicious Food"
74 }],
75 "count": 2,
76 "pagination": {
77 "previous": nil,
78 "next": nil,
79 "current": 1,
80 "per_page": 10,
81 "count": 2,
82 "pages": 1
83 }
84 }
22b6142 @Sutto More readme tweaks.
authored
85 ```
86
d6092e9 @Sutto We need the version in the URL
authored
87 with the `Cache-Control` header set whilst hitting `GET http://localhost:3000/1/foods/1` would return:
7a362ce @Sutto More tweaks! Namely to the README
authored
88
89 ```json
90 {
91 "response": {
92 "id": 1,
93 "name": "Delicious Food"
94 }
95 }
96 ```
97
98 with the `Etag` header set.
99
aa5dc16 @Sutto Add JSONP notes
authored
100 #### JSONP
101
102 If you want to enable JSONP support, it's as simple as calling `jsonp` in your class method:
103
104 ```ruby
105 class MyController < RocketPants::Base
106 jsonp
107 end
108 ```
109
110 By default this will use the `callback` parameter, e.g. `GET /1/my?callback=console.log`.
111 To change this parameter, specify the `parameter` option like so:
112
113 ```ruby
114 class MyController < RocketPants::Base
115 jsonp :parameter => :jsonp
116 end
117 ```
118
119 Finally, to disable it in a subclass, simple call `jsonp` in the child and pass `:enable => false` as an option.
120
6c3caed @Sutto Initial link documentation
authored
121 #### Header Metadata
122
123 When `RocketPants.header_metadata` or `config.rocket_pants.header_metadata` are set to true, RocketPants can automatically
124 expose metadata via `X-Api-` headers. Likewise, for paginated responses, if you implement `page_url(page_number)` in your controller
125 with header metadata enabled, RocketPants will automatically add HTTP Link Headers for the next, prev, first and last to your
126 response.
127
128 Likewise, you can manually add link headers using the `link(rel, href, attributes = {})` method like so:
129
130 ```ruby
131 def index
132 # Not an actual rel, just an example...
133 link :profile, user_profile_path(current_user)
134 expose current_user
135 end
136 ```
137
138 For batch adding links, you can use the `links` method:
139
140 ```ruby
141 def index
142 # Probably not the best example...
143 links :next => random_wallpaper_path, :prev => random_wallpaper_path
144 expose Wallpaper.random
145 end
146 ```
147
0222651 @Sutto Add client examples
authored
148 ### Example Client Code
149
150 Using the example above, we could then use the following to write a client:
151
152 ```ruby
153 class FoodsClient < RocketPants::Client
154
155 version 1
156 base_uri 'http://localhost:3000'
157
158 class Food < APISmith::Smash
159 property :id
160 property :name
161 end
162
163 def foods
164 get 'foods', :transformer => Food
165 end
166
167 def food(id)
168 get "foods/#{id}", :transformer => Food
169 end
170
171 end
172 ```
173
98d2351 @Sutto README work and License tweaks
authored
174 ## General Structure
175
176 RocketPants builds upon the mixin-based approach to ActionController-based rails applications that Rails 3 made possible. Instead of including everything like Rails does in `ActionController::Base`, RocketPants only includes the bare minimum to make apis. In the near future, it may be modified to work with `ActionController::Base` for the purposes of better compatibility with other gems.
177
178 Out of the box, we use the following ActionController components:
179
180 * `ActionController::HideActions` - Lets you hide methods from actions.
181 * `ActionController::UrlFor` - `url_for` helpers / tweaks by Rails to make integration with routes work better.
182 * `ActionController::Redirecting` - Allows you to use `redirect_to`.
183 * `ActionController::ConditionalGet` - Adds support for Rails caching controls, e.g. `fresh_when` and `expires_in`.
184 * `ActionController::RackDelegation` - Lets you reset the session and set the response body.
185 * `ActionController::RecordIdentifier` - Gives `dom_class` and `dom_id` methods, used for polymorphic routing.
9858dfb @Sutto Readme updates
authored
186 * `ActionController::HttpAuthentication` Mixins - Gives Token, Digest and Basic authentication.
98d2351 @Sutto README work and License tweaks
authored
187 * `AbstractController::Callbacks` - Adds support for callbacks / filters.
188 * `ActionController::Rescue` - Lets you use `rescue_from`.
189
45ed4af @fredwu Fixed some small typos and enhanced syntax highlighting in the README
fredwu authored
190 And added our own:
98d2351 @Sutto README work and License tweaks
authored
191
192 * `RocketPants::UrlFor` - Automatically includes the current version when generating URLs from the controller.
193 * `RocketPants::Respondable` - The core of RocketPants, the code that handles converting objects to the different container types.
194 * `RocketPants::Versioning` - Allows versioning requirements on the controller to ensure it is only callable with a specific api version.
195 * `RocketPants::Instrumentation` - Adds Instrumentation notifications making it easy to use and hook into with Rails.
196 * `RocketPants::Caching` - Implements time-based caching for index actions and etag-based efficient validation for singular resources.
197 * `RocketPants::ErrorHandling` - Short hand to create errors as well as simplifications to catch and render a standardised error representation.
198 * `RocketPants::Rescuable` - Allows you to hook in to rescuing exceptions and to make it easy to post notifications to tools such as AirBrake.
199
200 To use RocketPants, instead of inheriting from `ActionController::Base`, just inherit from `RocketPants::Base`.
201
45ed4af @fredwu Fixed some small typos and enhanced syntax highlighting in the README
fredwu authored
202 Likewise, in Rails applications RocketPants also adds `RocketPants::CacheMiddleware` before the controller endpoints to implement ["Efficient Validation"](http://rtomayko.github.com/rack-cache/faq).
98d2351 @Sutto README work and License tweaks
authored
203
149db46 @Sutto More README docs / tweaks
authored
204 ## Installing RocketPants
205
206 Installing RocketPants is a simple matter of adding:
207
208 gem 'rocket_pants', '~> 1.0'
209
45ed4af @fredwu Fixed some small typos and enhanced syntax highlighting in the README
fredwu authored
210 To your `Gemfile` and running `bundle install`. Next, instead of inherited from `ActionController::Base`, simply inherit from `RocketPants::Base` instead. If you're working with an API-only application, I typically change this in `ApplicationController` and inherit from `ApplicationController` as usual. Otherwise, I generate a new `ApiController` base controller along side `ApplicationController` which instead inherits from `RocketPants::Base` and place all my logic there.
149db46 @Sutto More README docs / tweaks
authored
211
212 ## Configuration
213
45ed4af @fredwu Fixed some small typos and enhanced syntax highlighting in the README
fredwu authored
214 Setting up RocketPants in your rails application is pretty simple and requires a minimal amount of effort. Inside your environment configuration, RocketPants offers the following options to control how it's configured (and their expanded alternatives):
149db46 @Sutto More README docs / tweaks
authored
215
216 - `config.rocket_pants.use_caching` - Defaulting to true for production environments and false elsewhere, defines whether RocketPants caching setup as described below is used.
45ed4af @fredwu Fixed some small typos and enhanced syntax highlighting in the README
fredwu authored
217 - `config.rocket_pants.cache` - A `Moneta::Store` instance used as the RocketPants cache, defaulting to a moneta memory instance. Change for proper caching. (See [here](https://github.com/wycats/moneta) for more information on Moneta.)
149db46 @Sutto More README docs / tweaks
authored
218
219 ## Version Controllers / Routes
220
45ed4af @fredwu Fixed some small typos and enhanced syntax highlighting in the README
fredwu authored
221 The current preferred way of dealing with version APIs in RocketPants is to do it using routes in the form of `/:version/:endpoint` - e.g. `GET /1/users/324`. RocketPants has support in the router and controller level for enforcing and controlling this. In the controller, it's a matter of specifying the required API versions:
149db46 @Sutto More README docs / tweaks
authored
222
45ed4af @fredwu Fixed some small typos and enhanced syntax highlighting in the README
fredwu authored
223 ```ruby
224 class UsersController < RocketPants::Base
225 version 1 # A single version
226 # or...
227 version 2..3 # 2-3 support this controller
228 end
229 ```
149db46 @Sutto More README docs / tweaks
authored
230
45ed4af @fredwu Fixed some small typos and enhanced syntax highlighting in the README
fredwu authored
231 And in the case of multiple versions, I strongly encourage namespaces the controllers inside modules. If the version param (as specified) by the URL does not match, then the specified controller will return an `:invalid_version` error as shown below.
149db46 @Sutto More README docs / tweaks
authored
232
233 Next, in your `config/routes.rb` file, you can also declare versions using the following syntax and it will automatically set up the routes for you:
234
45ed4af @fredwu Fixed some small typos and enhanced syntax highlighting in the README
fredwu authored
235 ```ruby
236 api :version => 1 do
237 get 'x', :to => 'test#item'
238 end
239 ```
149db46 @Sutto More README docs / tweaks
authored
240
241 Which will route `GET /1/x` to `TestController#item`.
242
243 Likewise, you can specify a route for multiple versions by:
244
45ed4af @fredwu Fixed some small typos and enhanced syntax highlighting in the README
fredwu authored
245 ```ruby
246 api :versions => 1..3 do
247 get 'x', :to => 'test#item'
248 end
249 ```
149db46 @Sutto More README docs / tweaks
authored
250
98d2351 @Sutto README work and License tweaks
authored
251 ## Working with data
252
45ed4af @fredwu Fixed some small typos and enhanced syntax highlighting in the README
fredwu authored
253 When using RocketPants, you write your controllers the same as how you would with normal ActionController, the only thing that changes is how you handle data. `head` and `redirect_to` still work exactly the same as in Rails, but instead of using `respond_with` and `render` you instead use RocketPant's `exposes` methods (and it's kind). Namely:
3f8d609 @Sutto More type conversion docs
authored
254
255 - `expose` / `exposes` - The core of all type conversion, will check the type of data and automatically convert it to the correct time (for either a singular, collection or paginated resource).
256 - `paginated` - Render an object as a paginated collection of data.
257 - `collection` - Renders a collection of objects - e.g. an array of users.
258 - `resource` - Renders a single object.
259
260 Along side the above that wrap data, it also provides:
261
262 - `responds` - Renders JSON, normalizing the object first (unwrapped).
263 - `render_json` - Renders an object as JSON.
264
265 ### Singular Resources
266
45ed4af @fredwu Fixed some small typos and enhanced syntax highlighting in the README
fredwu authored
267 Singular resources will be converted to JSON via `serializable_hash`, passing through any objects
3f8d609 @Sutto More type conversion docs
authored
268 and then wrapped in an object as the `response` key:
269
45ed4af @fredwu Fixed some small typos and enhanced syntax highlighting in the README
fredwu authored
270 ```json
271 {
272 "response": {
273 "your": "serialized-object"
274 }
275 }
276 ```
3f8d609 @Sutto More type conversion docs
authored
277
278 ### Collections
279
280 Similar to singular resources, but also include extra data about the count of items.
281
45ed4af @fredwu Fixed some small typos and enhanced syntax highlighting in the README
fredwu authored
282 ```json
283 {
284 "response": [{
285 "name": "object-one"
286 }, {
287 "name": "object-two"
288 }],
289 "count": 2
290 }
291 ```
3f8d609 @Sutto More type conversion docs
authored
292
293 ### Paginated Collections
294
c741f37 @paxer typo fix
paxer authored
295 The final type, similar to collection objects but it includes details about the paginated data:
3f8d609 @Sutto More type conversion docs
authored
296
45ed4af @fredwu Fixed some small typos and enhanced syntax highlighting in the README
fredwu authored
297 ```json
298 {
299 "response": [
300 {"name": "object-one"},
301 {"name": "object-two"},
302 {"name": "object-three"},
303 {"name": "object-four"},
304 {"name": "object-five"}
305 ],
306 "count": 5,
307 "pagination": {
308 "previous": 1,
309 "next": 3,
310 "current": 2,
311 "per_page": 5,
1e498dc @levibuzolic Missing comma in paginated collections example
levibuzolic authored
312 "count": 23,
45ed4af @fredwu Fixed some small typos and enhanced syntax highlighting in the README
fredwu authored
313 "pages": 5
314 }
315 }
316 ```
98d2351 @Sutto README work and License tweaks
authored
317
318 ## Registering / Dealing with Errors
319
45ed4af @fredwu Fixed some small typos and enhanced syntax highlighting in the README
fredwu authored
320 One of the built in features of RocketPants is the ability to handle rescuing / controlling exceptions and more importantly to handle mapping exceptions to names, messages and error codes.
4da07ec @Sutto Started writing docs on the error handling
authored
321
45ed4af @fredwu Fixed some small typos and enhanced syntax highlighting in the README
fredwu authored
322 This comes in useful when you wish to automatically convert exceptions such as `ActiveRecord::RecordNotFound` to a structured bit of data in the response. Namely, it makes it trivial to generate objects that follow the JSON structure of:
4da07ec @Sutto Started writing docs on the error handling
authored
323
45ed4af @fredwu Fixed some small typos and enhanced syntax highlighting in the README
fredwu authored
324 ```json
325 {
326 "error": "standard_error_name",
327 "error_description": "A translated error message describing what happened."
328 }
329 ```
4da07ec @Sutto Started writing docs on the error handling
authored
330
331 It also adds a facilities to make it easy to add extra information to the response.
332
333 RocketPants will also attempt to convert all errors in the controller, defaulting to the `"system"` exception name and message as the error description. We also provide a registry to allow throwing exception from their symbolic name like so:
334
45ed4af @fredwu Fixed some small typos and enhanced syntax highlighting in the README
fredwu authored
335 ```ruby
336 error! :not_found
337 ```
4da07ec @Sutto Started writing docs on the error handling
authored
338
339 In the controller.
340
341 Out of the box, the following exceptions come pre-registered and setup:
342
343 - `:throttled` - The user has hit an api throttled error.
344 - `:unauthenticated` - The user doesn't have valid authentication details.
345 - `:invalid_version` - An invalid API version was specified.
346 - `:not_implemented` - The specified endpoint is not yet implemented.
347 - `:not_found` - The given resource could not be found.
348
6d970f0 @Sutto Add error context extras to the README
authored
349 Note that error also excepts a Hash of contextual options, many which will be passed through to the Rails I18N subsystem. E.g:
350
351 ```ruby
352 error! :throttled, :max_per_hour => 100
353 ```
354
355 Will look up the translation `rocket_pants.errors.throttled` in your I18N files, and call them with `:max_per_hour` as an argument.
356
357 Finally, You can use this to also pass custom values to include in the response, e.g:
358
359 ```ruby
360 error! :throttled, :extras => {:code => 123}
361 ```
362
363 Will return something similar to:
364
365 ```json
366 {
367 "error": "throttled",
368 "error_description": "The example error message goes here",
369 "code": 123
370 }
371 ```
372
98d2351 @Sutto README work and License tweaks
authored
373 ## Implementing Efficient Validation
374
45ed4af @fredwu Fixed some small typos and enhanced syntax highlighting in the README
fredwu authored
375 One of the core design principles built into RocketPants is simple support for "Efficient Validation" as described in the [Rack::Cache FAQ](http://rtomayko.github.com/rack-cache/faq) - Namely, it adds simple support for object-level caching using etags with fast verification thanks to the `RocketPants::CacheMiddleware` cache middleware.
149db46 @Sutto More README docs / tweaks
authored
376
45ed4af @fredwu Fixed some small typos and enhanced syntax highlighting in the README
fredwu authored
377 To do this, it uses `RocketPants.cache`, by default any Moneta-based store, to keep a mapping of object -> current cache key. RocketPants will then generate the etag when caching is enabled in the controller for singular-responses, generating an etag that can be quickly validated.
149db46 @Sutto More README docs / tweaks
authored
378
379 For example, you'd add the following to your model:
380
45ed4af @fredwu Fixed some small typos and enhanced syntax highlighting in the README
fredwu authored
381 ```ruby
382 class User < ActiveRecord::Base
383 include RocketPants::Cacheable
384 end
385 ```
149db46 @Sutto More README docs / tweaks
authored
386
387 And then in your controller, you'd have something like:
388
45ed4af @fredwu Fixed some small typos and enhanced syntax highlighting in the README
fredwu authored
389 ```ruby
390 class UsersController < RocketPants::Base
149db46 @Sutto More README docs / tweaks
authored
391
45ed4af @fredwu Fixed some small typos and enhanced syntax highlighting in the README
fredwu authored
392 version 1
149db46 @Sutto More README docs / tweaks
authored
393
45ed4af @fredwu Fixed some small typos and enhanced syntax highlighting in the README
fredwu authored
394 # Time based, e.g. collections, will be cached for 5 minutes - whilst singular
395 # items e.g. show will use etag-based caching:
396 caches :show, :index, :caches_for => 5.minutes
149db46 @Sutto More README docs / tweaks
authored
397
45ed4af @fredwu Fixed some small typos and enhanced syntax highlighting in the README
fredwu authored
398 def index
399 expose User.all
400 end
149db46 @Sutto More README docs / tweaks
authored
401
45ed4af @fredwu Fixed some small typos and enhanced syntax highlighting in the README
fredwu authored
402 def show
403 expose User.find(params[:id])
404 end
149db46 @Sutto More README docs / tweaks
authored
405
45ed4af @fredwu Fixed some small typos and enhanced syntax highlighting in the README
fredwu authored
406 end
407 ```
149db46 @Sutto More README docs / tweaks
authored
408
45ed4af @fredwu Fixed some small typos and enhanced syntax highlighting in the README
fredwu authored
409 When the user hits the index endpoint, it will generate an expiry-based caching header that caches the result for up to 5 minutes. When the user instead hits the show endpoint, it will generate a special etag that contains and object identifier portion and an object cache key. Inside `RocketPants.cache`, we store the mapping and then inside `RocketPants::CacheMiddleware`, we simply check if the given cache key matches the specified object identifier. If it does, we return a not modified response otherwise we pass it through to controller - giving the advantage of efficient caching without having to hit the full database on every request.
98d2351 @Sutto README work and License tweaks
authored
410
45ed4af @fredwu Fixed some small typos and enhanced syntax highlighting in the README
fredwu authored
411 ## Using with RSpec
73b2f4e Add misc. test helpers
Darcy Laycock authored
412
f0a3bbd @Sutto Update README.md to mention needing the version parameters in specs. …
authored
413 When testing controllers written using RocketPants, your normal rails approach should work.
414 The only difference one needs to take into the account is the need to specify the `:version`
415 parameter on any http requests, e.g:
416
417 ```ruby
418 get :index, :version => 1
419 ```
420
421 Otherwise it will raise an exception.
422
98d2351 @Sutto README work and License tweaks
authored
423 RocketPants includes a set of helpers to make testing controllers built on `RocketPants::Base` simpler.
424
19b8bc5 @Sutto RSpec integration docs
authored
425 * `be_singular_resource` - Checks the response is a single resource - e.g. `response.should be_siingular_resource`.
426 * `be_collection_resource` - Checks the response is collection of resources - e.g. `response.should be_collection_resource`.
e7f4299 @Sutto Finish implementing jsonp, add a stubbed out helper_method implementa…
authored
427 * `be_paginated_resource` - Checks the response is paginated - e.g. `response.should be_paginated_resource`.
19b8bc5 @Sutto RSpec integration docs
authored
428 * `be_api_error(type = any)` - Checks it returned an error for the specified exception (or check the response is an error without any argument) - e.g. `response.should be_api_error RocketPants::NotFound`.
429 * `have_exposed(data, options = {})` - Given an object and conversion options, lets you check the output exposed the same object. e.g: `response.should have_exposed user`
430
431 Likewise, it adds the following helper methods:
432
433 - `parsed_body` - A parsed-JSON representation of the response.
434 - `decoded_body` - A `Hashie::Mash` of the response body.
435
436 To set up the integration, in your `spec/spec_helper.rb` add:
437
45ed4af @fredwu Fixed some small typos and enhanced syntax highlighting in the README
fredwu authored
438 ```ruby
439 config.include RocketPants::TestHelper, :type => :controller
440 config.include RocketPants::RSpecMatchers, :type => :controller
441 ```
19b8bc5 @Sutto RSpec integration docs
authored
442
443 Inside the `RSpec.configure do |config|` block.
98d2351 @Sutto README work and License tweaks
authored
444
8ced3cb @Sutto Update README.md
authored
445 ## Contributors
446
447 - [Darcy Laycock](https://github.com/Sutto) - Main developer, current maintainer.
448 - [Steve Webb](https://github.com/swebb) - Helped with original work at [The Frontier Group](https://github.com/thefrontiergroup), inc. original design.
449 - [Fred Wu](https://github.com/fredwu) - README fixes.
450 - [Levi Buzolic](https://github.com/levibuzolic) - README fixes.
451
98d2351 @Sutto README work and License tweaks
authored
452 ## Contributing
453
454 We encourage all community contributions. Keeping this in mind, please follow these general guidelines when contributing:
455
456 * Fork the project
457 * Create a topic branch for what you’re working on (git checkout -b awesome_feature)
458 * Commit away, push that up (git push your\_remote awesome\_feature)
459 * Create a new GitHub Issue with the commit, asking for review. Alternatively, send a pull request with details of what you added.
460 * Once it’s accepted, if you want access to the core repository feel free to ask! Otherwise, you can continue to hack away in your own fork.
461
462 Other than that, our guidelines very closely match the GemCutter guidelines [here](http://wiki.github.com/qrush/gemcutter/contribution-guidelines).
463
464 (Thanks to [GemCutter](http://wiki.github.com/qrush/gemcutter/) for the contribution guide)
73b2f4e Add misc. test helpers
Darcy Laycock authored
465
98d2351 @Sutto README work and License tweaks
authored
466 ## License
73b2f4e Add misc. test helpers
Darcy Laycock authored
467
22b6142 @Sutto More readme tweaks.
authored
468 RocketPants is released under the MIT License (see the [license file](https://github.com/filtersquad/rocket_pants/blob/master/LICENSE)) and is copyright Filter Squad, 2012.
Something went wrong with that request. Please try again.