Class: Uberspec::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/uberspec.rb

Direct Known Subclasses

Rspec

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(watchr_script, config) ⇒ Base

Returns a new instance of Base.



26
27
28
29
30
# File 'lib/uberspec.rb', line 26

def initialize(watchr_script,config)
  @watchr = watchr_script
  @config = config
  @notifier = set_notifier
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



23
24
25
# File 'lib/uberspec.rb', line 23

def config
  @config
end

#matchesObject (readonly)

Returns the value of attribute matches.



22
23
24
# File 'lib/uberspec.rb', line 22

def matches
  @matches
end

#notifierObject (readonly)

Returns the value of attribute notifier.



24
25
26
# File 'lib/uberspec.rb', line 24

def notifier
  @notifier
end

#watchrObject (readonly)

Returns the value of attribute watchr.



21
22
23
# File 'lib/uberspec.rb', line 21

def watchr
  @watchr
end

Class Method Details

.run_allObject



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

def run_all
  ObjectSpace.each_object(self) { |o| o.run_all }
end

.watch(watchr_script, config = Config.new) {|config| ... } ⇒ Object

Yields:



9
10
11
12
13
14
# File 'lib/uberspec.rb', line 9

def watch(watchr_script, config = Config.new)
  yield config if block_given?
  tester = new(watchr_script,config)
  tester.start_watching
  tester
end

Instance Method Details

#all_pathsObject



53
54
55
# File 'lib/uberspec.rb', line 53

def all_paths
  (@config.spec_paths + @config.code_paths).uniq
end

#all_test_filesObject



57
58
59
# File 'lib/uberspec.rb', line 57

def all_test_files
  raise "'all_test_files' Must be defined in test suite specific implimentation"
end

#clearObject



70
71
72
# File 'lib/uberspec.rb', line 70

def clear
  system("clear")
end

#commandObject



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

def command
  raise "'command' Must be defined in test suite specific implimentation"
end

#find_and_run_match(thing_to_match) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/uberspec.rb', line 44

def find_and_run_match(thing_to_match)
  @matches = all_test_files.grep(/#{thing_to_match}/i)
  if matches.empty?
    puts "No matches found for #{thing_to_match}"
  else
    run
  end
end

#parse_results(results) ⇒ Object



79
80
81
# File 'lib/uberspec.rb', line 79

def parse_results(results)
  raise "'parse_results' Must be defined in test suit specific implimentation"
end

#runObject



74
75
76
77
# File 'lib/uberspec.rb', line 74

def run
  clear
  system_with_notify("#{command} #{matches.join(' ')}") 
end

#run_allObject



65
66
67
68
# File 'lib/uberspec.rb', line 65

def run_all
  @matches = all_test_files
  run
end

#set_notifierObject



32
33
34
35
36
# File 'lib/uberspec.rb', line 32

def set_notifier
  return false if config.notify == false
  raise "Unsupported Notification library (try 'LibNotify' or 'Growl')." unless ['LibNotify', 'Growl'].include? config.notify
  eval("Uberspec::Notify::#{config.notify}").new(config.passed_image,config.failed_image)
end

#start_watchingObject



38
39
40
41
42
# File 'lib/uberspec.rb', line 38

def start_watching
  all_paths.each do |path|
    watchr.watch(path) {|m| find_and_run_match(m[1]) }
  end
end

#system_with_notify(command) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/uberspec.rb', line 83

def system_with_notify(command)
  #my_io = MyIO.new($stdout)
  #$stdout = my_io
  #system(command)
  #$stdout = my_io.old_io
  #results = my_io.captured
  if notifier
    results = %x{#{command}}
    notifier.notify(parse_results(results))
    puts results 
  else
    system(command)
  end
end