Sha256: 4b49a9c5aad299c27c39c2fe4fd9c8ad892610c3c2abc23e5801caf3038808d8

Contents?: true

Size: 805 Bytes

Versions: 1

Compression:

Stored size: 805 Bytes

Contents

# frozen_string_literal: true

require 'test_helper'
require 'webhookr/ostruct_utils'
require 'ostruct'

class OstructUtilsTest < ActiveSupport::TestCase
  def setup
    @hash = { a: { b: { c: 1 } }, a1: [ { b1: { c1: 1 } } ] }
    @converted = Webhookr::OstructUtils.to_ostruct(@hash)
  end

  test 'should be an OpenStruct' do
    assert_instance_of(OpenStruct, @converted)
  end

  test 'should have a nested OpenStruct' do
    assert_instance_of(OpenStruct, @converted.a)
  end

  test 'should have a nested nested OpenStruct' do
    assert_instance_of(OpenStruct, @converted.a.b)
  end

  test 'should have a nested nested nested value of 1' do
    assert_equal(1, @converted.a.b.c)
  end

  test 'should replace a nested hash in an array' do
    assert_equal(1, @converted.a1.first.b1.c1)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
webhookr-0.3.0 test/unit/webhookr/ostruct_utils_test.rb