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.1.38 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.2.1.37 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.2.1.36 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.2.1.35 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.2.1.34 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.2.1.33 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.2.1.32 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.2.1.31 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.2.1.30 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.2.1.29 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.2.1.28 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.2.1.27 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.2.1.26 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.2.1.25 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.2.1.24 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.2.1.23 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.2.1.22 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.2.1.21 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.2.1.20 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.2.1.19 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb