what_weve_got_here_is_an_error_to_communicate 0.0.3 → 0.0.4
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 +4 -4
- data/Readme.md +5 -4
- data/lib/error_to_communicate/rspec_formatter.rb +8 -1
- data/lib/error_to_communicate/version.rb +1 -1
- data/spec/rspec_formatter_spec.rb +36 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ca3047fc7ba0e7fb3e7a4fe8ca51b4f446d3eb7
|
4
|
+
data.tar.gz: ab9dfedf5db56ff643deca9372afb664f8bda1be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 63d38ceee5ac2921c79ea3d4bf517770d75ceeabe96345dc50c33f59f17c822d6bbec08e30438df2af23d81f066b6dcd6d0cb16661259aa32d2409f5afbb259a
|
7
|
+
data.tar.gz: a898e22af4fd9c765a8c43cc15dcc818ca50a9271b0e82d532c285eb9ef1b94dcd262da82c132543fc63c995460c80137f6f3d65cd05f8dc920ef13f98bdcd82
|
data/Readme.md
CHANGED
@@ -7,7 +7,7 @@ Blog explaining the goal [here](http://blog.turing.io/2015/01/18/what-we-ve-got-
|
|
7
7
|
|
8
8
|
A screenshot of the code rendering an `ArgumentError`.
|
9
9
|
|
10
|
-

|
11
11
|
|
12
12
|
|
13
13
|
This is still early and Rough
|
@@ -16,10 +16,11 @@ This is still early and Rough
|
|
16
16
|
But I've been using it on its own test suite, and have to say it's compelling!
|
17
17
|
|
18
18
|
|
19
|
-
Using this with RSpec or
|
20
|
-
|
19
|
+
Using this with RSpec or Minitest
|
20
|
+
---------------------------------
|
21
21
|
|
22
|
-
Place this in your .rspec file
|
22
|
+
Place this in your .rspec file to use with RSpec. Or just use [MRspec](https://github.com/JoshCheek/mrspec),
|
23
|
+
which works with both RSpec and Minitest and requires no configuration :)
|
23
24
|
|
24
25
|
```
|
25
26
|
--colour
|
@@ -3,6 +3,13 @@ require 'rspec/core/formatters/documentation_formatter'
|
|
3
3
|
|
4
4
|
module ErrorToCommunicate
|
5
5
|
class Heuristic::RSpecFailure < Heuristic
|
6
|
+
def self.fix_whitespace(str)
|
7
|
+
str = str.dup
|
8
|
+
str.sub! /\A\n*/, "" # remove leading newlines
|
9
|
+
str.sub! /\n*\Z/, "" # remove trailing newlines
|
10
|
+
str << "\n" # one newline on the end
|
11
|
+
end
|
12
|
+
|
6
13
|
attr_accessor :failure, :failure_number, :config
|
7
14
|
attr_accessor :semantic_summary, :semantic_info
|
8
15
|
|
@@ -21,7 +28,7 @@ module ErrorToCommunicate
|
|
21
28
|
# format it with our lib
|
22
29
|
self.semantic_info =
|
23
30
|
[:heuristic, [ # ":heuristic" is dumb, it's not a heuristic, it's an error message, Maybe we need a :section or something?
|
24
|
-
[:message,
|
31
|
+
[:message, self.class.fix_whitespace(message)],
|
25
32
|
*backtrace.take(1).map { |loc|
|
26
33
|
[:code, {location: loc, context: (-5..5), emphasis: :code}]
|
27
34
|
}
|
@@ -129,7 +129,7 @@ RSpec.describe ErrorToCommunicate::RSpecFormatter, rspec_formatter: true do
|
|
129
129
|
expect(columns.map &:last).to eq [999, 'DESC']
|
130
130
|
end
|
131
131
|
|
132
|
-
specify 'the info is the error message and first line from the backtrace with some context' do
|
132
|
+
specify 'the info is the formatted error message and first line from the backtrace with some context' do
|
133
133
|
config = ErrorToCommunicate::Config.new
|
134
134
|
heuristic = ErrorToCommunicate::Heuristic::RSpecFailure.new \
|
135
135
|
config: ErrorToCommunicate::Config.default,
|
@@ -138,7 +138,7 @@ RSpec.describe ErrorToCommunicate::RSpecFormatter, rspec_formatter: true do
|
|
138
138
|
heuristicname, ((messagename, message), (codename, codeattrs), *rest) = heuristic.semantic_info
|
139
139
|
expect(heuristicname).to eq :heuristic
|
140
140
|
expect(messagename ).to eq :message
|
141
|
-
expect(message ).to eq
|
141
|
+
expect(message ).to eq "MESSAGE\n"
|
142
142
|
expect(codename ).to eq :code
|
143
143
|
expect(codeattrs[:location].path.to_s).to eq '/file'
|
144
144
|
expect(codeattrs[:context]).to eq (-5..5)
|
@@ -155,7 +155,7 @@ RSpec.describe ErrorToCommunicate::RSpecFormatter, rspec_formatter: true do
|
|
155
155
|
heuristicname, ((messagename, message), *rest) = heuristic.semantic_info
|
156
156
|
expect(heuristicname).to eq :heuristic
|
157
157
|
expect(messagename ).to eq :message
|
158
|
-
expect(message ).to eq
|
158
|
+
expect(message ).to eq "MESSAGE\n"
|
159
159
|
expect(rest).to be_empty
|
160
160
|
end
|
161
161
|
end
|
@@ -200,4 +200,37 @@ RSpec.describe ErrorToCommunicate::RSpecFormatter, rspec_formatter: true do
|
|
200
200
|
expect(heuristic.semantic_info).to eq "SEMANTICINFO"
|
201
201
|
end
|
202
202
|
end
|
203
|
+
|
204
|
+
context 'fixing the message\'s whitespace' do
|
205
|
+
def fix_whitespace(str)
|
206
|
+
ErrorToCommunicate::Heuristic::RSpecFailure.fix_whitespace str
|
207
|
+
end
|
208
|
+
|
209
|
+
it 'removes leading newlines' do
|
210
|
+
expect(fix_whitespace "\na").to start_with "a"
|
211
|
+
expect(fix_whitespace "\n\n\na").to start_with "a"
|
212
|
+
end
|
213
|
+
|
214
|
+
it 'removes all but one trailing newline' do
|
215
|
+
expect(fix_whitespace "a\n").to start_with "a\n"
|
216
|
+
expect(fix_whitespace "a\n\n").to start_with "a\n"
|
217
|
+
expect(fix_whitespace "a\n\n\n").to start_with "a\n"
|
218
|
+
end
|
219
|
+
|
220
|
+
it 'adds a trailing newline if its missing' do
|
221
|
+
expect(fix_whitespace "a").to start_with "a\n"
|
222
|
+
end
|
223
|
+
|
224
|
+
it 'doesn\'t modify the original string' do
|
225
|
+
a = "\na"
|
226
|
+
b = "a"
|
227
|
+
c = "a\n\n"
|
228
|
+
d = "a\n"
|
229
|
+
[a, b, c, d].each { |s| fix_whitespace s }
|
230
|
+
expect(a).to eq "\na"
|
231
|
+
expect(b).to eq "a"
|
232
|
+
expect(c).to eq "a\n\n"
|
233
|
+
expect(d).to eq "a\n"
|
234
|
+
end
|
235
|
+
end
|
203
236
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: what_weve_got_here_is_an_error_to_communicate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Cheek
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-06-
|
12
|
+
date: 2015-06-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rouge
|