Sha256: 17bad0399749b96dc54357ed89687fd477f238833b50f696e28a6bfdd9eb6a2e

Contents?: true

Size: 748 Bytes

Versions: 14

Compression:

Stored size: 748 Bytes

Contents

class BowlingCase < OpenStruct
  def test_name
    "test_#{description.downcase.tr(' ', '_')}"
  end

  def skipped
    index.zero? ? '# skip' : 'skip'
  end

  def work_load
    indent_lines(assert)
  end

  private

  def roll
    "roll(#{rolls})"
  end

  def assert
    if assert_error?
      [
        'assert_raises StandardError do',
        "  #{roll}",
        '  @game.score',
        'end'
      ]
    else
      [roll, "assert_equal #{expected}, @game.score"]
    end
  end

  def assert_error?
    expected == -1
  end

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

BowlingCases = proc do |data|
  JSON.parse(data)['score']['cases'].map.with_index do |row, i|
    BowlingCase.new(row.merge('index' => i))
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
trackler-2.0.3.0 tracks/ruby/lib/bowling_cases.rb
trackler-2.0.2.0 tracks/ruby/lib/bowling_cases.rb
trackler-2.0.1.2 tracks/ruby/lib/bowling_cases.rb
trackler-2.0.1.1 tracks/ruby/lib/bowling_cases.rb
trackler-2.0.1.0 tracks/ruby/lib/bowling_cases.rb
trackler-2.0.0.10 tracks/ruby/lib/bowling_cases.rb
trackler-2.0.0.9 tracks/ruby/lib/bowling_cases.rb
trackler-2.0.0.8 tracks/ruby/lib/bowling_cases.rb
trackler-2.0.0.7 tracks/ruby/lib/bowling_cases.rb
trackler-2.0.0.6 tracks/ruby/lib/bowling_cases.rb
trackler-2.0.0.5 tracks/ruby/lib/bowling_cases.rb
trackler-2.0.0.4 tracks/ruby/lib/bowling_cases.rb
trackler-2.0.0.3 tracks/ruby/lib/bowling_cases.rb
trackler-2.0.0.2 tracks/ruby/lib/bowling_cases.rb