[VCR] Response.bodyのJSONをprettyにする


###概要
フォーマットはデフォルトのYAMLのままで、response.bodyのJSONのみを読みやすくなるよう整形してみます。

###環境
* ruby 2.1.3p242 (2014-09-19 revision 47630) [x86_64-darwin13.0]
* rspec 3.1.7
* vcr 2.9.3

###整形前のCassette

```example.yml
---
http_interactions:
- request:
    method: get
    uri: http://weather.livedoor.com/forecast/webservice/json/v1?city=020020
    body:
      encoding: US-ASCII
      string: ''
    headers:
      Accept:
      - application/json
      Accept-Encoding:
      - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
      User-Agent:
      - Ruby
  response:
    status:
      code: 200
      message: OK
    headers:
      Server:
      - nginx
      Date:
      - Wed, 20 May 2015 11:17:59 GMT
      Content-Type:
      - application/json; charset=utf-8
      Transfer-Encoding:
      - chunked
      Connection:
      - keep-alive
      Keep-Alive:
      - timeout=3
      X-Content-Type-Options:
      - nosniff
      X-Frame-Options:
      - DENY
      Set-Cookie:
      - ldsuid=CoItjFVcbWehDUPA2M8oAg==; expires=Tue, 18-Aug-15 11:17:59 GMT; path=/
    body:
      encoding: UTF-8
      string: '{"pinpointLocations":[{"link":"http://weather.livedoor.com/area/forecast/0220800","name":"\u3080\u3064\u5e02"},{"link":"http://weather.livedoor.com/area/forecast/0242300","name":"\u5927\u9593\u753a"},{"link":"http://weather.livedoor.com/area/forecast/0242400","name":"\u6771\u901a\u6751"},{"link":"http://weather.livedoor.com/area/forecast/0242500","name":"\u98a8\u9593\u6d66\u6751"},{"link":"http://weather.livedoor.com/area/forecast/0242600","name":"\u4f50\u4e95\u6751"}],"link":"http://weather.livedoor.com/area/forecast/020020","forecasts":[{"dateLabel":"\u4eca\u65e5","telop":"\u66c7\u308a","date":"2015-05-20","temperature":{"min":null,"max":null},"image":{"width":50,"url":"http://weather.livedoor.com/img/icon/8.gif","title":"\u66c7\u308a","height":31}},{"dateLabel":"\u660e\u65e5","telop":"\u66c7\u306e\u3061\u6674","date":"2015-05-21","temperature":{"min":{"celsius":"9","fahrenheit":"48.2"},"max":{"celsius":"19","fahrenheit":"66.2"}},"image":{"width":50,"url":"http://weather.livedoor.com/img/icon/12.gif","title":"\u66c7\u306e\u3061\u6674","height":31}},{"dateLabel":"\u660e\u5f8c\u65e5","telop":"\u6674\u6642\u3005\u66c7","date":"2015-05-22","temperature":{"min":null,"max":null},"image":{"width":50,"url":"http://weather.livedoor.com/img/icon/2.gif","title":"\u6674\u6642\u3005\u66c7","height":31}}],"location":{"city":"\u3080\u3064","area":"\u6771\u5317","prefecture":"\u9752\u68ee\u770c"},"publicTime":"2015-05-20T20:00:00\u002b0900","copyright":{"provider":[{"link":"http://tenki.jp/","name":"\u65e5\u672c\u6c17\u8c61\u5354\u4f1a"}],"link":"http://weather.livedoor.com/","title":"(C)
        LINE Corporation","image":{"width":118,"link":"http://weather.livedoor.com/","url":"http://weather.livedoor.com/img/cmn/livedoor.gif","title":"livedoor
        \u5929\u6c17\u60c5\u5831","height":26}},"title":"\u9752\u68ee\u770c \u3080\u3064
        \u306e\u5929\u6c17","description":{"text":"\u5927\u9678\u304b\u3089\u672c\u5dde\u4ed8\u8fd1\u306b\u9ad8\u6c17\u5727\u304c\u5f35\u308a\u51fa\u3057\u3066\u3044\u307e\u3059\u3002\u307e\u305f\u65e5\u672c\u6d77\u306b\u306f\u4f4e\u6c17\u5727\u304c\u3042\n\u3063\u3066\u6771\u3078\u9032\u3093\u3067\u3044\u307e\u3059\u3002\n\n\u9752\u68ee\u770c\u306f\u3001\u66c7\u308a\u3084\u6674\u308c\u3067\u3001\u96e8\u306e\u964d\u3063\u3066\u3044\u308b\u6240\u304c\u3042\u308a\u307e\u3059\u3002\n\n20\u65e5\u591c\u306f\u3001\u6c17\u5727\u306e\u8c37\u3084\u5bd2\u6c17\u306e\u5f71\u97ff\u306b\u3088\u308a\u3001\u66c7\u308a\u3067\u96e8\u306e\u964d\u308b\u6240\u304c\u3042\u308b\u3067\u3057\u3087\n\u3046\u3002\n\n21\u65e5\u306f\u3001\u5bd2\u6c17\u306e\u5f71\u97ff\u306b\u3088\u308a\u3001\u306f\u3058\u3081\u66c7\u308a\u3067\u96e8\u306e\u964d\u308b\u6240\u304c\u3042\u308a\u307e\u3059\u304c\u3001\u663c\u9803\n\u304b\u3089\u306f\u6674\u308c\u308b\u898b\u8fbc\u307f\u3067\u3059\u3002\n\n\u003c\u5929\u6c17\u5909\u5316\u7b49\u306e\u7559\u610f\u70b9\u003e\n21\u65e5\u306f\u3001\u7279\u306b\u306a\u3057\u3002","publicTime":"2015-05-20T19:35:00\u002b0900"}}'
    http_version: 
  recorded_at: Wed, 20 May 2015 11:17:58 GMT
recorded_with: VCR 2.9.3
```

