Skip to content

asserts_json doesn't handle numeric keys #4

@smullins7

Description

@smullins7

I have JSON that contains a numeric key in string form (e.g. {"1": 2}). However, asserts_json("1").equals(2) is always failing, saying that the value is actually Nil. It probably has something to do with the json_path helper.

test that shows the failure:
diff --git a/test/assertions/asserts_json_test.rb b/test/assertions/asserts_json_test.rb
index 7816bcb..5c63079 100644
--- a/test/assertions/asserts_json_test.rb
+++ b/test/assertions/asserts_json_test.rb
@@ -5,7 +5,8 @@ context "The asserts_json macro" do
helper(:response) do
{
"a" => {"b" => "foo"},

  •  "c" => [["foo", 1], ["bar", 2]]
    
  •  "c" => [["foo", 1], ["bar", 2]],
    
  •  "1" => 33
    
    }
    end

@@ -15,4 +16,6 @@ context "The asserts_json macro" do
value.map { |string, number| number }
end.equals([1,2])

  • asserts_json("1").equals(33)

end # The asserts_json macro

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions