{"action":"created","issue":{"url":"https://api.github.com/repos/Validic/validic/issues/16","labels_url":"https://api.github.com/repos/Validic/validic/issues/16/labels{/name}","comments_url":"https://api.github.com/repos/Validic/validic/issues/16/comments","events_url":"https://api.github.com/repos/Validic/validic/issues/16/events","html_url":"https://github.com/Validic/validic/issues/16","id":67678503,"number":16,"title":"undefined method `each' When testing sleep with webmock - validic gem version 0.4.1","user":{"login":"topher6345","id":911359,"avatar_url":"https://avatars.githubusercontent.com/u/911359?v=3","gravatar_id":"","url":"https://api.github.com/users/topher6345","html_url":"https://github.com/topher6345","followers_url":"https://api.github.com/users/topher6345/followers","following_url":"https://api.github.com/users/topher6345/following{/other_user}","gists_url":"https://api.github.com/users/topher6345/gists{/gist_id}","starred_url":"https://api.github.com/users/topher6345/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/topher6345/subscriptions","organizations_url":"https://api.github.com/users/topher6345/orgs","repos_url":"https://api.github.com/users/topher6345/repos","events_url":"https://api.github.com/users/topher6345/events{/privacy}","received_events_url":"https://api.github.com/users/topher6345/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-04-10T20:42:48Z","updated_at":"2015-04-13T14:48:01Z","closed_at":null,"body":"Context: I'm in the process of writing unit tests for my app to handle the various responses returned from the validic API.\r\n\r\nWhen I call \r\n```ruby\r\n@client.create_sleep @sleep\r\n```\r\nI get the following error in my tests:\r\n\r\n```\r\n#<NoMethodError: undefined method `each' for \"sleep\":String>\r\n~/.rvm/gems/ruby-2.1.5/gems/validic-0.4.1/lib/validic/utils.rb:5:in `attributes_builder'\r\n~/.rvm/gems/ruby-2.1.5/gems/validic-0.4.1/lib/validic/sleep.rb:5:in `initialize'\r\n~/.rvm/gems/ruby-2.1.5/gems/validic-0.4.1/lib/validic/rest/sleep.rb:17:in `new'\r\n~/.rvm/gems/ruby-2.1.5/gems/validic-0.4.1/lib/validic/rest/sleep.rb:17:in `create_sleep'\r\n```\r\nMy theory is that the problem lies in this line:\r\n \r\n```ruby\r\n# validic-0.4.1/lib/validic/rest/sleep.rb:16\r\nresponse = post_request(:sleep, options)\r\nValidic::Sleep.new(response['sleep'])\r\n```\r\nIn my tests it looks like `response` is stubbed as a string, is this the proper format?\r\n\r\nHere is my stubbed request using webmock:\r\n\r\n```ruby\r\ndef stubbed_request\r\n    request = stub_request(\r\n      :post, \"https://api.validic.com/v1/organizations/#{ENV['VALIDIC_PUSH_ORGANIZATION_ID']}/sleep.json\")\r\n    request.with(:body => body, :headers => headers)\r\n    request.to_return(:status => 200, :body => response_body.to_json, :headers => {})\r\n  end\r\n\r\n  def response_body\r\n  {\r\n    \"code\"=>201,\r\n     \"message\"=>\"Ok\",\r\n     \"sleep\"=>{\r\n        \"timestamp\"=> @sleep.created_at.to_datetime.new_offset.iso8601,\r\n        \"utc_offset\"=>\"-7:00\",\r\n        \"awake\"=>nil,\r\n        \"deep\"=>nil,\r\n        \"light\"=>nil,\r\n        \"rem\"=>nil,\r\n        \"times_woken\"=>nil,\r\n        \"total_sleep\"=>28800.0,\r\n        \"activity_id\"=>255050412,\r\n        \"extra\"=>{\"quality\"=>\"3\"},\r\n        \"source\"=>\"sample_app\",\r\n        \"source_name\"=>\"Sample App\",\r\n        \"last_updated\"=>\"2013-03-10T07:12:16+00:00\"}}\r\n  end\r\n  ```"},"comment":{"url":"https://api.github.com/repos/Validic/validic/issues/comments/92386879","html_url":"https://github.com/Validic/validic/issues/16#issuecomment-92386879","issue_url":"https://api.github.com/repos/Validic/validic/issues/16","id":92386879,"user":{"login":"allcentury","id":5561166,"avatar_url":"https://avatars.githubusercontent.com/u/5561166?v=3","gravatar_id":"","url":"https://api.github.com/users/allcentury","html_url":"https://github.com/allcentury","followers_url":"https://api.github.com/users/allcentury/followers","following_url":"https://api.github.com/users/allcentury/following{/other_user}","gists_url":"https://api.github.com/users/allcentury/gists{/gist_id}","starred_url":"https://api.github.com/users/allcentury/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/allcentury/subscriptions","organizations_url":"https://api.github.com/users/allcentury/orgs","repos_url":"https://api.github.com/users/allcentury/repos","events_url":"https://api.github.com/users/allcentury/events{/privacy}","received_events_url":"https://api.github.com/users/allcentury/received_events","type":"User","site_admin":false},"created_at":"2015-04-13T14:48:01Z","updated_at":"2015-04-13T14:48:01Z","body":"I see, well hopefully these gem changes will simplify your tests.  Previously you were having to stub out the responses from the API but that's no longer necessary as we're already testing that in the gem itself.  What I'd recommend in your test is to stub out the `Validic::Client` like this:\r\n\r\n\r\n```ruby\r\n  it 'fetches data' do\r\n    @fitness = Validic::Fitness.new(steps: 1.5, distance: 0.5)\r\n    @client = double(\"Validic::Client\", get_fitness: @fitness)\r\n    allow(Validic::Client).to receive(:new).and_return @client\r\n\r\n    expect(@client.get_fitness.distance).to eq 0.5\r\n  end\r\n```\r\n\r\nYou can then extract those to a `before` block if you want to share the client across multiple tests.  "}}