Sha256: a8d84ed8fab081f7b164fcc3c018ab72da20d44ef8c5e64b11398fc05a1507a7

Contents?: true

Size: 1.1 KB

Versions: 67

Compression:

Stored size: 1.1 KB

Contents

class ClockCase < OpenStruct
  def name
    'test_%s' % description
                .gsub(/[() -]/, '_')
                .gsub('=', 'is_equal_to')
                .chomp('_')
  end

  def test_body
    section == 'equal' ? compare_clocks : simple_test
  end

  def compare_clocks
    "clock1 = Clock.at(#{clock1['hour']}, #{clock1['minute']})
    clock2 = Clock.at(#{clock2['hour']}, #{clock2['minute']})
    #{assert_or_refute} clock1 == clock2"
  end

  def simple_test
    [
      "assert_equal #{expected.inspect}, ",
      "#{'(' if add_to_clock}Clock.at(#{hour}, ",
      "#{minute})#{add_to_clock}#{')' if add_to_clock}.to_s"
    ].join
  end

  def assert_or_refute
    expected ? 'assert' : 'refute'
  end

  def add_to_clock
    " + #{add}" if add
  end

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

ClockCases = proc do |data|
  i = 0
  json = JSON.parse(data)
  cases = []
  %w(create add equal).each do |section|
    json[section]['cases'].each do |row|
      row = row.merge(row.merge('index' => i, 'section' => section))
      cases << ClockCase.new(row)
      i += 1
    end
  end
  cases
end

Version data entries

67 entries across 67 versions & 1 rubygems

Version Path
trackler-2.0.6.11 tracks/ruby/lib/clock_cases.rb
trackler-2.0.6.10 tracks/ruby/lib/clock_cases.rb
trackler-2.0.6.9 tracks/ruby/lib/clock_cases.rb
trackler-2.0.6.8 tracks/ruby/lib/clock_cases.rb
trackler-2.0.6.7 tracks/ruby/lib/clock_cases.rb
trackler-2.0.6.6 tracks/ruby/lib/clock_cases.rb
trackler-2.0.6.5 tracks/ruby/lib/clock_cases.rb
trackler-2.0.6.4 tracks/ruby/lib/clock_cases.rb
trackler-2.0.6.3 tracks/ruby/lib/clock_cases.rb
trackler-2.0.6.2 tracks/ruby/lib/clock_cases.rb
trackler-2.0.6.1 tracks/ruby/lib/clock_cases.rb
trackler-2.0.6.0 tracks/ruby/lib/clock_cases.rb
trackler-2.0.5.18 tracks/ruby/lib/clock_cases.rb
trackler-2.0.5.17 tracks/ruby/lib/clock_cases.rb
trackler-2.0.5.16 tracks/ruby/lib/clock_cases.rb
trackler-2.0.5.15 tracks/ruby/lib/clock_cases.rb
trackler-2.0.5.14 tracks/ruby/lib/clock_cases.rb
trackler-2.0.5.13 tracks/ruby/lib/clock_cases.rb
trackler-2.0.5.12 tracks/ruby/lib/clock_cases.rb
trackler-2.0.5.11 tracks/ruby/lib/clock_cases.rb