Sha256: 80f3bad0165a420d4620c88b73c9c31d7460f4849e2d05d6b13216d4aae14424

Contents?: true

Size: 1.19 KB

Versions: 20

Compression:

Stored size: 1.19 KB

Contents

require 'spec_helper'

module Startback
  describe Context, "h information contract" do

    it "has a to_json that dumps it" do
      expect(Context.new.to_json).to eql("{}")
    end

    class SubContext < Context
      attr_accessor :foo
      h_factory do |c,h|
        c.foo = h["foo"]
      end
      h_dump do |h|
        h.merge!("foo" => foo)
      end
    end

    class SubContext
      attr_accessor :bar
      h_factory do |c,h|
        c.bar = h["bar"]
      end
      h_dump do |h|
        h.merge!("bar" => bar)
      end
    end

    it 'allows installing factories' do
      expect(Context.h_factories).to be_empty
      expect(SubContext.h_factories.size).to eql(2)
    end

    it 'has a `to_h` information contract that works as expected' do
      context = SubContext.new.tap{|c|
        c.foo = "Hello"
        c.bar = "World"
      }
      expect(context.to_h).to eql({ "foo" => "Hello", "bar" => "World" })
    end

    it 'has a `h` information contract that works as expected' do
      context = SubContext.h({ "foo" => "Hello", "bar" => "World" })
      expect(context).to be_a(SubContext)
      expect(context.foo).to eql("Hello")
      expect(context.bar).to eql("World")
    end

  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
startback-0.12.1 spec/unit/context/test_h_factory.rb
startback-0.12.0 spec/unit/context/test_h_factory.rb
startback-0.11.5 spec/unit/context/test_h_factory.rb
startback-0.11.4 spec/unit/context/test_h_factory.rb
startback-0.11.3 spec/unit/context/test_h_factory.rb
startback-0.11.0 spec/unit/context/test_h_factory.rb
startback-0.10.1 spec/unit/context/test_h_factory.rb
startback-0.10.0 spec/unit/context/test_h_factory.rb
startback-0.9.1 spec/unit/context/test_h_factory.rb
startback-0.9.0 spec/unit/context/test_h_factory.rb
startback-0.8.3 spec/unit/context/test_h_factory.rb
startback-0.8.2 spec/unit/context/test_h_factory.rb
startback-0.8.1 spec/unit/context/test_h_factory.rb
startback-0.8.0 spec/unit/context/test_h_factory.rb
startback-0.7.6 spec/unit/context/test_h_factory.rb
startback-0.7.5 spec/unit/context/test_h_factory.rb
startback-0.7.4 spec/unit/context/test_h_factory.rb
startback-0.7.3 spec/unit/context/test_h_factory.rb
startback-0.7.2 spec/unit/context/test_h_factory.rb
startback-0.7.1 spec/unit/context/test_h_factory.rb