collectiveidea / json_spec

Easily handle JSON in RSpec and Cucumber
rubygems.org/gems/json_spec
MIT License
919 stars 114 forks source link

Second level of nesting issue #44

Closed rangerscience closed 11 years ago

rangerscience commented 11 years ago

I have this kind of structure:

"attribute" : {
  "data": {
    "object": {
      "data": "bacon"
    }
}

and my the JSON should be step is failing with this kind of error:

"attribute" : {
  "data": "{:object=>\"bacon\"}"
}

Ruby2 / Rails 4 / json_spec 1.1.1

laserlemon commented 11 years ago

What exactly does your Cucumber scenario look like?

rangerscience commented 11 years ago
Scenario: Fetch Test
  When I fetch the sample "content" "ContentName"
  Then the JSON response should be (in yaml):
    """
      attribute:
        data:
          object: bacon
    """
Then /^the JSON response should be \(in yaml\):$/  do |yaml|
  data = YAML.parse(yaml)
  step 'the JSON response should be:' data.to_json
end

It works for my flatter test:

Scenario: Flatter Test
  When I fetch the sample "content" "ContentName"
  Then the JSON response should be (in yaml):
    """
      attribute:
        object: bacon
    """

That test passes.

laserlemon commented 11 years ago

What do you see if you put

puts data.to_json

after your

data = YAML.parse(yaml)
rangerscience commented 11 years ago
$ JSON.pretty_generate(data)
{
  "attribute": {
    "data": {
        "object": "bacon",
    }
  }
}
laserlemon commented 11 years ago

I can't figure what the issue here is. If you're able, please try to write a failing test that doesn't involve stepping through YAML.

rangerscience commented 11 years ago

Aha; you are correct, sir, and my apologies. The error is neither in json_spec nor YAML interpertation; it's with saving to hstore!

rangerscience commented 11 years ago

Closing - Issue not with JSON Spec.