Sha256: 5e9714a076bb4c6424855aa76bdae884edb6e7738d4a08bb3c7f1e8b09d149f8

Contents?: true

Size: 1.48 KB

Versions: 3

Compression:

Stored size: 1.48 KB

Contents

require_relative "spec_helper"

describe DeepTree do
  
  before do
    @result_data = {
      'one_level'   => 'SUCCESS',
      'three_level' => {
        'level_two' => {
          'level_one' => 'HOORAY'
        }
      }
    }
  end
  
  describe :class do
    
    it "raises an exception for invalid inputs" do
      proc { DeepTree.new(Array.new) }.must_raise(DeepTree::InvalidTreeError)
    end
    
    it "gets a leaf node" do
      DeepTree.get_leaf(@result_data, 'three_level', 'level_two', 'level_one').must_equal 'HOORAY'
    end
    
  end
  
  describe :instance do
    
    before(:each) do
      @deep_tree = DeepTree.new(@result_data)
    end
  
    it "gets a single level's node" do
      @deep_tree.get_leaf('one_level').must_equal 'SUCCESS'
    end
  
    it "gets a deeply nested node" do
      @deep_tree.get_leaf('three_level', 'level_two', 'level_one').must_equal 'HOORAY'
    end
  
    it "responds with nil for a shallow missing node" do
      @deep_tree.get_leaf('missing').must_be_nil
    end
  
    it "responds with nil for a deep missing node" do
      @deep_tree.get_leaf('three_level', 'level_two', 'missing').must_be_nil
    end
  
    it "responds with nil when it encounters a non-hash in the path" do
      @deep_tree.get_leaf('three_level', 'level_two', 'level_one', 'level_zero').must_be_nil
    end
  
    it "evaluates a block instead of returning nil if a block is given" do
      @deep_tree.get_leaf('nope') { 'potato' }.must_equal 'potato'
    end
    
  end
  
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
deep_tree-0.0.3 spec/deep_tree_spec.rb
deep_tree-0.0.2 spec/deep_tree_spec.rb
deep_tree-0.0.1 spec/deep_tree_spec.rb