Sha256: a01eb063d12f5e72fda696191fd5df035e68e5a16ef37c301efeb3dcca039464

Contents?: true

Size: 1.17 KB

Versions: 3

Compression:

Stored size: 1.17 KB

Contents

require 'spec_helper'
require 'analyst'

describe Society::Formatter::Graph::JSON do

  let(:graph) { Struct.new(:nodes, :edges)}
  let(:node) { Struct.new(:full_name) }
  let(:edge) { Struct.new(:from, :to) }

  let(:node_instance_1) { node.new("sample_node")}
  let(:node_instance_2) { node.new("other_node")}
  let(:edge_instance) { edge.new(node_instance_1, node_instance_2) }

  let(:graph_instance) { graph.new(
      [node_instance_1, node_instance_2],
      [edge_instance]
    )
  }

  let(:formatter) { Society::Formatter::Graph::JSON.new(graph_instance) }

  describe "#to_hash" do

    let(:hash) { formatter.to_hash }

    context "returns a hash" do
      it "with properly formatted nodes" do
        expect(hash[:nodes]).to eq(
          [
            {name: "sample_node"},
            {name: "other_node"}
          ]
        )
      end

      it "with properly formatted edges" do
        expect(hash[:edges]).to eq([{from: 0, to: 1}])
      end
    end
  end

  describe "#to_json" do

    let(:json) { formatter.to_json }
    let(:hash) { formatter.to_hash }

    it "returns json string for the result of #to_hash" do
      expect(json).to eq hash.to_json
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
society-1.1.1 spec/formatter/graph/json_spec.rb
society-1.1.0 spec/formatter/graph/json_spec.rb
society-1.0.0 spec/formatter/graph/json_spec.rb