Skip to content

Commit

Permalink
Merge pull request #84 from ksss/block-fault
Browse files Browse the repository at this point in the history
Output code snippet adjust line to assert in block

Patch by Yuki Kurihara. Thanks!!!
  • Loading branch information
kou committed Nov 9, 2014
2 parents 6644e50 + 2040929 commit 090be48
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/test/unit/fault-location-detector.rb
Expand Up @@ -66,7 +66,7 @@ def target_source_location?(file, line_number, method_name)
end

def target_method?(method_name)
@fault_method_name == method_name
@fault_method_name == method_name.split(/\s+/).last
end

def guess_indent_level(line)
Expand Down
39 changes: 37 additions & 2 deletions test/test-fault-location-detector.rb
Expand Up @@ -24,12 +24,16 @@ def run_test_case(test_case)
def assert_detect(fault, target_line_number)
detector = Test::Unit::FaultLocationDetector.new(fault, @fetcher)

snippet_is_shown = false
expected = fault.location.collect do |backtrace_entry|
_, line_number, = detector.split_backtrace_entry(backtrace_entry)
[backtrace_entry, target_line_number == line_number]
snippet_is_shown = true if !snippet_is_shown && target_line_number == line_number
[backtrace_entry, snippet_is_shown]
end
snippet_is_shown = false
actual = fault.location.collect do |backtrace_entry|
[backtrace_entry, detector.target?(backtrace_entry)]
snippet_is_shown = true if !snippet_is_shown && detector.target?(backtrace_entry)
[backtrace_entry, snippet_is_shown]
end
assert_equal(expected, actual)
end
Expand Down Expand Up @@ -122,4 +126,35 @@ def test_failed
assert_detect(fault, test_case.target_line_number)
end
end

class TestInBlock < self
def test_in_block
test_case = Class.new(Test::Unit::TestCase) do
include AlwaysFailAssertion

class << self
def target_line_number
@@target_line_number
end

def target_line_number=(line_number)
@@target_line_number = line_number
end
end

def run_yield
yield
end

def test_failed
run_yield do
self.class.target_line_number = __LINE__; assert_always_failed
end
end
end

fault = run_test_case(test_case)
assert_detect(fault, test_case.target_line_number)
end
end
end

0 comments on commit 090be48

Please sign in to comment.