rsanheim-beholder 0.5.13 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Rakefile CHANGED
@@ -1,5 +1,3 @@
1
- GEM_VERSION = "0.5.5.1"
2
-
3
1
  begin
4
2
  require 'jeweler'
5
3
  Jeweler::Tasks.new do |s|
@@ -48,6 +48,14 @@ describe Beholder do
48
48
  beholder.on_change files
49
49
  end
50
50
 
51
+ it "should re-eval the treasure map if the map was modified" do
52
+ treasure_map = "#{Dir.pwd}/.treasure_map.rb"
53
+ beholder = Beholder.new
54
+ stub(File).exist?(treasure_map) { true }
55
+ mock(beholder).read_map_at(treasure_map)
56
+ beholder.on_change treasure_map
57
+ end
58
+
51
59
  end
52
60
 
53
61
  describe "build_cmd" do
@@ -98,14 +106,20 @@ describe Beholder do
98
106
 
99
107
  it "adds paths to watch" do
100
108
  beholder = Beholder.new
101
- beholder.watch "foo", "bar"
102
- beholder.paths_to_watch.should == ["foo", "bar"]
109
+ beholder.watch "bar", "foo"
110
+ beholder.paths_to_watch.should == ["bar", "foo"]
103
111
  end
104
112
 
105
113
  it "aliases keep_a_watchful_eye_for to watch" do
106
114
  beholder = Beholder.new
107
- beholder.keep_a_watchful_eye_for "foo", "bar"
108
- beholder.paths_to_watch.should == ["foo", "bar"]
115
+ beholder.keep_a_watchful_eye_for "bar", "foo"
116
+ beholder.paths_to_watch.should == ["bar", "foo"]
117
+ end
118
+
119
+ it "should uniq and sort the paths" do
120
+ beholder = Beholder.new
121
+ beholder.watch "foo", "bar", "specs", "foo", "bar", "bar2"
122
+ beholder.paths_to_watch.should == ["bar", "bar2", "foo", "specs"]
109
123
  end
110
124
  end
111
125
 
@@ -135,4 +149,30 @@ describe Beholder do
135
149
  end
136
150
  end
137
151
 
152
+ describe "read_map_at" do
153
+
154
+ it "rescues exceptions from instance_eval'ing the map, and carrys on" do
155
+ beholder = Beholder.new
156
+ stub(File).exist? { true }
157
+ mock(File).readlines("my_map.rb") { ["!and this is invalid Ruby;end\nand more"] }
158
+ stub(beholder).puts
159
+ lambda { beholder.read_map_at("my_map.rb") }.should_not raise_error
160
+ end
161
+
162
+ end
163
+
164
+ describe "output" do
165
+
166
+ it "say puts to stdout if verbose is true" do
167
+ begin
168
+ ARGV.push("-v")
169
+ beholder = Beholder.new
170
+ mock(beholder).puts("yo dawg")
171
+ beholder.__send__ :say, "yo dawg"
172
+ ensure
173
+ ARGV.pop
174
+ end
175
+ end
176
+ end
177
+
138
178
  end
data/lib/beholder.rb CHANGED
@@ -42,7 +42,9 @@ class Beholder
42
42
  end
43
43
 
44
44
  def watch(*paths)
45
- @paths_to_watch.concat(paths)
45
+ self.paths_to_watch.concat(paths)
46
+ self.paths_to_watch.uniq!
47
+ self.paths_to_watch.sort!
46
48
  end
47
49
 
48
50
  alias :keep_a_watchful_eye_for :watch
@@ -55,6 +57,8 @@ class Beholder
55
57
 
56
58
  def on_change(paths)
57
59
  say "#{paths} changed" unless paths.nil? || paths.empty?
60
+ treasure_maps_changed = paths.select { |p| possible_map_locations.include?(p) }
61
+ treasure_maps_changed.each {|map_path| read_map_at(map_path) }
58
62
  matches = paths.map { |path| find_matches(path) }.uniq.compact
59
63
  run_tests matches
60
64
  end
@@ -73,20 +77,24 @@ class Beholder
73
77
  cmd
74
78
  end
75
79
 
76
- protected
77
-
78
80
  def read_all_maps
79
81
  read_default_map
80
-
81
- possible_map_locations.each do |map_location|
82
- if File.exist?(map_location)
83
- say "Found a map at #{map_location}"
84
- instance_eval(File.readlines(map_location).join("\n"))
85
- return
86
- end
82
+ possible_map_locations.each { |path| read_map_at(path) }
83
+ end
84
+
85
+ def read_map_at(path)
86
+ return unless File.exist?(path)
87
+ say "Found a map at #{path}"
88
+ begin
89
+ instance_eval(File.readlines(path).join("\n"))
90
+ rescue Object => e
91
+ puts "Exception caught trying to load map at #{path}"
92
+ puts e
87
93
  end
88
94
  end
89
95
 
96
+ protected
97
+
90
98
  def prepare
91
99
  trap 'INT' do
92
100
  if @sent_an_int then
@@ -102,13 +110,18 @@ class Beholder
102
110
  end
103
111
 
104
112
  def start
105
- say("Watching the following locations:\n #{paths_to_watch.join(", ")}")
113
+ startup_msg
106
114
  @watcher = FSEvents::Stream.watch(paths_to_watch) do |event|
107
115
  on_change(event.modified_files)
108
- puts "\n\nWaiting to hear from the disk since #{Time.now}"
116
+ puts "\n\nWaiting for changes since #{Time.now}"
109
117
  end
110
118
  @watcher.run
111
- end
119
+ end
120
+
121
+ def startup_msg
122
+ puts %[Beholder has loaded - CTRL-C once to reset, twice to quit.]
123
+ puts %[Watching the following paths: #{paths_to_watch.join(", ")}]
124
+ end
112
125
 
113
126
  def read_default_map
114
127
  map_for(:default) do |m|
@@ -180,6 +193,7 @@ class Beholder
180
193
  end
181
194
 
182
195
  private
196
+
183
197
  def say(msg)
184
198
  puts msg if verbose
185
199
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rsanheim-beholder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.13
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chad Humphries, Rob Sanheim
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-05 00:00:00 -08:00
12
+ date: 2009-03-23 00:00:00 -07:00
13
13
  default_executable: beholder
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency