Class: EEtee::Runner

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/eetee/runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRunner

Returns a new instance of Runner.



11
12
13
14
# File 'lib/eetee/runner.rb', line 11

def initialize
  @reporter = EEtee.default_reporter_class.new
  @focus_mode = false
end

Instance Attribute Details

#focus_modeObject (readonly)

Returns the value of attribute focus_mode.



7
8
9
# File 'lib/eetee/runner.rb', line 7

def focus_mode
  @focus_mode
end

Instance Method Details

#describe(description, &block) ⇒ Object



65
66
67
# File 'lib/eetee/runner.rb', line 65

def describe(description, &block)
  Context.new(description, 0, @reporter, {}, @focus_mode, &block)
end

#report_resultsObject



61
62
63
# File 'lib/eetee/runner.rb', line 61

def report_results
  @reporter.report_results()
end

#run(&block) ⇒ Object



16
17
18
19
# File 'lib/eetee/runner.rb', line 16

def run(&block)
  instance_eval(&block)
  @reporter.report_results()
end

#run_files(paths) ⇒ Object

run the files relative to the caller.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/eetee/runner.rb', line 33

def run_files(paths)
  paths.each do |path|
    if File.exist?(path)
      data = File.read(path)
      if data =~ /^\s+(should|it).*?,\s+:?focus.* do$/
        puts "Focus enabled."
        @focus_mode = true
      else
        @focus_mode = false
      end
      
      begin
        instance_eval(data, path)
      rescue => err
        test = EEtee::Test.new("(Loading)", @reporter){}
        @reporter.add_error( EEtee::Error.new(err, test))
        
      end
      
    else
      puts "!!! file does not exists: #{path}"
    end
  end
  
rescue SyntaxError => ex
  puts ex.message
end

#run_pattern(pattern) ⇒ Object



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

def run_pattern(pattern)
  paths = []
  caller_path = caller[0].split(':').first
  pattern = File.expand_path("../#{pattern}", caller_path)
  
  paths = Dir[pattern].to_a
  run_files(paths)
end