Sha256: ce3309cd5a7d34a005eccc38802d8f6db56ef59b8d6c58b1323a532059a712f5

Contents?: true

Size: 818 Bytes

Versions: 233

Compression:

Stored size: 818 Bytes

Contents

require 'generator/exercise_case'

class BowlingCase < Generator::ExerciseCase

  def workload
    indent_lines(assert)
  end

  private

  def roll_previous
    "record(#{previous_rolls})"
  end

  def assert
    if assert_error?
      property == 'score' ? score_raises : roll_raises
    else
      [roll_previous, "assert_equal #{expected}, @game.score"]
    end
  end

  def roll_raises
    [
      roll_previous,
      'assert_raises Game::BowlingError do',
      '  @game.roll(' + roll.to_s + ')',
      'end'
    ]
  end

  def score_raises
    [
      roll_previous,
      'assert_raises Game::BowlingError do',
      '  @game.score',
      'end'
    ]
  end

  def assert_error?
    expected.respond_to?(:key?) && expected.key?('error')
  end

  def indent_lines(code)
    code.join("\n" + ' ' * 4)
  end
end

Version data entries

233 entries across 233 versions & 1 rubygems

Version Path
trackler-2.1.0.20 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.1.0.19 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.1.0.18 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.1.0.17 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.1.0.16 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.1.0.15 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.1.0.14 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.1.0.13 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.1.0.12 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.1.0.11 tracks/ruby/exercises/bowling/.meta/generator/bowling_cases.rb
trackler-2.1.0.10 tracks/ruby/exercises/bowling/.meta/generator/bowling_cases.rb
trackler-2.1.0.9 tracks/ruby/exercises/bowling/.meta/generator/bowling_cases.rb
trackler-2.1.0.8 tracks/ruby/exercises/bowling/.meta/generator/bowling_cases.rb