Module: Exemplor

Extended by:
Exemplor
Included in:
Exemplor
Defined in:
lib/checker.rb,
lib/examples.rb,
lib/exemplor.rb,
lib/environment.rb,
lib/result_printer.rb

Defined Under Namespace

Classes: Assert, Check, Environment, ExampleDefinitionError, Examples, ResultPrinter, Show

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.load_ansicolorObject

todo: remove this dependency at some point



5
6
7
8
9
10
# File 'lib/result_printer.rb', line 5

def self.load_ansicolor
  @aniscolor_loaded ||= begin
    $:.unshift Exemplor.path('/../vendor/term-ansicolor-1.0.5/lib')
    require 'term/ansicolor'
  end
end

Instance Method Details

#environmentObject



121
122
123
# File 'lib/environment.rb', line 121

def environment
  Environment
end

#example_file_set?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/examples.rb', line 12

def example_file_set?
  !!@example_file
end

#examplesObject



3
4
5
# File 'lib/examples.rb', line 3

def examples
  @examples ||= Examples.new
end

#make_example_name_from(caller_trace) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/examples.rb', line 22

def make_example_name_from(caller_trace)
  file, line_number = caller_trace.first.match(/^(.+):(\d+)/).captures
  line = File.readlines(file)[line_number.to_i - 1].strip
  name = line[/^eg\s*\{\s*(.+?)\s*\}$/,1]
  raise Exemplor::ExampleDefinitionError, "example at #{caller_trace.first} has no name so must be on one line" if name.nil?
  name
end

#path(rel_path) ⇒ Object



9
10
11
# File 'lib/exemplor.rb', line 9

def path(rel_path)
  File.join(File.dirname(__FILE__), rel_path)
end

#run_directly?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/examples.rb', line 16

def run_directly?
  @example_file == $0
end

#set_example_file_from(caller_trace) ⇒ Object

sets @example_file to first file that calls the ‘eg` method



8
9
10
# File 'lib/examples.rb', line 8

def set_example_file_from(caller_trace)
  @example_file ||= caller_trace.first.split(":").first
end

#versionObject



13
14
15
# File 'lib/exemplor.rb', line 13

def version
  File.read(path('/../VERSION'))
end