Class: TestShellExpressionEvaluator
- Defined in:
- lib/evaluate_shell_expressions.rb
Instance Method Summary collapse
- #setup ⇒ Object
- #test_empty_expressions_list ⇒ Object
- #test_initial_code_execution ⇒ Object
- #test_invalid_expression ⇒ Object
- #test_large_number_of_expressions ⇒ Object
- #test_multiple_expressions ⇒ Object
- #test_single_expression ⇒ Object
Instance Method Details
#setup ⇒ Object
55 56 57 58 59 60 |
# File 'lib/evaluate_shell_expressions.rb', line 55 def setup @initial_code = <<~BASH #!/bin/sh echo "Initial setup..." BASH end |
#test_empty_expressions_list ⇒ Object
82 83 84 85 86 87 |
# File 'lib/evaluate_shell_expressions.rb', line 82 def test_empty_expressions_list expressions = {} result = evaluate_shell_expressions(@initial_code, expressions) assert_nil result end |
#test_initial_code_execution ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/evaluate_shell_expressions.rb', line 99 def test_initial_code_execution initial_code = <<~BASH #!/bin/sh echo "Custom setup message" BASH expressions = { "test" => "echo Test after initial setup" } result = evaluate_shell_expressions(initial_code, expressions) assert_equal "Test after initial setup", result["%<test>"] end |
#test_invalid_expression ⇒ Object
89 90 91 92 93 94 95 96 97 |
# File 'lib/evaluate_shell_expressions.rb', line 89 def test_invalid_expression expressions = { "invalid" => "invalid_command" } error = assert_raises(RuntimeError) do evaluate_shell_expressions(@initial_code, expressions) end assert_match /Shell script execution failed/, error. end |
#test_large_number_of_expressions ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/evaluate_shell_expressions.rb', line 111 def test_large_number_of_expressions expressions = (1..100).map { |i| ["expr_#{i}", "echo Expression #{i}"] }.to_h result = evaluate_shell_expressions(@initial_code, expressions) expressions.each_with_index do |(key, _expression), index| assert_equal "Expression #{index + 1}", result["%<#{key}>"] end end |
#test_multiple_expressions ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/evaluate_shell_expressions.rb', line 69 def test_multiple_expressions expressions = { "greeting" => "echo 'Hello, World!'", "date" => "date +%Y-%m-%d", "kernel" => "uname -r" } result = evaluate_shell_expressions(@initial_code, expressions) assert_equal "Hello, World!", result["%<greeting>"] assert_match /\d{4}-\d{2}-\d{2}/, result["%<date>"] assert_match /\d+\.\d+\.\d+/, result["%<kernel>"] end |
#test_single_expression ⇒ Object
62 63 64 65 66 67 |
# File 'lib/evaluate_shell_expressions.rb', line 62 def test_single_expression expressions = { "greeting" => "echo 'Hello, World!'" } result = evaluate_shell_expressions(@initial_code, expressions) assert_equal "Hello, World!", result["%<greeting>"] end |