Class: Beholder
- Inherits:
-
Object
- Object
- Beholder
- Defined in:
- lib/beholder.rb
Constant Summary collapse
- DEFAULT_RUNNER =
'ruby'
Class Attribute Summary collapse
Instance Attribute Summary collapse
-
#be_verbose ⇒ Object
readonly
Returns the value of attribute be_verbose.
-
#mappings ⇒ Object
readonly
Returns the value of attribute mappings.
-
#paths_to_watch ⇒ Object
readonly
Returns the value of attribute paths_to_watch.
-
#sent_an_int ⇒ Object
readonly
Returns the value of attribute sent_an_int.
-
#treasure_maps ⇒ Object
readonly
Returns the value of attribute treasure_maps.
-
#watcher ⇒ Object
readonly
Returns the value of attribute watcher.
Class Method Summary collapse
Instance Method Summary collapse
- #build_cmd(runner, paths) ⇒ Object
- #default_options ⇒ Object
-
#initialize ⇒ Beholder
constructor
A new instance of Beholder.
- #keep_a_watchful_eye_for(*paths) ⇒ Object (also: #watch)
- #map_for(map_name) ⇒ Object
- #on_change(paths) ⇒ Object
- #prepare_spell_for(pattern, options = {}, &blk) ⇒ Object (also: #add_mapping)
- #read_all_maps ⇒ Object
- #read_map_at(path) ⇒ Object
- #run ⇒ Object
- #shutdown ⇒ Object
- #tests_matching(name) ⇒ Object
Constructor Details
#initialize ⇒ Beholder
Returns a new instance of Beholder.
55 56 57 58 59 60 |
# File 'lib/beholder.rb', line 55 def initialize @paths_to_watch = [] @mappings, @treasure_maps = {}, {} @sent_an_int = false @be_verbose = ARGV.include?("-v") || ARGV.include?("--verbose") end |
Class Attribute Details
.possible_treasure_map_locations ⇒ Object
14 15 16 |
# File 'lib/beholder.rb', line 14 def possible_treasure_map_locations @possible_treasure_map_locations ||= ["#{Dir.pwd}/.treasure_map.rb", "#{Dir.pwd}/treasure_map.rb", "#{Dir.pwd}/config/treasure_map.rb"] end |
.runner ⇒ Object
10 11 12 |
# File 'lib/beholder.rb', line 10 def runner @runner ||= ::Beholder::DEFAULT_RUNNER end |
.test_types ⇒ Object
18 19 20 |
# File 'lib/beholder.rb', line 18 def test_types @test_types ||= %w{spec examples test} end |
Instance Attribute Details
#be_verbose ⇒ Object (readonly)
Returns the value of attribute be_verbose.
52 53 54 |
# File 'lib/beholder.rb', line 52 def be_verbose @be_verbose end |
#mappings ⇒ Object (readonly)
Returns the value of attribute mappings.
52 53 54 |
# File 'lib/beholder.rb', line 52 def mappings @mappings end |
#paths_to_watch ⇒ Object (readonly)
Returns the value of attribute paths_to_watch.
52 53 54 |
# File 'lib/beholder.rb', line 52 def paths_to_watch @paths_to_watch end |
#sent_an_int ⇒ Object (readonly)
Returns the value of attribute sent_an_int.
52 53 54 |
# File 'lib/beholder.rb', line 52 def sent_an_int @sent_an_int end |
#treasure_maps ⇒ Object (readonly)
Returns the value of attribute treasure_maps.
53 54 55 |
# File 'lib/beholder.rb', line 53 def treasure_maps @treasure_maps end |
#watcher ⇒ Object (readonly)
Returns the value of attribute watcher.
53 54 55 |
# File 'lib/beholder.rb', line 53 def watcher @watcher end |
Class Method Details
.all_tests ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/beholder.rb', line 35 def all_tests lambda { dirs = [] test_directories.each do |dir| test_extensions.each do |test_ext| files = Dir["#{dir}/**/*_#{test_ext}.rb"] # Ignore tarantula tests for now until we add a cleaner way files.reject! { |file| file.include?('tarantula/') } next if files.empty? dirs << files end end dirs.flatten! }.call end |
.run ⇒ Object
68 69 70 71 72 |
# File 'lib/beholder.rb', line 68 def self.run beholder = new beholder.run self end |
.test_directories ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/beholder.rb', line 26 def test_directories return @test_directories if @test_directories @test_directories = [] test_types.each do |test_type| @test_directories << test_type if File.exist?(test_type) end @test_directories end |
.test_extensions ⇒ Object
22 23 24 |
# File 'lib/beholder.rb', line 22 def test_extensions @test_extensions ||= %w{spec example test} end |
Instance Method Details
#build_cmd(runner, paths) ⇒ Object
129 130 131 132 133 134 |
# File 'lib/beholder.rb', line 129 def build_cmd(runner, paths) puts "\nRunning #{paths.join(', ').inspect} with #{runner}" cmd = "#{runner} #{paths.join(' ')}" say cmd cmd end |
#default_options ⇒ Object
82 83 84 |
# File 'lib/beholder.rb', line 82 def { :command => ::Beholder.runner } end |
#keep_a_watchful_eye_for(*paths) ⇒ Object Also known as: watch
91 92 93 94 95 |
# File 'lib/beholder.rb', line 91 def keep_a_watchful_eye_for(*paths) @paths_to_watch.concat(paths) @paths_to_watch.uniq! @paths_to_watch.sort! end |
#map_for(map_name) ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/beholder.rb', line 74 def map_for(map_name) @treasure_maps[map_name] ||= [] @current_map = @treasure_maps[map_name] yield self if block_given? ensure @current_map = nil end |
#on_change(paths) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/beholder.rb', line 105 def on_change(paths) say "#{paths} changed" unless paths.nil? || paths.empty? treasure_maps_changed = paths.select { |p| ::Beholder.possible_treasure_map_locations.include?(p) } treasure_maps_changed.each {|map_path| read_map_at(map_path) } runners_with_paths = {} paths.each do |path| find_and_populate_matches(path, runners_with_paths) end runners_with_paths.each do |runner, paths| paths.uniq! paths.compact! end run_tests runners_with_paths end |
#prepare_spell_for(pattern, options = {}, &blk) ⇒ Object Also known as: add_mapping
86 87 88 89 |
# File 'lib/beholder.rb', line 86 def prepare_spell_for(pattern, = {}, &blk) = .merge() @current_map << [pattern, , blk] end |
#read_all_maps ⇒ Object
136 137 138 139 |
# File 'lib/beholder.rb', line 136 def read_all_maps read_default_map ::Beholder::possible_treasure_map_locations.each { |path| read_map_at(path) } end |
#read_map_at(path) ⇒ Object
141 142 143 144 145 146 147 148 149 150 |
# File 'lib/beholder.rb', line 141 def read_map_at(path) return unless File.exist?(path) say "Found a map at #{path}" begin instance_eval(File.readlines(path).join("\n")) rescue Object => e puts "Exception caught trying to load map at #{path}" puts e end end |
#run ⇒ Object
62 63 64 65 66 |
# File 'lib/beholder.rb', line 62 def run read_all_maps prepare start end |
#shutdown ⇒ Object
100 101 102 103 |
# File 'lib/beholder.rb', line 100 def shutdown watcher.shutdown exit end |