Sha256: 698f3d567509e70b813c9aa0dc8dd61d8cae81cb6d7a440adb4c32a6f59cc199

Contents?: true

Size: 988 Bytes

Versions: 2

Compression:

Stored size: 988 Bytes

Contents

class Mumukit::Assistant::Rule::TheseExpectationsFailed < Mumukit::Assistant::Rule::SubmissionPassedWithWarnings
  def initialize(message, expectations, strict: false)
    raise 'missing expectations' if expectations.blank?
    super(message)
    @expectations = expectations
    @strict = strict
  end

  def matches?(submission)
    (!@strict || super) && matches_failing_expectations?(submission)
  end

  def matches_failing_expectations?(submission)
    @expectations.all? do |it|
      includes_failing_expectation? it, submission
    end
  end

  def failed_expectations(submission)
    @failed_expectations ||= submission.expectation_results.select { |it| it.indifferent_get(:result).failed? }
  end

  def includes_failing_expectation?(humanized_expectation, submission)
    binding, inspection = humanized_expectation.split(' ')
    failed_expectations(submission).any? { |it| it.indifferent_get(:binding) == binding && it.indifferent_get(:inspection) == inspection }
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mumukit-assistant-0.4.0 lib/mumukit/assistant/rule/these_expectations_failed.rb
mumukit-assistant-0.3.0 lib/mumukit/assistant/rule/these_expectations_failed.rb