what_weve_got_here_is_an_error_to_communicate 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f9ff0e4e8188c71874623d5b7f91c3b1628c733c
4
- data.tar.gz: aa5acc32a411201dc00d52ebf551b533a36d85fc
3
+ metadata.gz: db03e1ff78b344563fa7bda3ae8fe71e11831f4c
4
+ data.tar.gz: 16e844d556f1f78ffed35268471854e369dd54b3
5
5
  SHA512:
6
- metadata.gz: ad7c22761d89cce4c92264aadd62b3c1c1609d5713ed97c76d06d50cb6c7e5057b8856a3ac2240cb0f14122401cc51c10453bff5ff1f3385a1292cc1124205af
7
- data.tar.gz: 67ced68e105811bb22d0a1382eced38ae2830e1c8ebcb06f62852aeb9c0bde436b654217b31c3641452b2a674eee06c2eb45b2a63741a1c8461373cdada82fae
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, ' (expected '],
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
  ]
@@ -1,3 +1,3 @@
1
1
  module ErrorToCommunicate
2
- VERSION = '0.0.7'.freeze
2
+ VERSION = '0.0.8'.freeze
3
3
  end
@@ -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 include 'Wrong number of arguments'
30
- expect(stderr).to include '(expected 0, sent 1)'
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.7
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: 2015-12-24 00:00:00.000000000 Z
12
+ date: 2016-02-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rouge