class StonesSpec::Postcondition::ExpectedBoom

Attributes

error_type[R]
example[R]

Public Class Methods

new(example) click to toggle source
# File lib/postcondition/expected_boom.rb, line 8
def initialize(example)
  @example = example
  @error_type = known_error_types[example.error.to_sym]
end

Public Instance Methods

validate(initial_board_gbb, actual_final_board_gbb, result, status) click to toggle source
# File lib/postcondition/expected_boom.rb, line 13
def validate(initial_board_gbb, actual_final_board_gbb, result, status)
  if status == :failed || status == :unknown_error
    check_right_error_type initial_board_gbb, result, status
  else
    boards = [['Tablero inicial', initial_board_gbb], ['Tablero final', actual_final_board_gbb]]
    make_boards_output example.title, boards, :failed, failure_message
  end
end

Private Instance Methods

check_right_error_type(initial_board_gbb, result, status) click to toggle source
# File lib/postcondition/expected_boom.rb, line 24
def check_right_error_type(initial_board_gbb, result, status)
  if error_type_matches? result
    [example.title, :passed, make_error_output(result, status, initial_board_gbb)]
  else
    [example.title, :failed, "#{invalid_boom_type_message}\n#{make_error_output(result, status, initial_board_gbb)}"]
  end
end
error_type_matches?(result) click to toggle source
# File lib/postcondition/expected_boom.rb, line 32
def error_type_matches?(result)
   error_type[:matcher] =~ result
end
failure_message() click to toggle source
# File lib/postcondition/expected_boom.rb, line 46
def failure_message
  'Se esperaba que el programa hiciera BOOM pero se obtuvo un tablero final.'
end
invalid_boom_type_message() click to toggle source
# File lib/postcondition/expected_boom.rb, line 50
def invalid_boom_type_message
  "<p>Se esperaba que el programa hiciera BOOM por #{error_type[:friendly_message]}.</p>"
end
known_error_types() click to toggle source
# File lib/postcondition/expected_boom.rb, line 36
def known_error_types
  {
    out_of_board: { matcher: /La posición cae afuera del tablero/, friendly_message: 'caer fuera del tablero' },
    no_stones: { matcher: /No hay bolitas de ese color/, friendly_message: 'no haber bolitas' },
    unassigned_variable: { matcher: /podría no tener asignado ningún valor/, friendly_message: 'tener una variable sin asignar' },
    wrong_argument_type: { matcher: /El argumento de .+ debería ser/, friendly_message: 'tipo erróneo de un argumento' },
    wrong_arguments_quantity: { matcher: /Esperaba \d+ argumentos (.|\n)* Recibió \d+/, friendly_message: 'cantidad inválida de argumentos' }
  }
end