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.



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

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.



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

def config
  @config
end

#matchesObject (readonly)

Returns the value of attribute matches.



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

def matches
  @matches
end

#notifierObject (readonly)

Returns the value of attribute notifier.



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

def notifier
  @notifier
end

#watchrObject (readonly)

Returns the value of attribute watchr.



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

def watchr
  @watchr
end

Class Method Details

.run_allObject



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

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

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

Yields:



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

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



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

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

#all_test_filesObject



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

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

#clearObject



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

def clear
  system("clear")
end

#commandObject



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

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

#find_and_run_match(thing_to_match) ⇒ Object



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

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



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

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

#runObject



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

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

#run_allObject



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

def run_all
  @matches = all_test_files
  run
end

#set_notifierObject



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

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



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

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



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

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