Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Enough Coverage To Beat The Band

Enough Coverage To Beat The Band

The lights cut out. The crowd roars. It’s time. The band takes the stage. They’ve practiced the songs, particularly the covers. They’ve sound checked the coverage of the speakers. They know the lighting rig has the proper colored gels covering the lamps. They’re nervous, but they’ve got it all covered.

Similarly, code coverage can give you confidence before your app performs on production and also tell you how live code is used (or not used). We’ll cover how to leverage ruby’s different coverage measurement techniques in concert to assist your crew and delight your audience.

Kevin Murphy

October 25, 2020
Tweet

More Decks by Kevin Murphy

Other Decks in Programming

Transcript

  1. Kevin Murphy
    Enough Coverage
    To Beat The Band

    View Slide

  2. Nine Inch Nails
    CC BY-NC-SA 2.0

    View Slide

  3. View Slide

  4. Nine Inch Nails
    CC BY-NC-SA 2.0

    View Slide

  5. @kevin_j_m
    concert = Concert.new("RubyConf 2020")

    View Slide

  6. Coverage

    View Slide

  7. @kevin_j_m
    Kevin Murphy

    View Slide

  8. Test Coverage

    View Slide

  9. @kevin_j_m
    setlist.add_song(TheLineBeginsToBlur.new)

    View Slide

  10. @kevin_j_m
    setlist.add_song(TheLineBeginsToBlur.new)
    setlist.add_song(OneShotWayToGetThere.new)

    View Slide

  11. @kevin_j_m
    setlist.add_song(TheLineBeginsToBlur.new)
    setlist.add_song(OneShotWayToGetThere.new)
    setlist.add_song(VariousMethodsOfEscape.new)

    View Slide

  12. @kevin_j_m
    setlist.add_song(TheLineBeginsToBlur.new)
    setlist.add_song(OneShotWayToGetThere.new)
    setlist.add_song(VariousMethodsOfEscape.new)
    setlist.add_song(BranchesBones.new)

    View Slide

  13. @kevin_j_m
    setlist.add_song(TheLineBeginsToBlur.new)
    setlist.add_song(OneShotWayToGetThere.new)
    setlist.add_song(VariousMethodsOfEscape.new)
    setlist.add_song(BranchesBones.new)
    concert.setlist = setlist

    View Slide

  14. @kevin_j_m
    concert.perform

    View Slide

  15. @kevin_j_m
    setlist.songs
    [
    TheLineBeginsToBlur.new,
    OneShotWayToGetThere.new,
    VariousMethodsOfEscape.new,
    BranchesBones.new,
    ]

    View Slide

  16. The Line Begins To Blur
    Nine Inch Nails
    CC BY-NC-SA 2.0

    View Slide

  17. @kevin_j_m
    The Line Begins To Blur
    class String
    def pluck(fret:)
    end
    Nine Inch Nails CC BY-NC-SA 2.0

    View Slide

  18. @kevin_j_m
    The Line Begins To Blur
    class String
    def pluck(fret:)
    if exhausted?
    break_string
    end
    end
    Nine Inch Nails CC BY-NC-SA 2.0

    View Slide

  19. @kevin_j_m
    The Line Begins To Blur
    class String
    def pluck(fret:)
    if exhausted?
    break_string
    else
    @tension -= 1
    play_note(fret)
    end
    end
    Nine Inch Nails CC BY-NC-SA 2.0

    View Slide

  20. @kevin_j_m
    The Line Begins To Blur
    class String
    def exhausted?
    @tension.negative?
    end
    end
    Nine Inch Nails CC BY-NC-SA 2.0

    View Slide

  21. @kevin_j_m
    The Line Begins To Blur
    class String
    def exhausted?
    @tension.negative? || rand(1..1000) == 3
    end
    end
    Nine Inch Nails CC BY-NC-SA 2.0

    View Slide

  22. @kevin_j_m
    The Line Begins To Blur
    class String
    def break_string
    end
    end
    Nine Inch Nails CC BY-NC-SA 2.0

    View Slide

  23. @kevin_j_m
    The Line Begins To Blur
    class String
    def break_string
    @broken = true
    end
    end
    Nine Inch Nails CC BY-NC-SA 2.0

    View Slide

  24. @kevin_j_m
    The Line Begins To Blur
    class String
    def break_string
    @broken = true
    BrokenStringSound.new
    end
    end
    Nine Inch Nails CC BY-NC-SA 2.0

    View Slide

  25. @kevin_j_m
    The Line Begins To Blur
    # lib/tour_leg_1.rb
    10.times do
    end

    View Slide

  26. @kevin_j_m
    The Line Begins To Blur
    # lib/tour_leg_1.rb
    10.times do
    concert.perform
    end

    View Slide

  27. @kevin_j_m
    The Line Begins To Blur
    require "coverage"

    View Slide

  28. @kevin_j_m
    The Line Begins To Blur
    require "coverage"
    Coverage.start(lines: true)

    View Slide

  29. @kevin_j_m
    The Line Begins To Blur
    require "coverage"
    Coverage.start(lines: true)
    load "lib/tour_leg_1.rb"

    View Slide

  30. @kevin_j_m
    The Line Begins To Blur
    require "coverage"
    Coverage.start(lines: true)
    load "lib/tour_leg_1.rb"
    result = Coverage.result

    View Slide

  31. @kevin_j_m
    The Line Begins To Blur
    {
    "lib/tour_leg_1.rb"=> {:lines => […]},

    "…guitar/string.rb" => {:lines => [1, 1, 1, 1, 1, 1, nil,…]},

    }

    View Slide

  32. @kevin_j_m
    The Line Begins To Blur
    {
    "…guitar/string.rb" => {:lines => [1, 1, 1, 1, 1, 1, nil,…]},
    }

    View Slide

  33. @kevin_j_m
    The Line Begins To Blur
    {
    "…guitar/string.rb" => {:lines => [1, 1, 1, 1, 1, 1, nil,…]},
    }
    File

    View Slide

  34. @kevin_j_m
    The Line Begins To Blur
    {
    "…guitar/string.rb" => {:lines => [1, 1, 1, 1, 1, 1, nil,…]},
    }
    File
    Mode

    View Slide

  35. @kevin_j_m
    The Line Begins To Blur
    {
    "…guitar/string.rb" => {:lines => [1, 1, 1, 1, 1, 1, nil,…]},
    }
    File
    Mode
    Line 1 Count

    View Slide

  36. @kevin_j_m
    The Line Begins To Blur
    {
    "…guitar/string.rb" => {:lines => [1, 1, 1, 1, 1, 1, nil,…]},
    }
    File
    Mode
    Line 1 Count
    Irrelevant Line 7

    View Slide

  37. @kevin_j_m
    The Line Begins To Blur
    class String
    attr_reader :tension
    attr_reader :tuning_note
    def initialize(number:, tuning_note:)
    end
    4
    5
    6
    7
    8
    Nine Inch Nails CC BY-NC-SA 2.0

    View Slide

  38. @kevin_j_m
    The Line Begins To Blur
    string_lines = result["…guitar/string.rb"][:lines]

    View Slide

  39. @kevin_j_m
    The Line Begins To Blur
    class String
    def break_string
    @broken = true
    BrokenStringSound.new
    end
    end
    Nine Inch Nails CC BY-NC-SA 2.0
    53
    54
    55
    56

    View Slide

  40. @kevin_j_m
    The Line Begins To Blur
    class String
    def break_string
    @broken = true
    BrokenStringSound.new
    end
    end
    Nine Inch Nails CC BY-NC-SA 2.0
    53
    54
    55
    56

    View Slide

  41. @kevin_j_m
    The Line Begins To Blur
    string_lines = result["…guitar/string.rb"][:lines]

    View Slide

  42. @kevin_j_m
    The Line Begins To Blur
    string_lines = result["…guitar/string.rb"][:lines]
    "Number of broken strings: #{string_lines[53]}"

    View Slide

  43. @kevin_j_m
    The Line Begins To Blur
    string_lines = result["…guitar/string.rb"][:lines]
    "Number of broken strings: #{string_lines[53]}"
    => Number of broken strings: 16

    View Slide

  44. Nine Inch Nails
    CC BY-NC-SA 2.0

    View Slide

  45. @kevin_j_m
    setlist.songs
    [
    TheLineBeginsToBlur.new,
    OneShotWayToGetThere.new,
    VariousMethodsOfEscape.new,
    BranchesBones.new,
    ]

    View Slide

  46. One(Shot) Way To Get There
    Nine Inch Nails
    CC BY-NC-SA 2.0

    View Slide

  47. One(Shot) Way To Get There
    Nine Inch Nails
    CC BY-NC-SA 2.0

    View Slide

  48. One(Shot) Way To Get There
    Nine Inch Nails
    CC BY-NC-SA 2.0

    View Slide

  49. One(Shot) Way To Get There
    Nine Inch Nails
    CC BY-NC-SA 2.0

    View Slide

  50. One(Shot) Way To Get There
    Nine Inch Nails
    CC BY-NC-SA 2.0

    View Slide

  51. One(Shot) Way To Get There
    Nine Inch Nails
    CC BY-NC-SA 2.0
    drummer

    View Slide

  52. @kevin_j_m
    One(Shot) Way To Get There
    class Patch
    attr_reader :sound
    attr_reader :effect
    attr_reader :filter
    attr_reader :oscillator
    end
    Nine Inch Nails CC BY-NC-SA 2.0

    View Slide

  53. @kevin_j_m
    One(Shot) Way To Get There
    class Synthesizer
    def program(note)
    end
    end
    Nine Inch Nails CC BY-NC-SA 2.0

    View Slide

  54. @kevin_j_m
    One(Shot) Way To Get There
    class Synthesizer
    def program(note)
    set_patch(note.synth_sound.patch)
    end
    end
    Nine Inch Nails CC BY-NC-SA 2.0

    View Slide

  55. @kevin_j_m
    One(Shot) Way To Get There
    class Synthesizer
    def program(note)
    set_patch(note.synth_sound.patch)
    play_key(
    key: note.synth_sound.key,
    duration: note.duration,
    )
    end
    end
    Nine Inch Nails CC BY-NC-SA 2.0

    View Slide

  56. @kevin_j_m
    One(Shot) Way To Get There
    class MoogPatchMemory
    def read(location)
    case location

    end
    end
    end
    Nine Inch Nails CC BY-NC-SA 2.0

    View Slide

  57. @kevin_j_m
    One(Shot) Way To Get There
    class MoogPatchMemory
    def read(location)
    case location

    end
    end
    end
    Nine Inch Nails CC BY-NC-SA 2.0

    View Slide

  58. @kevin_j_m
    One(Shot) Way To Get There
    case location
    Nine Inch Nails CC BY-NC-SA 2.0

    View Slide

  59. @kevin_j_m
    One(Shot) Way To Get There
    case location
    when :a1
    @memory[0]
    Nine Inch Nails CC BY-NC-SA 2.0

    View Slide

  60. @kevin_j_m
    One(Shot) Way To Get There
    case location
    when :a1
    @memory[0]
    when :a2
    @memory[1]
    Nine Inch Nails CC BY-NC-SA 2.0

    View Slide

  61. @kevin_j_m
    One(Shot) Way To Get There
    case location
    when :a1
    @memory[0]
    when :a2
    @memory[1]
    when :b1
    @memory[2]
    Nine Inch Nails CC BY-NC-SA 2.0

    View Slide

  62. @kevin_j_m
    One(Shot) Way To Get There
    case location
    when :a1
    @memory[0]
    when :a2
    @memory[1]
    when :b1
    @memory[2]
    when :b2
    @memory[3]
    Nine Inch Nails CC BY-NC-SA 2.0

    View Slide

  63. @kevin_j_m
    # lib/festival_setlist.rb
    moog = Synthesizer.new(brand: :moog)
    One(Shot) Way To Get There

    View Slide

  64. @kevin_j_m
    # lib/festival_setlist.rb
    moog = Synthesizer.new(brand: :moog)
    moog.save_patch(location: :a1, patch: beep)
    One(Shot) Way To Get There

    View Slide

  65. @kevin_j_m
    # lib/festival_setlist.rb
    moog = Synthesizer.new(brand: :moog)
    moog.save_patch(location: :a1, patch: beep)
    moog.save_patch(location: :a2, patch: boop)
    One(Shot) Way To Get There

    View Slide

  66. @kevin_j_m
    # lib/festival_setlist.rb
    moog = Synthesizer.new(brand: :moog)
    moog.save_patch(location: :a1, patch: beep)
    moog.save_patch(location: :a2, patch: boop)
    moog.save_patch(location: :b1, patch: moog_buzz)
    One(Shot) Way To Get There

    View Slide

  67. @kevin_j_m
    # lib/festival_setlist.rb
    moog = Synthesizer.new(brand: :moog)
    moog.save_patch(location: :a1, patch: beep)
    moog.save_patch(location: :a2, patch: boop)
    moog.save_patch(location: :b1, patch: moog_buzz)
    moog.save_patch(location: :b2, patch: whirr)
    One(Shot) Way To Get There

    View Slide

  68. @kevin_j_m
    # lib/festival_setlist.rb
    concert.perform
    One(Shot) Way To Get There

    View Slide

  69. @kevin_j_m
    require "coverage"
    One(Shot) Way To Get There

    View Slide

  70. @kevin_j_m
    require "coverage"
    Coverage.start(oneshot_lines: true)
    One(Shot) Way To Get There

    View Slide

  71. @kevin_j_m
    require "coverage"
    Coverage.start(oneshot_lines: true)
    load "lib/festival_setlist.rb"
    One(Shot) Way To Get There

    View Slide

  72. @kevin_j_m
    require "coverage"
    Coverage.start(oneshot_lines: true)
    load "lib/festival_setlist.rb"
    result = Coverage.result
    One(Shot) Way To Get There

    View Slide

  73. @kevin_j_m
    {
    "lib/festival_setlist.rb"=>{:oneshot_lines=>[1, 2, 3…]},
    "moog_patch_memory.rb"=>{:oneshot_lines=>[1, 2, 3…]},
    }
    One(Shot) Way To Get There

    View Slide

  74. @kevin_j_m
    {
    "moog_patch_memory.rb"=>{:oneshot_lines=>[1, 2, 3…]},
    }
    One(Shot) Way To Get There

    View Slide

  75. @kevin_j_m
    {
    "moog_patch_memory.rb"=>{:oneshot_lines=>[1, 2, 3…]},
    }
    File
    One(Shot) Way To Get There

    View Slide

  76. @kevin_j_m
    {
    "moog_patch_memory.rb"=>{:oneshot_lines=>[1, 2, 3…]},
    }
    File
    Mode
    One(Shot) Way To Get There

    View Slide

  77. @kevin_j_m
    {
    "moog_patch_memory.rb"=>{:oneshot_lines=>[1, 2, 3…]},
    }
    File
    Mode
    executed line numbers
    One(Shot) Way To Get There

    View Slide

  78. @kevin_j_m
    moog = result["moog_patch_memory.rb"][:oneshot_lines]
    One(Shot) Way To Get There

    View Slide

  79. @kevin_j_m
    moog = result["moog_patch_memory.rb"][:oneshot_lines]
    => [1, 2, 3, 4, 5, 7, 11, 15, 28, 41, 43, 8, 29, 31, 33, 35, 37, 12, 44, 46, 16,
    18, 20, 24]
    One(Shot) Way To Get There

    View Slide

  80. @kevin_j_m
    One(Shot) Way To Get There
    case location
    when :a1
    @memory[0]
    when :a2
    @memory[1]
    when :b1
    @memory[2]
    when :b2
    @memory[3]
    Nine Inch Nails CC BY-NC-SA 2.0
    16
    17
    18
    19
    20
    21
    22
    23
    24

    View Slide

  81. @kevin_j_m
    One(Shot) Way To Get There
    case location
    when :a1
    @memory[0]
    when :a2
    @memory[1]
    when :b1
    @memory[2]
    when :b2
    @memory[3]
    Nine Inch Nails CC BY-NC-SA 2.0
    16
    17
    18
    19
    20
    21
    22
    23
    24

    View Slide

  82. @kevin_j_m
    puts "Moog Keyboard"
    puts "=============="
    One(Shot) Way To Get There

    View Slide

  83. @kevin_j_m
    puts "Moog Keyboard"
    puts "=============="
    puts "Location A1: #{moog.include?(18) ? 'Y' : 'N'}"
    One(Shot) Way To Get There

    View Slide

  84. @kevin_j_m
    puts "Moog Keyboard"
    puts "=============="
    puts "Location A1: #{moog.include?(18) ? 'Y' : 'N'}"
    puts "Location A2: #{moog.include?(20) ? 'Y' : 'N'}"
    One(Shot) Way To Get There

    View Slide

  85. @kevin_j_m
    puts "Moog Keyboard"
    puts "=============="
    puts "Location A1: #{moog.include?(18) ? 'Y' : 'N'}"
    puts "Location A2: #{moog.include?(20) ? 'Y' : 'N'}"
    puts "Location B1: #{moog.include?(22) ? 'Y' : 'N'}"
    One(Shot) Way To Get There

    View Slide

  86. @kevin_j_m
    puts "Moog Keyboard"
    puts "=============="
    puts "Location A1: #{moog.include?(18) ? 'Y' : 'N'}"
    puts "Location A2: #{moog.include?(20) ? 'Y' : 'N'}"
    puts "Location B1: #{moog.include?(22) ? 'Y' : 'N'}"
    puts "Location B2: #{moog.include?(24) ? 'Y' : 'N'}"
    One(Shot) Way To Get There

    View Slide

  87. @kevin_j_m
    Moog Keyboard
    =============
    Location A1: Y
    Location A2: Y
    Location B1: N
    Location B2: Y
    One(Shot) Way To Get There

    View Slide

  88. @kevin_j_m
    Moog Keyboard
    =============
    Location A1: Y
    Location A2: Y
    Location B1: N
    Location B2: Y
    One(Shot) Way To Get There
    Nord Keyboard
    =============
    Location A1: Y
    Location A2: N
    Location B1: N
    Location B2: N

    View Slide

  89. @kevin_j_m
    Moog Keyboard
    =============
    Location A1: Y
    Location A2: Y
    Location B1: Y
    Location B2: Y
    One(Shot) Way To Get There
    Nord Keyboard
    =============
    Location A1: Y
    Location A2: N
    Location B1: N
    Location B2: N

    View Slide

  90. @kevin_j_m
    Moog Keyboard
    =============
    Location A1: Y
    Location A2: Y
    Location B1: Y
    Location B2: Y
    One(Shot) Way To Get There
    Nord Keyboard
    =============
    Location A1: Y
    Location A2: N
    Location B1: N
    Location B2: N

    View Slide

  91. Nine Inch Nails
    CC BY-NC-SA 2.0

    View Slide

  92. @kevin_j_m
    setlist.songs
    [
    TheLineBeginsToBlur.new,
    OneShotWayToGetThere.new,
    VariousMethodsOfEscape.new,
    BranchesBones.new,
    ]

    View Slide

  93. Various Methods Of Escape
    Nine Inch Nails
    CC BY-NC-SA 2.0

    View Slide

  94. View Slide

  95. Various Methods Of Escape
    Nine Inch Nails
    CC BY-NC-SA 2.0

    View Slide

  96. Various Methods Of Escape
    Nine Inch Nails
    CC BY-NC-SA 2.0

    View Slide

  97. Various Methods Of Escape
    Nine Inch Nails
    CC BY-NC-SA 2.0

    View Slide

  98. Various Methods Of Escape
    Nine Inch Nails
    CC BY-NC-SA 2.0

    View Slide

  99. @kevin_j_m
    Various Methods Of Escape
    class LightingController
    def trigger(note)
    end
    Nine Inch Nails CC BY-NC-SA 2.0

    View Slide

  100. @kevin_j_m
    Various Methods Of Escape
    class LightingController
    def trigger(note)
    composition = note.lighting
    end
    Nine Inch Nails CC BY-NC-SA 2.0

    View Slide

  101. @kevin_j_m
    Various Methods Of Escape
    class LightingController
    def trigger(note)
    composition = note.lighting
    @powered_lights[composition.light].trigger(
    color: composition.color,
    effect: composition.effect,
    )
    end
    Nine Inch Nails CC BY-NC-SA 2.0

    View Slide

  102. @kevin_j_m
    Various Methods Of Escape
    class BeamProjector
    def trigger(color:, effect:)
    end
    end
    Nine Inch Nails CC BY-NC-SA 2.0

    View Slide

  103. @kevin_j_m
    Various Methods Of Escape
    class CanLight
    def trigger(color:, effect:)
    end
    end
    Nine Inch Nails CC BY-NC-SA 2.0

    View Slide

  104. @kevin_j_m
    Various Methods Of Escape
    class MovingLight
    def trigger(color:, effect:)
    end
    end
    Nine Inch Nails CC BY-NC-SA 2.0

    View Slide

  105. @kevin_j_m
    Various Methods Of Escape
    class Spotlight
    def trigger(color:, effect:)
    end
    end
    Nine Inch Nails CC BY-NC-SA 2.0

    View Slide

  106. @kevin_j_m
    Various Methods Of Escape
    # lib/lighting_inspection.rb
    controller = LightingController.new
    setlist.lighting = controller

    View Slide

  107. @kevin_j_m
    Various Methods Of Escape
    # lib/lighting_inspection.rb
    controller = LightingController.new
    setlist.lighting = controller
    concert.set_up

    View Slide

  108. @kevin_j_m
    Various Methods Of Escape
    # lib/lighting_inspection.rb
    controller = LightingController.new
    setlist.lighting = controller
    concert.set_up
    concert.perform

    View Slide

  109. @kevin_j_m
    Various Methods Of Escape
    # lib/lighting_inspection.rb
    controller = LightingController.new
    setlist.lighting = controller
    concert.set_up
    concert.perform
    concert.load_out

    View Slide

  110. @kevin_j_m
    Various Methods Of Escape
    require "coverage"

    View Slide

  111. @kevin_j_m
    Various Methods Of Escape
    require "coverage"
    Coverage.start(methods: true)

    View Slide

  112. @kevin_j_m
    Various Methods Of Escape
    require "coverage"
    Coverage.start(methods: true)
    load "lib/lighting_inspection.rb"

    View Slide

  113. @kevin_j_m
    Various Methods Of Escape
    require "coverage"
    Coverage.start(methods: true)
    load "lib/lighting_inspection.rb"
    result = Coverage.result

    View Slide

  114. @kevin_j_m
    Various Methods Of Escape
    "spotlight.rb"=>
    {:methods=>{[Spotlight, :trigger, 4, 6, 6, 9]=>2}},
    "beam_projector.rb"=>
    {:methods=>{[BeamProjector, :trigger, 4, 6, 6, 9]=>0}},
    "can_light.rb"=>
    {:methods=>{[CanLight, :trigger, 4, 6, 6, 9]=>2}},
    "moving_light.rb"=>
    {:methods=>{[MovingLight, :trigger, 4, 6, 6, 9]=>6}},

    View Slide

  115. @kevin_j_m
    {
    "spotlight.rb"=> {:methods=>{[Spotlight, :trigger, 4, 6, 6, 9]=>2}},
    }
    Various Methods Of Escape

    View Slide

  116. @kevin_j_m
    {
    "spotlight.rb"=> {:methods=>{[Spotlight, :trigger, 4, 6, 6, 9]=>2}},
    }
    File
    Various Methods Of Escape

    View Slide

  117. @kevin_j_m
    {
    "spotlight.rb"=> {:methods=>{[Spotlight, :trigger, 4, 6, 6, 9]=>2}},
    }
    File
    Mode
    Various Methods Of Escape

    View Slide

  118. @kevin_j_m
    {
    "spotlight.rb"=> {:methods=>{[Spotlight, :trigger, 4, 6, 6, 9]=>2}},
    }
    File
    Mode
    Various Methods Of Escape
    method

    View Slide

  119. @kevin_j_m
    {
    "spotlight.rb"=> {:methods=>{[Spotlight, :trigger, 4, 6, 6, 9]=>2}},
    }
    File
    Mode
    Various Methods Of Escape
    method
    count

    View Slide

  120. @kevin_j_m
    {
    "spotlight.rb"=> {:methods=>{[Spotlight, :trigger, 4, 6, 6, 9]=>2}},
    }
    File
    Mode
    Various Methods Of Escape
    method
    count

    View Slide

  121. @kevin_j_m
    [Spotlight, :trigger, 4, 6, 6, 9] => 2
    Various Methods Of Escape

    View Slide

  122. @kevin_j_m
    [Spotlight, :trigger, 4, 6, 6, 9] => 2
    Various Methods Of Escape
    count

    View Slide

  123. @kevin_j_m
    [Spotlight, :trigger, 4, 6, 6, 9] => 2
    Various Methods Of Escape
    class count

    View Slide

  124. @kevin_j_m
    [Spotlight, :trigger, 4, 6, 6, 9] => 2
    Various Methods Of Escape
    method
    class count

    View Slide

  125. @kevin_j_m
    [Spotlight, :trigger, 4, 6, 6, 9] => 2
    Various Methods Of Escape
    method
    class start line count

    View Slide

  126. @kevin_j_m
    [Spotlight, :trigger, 4, 6, 6, 9] => 2
    Various Methods Of Escape
    method
    class start line
    start column
    count

    View Slide

  127. @kevin_j_m
    [Spotlight, :trigger, 4, 6, 6, 9] => 2
    Various Methods Of Escape
    method
    class start line
    start column
    end line
    count

    View Slide

  128. @kevin_j_m
    [Spotlight, :trigger, 4, 6, 6, 9] => 2
    Various Methods Of Escape
    method
    class start line
    start column
    end line
    end column
    count

    View Slide

  129. @kevin_j_m
    Various Methods Of Escape
    "spotlight.rb"=>
    {:methods=>{[Spotlight, :trigger, 4, 6, 6, 9]=>2}},
    "beam_projector.rb"=>
    {:methods=>{[BeamProjector, :trigger, 4, 6, 6, 9]=>0}},
    "can_light.rb"=>
    {:methods=>{[CanLight, :trigger, 4, 6, 6, 9]=>2}},
    "moving_light.rb"=>
    {:methods=>{[MovingLight, :trigger, 4, 6, 6, 9]=>6}},

    View Slide

  130. @kevin_j_m
    Various Methods Of Escape
    "spotlight.rb"=>
    {:methods=>{[Spotlight, :trigger, 4, 6, 6, 9]=>2}},
    "beam_projector.rb"=>
    {:methods=>{[BeamProjector, :trigger, 4, 6, 6, 9]=>0}},
    "can_light.rb"=>
    {:methods=>{[CanLight, :trigger, 4, 6, 6, 9]=>2}},
    "moving_light.rb"=>
    {:methods=>{[MovingLight, :trigger, 4, 6, 6, 9]=>6}},

    View Slide

  131. @kevin_j_m
    Various Methods Of Escape
    class LightingController
    def turn_on_lights
    @powered_lights[:beam_projector] = BeamProjector.new
    @powered_lights[:can] = CanLight.new
    @powered_lights[:moving_light] = MovingLight.new
    @powered_lights[:spotlight] = Spotlight.new
    end
    end

    View Slide

  132. @kevin_j_m
    Various Methods Of Escape
    class LightingController
    def turn_on_lights
    @powered_lights[:beam_projector] = BeamProjector.new
    @powered_lights[:can] = CanLight.new
    @powered_lights[:moving_light] = MovingLight.new
    @powered_lights[:spotlight] = Spotlight.new
    end
    end

    View Slide

  133. @kevin_j_m
    Various Methods Of Escape
    class LightingController
    def turn_on_lights
    @powered_lights[:beam_projector] = BeamProjector.new
    @powered_lights[:can] = CanLight.new
    @powered_lights[:moving_light] = MovingLight.new
    @powered_lights[:spotlight] = Spotlight.new
    end
    end

    View Slide

  134. @kevin_j_m
    Various Methods Of Escape
    class LightingController
    def turn_on_lights
    @powered_lights[:can] = CanLight.new
    @powered_lights[:moving_light] = MovingLight.new
    @powered_lights[:spotlight] = Spotlight.new
    end
    end

    View Slide

  135. Nine Inch Nails
    CC BY-NC-SA 2.0

    View Slide

  136. @kevin_j_m
    setlist.songs
    [
    TheLineBeginsToBlur.new,
    OneShotWayToGetThere.new,
    VariousMethodsOfEscape.new,
    BranchesBones.new,
    ]

    View Slide

  137. Nine Inch Nails
    CC BY-NC-SA 2.0

    View Slide

  138. Nine Inch Nails
    CC BY-NC-SA 2.0
    Nine Inch Nails
    CC BY-NC-SA 2.0
    Nine Inch Nails
    CC BY-NC-SA 2.0
    Nine Inch Nails
    CC BY-NC-SA 2.0
    Nine Inch Nails
    CC BY-NC-SA 2.0

    View Slide

  139. @kevin_j_m
    Branches/Bones
    # lib/rehearsal.rb
    song = BranchesBones.new

    View Slide

  140. @kevin_j_m
    Branches/Bones
    # lib/rehearsal.rb
    song = BranchesBones.new
    song.performers = band

    View Slide

  141. @kevin_j_m
    Branches/Bones
    # lib/rehearsal.rb
    song = BranchesBones.new
    song.performers = band
    song.play

    View Slide

  142. @kevin_j_m
    Branches/Bones
    require "coverage"

    View Slide

  143. @kevin_j_m
    Branches/Bones
    require "coverage"
    Coverage.start(:all)

    View Slide

  144. @kevin_j_m
    Branches/Bones
    require "coverage"
    Coverage.start(:all)
    load "lib/rehearsal.rb"

    View Slide

  145. @kevin_j_m
    Branches/Bones
    require "coverage"
    Coverage.start(:all)
    load "lib/rehearsal.rb"
    result = Coverage.result

    View Slide

  146. @kevin_j_m
    Branches/Bones
    "branches_bones.rb"=>{
    :lines=>[1, 1, 1, 1, 1, nil, nil, nil, nil, nil, 1, nil, 1, nil, 1, nil, nil, nil, 1, nil, 1, nil, nil, nil, 1, nil,
    1, nil, nil, nil, nil, nil, 1, 2, nil, nil, 2, nil, nil, nil, nil, 2, nil, 2, 8, nil, nil, nil, nil, nil],
    :branches=>{[:if, 0, 34, 25, 34, 67]=>{[:then, 1, 34, 60, 34, 62]=>0, [:else, 2, 34, 65, 34,
    67]=>2}, [:if, 3, 42, 18, 42, 99]=>{[:then, 4, 42, 41, 42, 75]=>0, [:else, 5, 42, 78, 42, 99]=>2}},
    :methods=>{
    [RubyCoverBand::Songs::BranchesBones, :chorus, 33, 6, 47, 9]=>2
    [RubyCoverBand::Songs::BranchesBones, :outro, 25, 6, 29, 9]=>1,
    [RubyCoverBand::Songs::BranchesBones, :verse_2, 19, 6, 23, 9]=>1,
    [RubyCoverBand::Songs::BranchesBones, :verse_1, 13, 6, 17, 9]=>1,
    [RubyCoverBand::Songs::BranchesBones, :initialize, 4, 6, 9, 9]=>1}},

    View Slide

  147. @kevin_j_m
    Branches/Bones
    "branches_bones.rb"=>{
    :lines=>[1, 1, 1, 1, 1, nil, nil, nil, nil, nil, 1, nil, 1, nil, 1, nil, nil, nil, 1, nil, 1, nil, nil, nil, 1, nil,
    1, nil, nil, nil, nil, nil, 1, 2, nil, nil, 2, nil, nil, nil, nil, 2, nil, 2, 8, nil, nil, nil, nil, nil],
    :branches=>{[:if, 0, 34, 25, 34, 67]=>{[:then, 1, 34, 60, 34, 62]=>0, [:else, 2, 34, 65, 34,
    67]=>2}, [:if, 3, 42, 18, 42, 99]=>{[:then, 4, 42, 41, 42, 75]=>0, [:else, 5, 42, 78, 42, 99]=>2}},
    :methods=>{
    [RubyCoverBand::Songs::BranchesBones, :chorus, 33, 6, 47, 9]=>2
    [RubyCoverBand::Songs::BranchesBones, :outro, 25, 6, 29, 9]=>1,
    [RubyCoverBand::Songs::BranchesBones, :verse_2, 19, 6, 23, 9]=>1,
    [RubyCoverBand::Songs::BranchesBones, :verse_1, 13, 6, 17, 9]=>1,
    [RubyCoverBand::Songs::BranchesBones, :initialize, 4, 6, 9, 9]=>1}},

    View Slide

  148. @kevin_j_m
    Branches/Bones
    song_coverage = result["branches_bones.rb"]
    song_coverage.keys

    View Slide

  149. @kevin_j_m
    Branches/Bones
    song_coverage = result["branches_bones.rb"]
    song_coverage.keys
    => [:lines, :methods, :branches]

    View Slide

  150. @kevin_j_m
    Branches/Bones
    song_coverage[:lines].include?(0)
    => false

    View Slide

  151. @kevin_j_m
    Branches/Bones
    song_coverage[:methods].values.include?(0)
    => false

    View Slide

  152. @kevin_j_m
    Branches/Bones
    song_coverage[:branches]
    => {[:if, 0, 34, 25, 34, 67]=>{
    [:then, 1, 34, 60, 34, 62]=>0,
    [:else, 2, 34, 65, 34, 67]=>2,
    }}

    View Slide

  153. @kevin_j_m
    Branches/Bones
    {
    "branches_bones.rb" => { :branches =>
    {[:if, 0, 34, 25, 34, 67] => {
    [:then, 1, 34, 60, 34, 62] => 0,
    [:else, 2, 34, 65, 34, 67] => 2,
    }}
    }
    }

    View Slide

  154. @kevin_j_m
    Branches/Bones
    {
    "branches_bones.rb" => { :branches =>
    {[:if, 0, 34, 25, 34, 67] => {
    [:then, 1, 34, 60, 34, 62] => 0,
    [:else, 2, 34, 65, 34, 67] => 2,
    }}
    }
    }
    File

    View Slide

  155. @kevin_j_m
    Branches/Bones
    {
    "branches_bones.rb" => { :branches =>
    {[:if, 0, 34, 25, 34, 67] => {
    [:then, 1, 34, 60, 34, 62] => 0,
    [:else, 2, 34, 65, 34, 67] => 2,
    }}
    }
    }
    File mode

    View Slide

  156. @kevin_j_m
    Branches/Bones
    {
    "branches_bones.rb" => { :branches =>
    {[:if, 0, 34, 25, 34, 67] => {
    [:then, 1, 34, 60, 34, 62] => 0,
    [:else, 2, 34, 65, 34, 67] => 2,
    }}
    }
    }
    File mode
    conditional

    View Slide

  157. @kevin_j_m
    Branches/Bones
    {
    "branches_bones.rb" => { :branches =>
    {[:if, 0, 34, 25, 34, 67] => {
    [:then, 1, 34, 60, 34, 62] => 0,
    [:else, 2, 34, 65, 34, 67] => 2,
    }}
    }
    }
    File mode
    conditional
    branch

    View Slide

  158. @kevin_j_m
    Branches/Bones
    {
    "branches_bones.rb" => { :branches =>
    {[:if, 0, 34, 25, 34, 67] => {
    [:then, 1, 34, 60, 34, 62] => 0,
    [:else, 2, 34, 65, 34, 67] => 2,
    }}
    }
    }
    File mode
    conditional
    branch
    branch

    View Slide

  159. @kevin_j_m
    Branches/Bones
    {
    "branches_bones.rb" => { :branches =>
    {[:if, 0, 34, 25, 34, 67] => {
    [:then, 1, 34, 60, 34, 62] => 0,
    [:else, 2, 34, 65, 34, 67] => 2,
    }}
    }
    }
    File mode
    conditional
    branch
    branch

    View Slide

  160. @kevin_j_m
    Branches/Bones
    [:then, 1, 34, 60, 34, 62] => 0

    View Slide

  161. @kevin_j_m
    Branches/Bones
    [:then, 1, 34, 60, 34, 62] => 0
    count

    View Slide

  162. @kevin_j_m
    Branches/Bones
    [:then, 1, 34, 60, 34, 62] => 0
    branch count

    View Slide

  163. @kevin_j_m
    Branches/Bones
    [:then, 1, 34, 60, 34, 62] => 0
    branch count
    id

    View Slide

  164. @kevin_j_m
    Branches/Bones
    [:then, 1, 34, 60, 34, 62] => 0
    branch start line count
    id

    View Slide

  165. @kevin_j_m
    Branches/Bones
    [:then, 1, 34, 60, 34, 62] => 0
    branch start line
    start column
    count
    id

    View Slide

  166. @kevin_j_m
    Branches/Bones
    [:then, 1, 34, 60, 34, 62] => 0
    branch start line
    start column
    end line
    count
    id

    View Slide

  167. @kevin_j_m
    Branches/Bones
    [:then, 1, 34, 60, 34, 62] => 0
    branch start line
    start column
    end line
    end column
    count
    id

    View Slide

  168. @kevin_j_m
    Branches/Bones
    class BranchesBones < Song
    def chorus(number)
    echo_intensity = number.positive? && number.even? ? 10 : 30

    Lyric.new(line: line, effect: :echo, effect_level: echo_intensity)
    32
    33
    34
    35
    60
    62

    View Slide

  169. @kevin_j_m
    Branches/Bones
    class BranchesBones < Song
    def initialize
    notes = verse_1 + chorus(0) + verse_2 + chorus(1) + outro
    end
    def chorus(number)
    echo_intensity = number.positive? && number.even? ? 10 : 30
    end

    View Slide

  170. @kevin_j_m
    Branches/Bones
    class BranchesBones < Song
    def initialize
    notes = verse_1 + chorus(0) + verse_2 + chorus(1) + outro
    end
    def chorus(number)
    echo_intensity = number.positive? && number.even? ? 10 : 30
    end

    View Slide

  171. @kevin_j_m
    Branches/Bones
    class BranchesBones < Song
    def initialize
    notes = verse_1 + chorus(1) + verse_2 + chorus(2) + outro
    end
    def chorus(number)
    echo_intensity = number.positive? && number.even? ? 10 : 30
    end

    View Slide

  172. @kevin_j_m
    Branches/Bones
    song_coverage[:branches]
    => {[:if, 0, 34, 25, 34, 67]=>{
    [:then, 1, 34, 60, 34, 62]=>1,
    [:else, 2, 34, 65, 34, 67]=>1,
    }}

    View Slide

  173. Branches/Bones
    Nine Inch Nails
    CC BY-NC-SA 2.0

    View Slide

  174. encore

    View Slide

  175. @kevin_j_m
    {
    }
    coverage.summary

    View Slide

  176. @kevin_j_m
    {
    lines: "how many times was each line executed?",
    }
    coverage.summary

    View Slide

  177. @kevin_j_m
    {
    lines: "how many times was each line executed?",
    oneshot_lines: "which lines were executed?",
    }
    coverage.summary

    View Slide

  178. @kevin_j_m
    {
    lines: "how many times was each line executed?",
    oneshot_lines: "which lines were executed?",
    methods: "how many times was each method executed?",
    }
    coverage.summary

    View Slide

  179. @kevin_j_m
    {
    lines: "how many times was each line executed?",
    oneshot_lines: "which lines were executed?",
    methods: "how many times was each method executed?",
    branches: "how many times was each branch executed?",
    }
    coverage.summary

    View Slide

  180. @kevin_j_m
    Supporting Instruments
    Nine Inch Nails CC BY-NC-SA 2.0
    SimpleCov
    Coverband

    View Slide

  181. @kevin_j_m
    https://kevin-j-m.github.io/coverage
    #_rc_talk-enough-coverage-to-beat-the-band
    Nine Inch Nails CC BY-NC-SA 2.0

    View Slide