Class: MarkdownExec::TestHashDelegatorCollectRequiredCodeLines

Inherits:
Minitest::Test
  • Object
show all
Defined in:
lib/hash_delegator.rb

Instance Method Summary collapse

Instance Method Details

#setupObject



6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
# File 'lib/hash_delegator.rb', line 6520

def setup
  @hd = HashDelegator.new
  @mdoc = mock('YourMDocClass')
  @selected = FCB.new(
    body: ['key: value'],
    type: BlockType::VARS
  )
  HashDelegator.stubs(:read_required_blocks_from_temp_file).returns([])
  @hd.stubs(:string_send_color)
  @hd.stubs(:print)
end

#test_execute_block_type_port_code_lines_with_varsObject



6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
# File 'lib/hash_delegator.rb', line 6532

def test_execute_block_type_port_code_lines_with_vars
  YAML.stubs(:load).returns({ 'key' => 'value' })
  @mdoc.stubs(:collect_recursively_required_code)
       .returns({ context_code: [], transient_code: ['code line'] })
  result = @hd.execute_block_type_port_code_lines(
    mdoc: @mdoc, selected: @selected, block_source: {}
  )

  assert_equal ['key="value"'], result[:context_code]
  assert_equal ['code line'], result[:transient_code]
end

#test_transient_code_parameter_usageObject



6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
# File 'lib/hash_delegator.rb', line 6544

def test_transient_code_parameter_usage
  # Test that transient_code parameter is used correctly in execute_bash_script_lines
  transient_code = ["echo 'test'", "echo 'transient'"]
  export = OpenStruct.new(exportable: false, validate: //, transform: ->(x) { x })
  result = HashDelegator.execute_bash_script_lines(
    transient_code: transient_code,
    export: export,
    export_name: 'TEST',
    shell: '/bin/bash'
  )

  assert result.is_a?(CommandResult)
  assert_equal transient_code, result.script
end

#test_transient_code_vs_context_code_separationObject



6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
# File 'lib/hash_delegator.rb', line 6559

def test_transient_code_vs_context_code_separation
  # Test that transient_code is separate from context_code
  context_code = ['CONTEXT_VAR="context_value"']
  transient_code = ['TRANSIENT_VAR="transient_value"']

  # Simulate combining them
  all_code = HashDelegator.flatten_and_compact_arrays(
    context_code, transient_code
  )

  assert_equal 2, all_code.length
  assert_includes all_code, 'CONTEXT_VAR="context_value"'
  assert_includes all_code, 'TRANSIENT_VAR="transient_value"'
end