lib/daigaku/test_result.rb in daigaku-0.3.0 vs lib/daigaku/test_result.rb in daigaku-0.4.0

- old
+ new

@@ -1,10 +1,9 @@ -module Daigaku +require 'json' +module Daigaku class TestResult - require 'json' - attr_reader :examples, :example_count, :failure_count def initialize(result_json) @result = begin JSON.parse(result_json, symbolize_names: true) @@ -15,13 +14,13 @@ @example_count = @result[:summary][:example_count] @failure_count = @result[:summary][:failure_count] @examples = @result[:examples].map do |example| description = example[:full_description] - status = example[:status] - exception = example[:exception] - message = exception ? exception[:message] : nil + status = example[:status] + exception = example[:exception] + message = exception ? exception[:message] : nil TestExample.new(description: description, status: status, message: message) end end @@ -45,42 +44,40 @@ private def build_failed_summary message = examples.map do |example| - "#{example.description}\n#{example.status}: #{example.message}" + "#{example.description}\n#{example.status}: #{example.message}".strip end - summary = message.map(&:strip).join("\n" * 3) + message.join("\n" * 3) end def syntax_error_json { summary: {}, examples: [ { status: 'failed', - exception: { message: ":( You got an error in your code!" } + exception: { message: ':( You got an error in your code!' } } ] } end end class TestExample - attr_reader :description, :status, :message - EXAMPLE_PASSED_MESSAGE = "Your code passed this requirement." + EXAMPLE_PASSED_MESSAGE = 'Your code passed this requirement.'.freeze - def initialize(args = {}) - @description = args[:description] - @status = args[:status] - @message = args[:message] || EXAMPLE_PASSED_MESSAGE + def initialize(description:, status:, message: nil) + @description = description + @status = status + @message = message || EXAMPLE_PASSED_MESSAGE end def passed? @status == 'passed' end end - end