what_weve_got_here_is_an_error_to_communicate 0.0.7 → 0.0.8
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/lib/error_to_communicate/heuristic/no_method_error.rb +9 -0
- data/lib/error_to_communicate/heuristic/wrong_number_of_arguments.rb +3 -3
- data/lib/error_to_communicate/version.rb +1 -1
- data/spec/acceptance/no_methood_error_spec.rb +57 -0
- data/spec/acceptance/wrong_number_of_arguments_spec.rb +2 -2
- 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: db03e1ff78b344563fa7bda3ae8fe71e11831f4c
|
4
|
+
data.tar.gz: 16e844d556f1f78ffed35268471854e369dd54b3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f0cf2c3e453604fe5ec06a1b1f7ac2568c19fc2aa60263f2742c3ba6b2571cb8c6acd5ff8f5f555ba0c0639116a3e63bb9f675ed3f6c4baf587e20ba63ee67d
|
7
|
+
data.tar.gz: d664d9467c1248586c837232c77b83c05fc987798499d60eda0aacc0823734d55fadf79b9956162a06503da9380ef9682af9097481560f05c29e53abf40d805f
|
@@ -48,6 +48,15 @@ module ErrorToCommunicate
|
|
48
48
|
tokens = Rouge::Lexers::Ruby.lex(line).to_a
|
49
49
|
index = tokens.index { |token, text| text == undefined_method_name }
|
50
50
|
|
51
|
+
if !index
|
52
|
+
return nil
|
53
|
+
# this happens when the tokens don't match the name, eg
|
54
|
+
# method name of "[]", and tokens of:
|
55
|
+
# [[<Token Punctuation>, "["],
|
56
|
+
# [<Token Literal.Number.Integer>, "0"],
|
57
|
+
# [<Token Punctuation>, "]"]]
|
58
|
+
end
|
59
|
+
|
51
60
|
while 0 <= index
|
52
61
|
token, text = tokens[index]
|
53
62
|
break if token.qualname == "Name.Variable.Instance"
|
@@ -19,10 +19,10 @@ module ErrorToCommunicate
|
|
19
19
|
def semantic_explanation
|
20
20
|
[ :message,
|
21
21
|
[ [:explanation, explanation],
|
22
|
-
[:context, ' (
|
23
|
-
[:details, num_expected],
|
24
|
-
[:context, ', sent '],
|
22
|
+
[:context, ' (given '],
|
25
23
|
[:details, num_received],
|
24
|
+
[:context, ', expected '],
|
25
|
+
[:details, num_expected],
|
26
26
|
[:context, ')'],
|
27
27
|
]
|
28
28
|
]
|
@@ -45,4 +45,61 @@ RSpec.describe 'NoMethodError', acceptance: true do
|
|
45
45
|
expect(stderr).to match /no_method_error\.rb:7\n.*?backtrace4/
|
46
46
|
expect(stderr).to match /no_method_error\.rb:14\n.*?Test.backtrace2/
|
47
47
|
end
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
it 'doesn\'t freak out on methods with punctuation names' do
|
52
|
+
# https://github.com/JoshCheek/mrspec/issues/11
|
53
|
+
write_file 'punctuation_no_method_error.rb', <<-BODY
|
54
|
+
require 'error_to_communicate/at_exit'
|
55
|
+
class Bowling
|
56
|
+
def self.score(rolls)
|
57
|
+
new(rolls).score
|
58
|
+
end
|
59
|
+
|
60
|
+
def initialize(rolls)
|
61
|
+
@rolls = rolls
|
62
|
+
end
|
63
|
+
|
64
|
+
def score(total=0)
|
65
|
+
current = rolls.shift
|
66
|
+
if strike?
|
67
|
+
current + rolls[1] + rolls[2] + total
|
68
|
+
else
|
69
|
+
current + total
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
attr_reader :rolls
|
76
|
+
|
77
|
+
def strike?
|
78
|
+
self[0] == 10
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
Bowling.score([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
|
83
|
+
BODY
|
84
|
+
|
85
|
+
invocation = ruby 'punctuation_no_method_error.rb'
|
86
|
+
stderr = strip_color invocation.stderr
|
87
|
+
|
88
|
+
# sanity
|
89
|
+
expect(invocation.stdout).to eq ''
|
90
|
+
expect(invocation.exitstatus).to eq 1
|
91
|
+
|
92
|
+
# error: It prints the exception class and message
|
93
|
+
expect(stderr).to include 'NoMethodError'
|
94
|
+
expect(stderr).to include "undefined method `[]'"
|
95
|
+
|
96
|
+
# heuristic:
|
97
|
+
expect(stderr).to match /self\[0\] == 10 \[\] is undefined/
|
98
|
+
|
99
|
+
# backtrace: It displays each line of the backtrace and includes the code from that line
|
100
|
+
expect(stderr).to match /punctuation_no_method_error\.rb:25/
|
101
|
+
expect(stderr).to match /punctuation_no_method_error\.rb:13/
|
102
|
+
expect(stderr).to match /punctuation_no_method_error\.rb:4/
|
103
|
+
expect(stderr).to match /punctuation_no_method_error\.rb:29/
|
104
|
+
end
|
48
105
|
end
|
@@ -26,8 +26,8 @@ RSpec.context 'WrongNumberOfArguments', acceptance: true do
|
|
26
26
|
|
27
27
|
# error: It prints the exception class and prints the reworded message
|
28
28
|
expect(stderr).to include 'ArgumentError'
|
29
|
-
expect(stderr).to
|
30
|
-
expect(stderr).to include '(
|
29
|
+
expect(stderr).to match /wrong number of arguments/i
|
30
|
+
expect(stderr).to include '(given 1, expected 0)'
|
31
31
|
|
32
32
|
# heuristic:
|
33
33
|
# It displays name of the file with the line number of the error
|
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.8
|
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:
|
12
|
+
date: 2016-02-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rouge
|