guard-jstd 0.1.0 → 0.1.1
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/Changelog.md +13 -0
- data/README.md +7 -1
- data/lib/guard/jstd/case_finder.rb +1 -1
- data/lib/guard/jstd/formatter.rb +38 -11
- data/lib/guard/jstd/runner.rb +1 -0
- data/lib/guard/jstd/version.rb +1 -1
- data/lib/guard/jstd.rb +5 -0
- data/spec/guard/jstd/case_finder_spec.rb +1 -0
- data/spec/guard/jstd/formatter_spec.rb +62 -14
- data/spec/guard/jstd/runner_spec.rb +2 -1
- data/spec/guard/jstd_spec.rb +22 -3
- metadata +5 -4
data/Changelog.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
### 0.1.1 / 2011-04-09
|
2
|
+
|
3
|
+
* Enhancements
|
4
|
+
* Formatter - improved colorization
|
5
|
+
* Jstd - #reload runs all tests
|
6
|
+
* Bug fixes
|
7
|
+
* Jstd - disable #run_all when Guard::CoffeeScript is installed. Use #reload instead
|
8
|
+
* CaseFinder - removes duplicate TestCases
|
9
|
+
|
10
|
+
## 0.1.0 / 2011-04-08
|
11
|
+
|
12
|
+
* Enhancements
|
13
|
+
* Added configuration options
|
data/README.md
CHANGED
@@ -22,7 +22,9 @@ Generate the suggested Guardfile with:
|
|
22
22
|
|
23
23
|
See the [Guard](http://github.com/guard/guard) gem README for more information about using Guard.
|
24
24
|
|
25
|
-
|
25
|
+
By default, Guard::Jstd will attempt to start the JsTestDriver server. This is done as a forked process, so when you stop Guard with <tt>Ctrl-C</tt>, the Jstd server will also stop.
|
26
|
+
|
27
|
+
<tt>Ctrl-\</tt> or <tt>Ctrl-Z</tt> will run all of your tests.
|
26
28
|
|
27
29
|
## Configuration
|
28
30
|
|
@@ -53,3 +55,7 @@ The default JsTestDriver configuration file name is 'jsTestDriver.conf'. If you
|
|
53
55
|
## JsTestDriver
|
54
56
|
|
55
57
|
Information about setting up JsTestDriver on your system can be [found here](http://www.arailsdemo.com/posts/46) or on the JsTestDriver [homepage.](http://code.google.com/p/js-test-driver/)
|
58
|
+
|
59
|
+
## Guard::CoffeeScript
|
60
|
+
|
61
|
+
If you want to use CoffeeScript in your development, add the [guard-coffeescript gem.](https://github.com/guard/guard-coffeescript) To avoid conflict with Guard::CoffeeScript, <tt>Ctrl-\</tt> is disabled for Guard::Jstd. Use <tt>Ctrl-Z</tt> instead to run all tests.
|
data/lib/guard/jstd/formatter.rb
CHANGED
@@ -4,7 +4,8 @@ module Guard
|
|
4
4
|
TITLES =
|
5
5
|
{
|
6
6
|
:failed => 'You have failing tests.',
|
7
|
-
:success => "All of your tests passed."
|
7
|
+
:success => "All of your tests passed.",
|
8
|
+
:error => "You had some errors."
|
8
9
|
}
|
9
10
|
|
10
11
|
COLORS =
|
@@ -30,21 +31,47 @@ module Guard
|
|
30
31
|
@failed ||= results.match(/failed/)
|
31
32
|
end
|
32
33
|
|
34
|
+
def errors_present?
|
35
|
+
lines[0].match(/error/)
|
36
|
+
end
|
37
|
+
|
33
38
|
def notify
|
34
|
-
|
35
|
-
|
36
|
-
|
39
|
+
if errors_present?
|
40
|
+
status = :error
|
41
|
+
image = { :image => :failed }
|
42
|
+
message = lines[0]
|
43
|
+
else
|
44
|
+
status = any_failed? ? :failed : :success
|
45
|
+
image = { :image => status }
|
46
|
+
message = lines[1]
|
47
|
+
end
|
48
|
+
|
49
|
+
::Guard::Notifier.notify( message.lstrip,
|
50
|
+
{ :title => TITLES[status] }.merge(image)
|
37
51
|
)
|
38
52
|
end
|
39
53
|
|
40
54
|
def colorize_results
|
41
55
|
lines.collect do |line|
|
42
|
-
if line =~ /failed/
|
43
|
-
colorize(line, :failed)
|
44
|
-
elsif line =~ /Fails: (\d+);/
|
45
|
-
status = $1.to_i == 0 ? :success : :failed
|
46
|
-
colorize(line, status)
|
56
|
+
if line =~ /failed|error/
|
57
|
+
colorize(line, line, :failed)
|
47
58
|
else
|
59
|
+
if line =~ /((Passed: (\d+)); (Fails: (\d+)); (Errors:? (\d+)))/
|
60
|
+
if $5 == "0" && $7 == "0"
|
61
|
+
colorize(line, line, :success)
|
62
|
+
else
|
63
|
+
# if $3 != "0"
|
64
|
+
# colorize(line, $2, :success)
|
65
|
+
# end
|
66
|
+
[3, 5, 7].each do |tally|
|
67
|
+
if eval("$#{tally}") != "0"
|
68
|
+
status = tally == 3 ? :success : :failed
|
69
|
+
colorize(line, eval("$#{tally - 1}"), status)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
48
75
|
line
|
49
76
|
end
|
50
77
|
end.join("\n")
|
@@ -56,8 +83,8 @@ module Guard
|
|
56
83
|
|
57
84
|
private
|
58
85
|
|
59
|
-
def colorize(text, status)
|
60
|
-
"#{COLORS[status]}#{
|
86
|
+
def colorize(text, part, status)
|
87
|
+
text.gsub!(part, "#{COLORS[status]}#{part}\e[0m")
|
61
88
|
end
|
62
89
|
end
|
63
90
|
end
|
data/lib/guard/jstd/runner.rb
CHANGED
data/lib/guard/jstd/version.rb
CHANGED
data/lib/guard/jstd.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe Guard::Jstd::Formatter do
|
4
|
+
let(:klass) { ::Guard::Jstd::Formatter }
|
5
|
+
|
4
6
|
let(:failed) do
|
5
7
|
<<-FAILED
|
6
8
|
..
|
@@ -12,16 +14,6 @@ describe Guard::Jstd::Formatter do
|
|
12
14
|
FAILED
|
13
15
|
end
|
14
16
|
|
15
|
-
let(:passed) do
|
16
|
-
<<-PASSED
|
17
|
-
....
|
18
|
-
Total 4 tests (Passed: 4; Fails: 0; Errors: 0) (4.00 ms)
|
19
|
-
Chrome 10.0.648.204 Mac OS: Run 4 tests (Passed: 4; Fails: 0; Errors 0) (4.00 ms)
|
20
|
-
PASSED
|
21
|
-
end
|
22
|
-
|
23
|
-
let(:klass) { ::Guard::Jstd::Formatter }
|
24
|
-
|
25
17
|
context "--failed test--" do
|
26
18
|
subject { klass.new(failed) }
|
27
19
|
|
@@ -36,12 +28,16 @@ describe Guard::Jstd::Formatter do
|
|
36
28
|
end
|
37
29
|
|
38
30
|
describe "#colorized_results" do
|
39
|
-
it "adds color to the
|
31
|
+
it "adds color to the failure message" do
|
40
32
|
subject.colorize_results.should match /\[31m\s+Sneaky3.test/
|
41
33
|
end
|
42
34
|
|
43
|
-
it "adds color to the
|
44
|
-
subject.colorize_results.should match /\[
|
35
|
+
it "adds color to the failure tally" do
|
36
|
+
subject.colorize_results.should match /\[31mFails: 1/
|
37
|
+
end
|
38
|
+
|
39
|
+
it "adds color to the passed tally" do
|
40
|
+
subject.colorize_results.should match /\[32mPassed: 1/
|
45
41
|
end
|
46
42
|
end
|
47
43
|
|
@@ -55,6 +51,14 @@ describe Guard::Jstd::Formatter do
|
|
55
51
|
end
|
56
52
|
|
57
53
|
context "--all tests passed--" do
|
54
|
+
let(:passed) do
|
55
|
+
<<-PASSED
|
56
|
+
....
|
57
|
+
Total 4 tests (Passed: 4; Fails: 0; Errors: 0) (4.00 ms)
|
58
|
+
Chrome 10.0.648.204 Mac OS: Run 4 tests (Passed: 4; Fails: 0; Errors 0) (4.00 ms)
|
59
|
+
PASSED
|
60
|
+
end
|
61
|
+
|
58
62
|
subject { klass.new(passed) }
|
59
63
|
|
60
64
|
its(:any_failed?) { should be_false }
|
@@ -68,7 +72,51 @@ describe Guard::Jstd::Formatter do
|
|
68
72
|
end
|
69
73
|
|
70
74
|
it "#colorized_results adds color to the successful overview line" do
|
71
|
-
subject.colorize_results
|
75
|
+
colorized = subject.colorize_results
|
76
|
+
colorized.should match /\[32m\s*Total/
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context "--errors present--" do
|
81
|
+
context "-Java error-" do
|
82
|
+
let(:java_error) do
|
83
|
+
<<-ERROR
|
84
|
+
java.lang.RuntimeException: Connection error on: sun.net.www.protocol.
|
85
|
+
at com.google.jstestdriver.HttpServer.postJson(HttpServer.java:124)
|
86
|
+
ERROR
|
87
|
+
end
|
88
|
+
|
89
|
+
subject { klass.new(java_error) }
|
90
|
+
|
91
|
+
it "#notify should send :error arguments to Nofitier" do
|
92
|
+
message = "java.lang.RuntimeException: Connection error on: sun.net.www.protocol."
|
93
|
+
::Guard::Notifier.should_receive(:notify).with(
|
94
|
+
message, { :title => klass::TITLES[:error], :image => :failed }
|
95
|
+
)
|
96
|
+
subject.notify
|
97
|
+
end
|
98
|
+
|
99
|
+
it "#colorized_results adds color to the error description line" do
|
100
|
+
subject.colorize_results.should match /\[31m\s+java.lang./
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
context "-JavaScript error-" do
|
105
|
+
let(:javascript_error) do
|
106
|
+
<<-ERROR
|
107
|
+
|
108
|
+
Total 0 tests (Passed: 0; Fails: 0; Errors: 0) (0.00 ms)
|
109
|
+
Chrome 10.0.648.204 Mac OS: Run 1 tests (Passed: 0; Fails: 0; Errors 1) (0.00 ms)
|
110
|
+
error loading file: /test/javascripts/test/hello_test.js:33: Uncaught SyntaxError: Unexpected token ;
|
111
|
+
Tests failed: Tests failed. See log for details.
|
112
|
+
ERROR
|
113
|
+
end
|
114
|
+
|
115
|
+
subject { klass.new(javascript_error) }
|
116
|
+
|
117
|
+
it "#colorized_results add color to the summary line" do
|
118
|
+
subject.colorize_results.should match /\[31mErrors 1/
|
119
|
+
end
|
72
120
|
end
|
73
121
|
end
|
74
122
|
|
@@ -106,9 +106,10 @@ describe Guard::Jstd::Runner do
|
|
106
106
|
subject.start_server
|
107
107
|
end
|
108
108
|
|
109
|
-
it "traps the 'QUIT'
|
109
|
+
it "traps the 'QUIT' and 'TSTP' signals before sending it to the child process" do
|
110
110
|
subject.should_receive("`").with('hooha --port 1234') { 'hooha' }
|
111
111
|
subject.should_receive(:trap).with('QUIT', 'IGNORE')
|
112
|
+
subject.should_receive(:trap).with('TSTP', 'IGNORE')
|
112
113
|
subject.should_receive(:fork) { |&block| block.call }
|
113
114
|
subject.start_server
|
114
115
|
end
|
data/spec/guard/jstd_spec.rb
CHANGED
@@ -22,11 +22,30 @@ describe Guard::Jstd do
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
describe "#run_all" do
|
26
|
+
it "runs all tests" do
|
27
|
+
klass::Runner.should_receive(:run)
|
28
|
+
subject.run_all
|
29
|
+
end
|
30
|
+
|
31
|
+
# TODO remove ::Guard::CoffeeScript when test is done
|
32
|
+
it "does not run tests if Guard::CoffeeScript is present" do
|
33
|
+
::Guard::CoffeeScript = Class.new
|
34
|
+
Guard.stub(:guards) { [::Guard::CoffeeScript.new, ::Guard::Jstd.new] }
|
35
|
+
klass::Runner.should_not_receive(:run)
|
36
|
+
# Object.send :remove_const, "::Guard::CoffeeScript"
|
37
|
+
subject.run_all
|
38
|
+
end
|
28
39
|
end
|
29
40
|
|
41
|
+
describe "#reload" do
|
42
|
+
it "runs all without checking for CoffeeScript" do
|
43
|
+
klass::Runner.should_receive :run
|
44
|
+
subject.reload
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
|
30
49
|
describe "#run_on_change" do
|
31
50
|
it "starts the Runner with the corresponding TestCases" do
|
32
51
|
paths = ['foo/bar.js', 'hand/foot.js']
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: guard-jstd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- aRailsDemo
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-04-
|
18
|
+
date: 2011-04-10 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: guard
|
@@ -60,6 +60,7 @@ extra_rdoc_files: []
|
|
60
60
|
|
61
61
|
files:
|
62
62
|
- .gitignore
|
63
|
+
- Changelog.md
|
63
64
|
- Gemfile
|
64
65
|
- Guardfile
|
65
66
|
- LICENSE
|