Class: Beholder
- Inherits:
-
Object
- Object
- Beholder
- Defined in:
- lib/beholder.rb
Constant Summary collapse
- DEFAULT_RUNNER =
'ruby'
Class Attribute Summary collapse
-
.on_failure ⇒ Object
Returns the value of attribute on_failure.
-
.on_success ⇒ Object
Returns the value of attribute on_success.
- .possible_treasure_map_locations ⇒ Object
- .test_types ⇒ Object
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
- .all_tests ⇒ Object
- .run ⇒ Object
- .runner ⇒ Object
- .runner=(new_runner) ⇒ Object
- .test_directories ⇒ Object
- .test_extensions ⇒ Object
Instance Method Summary collapse
- #build_cmd(runner, paths) ⇒ 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.
60 61 62 63 64 65 |
# File 'lib/beholder.rb', line 60 def initialize @paths_to_watch = [] @mappings, @treasure_maps = {}, {} @sent_an_int = false @be_verbose = ARGV.include?("-v") || ARGV.include?("--verbose") end |
Class Attribute Details
.on_failure ⇒ Object
Returns the value of attribute on_failure.
9 10 11 |
# File 'lib/beholder.rb', line 9 def on_failure @on_failure end |
.on_success ⇒ Object
Returns the value of attribute on_success.
9 10 11 |
# File 'lib/beholder.rb', line 9 def on_success @on_success end |
.possible_treasure_map_locations ⇒ Object
19 20 21 |
# File 'lib/beholder.rb', line 19 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 |
.test_types ⇒ Object
23 24 25 |
# File 'lib/beholder.rb', line 23 def test_types @test_types ||= %w{spec examples test} end |
Instance Attribute Details
#be_verbose ⇒ Object (readonly)
Returns the value of attribute be_verbose.
57 58 59 |
# File 'lib/beholder.rb', line 57 def be_verbose @be_verbose end |
#mappings ⇒ Object (readonly)
Returns the value of attribute mappings.
57 58 59 |
# File 'lib/beholder.rb', line 57 def mappings @mappings end |
#paths_to_watch ⇒ Object (readonly)
Returns the value of attribute paths_to_watch.
57 58 59 |
# File 'lib/beholder.rb', line 57 def paths_to_watch @paths_to_watch end |
#sent_an_int ⇒ Object (readonly)
Returns the value of attribute sent_an_int.
57 58 59 |
# File 'lib/beholder.rb', line 57 def sent_an_int @sent_an_int end |
#treasure_maps ⇒ Object (readonly)
Returns the value of attribute treasure_maps.
58 59 60 |
# File 'lib/beholder.rb', line 58 def treasure_maps @treasure_maps end |
#watcher ⇒ Object (readonly)
Returns the value of attribute watcher.
58 59 60 |
# File 'lib/beholder.rb', line 58 def watcher @watcher end |
Class Method Details
.all_tests ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/beholder.rb', line 40 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
73 74 75 76 77 |
# File 'lib/beholder.rb', line 73 def self.run beholder = new beholder.run self end |
.runner ⇒ Object
11 12 13 |
# File 'lib/beholder.rb', line 11 def runner @runner ||= ::Beholder::DEFAULT_RUNNER end |
.runner=(new_runner) ⇒ Object
15 16 17 |
# File 'lib/beholder.rb', line 15 def runner=(new_runner) @runner = new_runner end |
.test_directories ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/beholder.rb', line 31 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
27 28 29 |
# File 'lib/beholder.rb', line 27 def test_extensions @test_extensions ||= %w{spec example test} end |
Instance Method Details
#build_cmd(runner, paths) ⇒ Object
131 132 133 134 135 136 |
# File 'lib/beholder.rb', line 131 def build_cmd(runner, paths) puts "\nRunning #{paths.join(', ').inspect} with #{runner}" cmd = "#{runner} #{paths.join(' ')}" say cmd cmd 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
79 80 81 82 83 84 85 |
# File 'lib/beholder.rb', line 79 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 123 124 |
# File 'lib/beholder.rb', line 105 def on_change(paths) say "#{paths} changed" unless paths.nil? || paths.empty? paths.reject! { |path| ::Beholder.possible_treasure_map_locations.include?(path) } runners_with_paths = {} paths.each do |path| runner, tests = *find_and_populate_matches(path) next if tests.nil? || tests.empty? tests.uniq! tests.compact! if tests.any? runners_with_paths[runner] = tests end end run_tests runners_with_paths end |
#prepare_spell_for(pattern, options = {}, &blk) ⇒ Object Also known as: add_mapping
87 88 89 |
# File 'lib/beholder.rb', line 87 def prepare_spell_for(pattern, = {}, &blk) @current_map << [pattern, , blk] end |
#read_all_maps ⇒ Object
138 139 140 141 |
# File 'lib/beholder.rb', line 138 def read_all_maps read_default_map ::Beholder::possible_treasure_map_locations.each { |path| read_map_at(path) } end |
#read_map_at(path) ⇒ Object
143 144 145 146 147 148 149 150 151 152 |
# File 'lib/beholder.rb', line 143 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
67 68 69 70 71 |
# File 'lib/beholder.rb', line 67 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 |