Sha256: ce5ef14f8fea1e327b3336b15555e8cae133a3a7453a33e29ad3a2561b2ca5fc

Contents?: true

Size: 1010 Bytes

Versions: 2

Compression:

Stored size: 1010 Bytes

Contents

require 'json'

require 'spec_helper'

require 'state_mate/adapters/json'

describe "StateMate::Adapters::JSON.read" do
  include_context "json"
  
  it "reads an empty file as nil" do
    expect( json.read [@filepath] ).to be nil
  end

  context "file with a string value in it" do
    let(:value) {
      "blah"
    }

    before(:each) {
      File.open(@filepath, 'w') {|f|
        f.write JSON.dump(value)
      }
    }

    it "should read the value" do
      expect( json.read [@filepath] ).to eq value
    end
  end

  context "file with a dict value in it" do
    let(:value) {
      {
        'x' => 1,
        'y' => 2,
        'z' => {
          'a' => 3,
        }
      }
    }

    before(:each) {
      File.open(@filepath, 'w') {|f|
        f.write JSON.dump(value)
      }
    }

    it "should read the root value" do
      expect( json.read [@filepath] ).to eq value
    end

    it "should read a deeper value" do
      expect( json.read "#{ @filepath }:z:a" ).to eq 3
    end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
state_mate-0.0.3 spec/state_mate/adapters/json/read_spec.rb
state_mate-0.0.2 spec/state_mate/adapters/json/read_spec.rb