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.180 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.2.1.179 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.2.1.178 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.2.1.177 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.2.1.176 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.2.1.175 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.2.1.174 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.2.1.173 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.2.1.172 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.2.1.171 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.2.1.170 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.2.1.169 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.2.1.167 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.2.1.166 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.2.1.165 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.2.1.164 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.2.1.163 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.2.1.162 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.2.1.161 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb
trackler-2.2.1.160 tracks/ruby/exercises/bowling/.meta/generator/bowling_case.rb