Module: Obsidian::Spec

Includes:
Test::Unit::Assertions
Included in:
MappingMatcher, SubsetMatcher, SupersetMatcher
Defined in:
lib/obsidian/spec.rb,
lib/obsidian/spec/map_spec_helper.rb,
lib/obsidian/spec/set_spec_helper.rb

Defined Under Namespace

Classes: MappingMatcher, SubsetMatcher, SupersetMatcher

Instance Method Summary collapse

Instance Method Details

#args_to_set(*args) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/obsidian/spec.rb', line 6

def args_to_set(*args)
  if args.size == 1
    args.first.respond_to?(:to_set) ? args.first.to_set : Set.new([args.first])
  else
    args.to_set
  end
end

#find_calling_line(trace, method_name) ⇒ Object

find the line in a stack trace above the one from method_name



15
16
17
18
19
20
21
22
23
24
# File 'lib/obsidian/spec.rb', line 15

def find_calling_line(trace, method_name)
  trace.each_cons(2) do |line, next_line|
    if /(.*):(\d+):in .(.*)'/ =~ line && 
       $3 == method_name &&
       /(.*):(\d+):in .(.*)'/ =~ next_line
      return [$1,$2]
    end
  end
  nil
end

#read_calling_line(trace, method_name) ⇒ Object



26
27
28
29
# File 'lib/obsidian/spec.rb', line 26

def read_calling_line(trace, method_name)
  file, line_number = find_calling_line(trace, method_name)
  File.readlines(file)[Integer(line_number) - 1].chop.strip if file
end