2012-04-02 2 views
1

私はRailsアプリケーションで "json_spec"宝石を使用しています。APIコードを文書化/テストするためのキュウリの手順をいくつか作成しようとしています。配列がない場合、 "json_spec" gemのパスをどのように使用しますか?

私は次のシナリオがあります。

Scenario: Create new authorization 
    Given an existing user and merchant 
    When I post to "/api/v1/authorizations.json" with: 
    """ 
    {"email":"[email protected]", "code": "43434", "merchant_account_id":1, "amount": 45.00} 
    """ 
    And I keep the JSON response at "authorization/id" as "AUTH_ID" 
    Then the JSON response should be: 
    """ 
    {"authorization":{"id":1,"email":"[email protected]","amount":45.0}} 
    """ 

を私は私に「権限」のハッシュで「ID」キーの値を与えるために、「認証/ ID」を期待しました。 json_specのドキュメントにあるすべての例には配列が含まれていますが、この場合、応答は1つのエンティティのみを含みます.JSONに配列を持つことは意味がありません。配列が存在しないときにパスを使用する方法はありますか?

答えて

0

確かに、使用した構文が正しいです。ドキュメンテーションの例のシナリオは、投稿への返答と、その投稿がコレクションの一部であるかどうか、つまり配列との関係で動作します。しかし、今投稿が最後の投稿であることを確認する場合は、ハッシュ構文を使用します。

Scenario: Create new authorization 
    Given an existing user and merchant 
    And I post to "/api/v1/authorizations.json" with: 
    """ 
    {"email":"[email protected]", "code": "43434", "merchant_account_id":1, "amount": 45.00} 
    """ 
    And I keep the JSON response at "authorization/id" as "AUTH_ID" 
    When I get from "/api/v1/authorizations/last.json" 
    Then the JSON response at "authorization/id" should be %{AUTH_ID} 
関連する問題