spicycode-beholder 0.6.1 → 1.0.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/examples/lib/beholder_example.rb +12 -13
- data/lib/beholder.rb +68 -42
- metadata +6 -8
@@ -36,15 +36,7 @@ describe Beholder do
|
|
36
36
|
it "should identify what was changed" do
|
37
37
|
files = ['widgets']
|
38
38
|
beholder = Beholder.new
|
39
|
-
mock(beholder).
|
40
|
-
beholder.on_change files
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should run tests for the file that changed" do
|
44
|
-
files = ['widgets']
|
45
|
-
beholder = Beholder.new
|
46
|
-
stub(beholder).find_matches('widgets') { 'widgets_example' }
|
47
|
-
mock(beholder).run_tests(['widgets_example'])
|
39
|
+
mock(beholder).find_and_populate_matches('widgets', {}) { nil }
|
48
40
|
beholder.on_change files
|
49
41
|
end
|
50
42
|
|
@@ -61,12 +53,12 @@ describe Beholder do
|
|
61
53
|
describe "build_cmd" do
|
62
54
|
it "contructs build cmd for a single file" do
|
63
55
|
beholder = Beholder.new
|
64
|
-
beholder.build_cmd(["test/foo_test.rb"]).should ==
|
56
|
+
beholder.build_cmd("ruby", ["test/foo_test.rb"]).should == "ruby test/foo_test.rb"
|
65
57
|
end
|
66
58
|
|
67
59
|
it "contructs build cmd for a multiple files" do
|
68
60
|
beholder = Beholder.new
|
69
|
-
beholder.build_cmd(["test/foo_test.rb", "test/functionals/foo_test.rb"]).should == %[ruby
|
61
|
+
beholder.build_cmd("ruby", ["test/foo_test.rb", "test/functionals/foo_test.rb"]).should == %[ruby test/foo_test.rb test/functionals/foo_test.rb]
|
70
62
|
end
|
71
63
|
|
72
64
|
end
|
@@ -129,14 +121,21 @@ describe Beholder do
|
|
129
121
|
beholder = Beholder.new
|
130
122
|
blk = lambda { "something" }
|
131
123
|
beholder.map_for(:example) { |m| m.add_mapping(%r%example_helper\.rb%, &blk) }
|
132
|
-
beholder.treasure_maps[:example].should == [[ %r%example_helper\.rb%, blk ]]
|
124
|
+
beholder.treasure_maps[:example].should == [[ %r%example_helper\.rb%, {:command => "ruby"}, blk ]]
|
133
125
|
end
|
134
126
|
|
135
127
|
it "aliases prepare_spell_for to add_mapping" do
|
136
128
|
beholder = Beholder.new
|
137
129
|
blk = lambda { "something" }
|
138
130
|
beholder.map_for(:example) { |m| m.prepare_spell_for(%r%example_helper\.rb%, &blk) }
|
139
|
-
beholder.treasure_maps[:example].should == [[ %r%example_helper\.rb%, blk ]]
|
131
|
+
beholder.treasure_maps[:example].should == [[ %r%example_helper\.rb%, {:command => "ruby"}, blk ]]
|
132
|
+
end
|
133
|
+
|
134
|
+
it "adds mapping using default command of ruby" do
|
135
|
+
beholder = Beholder.new
|
136
|
+
blk = lambda { "something" }
|
137
|
+
beholder.map_for(:example) { |m| m.add_mapping(%r%example_helper\.rb%, &blk) }
|
138
|
+
beholder.treasure_maps[:example].should == [[ %r%example_helper\.rb%, {:command => "ruby"}, blk ]]
|
140
139
|
end
|
141
140
|
end
|
142
141
|
|
data/lib/beholder.rb
CHANGED
@@ -5,30 +5,31 @@ require 'fsevents'
|
|
5
5
|
class Beholder
|
6
6
|
|
7
7
|
attr_reader :paths_to_watch, :sent_an_int, :mappings, :working_directory, :verbose
|
8
|
-
attr_reader :watcher, :treasure_maps, :possible_map_locations, :all_examples
|
9
|
-
|
8
|
+
attr_reader :watcher, :treasure_maps, :possible_map_locations, :all_examples, :default_runner
|
9
|
+
|
10
10
|
def initialize
|
11
11
|
@working_directory = Dir.pwd
|
12
12
|
@paths_to_watch, @all_examples = [], []
|
13
13
|
@mappings, @treasure_maps = {}, {}
|
14
14
|
@sent_an_int = false
|
15
15
|
@verbose = ARGV.include?("-v") || ARGV.include?("--verbose")
|
16
|
+
@default_runner = 'ruby'
|
16
17
|
@possible_map_locations = ["#{@working_directory}/.treasure_map.rb", "#{@working_directory}/treasure_map.rb", "#{@working_directory}/config/treasure_map.rb"]
|
17
18
|
end
|
18
|
-
|
19
|
+
|
19
20
|
def run
|
20
21
|
read_all_maps
|
21
22
|
set_all_examples if all_examples.empty?
|
22
23
|
prepare
|
23
24
|
start
|
24
25
|
end
|
25
|
-
|
26
|
+
|
26
27
|
def self.run
|
27
28
|
beholder = new
|
28
29
|
beholder.run
|
29
30
|
self
|
30
31
|
end
|
31
|
-
|
32
|
+
|
32
33
|
def map_for(map_name)
|
33
34
|
@treasure_maps[map_name] ||= []
|
34
35
|
@current_map = @treasure_maps[map_name]
|
@@ -36,17 +37,22 @@ class Beholder
|
|
36
37
|
ensure
|
37
38
|
@current_map = nil
|
38
39
|
end
|
40
|
+
|
41
|
+
def default_options
|
42
|
+
{ :command => "ruby" }
|
43
|
+
end
|
39
44
|
|
40
|
-
def add_mapping(pattern, &blk)
|
41
|
-
|
45
|
+
def add_mapping(pattern, options = {}, &blk)
|
46
|
+
options = default_options.merge(options)
|
47
|
+
@current_map << [pattern, options, blk]
|
42
48
|
end
|
43
49
|
|
44
50
|
def watch(*paths)
|
45
|
-
|
46
|
-
|
47
|
-
|
51
|
+
@paths_to_watch.concat(paths)
|
52
|
+
@paths_to_watch.uniq!
|
53
|
+
@paths_to_watch.sort!
|
48
54
|
end
|
49
|
-
|
55
|
+
|
50
56
|
alias :keep_a_watchful_eye_for :watch
|
51
57
|
alias :prepare_spell_for :add_mapping
|
52
58
|
|
@@ -57,24 +63,31 @@ class Beholder
|
|
57
63
|
|
58
64
|
def on_change(paths)
|
59
65
|
say "#{paths} changed" unless paths.nil? || paths.empty?
|
66
|
+
|
60
67
|
treasure_maps_changed = paths.select { |p| possible_map_locations.include?(p) }
|
61
68
|
treasure_maps_changed.each {|map_path| read_map_at(map_path) }
|
62
|
-
|
63
|
-
|
69
|
+
|
70
|
+
runners_with_paths = {}
|
71
|
+
paths.each do |path|
|
72
|
+
find_and_populate_matches(path, runners_with_paths)
|
73
|
+
end
|
74
|
+
|
75
|
+
runners_with_paths.each do |runner, paths|
|
76
|
+
paths.uniq!
|
77
|
+
paths.compact!
|
78
|
+
end
|
79
|
+
|
80
|
+
run_tests runners_with_paths
|
64
81
|
end
|
65
|
-
|
82
|
+
|
66
83
|
def examples_matching(name, suffix = "example")
|
67
84
|
regex = %r%.*#{name}_#{suffix}\.rb$%
|
68
85
|
all_examples.find_all { |ex| ex =~ regex }
|
69
86
|
end
|
70
87
|
|
71
|
-
def build_cmd(paths)
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
execute = %[-e "%w[#{classes}].each { |f| require f }"]
|
76
|
-
# Pickup command from treasure map here, probably
|
77
|
-
cmd = "ruby #{execute}"
|
88
|
+
def build_cmd(runner, paths)
|
89
|
+
puts "\nRunning #{paths.join(', ').inspect} with #{runner}"
|
90
|
+
cmd = "#{runner} #{paths.join(' ')}"
|
78
91
|
say cmd
|
79
92
|
cmd
|
80
93
|
end
|
@@ -83,7 +96,7 @@ class Beholder
|
|
83
96
|
read_default_map
|
84
97
|
possible_map_locations.each { |path| read_map_at(path) }
|
85
98
|
end
|
86
|
-
|
99
|
+
|
87
100
|
def read_map_at(path)
|
88
101
|
return unless File.exist?(path)
|
89
102
|
say "Found a map at #{path}"
|
@@ -106,7 +119,7 @@ class Beholder
|
|
106
119
|
puts " Did you just send me an INT? Ugh. I'll quit for real if you do it again."
|
107
120
|
@sent_an_int = true
|
108
121
|
Kernel.sleep 1.5
|
109
|
-
run_tests all_examples
|
122
|
+
run_tests default_runner => all_examples
|
110
123
|
end
|
111
124
|
end
|
112
125
|
end
|
@@ -119,12 +132,12 @@ class Beholder
|
|
119
132
|
end
|
120
133
|
@watcher.run
|
121
134
|
end
|
122
|
-
|
135
|
+
|
123
136
|
def startup_msg
|
124
137
|
puts %[Beholder has loaded - CTRL-C once to reset, twice to quit.]
|
125
138
|
puts %[Watching the following paths: #{paths_to_watch.join(", ")}]
|
126
139
|
end
|
127
|
-
|
140
|
+
|
128
141
|
def read_default_map
|
129
142
|
map_for(:default) do |m|
|
130
143
|
|
@@ -144,20 +157,21 @@ class Beholder
|
|
144
157
|
|
145
158
|
end
|
146
159
|
end
|
147
|
-
|
160
|
+
|
148
161
|
def clear_maps
|
149
162
|
@treasure_maps = {}
|
150
163
|
end
|
151
|
-
|
164
|
+
|
165
|
+
# TODO: These need to be lambdas to catch newly added files
|
152
166
|
def set_all_examples
|
153
167
|
if paths_to_watch.include?('examples')
|
154
168
|
@all_examples += Dir['examples/**/*_example.rb']
|
155
169
|
end
|
156
|
-
|
170
|
+
|
157
171
|
if paths_to_watch.include?('test')
|
158
172
|
@all_examples += Dir['test/**/*_test.rb']
|
159
173
|
end
|
160
|
-
|
174
|
+
|
161
175
|
if paths_to_watch.include?('spec')
|
162
176
|
@all_examples += Dir['spec/**/*_spec.rb']
|
163
177
|
end
|
@@ -167,35 +181,47 @@ class Beholder
|
|
167
181
|
@sent_an_int = false
|
168
182
|
end
|
169
183
|
|
170
|
-
def
|
184
|
+
def find_and_populate_matches(path, runners_with_paths)
|
171
185
|
treasure_maps.each do |name, map|
|
172
|
-
map.each do |pattern, blk|
|
186
|
+
map.each do |pattern, options, blk|
|
187
|
+
run_using = options[:command]
|
173
188
|
if match = path.match(pattern)
|
174
189
|
say "Found the match for #{path} using the #{name} map "
|
175
|
-
|
190
|
+
runners_with_paths[run_using] ||= []
|
191
|
+
runners_with_paths[run_using].concat(blk.call(match))
|
192
|
+
return
|
176
193
|
end
|
177
194
|
end
|
178
195
|
end
|
179
196
|
|
180
197
|
puts "Unknown file: #{path}"
|
181
|
-
return []
|
182
198
|
end
|
199
|
+
|
200
|
+
def run_tests(runners_with_paths)
|
201
|
+
remove_runners_with_no_valid_files_to_run(runners_with_paths)
|
183
202
|
|
184
|
-
|
185
|
-
paths.flatten!
|
203
|
+
return if runners_with_paths.empty?
|
186
204
|
|
187
|
-
|
188
|
-
|
189
|
-
puts "#{path} does not exist." unless found_treasure
|
205
|
+
runners_with_paths.each do |runner, paths|
|
206
|
+
system build_cmd(runner, paths)
|
190
207
|
end
|
191
|
-
|
192
|
-
return if paths.empty?
|
193
|
-
system build_cmd(paths)
|
208
|
+
|
194
209
|
blink
|
195
210
|
end
|
196
|
-
|
211
|
+
|
197
212
|
private
|
198
213
|
|
214
|
+
def remove_runners_with_no_valid_files_to_run(runners_with_paths)
|
215
|
+
runners_with_paths.each do |runner, paths|
|
216
|
+
paths.reject! do |path|
|
217
|
+
found_treasure = File.exist?(path)
|
218
|
+
puts "#{path} does not exist." unless found_treasure
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
runners_with_paths.reject! { |runner, paths| paths.empty? }
|
223
|
+
end
|
224
|
+
|
199
225
|
def say(msg)
|
200
226
|
puts msg if verbose
|
201
227
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spicycode-beholder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chad Humphries, Rob Sanheim
|
@@ -29,24 +29,21 @@ executables:
|
|
29
29
|
extensions: []
|
30
30
|
|
31
31
|
extra_rdoc_files:
|
32
|
-
- README.textile
|
33
32
|
- LICENSE
|
33
|
+
- README.textile
|
34
34
|
- TODO
|
35
35
|
files:
|
36
36
|
- LICENSE
|
37
37
|
- README.textile
|
38
38
|
- Rakefile
|
39
39
|
- TODO
|
40
|
-
- lib/beholder.rb
|
41
40
|
- examples/example_helper.rb
|
42
|
-
- examples/lib
|
43
41
|
- examples/lib/beholder_example.rb
|
44
|
-
-
|
42
|
+
- lib/beholder.rb
|
45
43
|
has_rdoc: true
|
46
44
|
homepage: http://github.com/rsanheim/beholder
|
47
45
|
post_install_message:
|
48
46
|
rdoc_options:
|
49
|
-
- --inline-source
|
50
47
|
- --charset=UTF-8
|
51
48
|
require_paths:
|
52
49
|
- lib
|
@@ -69,5 +66,6 @@ rubygems_version: 1.2.0
|
|
69
66
|
signing_key:
|
70
67
|
specification_version: 2
|
71
68
|
summary: An ancient beholder that watches your treasure, and deals with thiefs
|
72
|
-
test_files:
|
73
|
-
|
69
|
+
test_files:
|
70
|
+
- examples/example_helper.rb
|
71
|
+
- examples/lib/beholder_example.rb
|