実は[ここ](https://www.relishapp.com/vcr/vcr/docs/cassettes/cassette-format#request/response-data-can-be-saved-using-a-custom-serializer)を参考に何度か試行したのですが、これまで上手く動作しませんでした。（仔細はオトナのジジョーにより省きます）

###解決方法
before_recordのフックにてJSON.pretty_generateした結果をbodyに突っ込みました。

```spec/spec_helper.rb
VCR.configure do | c |
  c.before_record do | i |
    i.response.body.force_encoding 'UTF-8'
    i.response.body = JSON.pretty_generate(JSON.parse(i.response.body))
  end
end
```

###整形後のCassette

```example.yml
---
http_interactions:
- request:
    method: get
    uri: http://weather.livedoor.com/forecast/webservice/json/v1?city=020020
    body:
      encoding: US-ASCII
      string: ''
    headers:
      Accept:
      - application/json
      Accept-Encoding:
      - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
      User-Agent:
      - Ruby
  response:
    status:
      code: 200
      message: OK
    headers:
      Server:
      - nginx
      Date:
      - Wed, 20 May 2015 11:26:32 GMT
      Content-Type:
      - application/json; charset=utf-8
      Transfer-Encoding:
      - chunked
      Connection:
      - keep-alive
      Keep-Alive:
      - timeout=3
      X-Content-Type-Options:
      - nosniff
      X-Frame-Options:
      - DENY
      Set-Cookie:
      - ldsuid=CoIxjFVcb2hNRUap2Pu0Ag==; expires=Tue, 18-Aug-15 11:26:32 GMT; path=/
    body:
      encoding: UTF-8
      string: |-
        {
          "pinpointLocations": [
            {
              "link": "http://weather.livedoor.com/area/forecast/0220800",
              "name": "むつ市"
            },
            {
              "link": "http://weather.livedoor.com/area/forecast/0242300",
              "name": "大間町"
            },
            {
              "link": "http://weather.livedoor.com/area/forecast/0242400",
              "name": "東通村"
            },
            {
              "link": "http://weather.livedoor.com/area/forecast/0242500",
              "name": "風間浦村"
            },
            {
              "link": "http://weather.livedoor.com/area/forecast/0242600",
              "name": "佐井村"
            }
          ],
          "link": "http://weather.livedoor.com/area/forecast/020020",
          "forecasts": [
            {
              "dateLabel": "今日",
              "telop": "曇り",
              "date": "2015-05-20",
              "temperature": {
                "min": null,
                "max": null
              },
              "image": {
                "width": 50,
                "url": "http://weather.livedoor.com/img/icon/8.gif",
                "title": "曇り",
                "height": 31
              }
            },
            {
              "dateLabel": "明日",
              "telop": "曇のち晴",
              "date": "2015-05-21",
              "temperature": {
                "min": {
                  "celsius": "9",
                  "fahrenheit": "48.2"
                },
                "max": {
                  "celsius": "19",
                  "fahrenheit": "66.2"
                }
              },
              "image": {
                "width": 50,
                "url": "http://weather.livedoor.com/img/icon/12.gif",
                "title": "曇のち晴",
                "height": 31
              }
            },
            {
              "dateLabel": "明後日",
              "telop": "晴時々曇",
              "date": "2015-05-22",
              "temperature": {
                "min": null,
                "max": null
              },
              "image": {
                "width": 50,
                "url": "http://weather.livedoor.com/img/icon/2.gif",
                "title": "晴時々曇",
                "height": 31
              }
            }
          ],
          "location": {
            "city": "むつ",
            "area": "東北",
            "prefecture": "青森県"
          },
          "publicTime": "2015-05-20T20:00:00+0900",
          "copyright": {
            "provider": [
              {
                "link": "http://tenki.jp/",
                "name": "日本気象協会"
              }
            ],
            "link": "http://weather.livedoor.com/",
            "title": "(C) LINE Corporation",
            "image": {
              "width": 118,
              "link": "http://weather.livedoor.com/",
              "url": "http://weather.livedoor.com/img/cmn/livedoor.gif",
              "title": "livedoor 天気情報",
              "height": 26
            }
          },
          "title": "青森県 むつ の天気",
          "description": {
            "text": "大陸から本州付近に高気圧が張り出しています。また日本海には低気圧があ\nって東へ進んでいます。\n\n青森県は、曇りや晴れで、雨の降っている所があります。\n\n20日夜は、気圧の谷や寒気の影響により、曇りで雨の降る所があるでしょ\nう。\n\n21日は、寒気の影響により、はじめ曇りで雨の降る所がありますが、昼頃\nからは晴れる見込みです。\n\n<天気変化等の留意点>\n21日は、特になし。",
            "publicTime": "2015-05-20T19:35:00+0900"
          }
        }
    http_version: 
  recorded_at: Wed, 20 May 2015 11:26:31 GMT
recorded_with: VCR 2.9.3
```

成功でっす。
カスタムserializerは、bodyのみならずCasstte全体をごにょごにょしたいときに向いてそうですね。