Sha256: a67c7e9da9dfaeb451b36c377c72e6b0bcce233a73ee696d2b8c68485be28be5

Contents?: true

Size: 1.33 KB

Versions: 2

Compression:

Stored size: 1.33 KB

Contents

# frozen_string_literal: true

require_relative "setup"
require "ryo/json"
require "fileutils"

RSpec.describe Ryo::JSON do
  describe ".from_json" do
    context "with a path" do
      subject(:ryo) { described_class.from_json(path:, object:) }
      before { File.binwrite path, JSON.dump(x: 20, y: 40) }
      after { FileUtils.rm(path) }
      let(:path) { File.join(__dir__, "test.json") }

      context "with Ryo::Object" do
        let(:object) { Ryo::Object }
        it { is_expected.to be_instance_of(Ryo::Object) }
        it { is_expected.to eq("x" => 20, "y" => 40) }
      end

      context "with Ryo::BasicObject" do
        let(:object) { Ryo::BasicObject }
        it { expect(Ryo::BasicObject === ryo).to be(true) }
        it { is_expected.to eq("x" => 20, "y" => 40) }
      end
    end

    context "with a string" do
      subject(:ryo) { described_class.from_json(string: "{\"x\": 20, \"y\": 40}", object:) }

      context "with Ryo::Object" do
        let(:object) { Ryo::Object }
        it { is_expected.to be_instance_of(Ryo::Object) }
        it { is_expected.to eq("x" => 20, "y" => 40) }
      end

      context "with Ryo::BasicObject" do
        let(:object) { Ryo::BasicObject }
        it { expect(Ryo::BasicObject === ryo).to be(true) }
        it { is_expected.to eq("x" => 20, "y" => 40) }
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ryo.rb-0.5.6 spec/ryo_json_spec.rb
ryo.rb-0.5.5 spec/ryo_json_spec.rb