rsanheim-beholder 0.5.6 → 0.5.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -48,6 +48,13 @@ describe Beholder do
48
48
  beholder.on_change files
49
49
  end
50
50
 
51
+ it "should match stuff" do
52
+ files = ['widgets']
53
+ beholder = Beholder.new
54
+ stub(beholder).find_matches('widgets') { 'widgets_example' }
55
+ mock(beholder).run_tests(['widgets_example'])
56
+ beholder.on_change files
57
+ end
51
58
  end
52
59
 
53
60
  describe "blink" do
@@ -57,7 +64,7 @@ describe Beholder do
57
64
  beholder.instance_variable_set("@sent_an_int", true) # Not so hot, but I'm tired
58
65
 
59
66
  beholder.sent_an_int.should be_true
60
- beholder.blink
67
+ beholder.__send__ :blink
61
68
  beholder.sent_an_int.should be_false
62
69
  end
63
70
 
@@ -81,4 +88,36 @@ describe Beholder do
81
88
 
82
89
  end
83
90
 
91
+ describe "watch" do
92
+
93
+ it "adds paths to watch" do
94
+ beholder = Beholder.new
95
+ beholder.watch "foo", "bar"
96
+ beholder.paths_to_watch.should == ["foo", "bar"]
97
+ end
98
+
99
+ it "aliases keep_a_watchful_eye_for to watch" do
100
+ beholder = Beholder.new
101
+ beholder.keep_a_watchful_eye_for "foo", "bar"
102
+ beholder.paths_to_watch.should == ["foo", "bar"]
103
+ end
104
+ end
105
+
106
+ describe "add_mapping" do
107
+
108
+ it "adds pattern and block to current_map" do
109
+ beholder = Beholder.new
110
+ blk = lambda { "something" }
111
+ beholder.map_for(:example) { |m| m.add_mapping(%r%example_helper\.rb%, &blk) }
112
+ beholder.treasure_maps[:example].should == [[ %r%example_helper\.rb%, blk ]]
113
+ end
114
+
115
+ it "aliases prepare_spell_for to add_mapping" do
116
+ beholder = Beholder.new
117
+ blk = lambda { "something" }
118
+ beholder.map_for(:example) { |m| m.prepare_spell_for(%r%example_helper\.rb%, &blk) }
119
+ beholder.treasure_maps[:example].should == [[ %r%example_helper\.rb%, blk ]]
120
+ end
121
+ end
122
+
84
123
  end
data/lib/beholder.rb CHANGED
@@ -15,21 +15,58 @@ class Beholder
15
15
  @verbose = ARGV.include?("-v") || ARGV.include?("--verbose")
16
16
  @possible_map_locations = ["#{@working_directory}/.treasure_map.rb", "#{@working_directory}/treasure_map.rb", "#{@working_directory}/config/treasure_map.rb"]
17
17
  end
18
-
18
+
19
+ def run
20
+ read_all_maps
21
+ set_all_examples if all_examples.empty?
22
+ prepare
23
+ start
24
+ end
25
+
19
26
  def self.run
20
27
  beholder = new
21
- beholder.read_all_maps
22
- beholder.set_all_examples if beholder.all_examples.empty?
23
- beholder.prepare
24
- beholder.start
28
+ beholder.run
29
+ self
30
+ end
31
+
32
+ def map_for(map_name)
33
+ @treasure_maps[map_name] ||= []
34
+ @current_map = @treasure_maps[map_name]
35
+ yield self if block_given?
36
+ ensure
37
+ @current_map = nil
38
+ end
39
+
40
+ def add_mapping(pattern, &blk)
41
+ @current_map << [pattern, blk]
42
+ end
43
+
44
+ def watch(*paths)
45
+ @paths_to_watch.concat(paths)
46
+ end
47
+
48
+ alias :keep_a_watchful_eye_for :watch
49
+ alias :prepare_spell_for :add_mapping
50
+
51
+ def shutdown
52
+ watcher.shutdown
53
+ exit
54
+ end
55
+
56
+ def on_change(treasure)
57
+ say "#{treasure} changed" unless treasure.empty?
58
+ matches = treasure.map { |t| find_matches(t) }.uniq.compact
59
+ run_tests matches
25
60
  end
26
61
 
62
+ protected
63
+
27
64
  def read_all_maps
28
65
  read_default_map
29
66
 
30
67
  possible_map_locations.each do |map_location|
31
68
  if File.exist?(map_location)
32
- say "Found a treasure map at #{map_location}"
69
+ say "Found a map at #{map_location}"
33
70
  instance_eval(File.readlines(map_location).join("\n"))
34
71
  return
35
72
  end
@@ -79,18 +116,6 @@ class Beholder
79
116
  end
80
117
  end
81
118
 
82
- def map_for(map_name)
83
- @treasure_maps[map_name] ||= []
84
- @current_map = @treasure_maps[map_name]
85
- yield self if block_given?
86
- ensure
87
- @current_map = nil
88
- end
89
-
90
- def add_mapping(arcane_enemy, &spell)
91
- @current_map << [arcane_enemy, spell]
92
- end
93
-
94
119
  def clear_maps
95
120
  @treasure_maps = {}
96
121
  end
@@ -109,19 +134,10 @@ class Beholder
109
134
  end
110
135
  end
111
136
 
112
- def watch(*paths)
113
- @paths_to_watch.concat(paths)
114
- end
115
-
116
137
  def blink
117
138
  @sent_an_int = false
118
139
  end
119
140
 
120
- def shutdown
121
- watcher.shutdown
122
- exit
123
- end
124
-
125
141
  def find_matches(treasure)
126
142
  treasure_maps.each do |name, treasure_locations|
127
143
  treasure_locations.each do |stolen_by_enemy, spell|
@@ -151,12 +167,6 @@ class Beholder
151
167
  blink
152
168
  end
153
169
 
154
- def on_change(treasure)
155
- say "#{treasure} changed" unless treasure.empty?
156
- matches = treasure.map { |t| find_matches(t) }.uniq.compact
157
- run_tests matches
158
- end
159
-
160
170
  private
161
171
  def say(msg)
162
172
  puts msg if verbose
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.6
4
+ version: 0.5.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chad Humphries, Rob Sanheim