guard-rackunit 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.
- checksums.yaml +15 -0
- data/ChangeLog +3 -0
- data/LICENSE +674 -0
- data/README.md +82 -0
- data/lib/guard/rackunit.rb +88 -0
- data/lib/guard/rackunit/command.rb +48 -0
- data/lib/guard/rackunit/notifier.rb +35 -0
- data/lib/guard/rackunit/run_result.rb +108 -0
- data/lib/guard/rackunit/runner.rb +61 -0
- data/lib/guard/rackunit/templates/Guardfile +4 -0
- data/lib/guard/rackunit/version.rb +22 -0
- data/spec/lib/guard/rackunit/command_spec.rb +29 -0
- data/spec/lib/guard/rackunit/notifier_spec.rb +16 -0
- data/spec/lib/guard/rackunit/run_result_spec.rb +216 -0
- data/spec/lib/guard/rackunit/runner_spec.rb +84 -0
- data/spec/lib/guard/rackunit_spec.rb +133 -0
- data/spec/spec_helper.rb +23 -0
- data/spec/support/helpers.rb +86 -0
- data/spec/support/samples/failed_tests +12 -0
- data/spec/support/samples/runtime_error +16 -0
- data/spec/support/samples/success +2 -0
- metadata +135 -0
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Guard::RackUnit::Command do
|
4
|
+
|
5
|
+
let(:instance){described_class.new}
|
6
|
+
|
7
|
+
it 'returns failure result when it is unsuccessful' do
|
8
|
+
stub_failed_run do
|
9
|
+
expect(instance.execute(['paths'])).
|
10
|
+
to be_instance_of Guard::RackUnit::RunResult::Failure
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
it "returns a success result when it is successful" do
|
15
|
+
stub_successful_run do
|
16
|
+
expect(instance.execute(['paths'])).
|
17
|
+
to be_instance_of Guard::RackUnit::RunResult::Success
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns pending result if there are no are no paths" do
|
22
|
+
expect(instance.execute([])).to be_instance_of Guard::RackUnit::RunResult::Pending
|
23
|
+
end
|
24
|
+
|
25
|
+
it "runs the correct command" do
|
26
|
+
expect(Open3).to receive(:popen3).with("raco test paths1 paths2")
|
27
|
+
instance.execute(['paths1', 'paths2'])
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Guard::RackUnit::Notifier do
|
4
|
+
|
5
|
+
|
6
|
+
let(:valid_options) do
|
7
|
+
{image: :pending, priority: 2}
|
8
|
+
end
|
9
|
+
|
10
|
+
it "notifies" do
|
11
|
+
message = "A message!"
|
12
|
+
expect(Guard::Notifier).to receive(:notify).with(message, {title: 'RackUnit Results'}.merge(valid_options))
|
13
|
+
instance = described_class.new(message)
|
14
|
+
instance.notify(valid_options)
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,216 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Guard::RackUnit::RunResult do
|
4
|
+
|
5
|
+
context 'success' do
|
6
|
+
it "returns a result" do
|
7
|
+
stub_successful_run do |out, err, _|
|
8
|
+
result = described_class.create(out, err)
|
9
|
+
expect(result).to be_instance_of Guard::RackUnit::RunResult::Success
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'failure' do
|
15
|
+
it "returns a result" do
|
16
|
+
stub_failed_run do |out, err, _|
|
17
|
+
result = described_class.create(out,err)
|
18
|
+
expect(result).to be_instance_of Guard::RackUnit::RunResult::Failure
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "when there are successes too, but a runtime failure" do
|
23
|
+
|
24
|
+
it "returns a failure result" do
|
25
|
+
with_successful_stdout do |stdout|
|
26
|
+
with_failed_stderr('/samples/runtime_error') do |stderr|
|
27
|
+
stub_run(stdout, stderr)
|
28
|
+
result = described_class.create(stdout, stderr)
|
29
|
+
expect(result).to be_instance_of Guard::RackUnit::RunResult::Failure
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
it "prints both the stdout and stderr" do
|
35
|
+
with_successful_stdout do |stdout|
|
36
|
+
with_failed_stderr('/samples/runtime_error') do |stderr|
|
37
|
+
stub_run(stdout, stderr)
|
38
|
+
expected = stdout.read
|
39
|
+
stdout.rewind
|
40
|
+
expected << stderr.read
|
41
|
+
stderr.rewind
|
42
|
+
result = capture_stdout do
|
43
|
+
described_class.create(stdout,stderr)
|
44
|
+
end
|
45
|
+
expect(result).to eq expected
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe Guard::RackUnit::RunResult::Pending do
|
53
|
+
let(:instance){Guard::RackUnit::RunResult::Pending.new}
|
54
|
+
it 'returns an empty set of paths' do
|
55
|
+
expect(instance.paths).to be_instance_of Set
|
56
|
+
expect(instance.paths).to be_empty
|
57
|
+
end
|
58
|
+
|
59
|
+
it "issue notifications that do nothing" do
|
60
|
+
expect(Guard::Notifier).to_not receive(:notify)
|
61
|
+
instance.issue_notification
|
62
|
+
end
|
63
|
+
|
64
|
+
it "return false for successful" do
|
65
|
+
expect(instance.successful?).to be_false
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe Guard::RackUnit::RunResult::Success do
|
70
|
+
it "returns a set of empty paths" do
|
71
|
+
with_successful_stdout do |out|
|
72
|
+
result = Guard::RackUnit::RunResult::Success.new out
|
73
|
+
expect(result.paths).to be_instance_of Set
|
74
|
+
expect(result.paths).to be_empty
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
it "returns true for successful" do
|
79
|
+
with_successful_stdout do |out|
|
80
|
+
result = Guard::RackUnit::RunResult::Success.new out
|
81
|
+
expect(result.successful?).to be_true
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
it "issues the correct notification message" do
|
86
|
+
success =<<SUCCESS
|
87
|
+
raco test: (submod "tests/vm-tests.rkt" test)
|
88
|
+
8 tests passed
|
89
|
+
SUCCESS
|
90
|
+
result = Guard::RackUnit::RunResult::Success.new StringIO.new(success)
|
91
|
+
expect(Guard::Notifier).to receive(:notify).with("8 tests passed", {title: 'RackUnit Results', image: :success, priority: -2})
|
92
|
+
result.issue_notification
|
93
|
+
end
|
94
|
+
|
95
|
+
it "issues a default notification message when there is no content in stdout" do
|
96
|
+
result = Guard::RackUnit::RunResult::Success.new StringIO.new('')
|
97
|
+
expect(Guard::Notifier).to receive(:notify).with("Success", {title: 'RackUnit Results', image: :success, priority: -2})
|
98
|
+
result.issue_notification
|
99
|
+
end
|
100
|
+
|
101
|
+
|
102
|
+
it "outputs the stdout" do
|
103
|
+
expected = 'expected'
|
104
|
+
result = 'not expected'
|
105
|
+
with_successful_stdout do |out|
|
106
|
+
expected = out.read # read it to build the expectation
|
107
|
+
out.rewind
|
108
|
+
result = capture_stdout do
|
109
|
+
Guard::RackUnit::RunResult::Success.new out
|
110
|
+
end
|
111
|
+
end
|
112
|
+
expect(result).to eq expected
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe Guard::RackUnit::RunResult::Failure do
|
117
|
+
|
118
|
+
it "returns a populated set of failed paths" do
|
119
|
+
with_failed_stderr do |err|
|
120
|
+
result = Guard::RackUnit::RunResult::Failure.new(err)
|
121
|
+
expect(result.paths).to be_instance_of Set
|
122
|
+
expect(result.paths).to_not be_empty
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
it "returns false for successful" do
|
127
|
+
with_failed_stderr do |err|
|
128
|
+
result = Guard::RackUnit::RunResult::Failure.new(err)
|
129
|
+
expect(result.successful?).to be_false
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
|
134
|
+
it "retrieves the correct failed paths" do
|
135
|
+
failure =<<FAIL
|
136
|
+
--------------------
|
137
|
+
parsing: """
|
138
|
+
FAILURE
|
139
|
+
message: "No exception raised"
|
140
|
+
name: check-exn
|
141
|
+
location: (#<path:/home/test-user/racket-project/tests/sample-tests.rkt> 19 4 389 113)
|
142
|
+
expression: (check-exn exn:fail:parsack? (lambda () (parsack-parse string)))
|
143
|
+
params: (#<procedure:exn:fail:parsack?> #<procedure:temp6>)
|
144
|
+
|
145
|
+
Check failure
|
146
|
+
--------------------
|
147
|
+
1/101 test failures
|
148
|
+
FAIL
|
149
|
+
result = Guard::RackUnit::RunResult::Failure.new(StringIO.new(failure))
|
150
|
+
expect(result.paths).to include '/home/test-user/racket-project/tests/sample-tests.rkt'
|
151
|
+
end
|
152
|
+
|
153
|
+
it "outputs the stderr" do
|
154
|
+
expected = 'expected'
|
155
|
+
result = 'not expected'
|
156
|
+
with_failed_stderr do |err|
|
157
|
+
expected = err.read # read it to build the expectation
|
158
|
+
err.rewind
|
159
|
+
result = capture_stdout do
|
160
|
+
Guard::RackUnit::RunResult::Failure.new(err)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
expect(result).to eq expected
|
164
|
+
end
|
165
|
+
|
166
|
+
it "issues a notification with the correct message when it's simple" do
|
167
|
+
failure =<<FAIL
|
168
|
+
--------------------
|
169
|
+
parsing: """
|
170
|
+
FAILURE
|
171
|
+
message: "No exception raised"
|
172
|
+
name: check-exn
|
173
|
+
location: (#<path:/home/test-user/racket-project/tests/sample-tests.rkt> 19 4 389 113)
|
174
|
+
expression: (check-exn exn:fail:parsack? (lambda () (parsack-parse string)))
|
175
|
+
params: (#<procedure:exn:fail:parsack?> #<procedure:temp6>)
|
176
|
+
|
177
|
+
Check failure
|
178
|
+
--------------------
|
179
|
+
1/101 test failures
|
180
|
+
FAIL
|
181
|
+
result = Guard::RackUnit::RunResult::Failure.new(StringIO.new(failure))
|
182
|
+
expect(Guard::Notifier).to receive(:notify).with("1/101 test failures", {title: 'RackUnit Results', image: :failed, priority: 2})
|
183
|
+
result.issue_notification
|
184
|
+
end
|
185
|
+
|
186
|
+
it "issues a notification with default message if stderr is empty" do
|
187
|
+
result = Guard::RackUnit::RunResult::Failure.new(StringIO.new(''))
|
188
|
+
expect(Guard::Notifier).to receive(:notify).with("Failed", {title: 'RackUnit Results', image: :failed, priority: 2})
|
189
|
+
result.issue_notification
|
190
|
+
end
|
191
|
+
|
192
|
+
it "issues a notification with a message when hit hits an exception" do
|
193
|
+
stdout =<<FAILED
|
194
|
+
--------------------
|
195
|
+
creates an assembly s-expression
|
196
|
+
ERROR
|
197
|
+
this is an error
|
198
|
+
context...:
|
199
|
+
/home/calbers/src/mine/scheme-assembler/evaluator.rkt:50:0: parsed-sexp->sexp-assembly
|
200
|
+
/home/calbers/src/mine/scheme-assembler/tests/evaluator-tests.rkt: [running body]
|
201
|
+
/usr/share/racket/collects/compiler/commands/test.rkt:29:10: for-loop
|
202
|
+
f8
|
203
|
+
/usr/share/racket/collects/compiler/commands/test.rkt: [running body]
|
204
|
+
/usr/share/racket/collects/raco/raco.rkt: [running body]
|
205
|
+
/usr/share/racket/collects/raco/main.rkt: [running body]
|
206
|
+
|
207
|
+
--------------------
|
208
|
+
FAILED
|
209
|
+
result = Guard::RackUnit::RunResult::Failure.new(StringIO.new(stdout))
|
210
|
+
expect(Guard::Notifier).to receive(:notify).
|
211
|
+
with("ERROR: /home/calbers/src/mine/scheme-assembler/evaluator.rkt:50:0: parsed-sexp->sexp-assembly",
|
212
|
+
{title: 'RackUnit Results', image: :failed, priority: 2})
|
213
|
+
result.issue_notification
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Guard::RackUnit::Runner do
|
4
|
+
|
5
|
+
let(:instance){described_class.new}
|
6
|
+
let(:paths){['some_paths/']}
|
7
|
+
|
8
|
+
context "success" do
|
9
|
+
it "runs test with the given paths and returns a success result " do
|
10
|
+
stub_successful_run(paths) do
|
11
|
+
result = instance.run paths
|
12
|
+
expect(result).to be_instance_of Guard::RackUnit::RunResult::Success
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context "failure" do
|
18
|
+
it "runs test with the given paths and returns a failure result " do
|
19
|
+
stub_failed_run(paths) do
|
20
|
+
result = instance.run(paths)
|
21
|
+
expect(result).to be_instance_of Guard::RackUnit::RunResult::Failure
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'returns pending result when no paths have been supplied' do
|
27
|
+
expect(instance.run([])).to be_instance_of Guard::RackUnit::RunResult::Pending
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
it "does not run duplicates" do
|
32
|
+
paths_with_dups = ['/home/test-user/tests.rkt', '/home/test-user/tests.rkt']
|
33
|
+
expect(Open3).to receive(:popen3).with('raco test /home/test-user/tests.rkt')
|
34
|
+
stub_successful_run(paths_with_dups) do
|
35
|
+
instance.run(paths_with_dups)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context "with other failed tasks" do
|
40
|
+
let(:failed_output) do
|
41
|
+
<<FAILED
|
42
|
+
--------------------
|
43
|
+
parsing: """
|
44
|
+
FAILURE
|
45
|
+
message: "No exception raised"
|
46
|
+
name: check-exn
|
47
|
+
location: (#<path:/home/test-user/tests.rkt> 19 4 389 113)
|
48
|
+
expression: (check-exn exn:fail:parsack? (lambda () (parsack-parse string)))
|
49
|
+
params: (#<procedure:exn:fail:parsack?> #<procedure:temp6>)
|
50
|
+
|
51
|
+
Check failure
|
52
|
+
--------------------
|
53
|
+
1/101 test failures
|
54
|
+
FAILED
|
55
|
+
end
|
56
|
+
|
57
|
+
it "run all previous failed paths" do
|
58
|
+
stub_failed_run_err(StringIO.new(failed_output), '/home/test-user/tests.rkt') do
|
59
|
+
catch(:task_has_failed) do
|
60
|
+
instance.run(['/home/test-user/tests.rkt'])
|
61
|
+
end
|
62
|
+
end
|
63
|
+
expect(Open3).to receive(:popen3).with('raco test /home/test-user/tests.rkt /paths/test.rkt /paths/another.rkt')
|
64
|
+
stub_successful_run(['/home/test-user/tests.rkt','/paths/test.rkt', '/paths/another.rkt']) do
|
65
|
+
instance.run(['/paths/test.rkt', '/paths/another.rkt'])
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
it "does not run duplicates when new tests are added to the previous failed" do
|
70
|
+
first_path = '/home/test-user/tests.rkt'
|
71
|
+
stub_failed_run_err(StringIO.new(failed_output), '/home/test-user/tests.rkt') do
|
72
|
+
catch(:task_has_failed) do
|
73
|
+
instance.run(['/home/test-user/tests.rkt'])
|
74
|
+
end
|
75
|
+
end
|
76
|
+
new_path = '/new/path.rkt'
|
77
|
+
new_paths = [first_path, first_path, new_path]
|
78
|
+
expect(Open3).to receive(:popen3).with("raco test #{first_path} #{new_path}")
|
79
|
+
stub_successful_run(new_paths) do
|
80
|
+
instance.run(new_paths)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Guard::RackUnit do
|
4
|
+
it "is a plugin" do
|
5
|
+
expect(described_class.new).to be_kind_of Guard::Plugin
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "start" do
|
9
|
+
context "when all_on_start is enabled" do
|
10
|
+
let(:test_paths){['/tests']}
|
11
|
+
let(:instance){described_class.new({all_on_start: true, test_paths: test_paths})}
|
12
|
+
|
13
|
+
it "returns a success result on success" do
|
14
|
+
stub_successful_run(test_paths) do
|
15
|
+
result = instance.start
|
16
|
+
expect(result).to be_instance_of Guard::RackUnit::RunResult::Success
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
it "throw a :task_has_failed symbol when it has a test directory" do
|
21
|
+
stub_failed_run(test_paths) do
|
22
|
+
expect{instance.start}.to throw_symbol :task_has_failed
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it "returns a failure result on failure when it has a test directory" do
|
27
|
+
result = described_class.new({all_on_start: true}).start
|
28
|
+
expect(result).to be_instance_of Guard::RackUnit::RunResult::Pending
|
29
|
+
end
|
30
|
+
|
31
|
+
it "updates the UI" do
|
32
|
+
expect(::Guard::UI).to receive(:info).at_least(:once).ordered.with('Guard::RackUnit is running')
|
33
|
+
expect(::Guard::UI).to receive(:info).at_least(:once).ordered.with('Resetting', reset: true)
|
34
|
+
catch(:task_has_failed){instance.start}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "when all_on_start is not enabled" do
|
39
|
+
let(:instance){described_class.new}
|
40
|
+
|
41
|
+
it "updates the UI telling the user it has started" do
|
42
|
+
expect(::Guard::UI).to receive(:info).with('Guard::RackUnit is running')
|
43
|
+
instance.start
|
44
|
+
end
|
45
|
+
|
46
|
+
it "updates the UI telling the user it has started" do
|
47
|
+
expect(instance.start).to be_instance_of Guard::RackUnit::RunResult::Pending
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "run_all" do
|
53
|
+
|
54
|
+
let(:test_paths) { ['tests/'] }
|
55
|
+
let(:instance){described_class.new({test_paths: test_paths})}
|
56
|
+
|
57
|
+
context "success" do
|
58
|
+
it "returns a success result on success" do
|
59
|
+
stub_successful_run(test_paths) do
|
60
|
+
expect(instance.run_all).to be_instance_of Guard::RackUnit::RunResult::Success
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
it "issues a notification" do
|
65
|
+
expect(Guard::Notifier).to receive(:notify).with("8 tests passed", {title: 'RackUnit Results', image: :success, priority: -2})
|
66
|
+
stub_successful_run(test_paths) do
|
67
|
+
instance.run_all
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context "failure" do
|
73
|
+
it "returns a failure result on failure" do
|
74
|
+
stub_failed_run(test_paths) do
|
75
|
+
expect{instance.run_all}.to throw_symbol :task_has_failed
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
it "issues a notification" do
|
80
|
+
stub_failed_run(test_paths) do
|
81
|
+
expect(Guard::Notifier).to receive(:notify).with("1/101 test failures", {title: 'RackUnit Results', image: :failed, priority: 2})
|
82
|
+
catch(:task_has_failed){instance.run_all }
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
it "issues a notification" do
|
88
|
+
expect(Guard::UI).to receive(:info).with("Resetting", reset: true)
|
89
|
+
stub_successful_run(test_paths) do
|
90
|
+
instance.run_all
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe "running on modifications" do
|
96
|
+
let(:instance){described_class.new}
|
97
|
+
|
98
|
+
context "with no supplied paths" do
|
99
|
+
it "does not issue a notification when the path is empty" do
|
100
|
+
expect(Guard::UI).to_not receive(:info)
|
101
|
+
instance.run_on_modifications([])
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context "with paths" do
|
106
|
+
|
107
|
+
let(:test_paths){['/paths/test.rkt', '/paths/another.rkt']}
|
108
|
+
|
109
|
+
it "issues a notification" do
|
110
|
+
expect(Guard::UI).to receive(:info).with("Running: #{test_paths.join(', ')}", reset: true)
|
111
|
+
stub_successful_run(test_paths) do
|
112
|
+
instance.run_on_modifications(test_paths)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
it "returns a success result on success" do
|
117
|
+
stub_successful_run(test_paths) do
|
118
|
+
result = instance.run_on_modifications(test_paths)
|
119
|
+
expect(result).to be_instance_of Guard::RackUnit::RunResult::Success
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
it "throws a :task_has_failed symbol on failure" do
|
124
|
+
stub_failed_run(test_paths) do
|
125
|
+
expect do
|
126
|
+
result = instance.run_on_modifications(['/paths/test.rkt', '/paths/another.rkt'])
|
127
|
+
expect(result).to be_instance_of Guard::RackUnit::RunResult::Failure
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|