Sha256: f00872b24f40d44657be5e8de1e0915d7c0b15af9709dfd9a7c53be1a249dc33

Contents?: true

Size: 1.24 KB

Versions: 120

Compression:

Stored size: 1.24 KB

Contents

describe Appsignal::Utils::JSON do
  describe ".generate" do
    subject { Appsignal::Utils::JSON.generate(body) }

    context "with a valid body" do
      let(:body) do
        {
          "the" => "payload",
          1 => true,
          nil => "test",
          :foo => [1, 2, "three"],
          "bar" => nil,
          "baz" => { "foo" => "bar" }
        }
      end

      it "returns a JSON string" do
        is_expected.to eq %({"the":"payload","1":true,"":"test",) +
          %("foo":[1,2,"three"],"bar":null,"baz":{"foo":"bar"}})
      end
    end

    context "with a body that contains strings with invalid UTF-8 content" do
      let(:string_with_invalid_utf8) { [0x61, 0x61, 0x85].pack("c*") }
      let(:body) do
        {
          "field_one" => [0x61, 0x61].pack("c*"),
          :field_two => string_with_invalid_utf8,
          "field_three" => [
            "one", string_with_invalid_utf8
          ],
          "field_four" => {
            "one" => string_with_invalid_utf8
          }
        }
      end

      it "returns a JSON string with invalid UTF-8 content" do
        is_expected.to eq %({"field_one":"aa","field_two":"aa�",) +
          %("field_three":["one","aa�"],"field_four":{"one":"aa�"}})
      end
    end
  end
end

Version data entries

120 entries across 120 versions & 1 rubygems

Version Path
appsignal-4.0.6-java spec/lib/appsignal/utils/json_spec.rb
appsignal-4.0.6 spec/lib/appsignal/utils/json_spec.rb
appsignal-4.0.5-java spec/lib/appsignal/utils/json_spec.rb
appsignal-4.0.5 spec/lib/appsignal/utils/json_spec.rb
appsignal-4.0.4-java spec/lib/appsignal/utils/json_spec.rb
appsignal-4.0.4 spec/lib/appsignal/utils/json_spec.rb
appsignal-4.0.3-java spec/lib/appsignal/utils/json_spec.rb
appsignal-4.0.3 spec/lib/appsignal/utils/json_spec.rb
appsignal-4.0.2-java spec/lib/appsignal/utils/json_spec.rb
appsignal-4.0.2 spec/lib/appsignal/utils/json_spec.rb
appsignal-4.0.1-java spec/lib/appsignal/utils/json_spec.rb
appsignal-4.0.1 spec/lib/appsignal/utils/json_spec.rb
appsignal-4.0.0-java spec/lib/appsignal/utils/json_spec.rb
appsignal-4.0.0 spec/lib/appsignal/utils/json_spec.rb
appsignal-3.13.1-java spec/lib/appsignal/utils/json_spec.rb
appsignal-3.13.1 spec/lib/appsignal/utils/json_spec.rb
appsignal-3.13.1.alpha.1-java spec/lib/appsignal/utils/json_spec.rb
appsignal-3.13.1.alpha.1 spec/lib/appsignal/utils/json_spec.rb
appsignal-4.0.0.beta.2-java spec/lib/appsignal/utils/json_spec.rb
appsignal-4.0.0.beta.2 spec/lib/appsignal/utils/json_spec.rb