autowatchr 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{autowatchr}
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jeremy Stephens"]
12
- s.date = %q{2009-10-02}
12
+ s.date = %q{2009-10-06}
13
13
  s.description = %q{Provides some autotest-like behavior for watchr (http://github.com/mynyml/watchr).}
14
14
  s.email = %q{viking415@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -65,6 +65,19 @@ class Autowatchr
65
65
  end
66
66
  end
67
67
 
68
+ class Tee < StringIO
69
+ attr_reader :io
70
+ def initialize(io)
71
+ super("")
72
+ @io = io
73
+ end
74
+
75
+ def write(string)
76
+ super
77
+ @io.write(string)
78
+ end
79
+ end
80
+
68
81
  attr_reader :config
69
82
 
70
83
  def initialize(script, options = {})
@@ -114,25 +127,8 @@ class Autowatchr
114
127
  cmd = commands.join("; ")
115
128
  puts cmd
116
129
 
117
- # straight outta autotest
118
- results = []
119
- line = []
120
- open("| #{cmd}", "r") do |f|
121
- until f.eof? do
122
- c = f.getc
123
- putc c
124
- line << c
125
- if c == ?\n then
126
- results << if RUBY_VERSION >= "1.9" then
127
- line.join
128
- else
129
- line.pack "c*"
130
- end
131
- line.clear
132
- end
133
- end
134
- end
135
- handle_results(results.join, files)
130
+ results = execute_cmd(cmd)
131
+ handle_results(results, files)
136
132
  end
137
133
 
138
134
  def classname_to_path(s)
@@ -153,6 +149,20 @@ class Autowatchr
153
149
  @script.watch(@config.lib_re) { |md| run_lib_file(md[0]) }
154
150
  end
155
151
 
152
+ def execute_cmd(cmd)
153
+ tee = Tee.new($stdout)
154
+ $stdout = tee
155
+
156
+ system(cmd)
157
+
158
+ $stdout = tee.io
159
+ tee.rewind
160
+ results = tee.read
161
+ tee.close
162
+
163
+ results
164
+ end
165
+
156
166
  def handle_results(results, files_ran)
157
167
  return if !@config.failing_only
158
168
  num_previously_failed = @failed_tests.length
@@ -9,21 +9,42 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
9
9
  require 'autowatchr'
10
10
 
11
11
  class Test::Unit::TestCase
12
- def fake_result(name)
13
- StringIO.new(open(File.dirname(__FILE__) + "/fixtures/results/#{name}.txt").read)
12
+ end
13
+
14
+ module Mocha::ObjectMethods
15
+ def stubs_system_call(result_name = nil)
16
+ self.stubs(:system).with() do |_|
17
+ $stdout.print(result_name ? fake_result(result_name) : "")
18
+ true
19
+ end
14
20
  end
15
21
 
16
- # File vendor/rails/activesupport/lib/active_support/core_ext/kernel/reporting.rb, line 36
17
- def silence_stream(stream)
18
- old_stream = stream.dup
19
- stream.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null')
20
- stream.sync = true
21
- yield
22
- ensure
23
- stream.reopen(old_stream)
22
+ def expects_system_call(expected_command, result_name = nil)
23
+ self.expects(:system).with() do |actual_command|
24
+ if expected_command == actual_command
25
+ $stdout.print(result_name ? fake_result(result_name) : "")
26
+ true
27
+ else
28
+ false
29
+ end
30
+ end
24
31
  end
25
32
  end
26
33
 
34
+ def fake_result(name)
35
+ open(File.dirname(__FILE__) + "/fixtures/results/#{name}.txt").read
36
+ end
37
+
38
+ # File vendor/rails/activesupport/lib/active_support/core_ext/kernel/reporting.rb, line 36
39
+ def silence_stream(stream)
40
+ old_stream = stream.dup
41
+ stream.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null')
42
+ stream.sync = true
43
+ yield
44
+ ensure
45
+ stream.reopen(old_stream)
46
+ end
47
+
27
48
  def debug_p(obj, label = nil)
28
49
  $stderr.print "#{label}: " if label
29
50
  $stderr.puts obj.inspect
@@ -13,7 +13,7 @@ class TestAutowatchr < Test::Unit::TestCase
13
13
  @script = stub("fake watchr script", :watch => nil)
14
14
  @lib_dir = File.dirname(__FILE__) + "/fixtures/lib"
15
15
  @test_dir = File.dirname(__FILE__) + "/fixtures/test"
16
- Autowatchr.any_instance.stubs(:open)
16
+ Autowatchr.any_instance.stubs_system_call
17
17
  end
18
18
 
19
19
  def test_new_with_hash
@@ -86,9 +86,8 @@ class TestAutowatchr < Test::Unit::TestCase
86
86
  end
87
87
 
88
88
  def test_run_lib_file
89
- result = fake_result("foo")
90
- expected_cmd = "| /usr/local/bin/ruby -I.:#{@lib_dir}:#{@test_dir} #{@test_dir}/test_foo.rb"
91
- Autowatchr.any_instance.expects(:open).with(expected_cmd, "r").yields(result)
89
+ expected_cmd = "/usr/local/bin/ruby -I.:#{@lib_dir}:#{@test_dir} #{@test_dir}/test_foo.rb"
90
+ Autowatchr.any_instance.expects_system_call(expected_cmd, "foo")
92
91
 
93
92
  silence_stream(STDOUT) do
94
93
  aw = new_autowatchr
@@ -97,9 +96,8 @@ class TestAutowatchr < Test::Unit::TestCase
97
96
  end
98
97
 
99
98
  def test_running_multiple_test_files
100
- result = fake_result("all")
101
- expected_cmd = "| /usr/local/bin/ruby -I.:#{@lib_dir}:#{@test_dir} -e \"%w[#{@test_dir}/test_bar.rb #{@test_dir}/test_foo.rb].each { |f| require f }\""
102
- Autowatchr.any_instance.expects(:open).with(expected_cmd, "r").yields(result)
99
+ expected_cmd = "/usr/local/bin/ruby -I.:#{@lib_dir}:#{@test_dir} -e \"%w[#{@test_dir}/test_bar.rb #{@test_dir}/test_foo.rb].each { |f| require f }\""
100
+ Autowatchr.any_instance.expects_system_call(expected_cmd, "all")
103
101
 
104
102
  silence_stream(STDOUT) do
105
103
  aw = new_autowatchr
@@ -108,10 +106,9 @@ class TestAutowatchr < Test::Unit::TestCase
108
106
  end
109
107
 
110
108
  def test_runs_all_test_files_on_start
111
- result = fake_result("all")
112
109
  files = Dir.glob("#{@test_dir}/**/test_*.rb").join(" ")
113
- expected_cmd = %!| /usr/local/bin/ruby -I.:#{@lib_dir}:#{@test_dir} -e "%w[#{files}].each { |f| require f }"!
114
- Autowatchr.any_instance.expects(:open).with(expected_cmd, "r").yields(result)
110
+ expected_cmd = %!/usr/local/bin/ruby -I.:#{@lib_dir}:#{@test_dir} -e "%w[#{files}].each { |f| require f }"!
111
+ Autowatchr.any_instance.expects_system_call(expected_cmd, "all")
115
112
 
116
113
  silence_stream(STDOUT) do
117
114
  new_autowatchr
@@ -127,16 +124,14 @@ class TestAutowatchr < Test::Unit::TestCase
127
124
  end
128
125
 
129
126
  def test_only_runs_failing_tests
130
- result = fake_result("all")
131
- Autowatchr.any_instance.stubs(:open).yields(result)
127
+ Autowatchr.any_instance.stubs_system_call("all")
132
128
  aw = nil
133
129
  silence_stream(STDOUT) do
134
130
  aw = new_autowatchr
135
131
  end
136
132
 
137
- result = fake_result("foo_flunk")
138
- expected_cmd = %!| /usr/local/bin/ruby -I.:#{@lib_dir}:#{@test_dir} #{@test_dir}/test_foo.rb -n "/^(test_flunk)$/"!
139
- aw.expects(:open).with(expected_cmd, "r").yields(result)
133
+ expected_cmd = %!/usr/local/bin/ruby -I.:#{@lib_dir}:#{@test_dir} #{@test_dir}/test_foo.rb -n "/^(test_flunk)$/"!
134
+ aw.expects_system_call(expected_cmd, "foo_flunk")
140
135
 
141
136
  silence_stream(STDOUT) do
142
137
  aw.run_test_file("#{@test_dir}/test_foo.rb")
@@ -144,65 +139,57 @@ class TestAutowatchr < Test::Unit::TestCase
144
139
  end
145
140
 
146
141
  def test_clears_failing_test_when_it_passes
147
- result = fake_result("all")
148
- Autowatchr.any_instance.stubs(:open).yields(result)
142
+ Autowatchr.any_instance.stubs_system_call("all")
149
143
  aw = nil
150
144
  silence_stream(STDOUT) do
151
145
  aw = new_autowatchr
152
146
  end
153
147
 
154
- result = fake_result("foo_pass")
148
+ aw.stubs_system_call("foo_pass")
155
149
  silence_stream(STDOUT) do
156
150
  aw.run_test_file("#{@test_dir}/test_foo.rb")
157
151
  end
158
152
 
159
- result = fake_result("foo")
160
- expected_cmd = %!| /usr/local/bin/ruby -I.:#{@lib_dir}:#{@test_dir} #{@test_dir}/test_foo.rb!
161
- aw.expects(:open).with(expected_cmd, "r").yields(result)
153
+ expected_cmd = %!/usr/local/bin/ruby -I.:#{@lib_dir}:#{@test_dir} #{@test_dir}/test_foo.rb!
154
+ aw.expects_system_call(expected_cmd, "foo")
162
155
  silence_stream(STDOUT) do
163
156
  aw.run_test_file("#{@test_dir}/test_foo.rb")
164
157
  end
165
158
  end
166
159
 
167
160
  def test_not_only_running_failing_tests
168
- result = fake_result("all")
169
- Autowatchr.any_instance.stubs(:open).yields(result)
161
+ Autowatchr.any_instance.stubs_system_call("all")
170
162
  aw = nil
171
163
  silence_stream(STDOUT) do
172
164
  aw = new_autowatchr(:failing_only => false)
173
165
  end
174
166
 
175
- result = fake_result("foo")
176
- expected_cmd = %!| /usr/local/bin/ruby -I.:#{@lib_dir}:#{@test_dir} #{@test_dir}/test_foo.rb!
177
- aw.expects(:open).with(expected_cmd, "r").yields(result)
167
+ expected_cmd = %!/usr/local/bin/ruby -I.:#{@lib_dir}:#{@test_dir} #{@test_dir}/test_foo.rb!
168
+ aw.expects_system_call(expected_cmd, "foo")
178
169
  silence_stream(STDOUT) do
179
170
  aw.run_test_file("#{@test_dir}/test_foo.rb")
180
171
  end
181
172
  end
182
173
 
183
174
  def test_running_entire_suite_after_green
184
- result_1 = fake_result("all")
185
- Autowatchr.any_instance.stubs(:open).yields(result_1)
175
+ Autowatchr.any_instance.stubs_system_call("all")
186
176
  aw = nil
187
177
  silence_stream(STDOUT) do
188
178
  aw = new_autowatchr
189
179
  end
190
180
 
191
- result_2 = fake_result("foo_pass")
192
- expected_cmd_2 = %!| /usr/local/bin/ruby -I.:#{@lib_dir}:#{@test_dir} #{@test_dir}/test_foo.rb -n "/^(test_flunk)$/"!
193
- aw.expects(:open).with(expected_cmd_2, "r").yields(result_2)
181
+ expected_cmd_2 = %!/usr/local/bin/ruby -I.:#{@lib_dir}:#{@test_dir} #{@test_dir}/test_foo.rb -n "/^(test_flunk)$/"!
182
+ aw.expects_system_call(expected_cmd_2, "foo_pass")
194
183
  silence_stream(STDOUT) do
195
184
  aw.run_test_file("#{@test_dir}/test_foo.rb")
196
185
  end
197
186
 
198
- result_3 = fake_result("bar_pass")
199
- expected_cmd_3 = %!| /usr/local/bin/ruby -I.:#{@lib_dir}:#{@test_dir} #{@test_dir}/test_bar.rb -n "/^(test_flunk)$/"!
200
- aw.expects(:open).with(expected_cmd_3, "r").yields(result_3)
187
+ expected_cmd_3 = %!/usr/local/bin/ruby -I.:#{@lib_dir}:#{@test_dir} #{@test_dir}/test_bar.rb -n "/^(test_flunk)$/"!
188
+ aw.expects_system_call(expected_cmd_3, "bar_pass")
201
189
 
202
190
  files = Dir.glob("#{@test_dir}/**/test_*.rb").join(" ")
203
- result_4 = fake_result("all")
204
- expected_cmd_4 = %!| /usr/local/bin/ruby -I.:#{@lib_dir}:#{@test_dir} -e "%w[#{files}].each { |f| require f }"!
205
- aw.expects(:open).with(expected_cmd_4, "r").yields(result_4)
191
+ expected_cmd_4 = %!/usr/local/bin/ruby -I.:#{@lib_dir}:#{@test_dir} -e "%w[#{files}].each { |f| require f }"!
192
+ aw.expects_system_call(expected_cmd_4, "all")
206
193
 
207
194
  silence_stream(STDOUT) do
208
195
  aw.run_test_file("#{@test_dir}/test_bar.rb")
@@ -210,23 +197,20 @@ class TestAutowatchr < Test::Unit::TestCase
210
197
  end
211
198
 
212
199
  def test_not_running_entire_suite_after_green
213
- result_1 = fake_result("all")
214
- Autowatchr.any_instance.stubs(:open).yields(result_1)
200
+ Autowatchr.any_instance.stubs_system_call("all")
215
201
  aw = nil
216
202
  silence_stream(STDOUT) do
217
203
  aw = new_autowatchr(:run_suite => false)
218
204
  end
219
205
 
220
- result_2 = fake_result("foo_pass")
221
- expected_cmd_2 = %!| /usr/local/bin/ruby -I.:#{@lib_dir}:#{@test_dir} #{@test_dir}/test_foo.rb -n "/^(test_flunk)$/"!
222
- aw.expects(:open).with(expected_cmd_2, "r").yields(result_2)
206
+ expected_cmd_2 = %!/usr/local/bin/ruby -I.:#{@lib_dir}:#{@test_dir} #{@test_dir}/test_foo.rb -n "/^(test_flunk)$/"!
207
+ aw.expects_system_call(expected_cmd_2, "foo_pass")
223
208
  silence_stream(STDOUT) do
224
209
  aw.run_test_file("#{@test_dir}/test_foo.rb")
225
210
  end
226
211
 
227
- result_3 = fake_result("bar_pass")
228
- expected_cmd_3 = %!| /usr/local/bin/ruby -I.:#{@lib_dir}:#{@test_dir} #{@test_dir}/test_bar.rb -n "/^(test_flunk)$/"!
229
- aw.expects(:open).with(expected_cmd_3, "r").yields(result_3)
212
+ expected_cmd_3 = %!/usr/local/bin/ruby -I.:#{@lib_dir}:#{@test_dir} #{@test_dir}/test_bar.rb -n "/^(test_flunk)$/"!
213
+ aw.expects_system_call(expected_cmd_3, "bar_pass")
230
214
 
231
215
  silence_stream(STDOUT) do
232
216
  aw.run_test_file("#{@test_dir}/test_bar.rb")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: autowatchr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Stephens
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-02 00:00:00 -05:00
12
+ date: 2009-10-06 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency