autospec.watchr 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Andrew Timberlake
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
File without changes
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env ruby
2
+ system("watchr #{File.join(File.dirname(__FILE__), '..', 'lib', 'autospec.watchr.rb')}")
@@ -0,0 +1,108 @@
1
+ require 'set'
2
+ puts "Waiting... (Save a source or spec file and watch the magic happen)
3
+
4
+ watch(/spec\/factories.rb$/) { |file| spec(Dir["spec/**/*_spec.rb"]) }
5
+ watch(/config\/environment.*$/) { |file| spec(Dir["spec/**/*_spec.rb"]) }
6
+ watch(/config\/initializers\/.*$/) { |file| spec(Dir["spec/**/*_spec.rb"]) }
7
+ %w(helpers models controllers views).each do |spec_dir|
8
+ watch(/app\/#{spec_dir}\/.*\.rb/) { |file| spec(Dir["spec/**/#{file.to_s.sub(/.*\/([^\/]+).rb$/, '\1_spec.rb')}"]) }
9
+ watch(/spec\/#{spec_dir}\/.*\.rb/) { |file| spec(file) }
10
+ end
11
+ watch(/lib\/.*\.rb/) { |file| spec(Dir["spec/**/#{file.to_s.sub(/.*\/([^\/]+).rb$/, '\1_spec.rb')}"]) }
12
+ watch(/spec\/lib\/.*\.rb/) { |file| spec(file) }
13
+
14
+ # --------------------------------------------------
15
+ # Signal Handling
16
+ # --------------------------------------------------
17
+ Signal.trap('QUIT') { spec tests} # Ctrl-\
18
+ Signal.trap('INT' ) { abort("\n") } # Ctrl-C
19
+
20
+ # --------------------------------------------------
21
+ # Helpers
22
+ # --------------------------------------------------
23
+ @running_previous_error = false
24
+ @errors = Hash.new { |h,k| h[k] = [] }
25
+
26
+ def spec(*paths)
27
+ if paths.flatten.size > 0
28
+ paths = check_for_previous_errors(paths)
29
+
30
+ result = run spec_command(paths)
31
+ if @running_previous_error && result
32
+ @running_previous_error = false
33
+ path = paths[0].split(/:/)[0]
34
+ @errors.delete(path)
35
+ run spec_command(path)
36
+ if @errors.size > 0
37
+ puts "Still have errors in #{@errors.keys.join(', ')}"
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ def spec_command(*paths)
44
+ if File.exist?('.rspec')
45
+ "rspec #{paths.join(' ')}"
46
+ else
47
+ "spec -O spec/spec.opts #{paths.join(' ')}"
48
+ end
49
+ end
50
+
51
+ def check_for_previous_errors(paths)
52
+ @running_previous_error = false
53
+ paths.flatten.each do |path|
54
+ path = path.to_s
55
+ if @errors.has_key?(path)
56
+ new_path = "#{path}:#{@errors[path][0]}"
57
+ @errors.delete(path)
58
+ @running_previous_error = true
59
+ return [new_path]
60
+ end
61
+ end
62
+ end
63
+
64
+ def tests
65
+ Dir['spec/**/*_spec.rb']
66
+ end
67
+
68
+ def selenium_tests
69
+ Dir['selenium/**/*_spec.rb']
70
+ end
71
+
72
+ def run( cmd )
73
+ puts cmd
74
+
75
+ old_sync = $stdout.sync
76
+ $stdout.sync = true
77
+
78
+ ENV['AUTOTEST'] = 'true'
79
+
80
+ results = []
81
+ line = []
82
+ begin
83
+ open("| #{cmd}", "r") do |f|
84
+ until f.eof? do
85
+ c = f.getc or break
86
+ putc c
87
+ line << c
88
+ if c == ?\n
89
+ results << (RUBY_VERSION >= "1.9" ? line.join : line.pack("c*"))
90
+ line.clear
91
+ end
92
+ end
93
+ end
94
+ ensure
95
+ $stdout.sync = old_sync
96
+ end
97
+
98
+ pending = false
99
+ results.delete_if {|l| pending = true if pending == false && l =~ /Pending:/; pending = false if l =~ /^\d+\)/; pending == true; }
100
+ error_lines = results.grep(/_spec\.rb/).map{|l| l.sub(/.*?([^\s].*_spec.rb:\d+).*/, '\1').sub(/.*\s(.*_spec.rb:\d+)$/, '\1').strip }.uniq
101
+ #puts error_lines.inspect
102
+ if error_lines.empty?
103
+ true
104
+ else
105
+ error_lines.each{ |l| a = l.split(/:/); @errors[a[0].sub(/^\.\//, '')] << a[1] }
106
+ false
107
+ end
108
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: autospec.watchr
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Andrew Timberlake
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-09-15 00:00:00 +02:00
19
+ default_executable: autospec.watchr
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: watchr
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: rspec
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :development
48
+ version_requirements: *id002
49
+ description: Intelligently runs your specs as you edit files.
50
+ email: andrew@andrewtimberlake.com
51
+ executables:
52
+ - autospec.watchr
53
+ extensions: []
54
+
55
+ extra_rdoc_files:
56
+ - LICENSE
57
+ - README.rdoc
58
+ files:
59
+ - LICENSE
60
+ - VERSION
61
+ - lib/autospec.watchr.rb
62
+ - README.rdoc
63
+ - bin/autospec.watchr
64
+ has_rdoc: true
65
+ homepage: http://github.com/andrewtimberlake/autospec.watchr
66
+ licenses: []
67
+
68
+ post_install_message:
69
+ rdoc_options:
70
+ - --charset=UTF-8
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ hash: 3
79
+ segments:
80
+ - 0
81
+ version: "0"
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ hash: 3
88
+ segments:
89
+ - 0
90
+ version: "0"
91
+ requirements: []
92
+
93
+ rubyforge_project:
94
+ rubygems_version: 1.3.7
95
+ signing_key:
96
+ specification_version: 3
97
+ summary: Intelligently runs your specs as you edit files
98
+ test_files: []
99
+