Class: MarkdownExec::TestHashDelegator
- Defined in:
- lib/hash_delegator.rb
Instance Method Summary collapse
- #setup ⇒ Object
-
#test_execute_block_type_link_with_state_with_empty_body ⇒ Object
Test case for empty body.
-
#test_execute_block_type_link_with_state_with_file_key ⇒ Object
Test case for non-empty body with ‘file’ key.
-
#test_execute_block_type_link_with_state_without_file_key ⇒ Object
Test case for non-empty body without ‘file’ key.
- #test_execute_required_lines_with_argument_args_value ⇒ Object
- #test_indent_all_lines_with_empty_indent ⇒ Object
- #test_indent_all_lines_with_indent ⇒ Object
- #test_indent_all_lines_without_indent ⇒ Object
- #test_safeval_rescue_from_error ⇒ Object
- #test_safeval_successful_evaluation ⇒ Object
- #test_set_fcb_title ⇒ Object
Instance Method Details
#setup ⇒ Object
6305 6306 6307 6308 |
# File 'lib/hash_delegator.rb', line 6305 def setup @hd = HashDelegator.new @mdoc = mock('MarkdownDocument') end |
#test_execute_block_type_link_with_state_with_empty_body ⇒ Object
Test case for empty body
6337 6338 6339 6340 |
# File 'lib/hash_delegator.rb', line 6337 def test_execute_block_type_link_with_state_with_empty_body assert_equal LoadFile::REUSE, @hd.execute_block_type_link_with_state.load_file end |
#test_execute_block_type_link_with_state_with_file_key ⇒ Object
Test case for non-empty body with ‘file’ key
6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 |
# File 'lib/hash_delegator.rb', line 6352 def test_execute_block_type_link_with_state_with_file_key body = ["file: sample_file\nblock: sample_block\nvars:\n KEY: VALUE"] expected_result = LoadFileLinkState.new( LoadFile::LOAD, LinkState.new(block_name: 'sample_block', document_filename: 'sample_file', inherited_dependencies: {}, context_code: ['# ', 'KEY="VALUE"']) ) assert_equal expected_result, @hd.execute_block_type_link_with_state( link_block_body: body, selected: FCB.new(block_name: 'sample_block', filename: 'sample_file') ) end |
#test_execute_block_type_link_with_state_without_file_key ⇒ Object
Test case for non-empty body without ‘file’ key
6343 6344 6345 6346 6347 6348 6349 |
# File 'lib/hash_delegator.rb', line 6343 def test_execute_block_type_link_with_state_without_file_key body = ["vars:\n KEY: VALUE"] assert_equal LoadFile::REUSE, @hd.execute_block_type_link_with_state( link_block_body: body ).load_file end |
#test_execute_required_lines_with_argument_args_value ⇒ Object
6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 |
# File 'lib/hash_delegator.rb', line 6310 def test_execute_required_lines_with_argument_args_value # calling execute required lines # calls command execute with argument args value pigeon = 'E' obj = { output_execution_label_format: '', output_execution_label_name_color: 'plain', output_execution_label_value_color: 'plain' } c = MarkdownExec::HashDelegator.new(obj) c.pass_args = pigeon # Expect that method opts_command_execute is # called with argument args having value pigeon c.expects(:command_execute).with( '', args: pigeon, erls: {}, shell: ShellType::BASH ) # Call method opts_execute_required_lines c.execute_required_lines(shell: ShellType::BASH) end |
#test_indent_all_lines_with_empty_indent ⇒ Object
6384 6385 6386 6387 6388 6389 |
# File 'lib/hash_delegator.rb', line 6384 def test_indent_all_lines_with_empty_indent body = "Line 1\nLine 2" indent = '' assert_equal body, HashDelegator.indent_all_lines(body, indent) end |
#test_indent_all_lines_with_indent ⇒ Object
6369 6370 6371 6372 6373 6374 6375 |
# File 'lib/hash_delegator.rb', line 6369 def test_indent_all_lines_with_indent body = "Line 1\nLine 2" indent = ' ' # Two spaces expected_result = " Line 1\n Line 2" assert_equal expected_result, HashDelegator.indent_all_lines(body, indent) end |
#test_indent_all_lines_without_indent ⇒ Object
6377 6378 6379 6380 6381 6382 |
# File 'lib/hash_delegator.rb', line 6377 def test_indent_all_lines_without_indent body = "Line 1\nLine 2" indent = nil assert_equal body, HashDelegator.indent_all_lines(body, indent) end |
#test_safeval_rescue_from_error ⇒ Object
6395 6396 6397 6398 6399 |
# File 'lib/hash_delegator.rb', line 6395 def test_safeval_rescue_from_error assert_raises(SystemExit) do HashDelegator.safeval('invalid_code_raises_exception') end end |
#test_safeval_successful_evaluation ⇒ Object
6391 6392 6393 |
# File 'lib/hash_delegator.rb', line 6391 def test_safeval_successful_evaluation assert_equal 4, HashDelegator.safeval('2 + 2') end |
#test_set_fcb_title ⇒ Object
6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 |
# File 'lib/hash_delegator.rb', line 6401 def test_set_fcb_title # sample input and output data for # testing default_block_title_from_body method input_output_data = [ { input: MarkdownExec::FCB.new(title: nil, body: ["puts 'Hello, world!'"]), output: "puts 'Hello, world!'" }, { input: MarkdownExec::FCB.new(title: '', body: ['def add(x, y)', ' x + y', 'end']), output: "def add(x, y)\n x + y\n end" }, { input: MarkdownExec::FCB.new(title: 'foo', body: %w[bar baz]), output: 'foo' # expect the title to remain unchanged } ] # iterate over the input and output data and # assert that the method sets the title as expected input_output_data.each do |data| input = data[:input] output = data[:output] title = HashDelegator.default_block_title_from_body(input) assert_equal output, title end end |