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.2.0.5 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.2.0.4 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.2.0.3 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.2.0.2 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.2.0.1 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.2.0.0 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.1.0.55 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.1.0.54 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.1.0.53 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.1.0.52 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.1.0.51 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.1.0.50 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.1.0.49 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.1.0.48 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.1.0.47 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.1.0.46 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.1.0.45 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.1.0.44 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.1.0.43 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.1.0.42 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb