Skip to content

Commit

Permalink
Writing some (failing) tests for instrumentation
Browse files Browse the repository at this point in the history
  • Loading branch information
arfon committed Mar 2, 2015
1 parent 9a86b9a commit c22a656
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions test/test_instrumentation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
require_relative "./helper"

class TestInstrumentation < Minitest::Test
include Linguist

class LocalInstrumenter
Event = Struct.new(:name, :args)

attr_reader :events

def initialize
@events = []
end

def instrument(name, *args)
@events << Event.new(name, args)
end
end

def setup
Linguist.instrumenter = LocalInstrumenter.new
end

def teardown
Linguist.instrumenter = nil
end

def test_detection_instrumentation_with_binary_blob
binary_blob = fixture_blob("Binary/octocat.ai")
Language.detect(binary_blob)

# Shouldn't instrument this (as it's binary)
assert_equal 0, Linguist.instrumenter.events.size
end

def test_modeline_instrumentation
blob = fixture_blob("Data/Modelines/ruby")
Language.detect(blob)

assert_equal 3, Linguist.instrumenter.events.size

This comment has been minimized.

Copy link
@arfon

arfon Mar 2, 2015

Author Contributor

@bkeepers - I would expect three events here:

  1. The initial linguist.detection
  2. One linguist.strategy (for the modeline detection)
  3. A final linguist.detected when we return the classification

Any ideas why this might not be happening?

assert_equal "linguist.detected", Linguist.instrumenter.events.last.name
end
end

0 comments on commit c22a656

Please sign in to comment.