autowatchr 0.1.4 → 0.1.5
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/README.rdoc +35 -3
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/lib/autowatchr.rb +29 -3
- metadata +34 -20
- data/.gitignore +0 -5
data/README.rdoc
CHANGED
@@ -11,16 +11,18 @@ Provides some autotest-like behavior for watchr (http://github.com/mynyml/watchr
|
|
11
11
|
* Auto-watches test and lib files using the autotest layout
|
12
12
|
* Optionally run only failing-tests
|
13
13
|
* Optionally run entire suite after all tests pass
|
14
|
+
* Traps INT signal (Control-C) and re-runs all tests.
|
14
15
|
|
15
16
|
== Todo
|
16
17
|
|
17
18
|
* Cucumber support
|
18
19
|
* Expose algorithm to map test classes to test files
|
19
|
-
* Add INT signal trapping
|
20
20
|
|
21
21
|
== Example use
|
22
22
|
|
23
|
-
|
23
|
+
Create a <tt>.watchr</tt> file for your project and simply declare an Autowatchr block within it:
|
24
|
+
|
25
|
+
# test/test.watchr
|
24
26
|
require 'autowatchr'
|
25
27
|
|
26
28
|
Autowatchr.new(self) do |config|
|
@@ -29,6 +31,9 @@ test.watchr
|
|
29
31
|
config.test_dir = 'leet_test'
|
30
32
|
end
|
31
33
|
|
34
|
+
Your tests can then be run with:
|
35
|
+
$ watchr test/test.watchr
|
36
|
+
|
32
37
|
=== Configuration options
|
33
38
|
* command
|
34
39
|
* An ERB template for the command
|
@@ -53,8 +58,11 @@ test.watchr
|
|
53
58
|
* The regexp to use for discovering library files
|
54
59
|
* Default: <tt>'^%s.*/.*\.rb$' % self.lib_dir</tt>
|
55
60
|
* test_re
|
56
|
-
* The regexp to use for discovering
|
61
|
+
* The regexp to use for discovering test files
|
57
62
|
* Default: <tt>'^%s.*/test_.*\.rb$' % self.test_dir</tt>
|
63
|
+
* test_file
|
64
|
+
* The filename pattern for correlating test files with lib files. The %s will be substituted for the basename of the lib file.
|
65
|
+
* Default: <tt>'test_%s.rb'</tt>
|
58
66
|
* failing_only
|
59
67
|
* Run only failing tests the next time a test file is run
|
60
68
|
* Default: <tt>true</tt>
|
@@ -64,8 +72,32 @@ test.watchr
|
|
64
72
|
|
65
73
|
All of the config options are optional. You can also pass in a hash instead of a block. Also see: test.watchr[http://github.com/viking/autowatchr/blob/master/test.watchr].
|
66
74
|
|
75
|
+
== Using with RSpec
|
76
|
+
|
77
|
+
Autowatchr can easily be configured to work with the standard RSpec file hierarchy:
|
78
|
+
|
79
|
+
# spec/spec.watchr
|
80
|
+
require 'autowatchr'
|
81
|
+
|
82
|
+
Autowatchr.new(self) do |config|
|
83
|
+
config.test_dir = 'spec'
|
84
|
+
config.test_re = "^#{config.test_dir}/(.*)_spec\.rb$"
|
85
|
+
config.test_file = '%s_spec.rb'
|
86
|
+
end
|
87
|
+
|
88
|
+
Be sure you have <tt>spec_helper.rb</tt> required in every spec file, or else put it in your <tt>.watchr</tt> file.
|
89
|
+
|
90
|
+
== Prettier Results
|
91
|
+
|
92
|
+
Autowatchr is compatible with the Watchr redgreen gem. Install 'mynyml-redgreen' and simply require it in your <tt>.watchr</tt> file.
|
93
|
+
|
67
94
|
== Copyright
|
68
95
|
|
69
96
|
Copyright (c) 2009 Jeremy Stephens. See LICENSE for details.
|
70
97
|
|
71
98
|
Many snippets were taken from ZenTest[http://github.com/seattlerb/ZenTest].
|
99
|
+
|
100
|
+
== Contributors
|
101
|
+
|
102
|
+
* Stephen Eley (SFEley)
|
103
|
+
* Adam Grant (harmon)
|
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.5
|
data/lib/autowatchr.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
require 'erb'
|
2
|
+
require 'stringio'
|
2
3
|
|
3
4
|
class Autowatchr
|
4
5
|
class Config
|
5
6
|
attr_writer :command, :ruby, :include, :require, :lib_dir, :test_dir,
|
6
|
-
:lib_re, :test_re, :failed_results_re, :completed_re,
|
7
|
-
:run_suite
|
7
|
+
:lib_re, :test_re, :test_file, :failed_results_re, :completed_re,
|
8
|
+
:failing_only, :run_suite
|
8
9
|
|
9
10
|
def initialize(options = {})
|
10
11
|
@failing_only = @run_suite = true
|
@@ -58,6 +59,10 @@ class Autowatchr
|
|
58
59
|
def test_re
|
59
60
|
@test_re ||= '^%s.*/test_.*\.rb$' % self.test_dir
|
60
61
|
end
|
62
|
+
|
63
|
+
def test_file
|
64
|
+
@test_file ||= 'test_%s.rb'
|
65
|
+
end
|
61
66
|
|
62
67
|
def failed_results_re
|
63
68
|
@failed_results_re ||= /^\s+\d+\) (?:Failure|Error):\n(.*?)\((.*?)\)/
|
@@ -94,6 +99,7 @@ class Autowatchr
|
|
94
99
|
end
|
95
100
|
|
96
101
|
attr_reader :config
|
102
|
+
attr_accessor :interrupt_received
|
97
103
|
|
98
104
|
def initialize(script, options = {})
|
99
105
|
@config = Config.new(options)
|
@@ -105,12 +111,31 @@ class Autowatchr
|
|
105
111
|
discover_files
|
106
112
|
run_all_tests
|
107
113
|
start_watching_files
|
114
|
+
start_sigint_handler
|
115
|
+
end
|
116
|
+
|
117
|
+
# Traps any INT signals (like Control-C) and re-runs all
|
118
|
+
# the tests, unless the user sends the INT signal again within
|
119
|
+
# 2 seconds.
|
120
|
+
def start_sigint_handler
|
121
|
+
Signal.trap 'INT' do
|
122
|
+
if self.interrupt_received
|
123
|
+
exit 0
|
124
|
+
else
|
125
|
+
self.interrupt_received = true
|
126
|
+
puts "\nInterrupt a second time to quit"
|
127
|
+
Kernel.sleep 2
|
128
|
+
self.interrupt_received = false
|
129
|
+
puts "Running all tests..."
|
130
|
+
run_all_tests
|
131
|
+
end
|
132
|
+
end
|
108
133
|
end
|
109
134
|
|
110
135
|
def run_lib_file(file)
|
111
136
|
md = file.match(%r{^#{@config.lib_dir}#{File::SEPARATOR}?(.+)$})
|
112
137
|
parts = md[1].split(File::SEPARATOR)
|
113
|
-
parts[-1] =
|
138
|
+
parts[-1] = config.test_file % File.basename(parts[-1],'.rb')
|
114
139
|
file = "#{@config.test_dir}/" + File.join(parts)
|
115
140
|
run_test_file(file)
|
116
141
|
end
|
@@ -214,4 +239,5 @@ class Autowatchr
|
|
214
239
|
tr("-", "_").
|
215
240
|
downcase
|
216
241
|
end
|
242
|
+
|
217
243
|
end
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: autowatchr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 5
|
9
|
+
version: 0.1.5
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Jeremy Stephens
|
@@ -9,29 +14,35 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date:
|
17
|
+
date: 2011-02-09 00:00:00 -06:00
|
13
18
|
default_executable:
|
14
19
|
dependencies:
|
15
20
|
- !ruby/object:Gem::Dependency
|
16
21
|
name: watchr
|
17
|
-
|
18
|
-
|
19
|
-
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
20
25
|
requirements:
|
21
26
|
- - ">="
|
22
27
|
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
23
30
|
version: "0"
|
24
|
-
|
31
|
+
type: :runtime
|
32
|
+
version_requirements: *id001
|
25
33
|
- !ruby/object:Gem::Dependency
|
26
34
|
name: mocha
|
27
|
-
|
28
|
-
|
29
|
-
|
35
|
+
prerelease: false
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
30
38
|
requirements:
|
31
39
|
- - ">="
|
32
40
|
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 0
|
33
43
|
version: "0"
|
34
|
-
|
44
|
+
type: :development
|
45
|
+
version_requirements: *id002
|
35
46
|
description: Provides some autotest-like behavior for watchr (http://github.com/mynyml/watchr).
|
36
47
|
email: viking415@gmail.com
|
37
48
|
executables: []
|
@@ -43,7 +54,6 @@ extra_rdoc_files:
|
|
43
54
|
- README.rdoc
|
44
55
|
files:
|
45
56
|
- .document
|
46
|
-
- .gitignore
|
47
57
|
- LICENSE
|
48
58
|
- README.rdoc
|
49
59
|
- Rakefile
|
@@ -70,34 +80,38 @@ homepage: http://github.com/viking/autowatchr
|
|
70
80
|
licenses: []
|
71
81
|
|
72
82
|
post_install_message:
|
73
|
-
rdoc_options:
|
74
|
-
|
83
|
+
rdoc_options: []
|
84
|
+
|
75
85
|
require_paths:
|
76
86
|
- lib
|
77
87
|
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
78
89
|
requirements:
|
79
90
|
- - ">="
|
80
91
|
- !ruby/object:Gem::Version
|
92
|
+
segments:
|
93
|
+
- 0
|
81
94
|
version: "0"
|
82
|
-
version:
|
83
95
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
84
97
|
requirements:
|
85
98
|
- - ">="
|
86
99
|
- !ruby/object:Gem::Version
|
100
|
+
segments:
|
101
|
+
- 0
|
87
102
|
version: "0"
|
88
|
-
version:
|
89
103
|
requirements: []
|
90
104
|
|
91
105
|
rubyforge_project:
|
92
|
-
rubygems_version: 1.3.
|
106
|
+
rubygems_version: 1.3.7
|
93
107
|
signing_key:
|
94
108
|
specification_version: 3
|
95
109
|
summary: Provides some autotest-like behavior for watchr
|
96
110
|
test_files:
|
97
|
-
- test/fixtures/test/test_foo.rb
|
98
|
-
- test/fixtures/test/test_bar.rb
|
99
|
-
- test/fixtures/test/helper.rb
|
100
111
|
- test/fixtures/lib/bar.rb
|
101
112
|
- test/fixtures/lib/foo.rb
|
102
|
-
- test/
|
113
|
+
- test/fixtures/test/helper.rb
|
114
|
+
- test/fixtures/test/test_bar.rb
|
115
|
+
- test/fixtures/test/test_foo.rb
|
103
116
|
- test/helper.rb
|
117
|
+
- test/test_autowatchr.rb
|