Skip to content

Commit

Permalink
Spec: allow running single spec by specifying any line inside an it
Browse files Browse the repository at this point in the history
… call, using __END_LINE__. Related to #3552
Ary Borenszweig committed Nov 24, 2016
1 parent c954969 commit d13e650
Showing 2 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/spec.cr
Original file line number Diff line number Diff line change
@@ -164,18 +164,18 @@ module Spec
end

# :nodoc:
def self.matches?(description, file, line)
def self.matches?(description, file, line, end_line = line)
spec_pattern = @@pattern
spec_line = @@line
locations = @@locations

if line == spec_line
if spec_line && line <= spec_line <= end_line
return true
end

if locations
lines = locations[file]?
return true if lines && lines.includes?(line)
return true if lines && lines.any? { |l| line <= l <= end_line }
end

if spec_pattern || spec_line || locations
12 changes: 6 additions & 6 deletions src/spec/dsl.cr
Original file line number Diff line number Diff line change
@@ -7,8 +7,8 @@ module Spec::DSL
describe(description.to_s, file, line, &block)
end

def it(description, file = __FILE__, line = __LINE__, &block)
return unless Spec.matches?(description, file, line)
def it(description, file = __FILE__, line = __LINE__, end_line = __END_LINE__, &block)
return unless Spec.matches?(description, file, line, end_line)

Spec.formatters.each(&.before_example(description))

@@ -28,16 +28,16 @@ module Spec::DSL
end
end

def pending(description, file = __FILE__, line = __LINE__, &block)
return unless Spec.matches?(description, file, line)
def pending(description, file = __FILE__, line = __LINE__, end_line = __END_LINE__, &block)
return unless Spec.matches?(description, file, line, end_line)

Spec.formatters.each(&.before_example(description))

Spec::RootContext.report(:pending, description, file, line)
end

def assert(file = __FILE__, line = __LINE__, &block)
it("assert", file, line, &block)
def assert(file = __FILE__, line = __LINE__, end_line = __END_LINE__, &block)
it("assert", file, line, end_line, &block)
end

def fail(msg, file = __FILE__, line = __LINE__)

0 comments on commit d13e650

Please sign in to comment.