Class: MarkdownExec::TestUxBlockEvalForExport
- Defined in:
- lib/hash_delegator.rb
Overview
Comprehensive tests for ux_block_eval_for_export function
Instance Method Summary collapse
- #setup ⇒ Object
- #teardown ⇒ Object
- #test_boolean_false_input ⇒ Object
-
#test_boolean_true_input ⇒ Object
Test boolean inputs.
-
#test_empty_hash_input ⇒ Object
Edge case: empty hash.
-
#test_empty_string_input ⇒ Object
Edge case: empty string.
-
#test_environment_variable_setting ⇒ Object
Test environment variable setting.
-
#test_exit_status_required_empty_silent ⇒ Object
Test EXIT_STATUS_REQUIRED_EMPTY handling with silent flag.
-
#test_exit_status_required_empty_with_warning ⇒ Object
Test EXIT_STATUS_REQUIRED_EMPTY handling.
-
#test_float_input ⇒ Object
Test float input.
-
#test_hash_input_first_only ⇒ Object
Test hash input with first_only flag.
-
#test_hash_input_non_exportable_variables ⇒ Object
Test hash with non-exportable variables.
-
#test_hash_input_success ⇒ Object
Test hash input - typical case.
-
#test_hash_with_nil_values ⇒ Object
Edge case: hash with nil values.
-
#test_integer_input ⇒ Object
Test integer input.
-
#test_join_array_of_arrays_called ⇒ Object
Test join_array_of_arrays is called correctly.
-
#test_nil_data_input ⇒ Object
Edge case: nil data (uses string.nil? check).
-
#test_standard_error_rescue ⇒ Object
Test error handling - StandardError rescue.
-
#test_string_input_success ⇒ Object
Test string input - typical case.
-
#test_string_input_with_printf_expand ⇒ Object
Test string input with printf_expand.
-
#test_string_parameter_override ⇒ Object
Test string parameter override.
-
#test_unsupported_input_type_array ⇒ Object
Edge case: unsupported input type (Array).
-
#test_unsupported_input_type_object ⇒ Object
Edge case: unsupported input type (custom object).
Instance Method Details
#setup ⇒ Object
7211 7212 7213 7214 7215 7216 7217 7218 7219 7220 7221 |
# File 'lib/hash_delegator.rb', line 7211 def setup @hd = HashDelegator.new @bash_script_lines = ['#!/bin/bash', 'set -e'] @export = OpenStruct.new(name: 'TEST_VAR', required: ['TEST_VAR']) @mock_result = OpenStruct.new( exit_status: 0, stdout: 'test_output', stderr: '', warning: nil ) end |
#teardown ⇒ Object
7223 7224 7225 7226 7227 7228 |
# File 'lib/hash_delegator.rb', line 7223 def teardown # Clean up environment variables set during tests ENV.delete('TEST_VAR') ENV.delete('VAR1') ENV.delete('VAR2') end |
#test_boolean_false_input ⇒ Object
7306 7307 7308 7309 7310 7311 7312 7313 7314 7315 7316 7317 7318 7319 7320 7321 |
# File 'lib/hash_delegator.rb', line 7306 def test_boolean_false_input @hd.stubs(:output_from_adhoc_bash_script_file).returns([@mock_result, true]) @hd.stubs(:variable_is_exportable).returns(true) result = @hd.ux_block_eval_for_export( @bash_script_lines, @export, data: false, force: false, silent: false ) command_result, exportable, = result assert_equal @mock_result, command_result assert_equal true, exportable end |
#test_boolean_true_input ⇒ Object
Test boolean inputs
7289 7290 7291 7292 7293 7294 7295 7296 7297 7298 7299 7300 7301 7302 7303 7304 |
# File 'lib/hash_delegator.rb', line 7289 def test_boolean_true_input @hd.stubs(:output_from_adhoc_bash_script_file).returns([@mock_result, true]) @hd.stubs(:variable_is_exportable).returns(true) result = @hd.ux_block_eval_for_export( @bash_script_lines, @export, data: true, force: false, silent: false ) command_result, exportable, = result assert_equal @mock_result, command_result assert_equal true, exportable end |
#test_empty_hash_input ⇒ Object
Edge case: empty hash
7513 7514 7515 7516 7517 7518 7519 7520 7521 7522 7523 7524 7525 |
# File 'lib/hash_delegator.rb', line 7513 def test_empty_hash_input result = @hd.ux_block_eval_for_export( @bash_script_lines, @export, data: {}, force: false, silent: false ) command_result, exportable, new_lines = result assert_nil command_result # No iterations, so command_result remains nil assert_equal true, exportable # Initial value assert_equal 0, new_lines.length end |
#test_empty_string_input ⇒ Object
Edge case: empty string
7477 7478 7479 7480 7481 7482 7483 7484 7485 7486 7487 7488 7489 7490 7491 7492 |
# File 'lib/hash_delegator.rb', line 7477 def test_empty_string_input @hd.stubs(:output_from_adhoc_bash_script_file).returns([@mock_result, true]) @hd.stubs(:variable_is_exportable).returns(true) result = @hd.ux_block_eval_for_export( @bash_script_lines, @export, data: '', force: false, silent: false ) command_result, exportable, = result assert_equal @mock_result, command_result assert_equal true, exportable end |
#test_environment_variable_setting ⇒ Object
Test environment variable setting
7594 7595 7596 7597 7598 7599 7600 7601 7602 7603 7604 7605 7606 7607 7608 |
# File 'lib/hash_delegator.rb', line 7594 def test_environment_variable_setting @hd.stubs(:output_from_adhoc_bash_script_file).returns([@mock_result, true]) @hd.stubs(:variable_is_exportable).returns(true) # Mock EnvInterface.set to verify it's called EnvInterface.expects(:set).with('TEST_VAR', 'test_output') @hd.ux_block_eval_for_export( @bash_script_lines, @export, data: 'echo "test"', force: false, silent: false ) end |
#test_exit_status_required_empty_silent ⇒ Object
Test EXIT_STATUS_REQUIRED_EMPTY handling with silent flag
7433 7434 7435 7436 7437 7438 7439 7440 7441 7442 7443 7444 7445 7446 7447 7448 7449 7450 7451 7452 7453 7454 |
# File 'lib/hash_delegator.rb', line 7433 def test_exit_status_required_empty_silent failed_result = OpenStruct.new( exit_status: 248, stdout: '', stderr: 'Required variable empty', warning: nil ) @hd.stubs(:output_from_adhoc_bash_script_file).returns([failed_result, false]) result = @hd.ux_block_eval_for_export( @bash_script_lines, @export, data: 'echo ""', force: false, silent: true ) command_result, exportable, = result assert_equal failed_result, command_result assert_equal false, exportable assert_nil command_result.warning # No warning when silent end |
#test_exit_status_required_empty_with_warning ⇒ Object
Test EXIT_STATUS_REQUIRED_EMPTY handling
7407 7408 7409 7410 7411 7412 7413 7414 7415 7416 7417 7418 7419 7420 7421 7422 7423 7424 7425 7426 7427 7428 7429 7430 |
# File 'lib/hash_delegator.rb', line 7407 def test_exit_status_required_empty_with_warning failed_result = OpenStruct.new( exit_status: 248, # EXIT_STATUS_REQUIRED_EMPTY stdout: '', stderr: 'Required variable empty', warning: nil ) @hd.stubs(:output_from_adhoc_bash_script_file).returns([failed_result, false]) @hd.stubs(:warning_required_empty).returns('Warning: required empty') result = @hd.ux_block_eval_for_export( @bash_script_lines, @export, data: 'echo ""', force: false, silent: false ) command_result, exportable, new_lines = result assert_equal failed_result, command_result assert_equal false, exportable assert_equal 0, new_lines.length assert_equal 'Warning: required empty', command_result.warning end |
#test_float_input ⇒ Object
Test float input
7324 7325 7326 7327 7328 7329 7330 7331 7332 7333 7334 7335 7336 7337 7338 7339 |
# File 'lib/hash_delegator.rb', line 7324 def test_float_input @hd.stubs(:output_from_adhoc_bash_script_file).returns([@mock_result, true]) @hd.stubs(:variable_is_exportable).returns(true) result = @hd.ux_block_eval_for_export( @bash_script_lines, @export, data: 3.14, force: false, silent: false ) command_result, exportable, = result assert_equal @mock_result, command_result assert_equal true, exportable end |
#test_hash_input_first_only ⇒ Object
Test hash input with first_only flag
7365 7366 7367 7368 7369 7370 7371 7372 7373 7374 7375 7376 7377 7378 7379 7380 7381 7382 7383 7384 |
# File 'lib/hash_delegator.rb', line 7365 def test_hash_input_first_only hash_data = { 'VAR1' => 'value1', 'VAR2' => 'value2' } @hd.stubs(:output_from_adhoc_bash_script_file).returns([@mock_result, true]) @hd.stubs(:variable_is_exportable).returns(true) @hd.stubs(:code_line_to_assign_a_variable).returns('VAR1=value1') result = @hd.ux_block_eval_for_export( @bash_script_lines, @export, data: hash_data, first_only: true, force: false, silent: false ) command_result, _, new_lines = result assert_equal @mock_result, command_result assert_equal 1, new_lines.length assert_equal 'VAR1', new_lines.first[:name] end |
#test_hash_input_non_exportable_variables ⇒ Object
Test hash with non-exportable variables
7387 7388 7389 7390 7391 7392 7393 7394 7395 7396 7397 7398 7399 7400 7401 7402 7403 7404 |
# File 'lib/hash_delegator.rb', line 7387 def test_hash_input_non_exportable_variables hash_data = { 'LOCAL_VAR' => 'value1' } @hd.stubs(:output_from_adhoc_bash_script_file).returns([@mock_result, true]) @hd.stubs(:variable_is_exportable).returns(false) @hd.stubs(:code_line_to_assign_a_variable).returns('LOCAL_VAR=value1') result = @hd.ux_block_eval_for_export( @bash_script_lines, @export, data: hash_data, force: false, silent: false ) command_result, _, new_lines = result assert_equal @mock_result, command_result assert_equal 0, new_lines.length # No exportable variables end |
#test_hash_input_success ⇒ Object
Test hash input - typical case
7342 7343 7344 7345 7346 7347 7348 7349 7350 7351 7352 7353 7354 7355 7356 7357 7358 7359 7360 7361 7362 |
# File 'lib/hash_delegator.rb', line 7342 def test_hash_input_success hash_data = { 'VAR1' => 'value1', 'VAR2' => 'value2' } @hd.stubs(:output_from_adhoc_bash_script_file).returns([@mock_result, true]) @hd.stubs(:variable_is_exportable).returns(true) @hd.stubs(:code_line_to_assign_a_variable).returns('VAR1=value1') result = @hd.ux_block_eval_for_export( @bash_script_lines, @export, data: hash_data, force: false, silent: false ) command_result, exportable, new_lines = result assert_equal @mock_result, command_result assert_equal true, exportable assert_equal 2, new_lines.length assert_equal 'VAR1', new_lines.first[:name] assert_equal 'VAR2', new_lines.last[:name] end |
#test_hash_with_nil_values ⇒ Object
Edge case: hash with nil values
7528 7529 7530 7531 7532 7533 7534 7535 7536 7537 7538 7539 7540 7541 7542 7543 7544 7545 7546 |
# File 'lib/hash_delegator.rb', line 7528 def test_hash_with_nil_values hash_data = { 'VAR1' => nil, 'VAR2' => 'value2' } @hd.stubs(:output_from_adhoc_bash_script_file).returns([@mock_result, true]) @hd.stubs(:variable_is_exportable).returns(true) @hd.stubs(:code_line_to_assign_a_variable).returns('VAR1=') result = @hd.ux_block_eval_for_export( @bash_script_lines, @export, data: hash_data, force: false, silent: false ) command_result, exportable, new_lines = result assert_equal @mock_result, command_result assert_equal true, exportable assert_equal 2, new_lines.length end |
#test_integer_input ⇒ Object
Test integer input
7270 7271 7272 7273 7274 7275 7276 7277 7278 7279 7280 7281 7282 7283 7284 7285 7286 |
# File 'lib/hash_delegator.rb', line 7270 def test_integer_input @hd.stubs(:output_from_adhoc_bash_script_file).returns([@mock_result, true]) @hd.stubs(:variable_is_exportable).returns(true) result = @hd.ux_block_eval_for_export( @bash_script_lines, @export, data: 42, force: true, silent: false ) command_result, exportable, new_lines = result assert_equal @mock_result, command_result assert_equal true, exportable assert_equal 1, new_lines.length end |
#test_join_array_of_arrays_called ⇒ Object
Test join_array_of_arrays is called correctly
7611 7612 7613 7614 7615 7616 7617 7618 7619 7620 7621 7622 7623 7624 7625 7626 7627 7628 7629 |
# File 'lib/hash_delegator.rb', line 7611 def test_join_array_of_arrays_called @hd.stubs(:output_from_adhoc_bash_script_file).returns([@mock_result, true]) @hd.stubs(:variable_is_exportable).returns(true) # Mock join_array_of_arrays to verify it's called with correct parameters @hd.expects(:join_array_of_arrays).with( @bash_script_lines, ['test_data'] ).returns(['combined_script_lines']) @hd.ux_block_eval_for_export( @bash_script_lines, @export, data: 'test_data', force: false, printf_expand: false, silent: false ) end |
#test_nil_data_input ⇒ Object
Edge case: nil data (uses string.nil? check)
7495 7496 7497 7498 7499 7500 7501 7502 7503 7504 7505 7506 7507 7508 7509 7510 |
# File 'lib/hash_delegator.rb', line 7495 def test_nil_data_input @hd.stubs(:output_from_adhoc_bash_script_file).returns([@mock_result, true]) @hd.stubs(:variable_is_exportable).returns(true) result = @hd.ux_block_eval_for_export( @bash_script_lines, @export, data: 'd1', force: false, silent: false ) command_result, exportable, = result assert_equal @mock_result, command_result assert_equal true, exportable end |
#test_standard_error_rescue ⇒ Object
Test error handling - StandardError rescue
7580 7581 7582 7583 7584 7585 7586 7587 7588 7589 7590 7591 |
# File 'lib/hash_delegator.rb', line 7580 def test_standard_error_rescue # Should not raise, but return nil due to rescue block result = @hd.ux_block_eval_for_export( @bash_script_lines, @export, data: 'test_data', force: false, silent: false ) command_result, = result assert_equal 127, command_result.exit_status end |
#test_string_input_success ⇒ Object
Test string input - typical case
7231 7232 7233 7234 7235 7236 7237 7238 7239 7240 7241 7242 7243 7244 7245 7246 7247 7248 7249 |
# File 'lib/hash_delegator.rb', line 7231 def test_string_input_success @hd.stubs(:output_from_adhoc_bash_script_file).returns([@mock_result, true]) @hd.stubs(:variable_is_exportable).returns(true) result = @hd.ux_block_eval_for_export( @bash_script_lines, @export, data: 'echo "hello"', force: false, silent: false ) command_result, exportable, new_lines = result assert_equal @mock_result, command_result assert_equal true, exportable assert_equal 1, new_lines.length assert_equal 'TEST_VAR', new_lines.first[:name] assert_equal 'test_output', new_lines.first[:text] end |
#test_string_input_with_printf_expand ⇒ Object
Test string input with printf_expand
7252 7253 7254 7255 7256 7257 7258 7259 7260 7261 7262 7263 7264 7265 7266 7267 |
# File 'lib/hash_delegator.rb', line 7252 def @hd.stubs(:output_from_adhoc_bash_script_file).returns([@mock_result, true]) @hd.stubs(:variable_is_exportable).returns(true) @hd.ux_block_eval_for_export( @bash_script_lines, @export, data: 'test_value', force: false, printf_expand: true, silent: false ) # Verify that join_array_of_arrays was called with printf wrapped expression # This tests that the expander lambda is applied correctly end |
#test_string_parameter_override ⇒ Object
Test string parameter override
7457 7458 7459 7460 7461 7462 7463 7464 7465 7466 7467 7468 7469 7470 7471 7472 7473 7474 |
# File 'lib/hash_delegator.rb', line 7457 def test_string_parameter_override @hd.stubs(:output_from_adhoc_bash_script_file).returns([@mock_result, true]) @hd.stubs(:variable_is_exportable).returns(true) result = @hd.ux_block_eval_for_export( @bash_script_lines, @export, data: 'original_data', string: 'override_string', force: false, silent: false ) # The function should use string parameter instead of data command_result, exportable, = result assert_equal @mock_result, command_result assert_equal true, exportable end |
#test_unsupported_input_type_array ⇒ Object
Edge case: unsupported input type (Array)
7549 7550 7551 7552 7553 7554 7555 7556 7557 7558 7559 7560 7561 |
# File 'lib/hash_delegator.rb', line 7549 def test_unsupported_input_type_array result = @hd.ux_block_eval_for_export( @bash_script_lines, @export, data: %w[item1 item2], force: false, silent: false ) command_result, exportable, new_lines = result assert_nil command_result # No processing for unsupported types assert_equal true, exportable # Initial value assert_equal 0, new_lines.length end |
#test_unsupported_input_type_object ⇒ Object
Edge case: unsupported input type (custom object)
7564 7565 7566 7567 7568 7569 7570 7571 7572 7573 7574 7575 7576 7577 |
# File 'lib/hash_delegator.rb', line 7564 def test_unsupported_input_type_object custom_object = Object.new result = @hd.ux_block_eval_for_export( @bash_script_lines, @export, data: custom_object, force: false, silent: false ) command_result, exportable, new_lines = result assert_nil command_result # No processing for unsupported types assert_equal true, exportable # Initial value assert_equal 0, new_lines.length end |