Sha256: 30a86953e58dec0709bb10f0bec063732e5609d3ee81e7afac12a4fc2ed3aabf

Contents?: true

Size: 821 Bytes

Versions: 131

Compression:

Stored size: 821 Bytes

Contents

require 'generator/exercise_case'

class AllergiesCase < Generator::ExerciseCase
  def workload
    assertions = list_expected? ? list_assertion : individual_assertions
    allergies_declaration = "allergies = Allergies.new(#{score})"
    indent_lines(assertions.unshift(allergies_declaration), 4)
  end

  def list_expected?
    property == 'list'
  end

  def list_assertion
    ["assert_equal %w(#{expected.join(' ')}), allergies.list"]
  end

  def individual_assertions
    expected.map do |assertion|
      substance = assertion['substance']
      result = assertion['result']
      "#{result ? assert(substance) : refute(substance)}"
    end
  end

  def refute(allergen)
    "refute allergies.allergic_to?('#{allergen}')"
  end

  def assert(allergen)
    "assert allergies.allergic_to?('#{allergen}')"
  end
end

Version data entries

131 entries across 131 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/ruby/exercises/allergies/.meta/generator/allergies_case.rb
trackler-2.2.1.179 tracks/ruby/exercises/allergies/.meta/generator/allergies_case.rb
trackler-2.2.1.178 tracks/ruby/exercises/allergies/.meta/generator/allergies_case.rb
trackler-2.2.1.177 tracks/ruby/exercises/allergies/.meta/generator/allergies_case.rb
trackler-2.2.1.176 tracks/ruby/exercises/allergies/.meta/generator/allergies_case.rb
trackler-2.2.1.175 tracks/ruby/exercises/allergies/.meta/generator/allergies_case.rb
trackler-2.2.1.174 tracks/ruby/exercises/allergies/.meta/generator/allergies_case.rb
trackler-2.2.1.173 tracks/ruby/exercises/allergies/.meta/generator/allergies_case.rb
trackler-2.2.1.172 tracks/ruby/exercises/allergies/.meta/generator/allergies_case.rb
trackler-2.2.1.171 tracks/ruby/exercises/allergies/.meta/generator/allergies_case.rb
trackler-2.2.1.170 tracks/ruby/exercises/allergies/.meta/generator/allergies_case.rb
trackler-2.2.1.169 tracks/ruby/exercises/allergies/.meta/generator/allergies_case.rb
trackler-2.2.1.167 tracks/ruby/exercises/allergies/.meta/generator/allergies_case.rb
trackler-2.2.1.166 tracks/ruby/exercises/allergies/.meta/generator/allergies_case.rb
trackler-2.2.1.165 tracks/ruby/exercises/allergies/.meta/generator/allergies_case.rb
trackler-2.2.1.164 tracks/ruby/exercises/allergies/.meta/generator/allergies_case.rb
trackler-2.2.1.163 tracks/ruby/exercises/allergies/.meta/generator/allergies_case.rb
trackler-2.2.1.162 tracks/ruby/exercises/allergies/.meta/generator/allergies_case.rb
trackler-2.2.1.161 tracks/ruby/exercises/allergies/.meta/generator/allergies_case.rb
trackler-2.2.1.160 tracks/ruby/exercises/allergies/.meta/generator/allergies_case.rb