humanist-errors 1.0.2
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 +7 -0
- data/.gitignore +15 -0
- data/.rspec +2 -0
- data/.travis.yml +7 -0
- data/Gemfile +11 -0
- data/LICENSE.txt +22 -0
- data/README.md +78 -0
- data/Rakefile +25 -0
- data/dictionaries/humanist_errors.en.yml +16 -0
- data/humanist-errors.gemspec +25 -0
- data/lib/humanist_errors/colors.rb +37 -0
- data/lib/humanist_errors/error_mapper.rb +24 -0
- data/lib/humanist_errors/exception_extensions.rb +17 -0
- data/lib/humanist_errors/monkey.rb +1 -0
- data/lib/humanist_errors/regex_hash.rb +12 -0
- data/lib/humanist_errors/search.rb +36 -0
- data/lib/humanist_errors/version.rb +3 -0
- data/lib/humanist_errors.rb +20 -0
- data/test/backlog/argument_error_test.rb +4 -0
- data/test/backlog/eof_error_test.rb +4 -0
- data/test/backlog/fatal_test.rb +5 -0
- data/test/backlog/float_domain_error_test.rb +5 -0
- data/test/backlog/index_error_test.rb +6 -0
- data/test/backlog/interrupt_test.rb +5 -0
- data/test/backlog/io_error_test.rb +5 -0
- data/test/backlog/key_error_test.rb +5 -0
- data/test/backlog/load_error_test.rb +5 -0
- data/test/backlog/local_jump_error_test.rb +5 -0
- data/test/backlog/name_error_test.rb +11 -0
- data/test/backlog/no_method_error_test.rb +5 -0
- data/test/backlog/not_implemented_error_test.rb +5 -0
- data/test/backlog/range_error_test.rb +4 -0
- data/test/backlog/runtime_error_test.rb +5 -0
- data/test/backlog/script_error_test.rb +6 -0
- data/test/backlog/security_error_test.rb +5 -0
- data/test/backlog/signal_exception_test.rb +5 -0
- data/test/backlog/standard_error_test.rb +5 -0
- data/test/backlog/system_call_error_test.rb +5 -0
- data/test/backlog/system_exit_test.rb +6 -0
- data/test/backlog/system_stack_error_test.rb +5 -0
- data/test/backlog/thread_error_test.rb +5 -0
- data/test/backlog/zero_division_error_test.rb +5 -0
- data/test/error_mapper/name_error_test.rb +10 -0
- data/test/error_mapper/no_method_error_test.rb +10 -0
- data/test/error_mapper/syntax_error_test.rb +24 -0
- data/test/error_mapper/zero_division_error_test.rb +9 -0
- data/test/features/syntax_error_test.rb +21 -0
- data/test/monkey_test.rb +5 -0
- data/test/regex_hash_test.rb +15 -0
- data/test/search_test.rb +18 -0
- data/test/test_helper.rb +41 -0
- metadata +158 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 67284e894c5c76e41c30d799c9a537b9e0581332
|
4
|
+
data.tar.gz: 54d763fa1deaa765133161ed33a523f8c3932454
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 24472ae9f37f64bffbfc097fdb9835f6d9b03e3120257d35fc7a86a02fbbd5d9967cdbba268a986177ef3f3ac471d45eeacdc56acdfa03d6724bfd2460aeafe2
|
7
|
+
data.tar.gz: 92880e6a9cd86dbf7c0ea89f33bfdb593225febdcaabaed5f1d26ca3efc5e181f656d711076099f097070d163af23f018ecd7aa02f7945ccff10a6146dbe85bc
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 TODO: Write your name
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
[](https://codeclimate.com/github/bgreg/humanist-errors)[](https://codeclimate.com/github/bgreg/humanist-errors)[](https://travis-ci.org/bgreg/humanist-errors)
|
2
|
+
|
3
|
+
# Humanist::Errors
|
4
|
+
|
5
|
+
[](https://gitter.im/bgreg/humanist-errors?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
6
|
+
|
7
|
+
Humanist errors is a system for extending ruby exception messages.
|
8
|
+
It will prepend the standard output with text defined in the humanist errors dictionary.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'humanist-errors'
|
16
|
+
```
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
$ gem install humanist-errors
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
Include humanist errors in your project, and when ever you want better errors wrap your code like this:
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
with_human_errors do
|
32
|
+
#...
|
33
|
+
end
|
34
|
+
```
|
35
|
+
This gem is intended for use in development and test environments only.
|
36
|
+
|
37
|
+
## Contributing
|
38
|
+
|
39
|
+
1. Fork it ( https://github.com/[my-github-username]/humanist-errors/fork )
|
40
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
41
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
42
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
43
|
+
5. Create a new Pull Request
|
44
|
+
|
45
|
+
|
46
|
+
## TODO
|
47
|
+
1) fill out tests for search.rb
|
48
|
+
|
49
|
+
High level exception tree:
|
50
|
+
----
|
51
|
+
```ruby
|
52
|
+
Exception
|
53
|
+
NoMethodError
|
54
|
+
ScriptError
|
55
|
+
LoadError
|
56
|
+
NotImplementedError
|
57
|
+
SyntaxError
|
58
|
+
SignalException
|
59
|
+
Interrupt
|
60
|
+
StandardError
|
61
|
+
ArgumentError
|
62
|
+
IOError
|
63
|
+
EOFError
|
64
|
+
IndexError
|
65
|
+
LocalJumpError
|
66
|
+
NameError
|
67
|
+
NoMethodError
|
68
|
+
RangeError
|
69
|
+
FloatDomainError
|
70
|
+
RuntimeError
|
71
|
+
SecurityError
|
72
|
+
SystemCallError
|
73
|
+
SystemStackError
|
74
|
+
ThreadError
|
75
|
+
ZeroDivisionError
|
76
|
+
SystemExit
|
77
|
+
fatal
|
78
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "byebug"
|
3
|
+
test = File.expand_path('../test', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(test) unless $LOAD_PATH.include?(test)
|
5
|
+
|
6
|
+
# require 'logger'
|
7
|
+
# $logger = Logger.new('test.log')
|
8
|
+
|
9
|
+
task default: :test
|
10
|
+
|
11
|
+
task :test do
|
12
|
+
Dir.glob(['./test/*_test.rb', './test/error_mapper/*_test.rb','./test/features/*_test.rb']).each { |file| require file}
|
13
|
+
end
|
14
|
+
|
15
|
+
task :test_error_mapper do
|
16
|
+
Dir.glob('./test/error_mapper/*_test.rb').each { |file| require file}
|
17
|
+
end
|
18
|
+
|
19
|
+
task :test_features do
|
20
|
+
Dir.glob('./test/features/*_test.rb').each { |file| require file}
|
21
|
+
end
|
22
|
+
|
23
|
+
task :search_test do
|
24
|
+
require './test/search_test.rb'
|
25
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
:syntax_error:
|
2
|
+
:unexpected_semi_colon: "You may have missed an argument and ended this line early with a semicolon."
|
3
|
+
:open_quote: "It looks like you typed an open quote near the end of the file."
|
4
|
+
:string_formatter: "% string formatter requires a string argument on the left, and a format argument on the right"
|
5
|
+
:missing_argument: "You indicated that you wanted to send another argument, but we did not see anything."
|
6
|
+
:missing_block_closer: "a block or method was started, but you forgot to add 'end'"
|
7
|
+
|
8
|
+
:no_method_error:
|
9
|
+
:undefined_method_for_nil: "Most likely you forgot to define the variable, or it was turned to nil along the way."
|
10
|
+
|
11
|
+
:name_error:
|
12
|
+
:undefined_word: "You typed a random string that wasn't defined. It is not a method or variable in this class, or it's ancestors"
|
13
|
+
|
14
|
+
:zero_division_error:
|
15
|
+
:divide_by_zero: "Science has not figured out how to divide by zero yet. Damn you science!!!"
|
16
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'humanist_errors/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "humanist-errors"
|
8
|
+
spec.version = HumanistErrors::VERSION
|
9
|
+
spec.authors = ["Chester Law", "Greg McGuirk"]
|
10
|
+
spec.email = ["chesterlaw@me.com", "bgregmc@icloud.com"]
|
11
|
+
spec.summary = %q{More readable and friendly errors, for humans.}
|
12
|
+
spec.description = %q{This gem appends on the Ruby error output to give a most likely explanation of the problem, as well as in more understandable terms.}
|
13
|
+
spec.homepage = "http://www.gregmcguirk.com"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features|error_mapper)/})
|
19
|
+
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.required_ruby_version = '>= 2.0.0'
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module HumanistErrors
|
2
|
+
class Color
|
3
|
+
|
4
|
+
def black(string)
|
5
|
+
"\033[30m#{string}\033[0m"
|
6
|
+
end
|
7
|
+
|
8
|
+
def red(string)
|
9
|
+
"\033[31m#{string}\033[0m"
|
10
|
+
end
|
11
|
+
|
12
|
+
def green(string)
|
13
|
+
"\033[32m#{string}\033[0m"
|
14
|
+
end
|
15
|
+
|
16
|
+
def brown(string)
|
17
|
+
"\033[33m#{string}\033[0m"
|
18
|
+
end
|
19
|
+
|
20
|
+
def blue(string)
|
21
|
+
"\033[34m#{string}\033[0m"
|
22
|
+
end
|
23
|
+
|
24
|
+
def magenta(string)
|
25
|
+
"\033[35m#{string}\033[0m"
|
26
|
+
end
|
27
|
+
|
28
|
+
def cyan(string)
|
29
|
+
"\033[36m#{string}\033[0m"
|
30
|
+
end
|
31
|
+
|
32
|
+
def gray(string)
|
33
|
+
"\033[37m#{string}\033[0m"
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module HumanistErrors
|
2
|
+
ERROR_MAPPER = {
|
3
|
+
syntax_error: HumanistErrors::RegexHash[
|
4
|
+
/syntax error, unexpected ';'/ => MESSAGE_DICTIONARY[:syntax_error][:unexpected_semi_colon],
|
5
|
+
/unterminated string meets end of file/ => MESSAGE_DICTIONARY[:syntax_error][:open_quote],
|
6
|
+
/unterminated quoted string meets end of file/ => MESSAGE_DICTIONARY[:syntax_error][:string_formatter],
|
7
|
+
/syntax error, unexpected end-of-input, expecting keyword_end/ => MESSAGE_DICTIONARY[:syntax_error][:missing_block_closer],
|
8
|
+
/syntax error, unexpected end-of-input/ => MESSAGE_DICTIONARY[:syntax_error][:missing_argument],
|
9
|
+
/.*/ => :no_result
|
10
|
+
],
|
11
|
+
no_method_error: HumanistErrors::RegexHash[
|
12
|
+
/undefined method `.*' for nil:NilClass/ => MESSAGE_DICTIONARY[:no_method_error][:undefined_method_for_nil],
|
13
|
+
/.*/ => :no_result
|
14
|
+
],
|
15
|
+
name_error: HumanistErrors::RegexHash[
|
16
|
+
/undefined local variable or method `.*'/ => MESSAGE_DICTIONARY[:name_error][:undefined_word],
|
17
|
+
/.*/ => :no_result
|
18
|
+
],
|
19
|
+
zero_division_error: HumanistErrors::RegexHash[
|
20
|
+
/divided by 0/ => MESSAGE_DICTIONARY[:zero_division_error][:divide_by_zero],
|
21
|
+
/.*/ => :no_result
|
22
|
+
]
|
23
|
+
}
|
24
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module HumanistErrors
|
2
|
+
module ExceptionExtensions
|
3
|
+
def to_s
|
4
|
+
searcher = Search.run(self.class, super)
|
5
|
+
if searcher.found_error == :no_result
|
6
|
+
super
|
7
|
+
else
|
8
|
+
color = Color.new
|
9
|
+
"\n#{STARTING_TOKEN}"+
|
10
|
+
"\t#{color.cyan(searcher.found_error)}\n"+
|
11
|
+
"#{ENDING_TOKEN}" +
|
12
|
+
super
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
::Exception.send(:prepend, HumanistErrors::ExceptionExtensions)
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module HumanistErrors
|
2
|
+
class RegexHash < Hash
|
3
|
+
def [](value)
|
4
|
+
result = self.select { |k| k =~ value }
|
5
|
+
if result.empty?
|
6
|
+
raise NotImplementedError, "Could not find Ruby message in dictionary: #{value}"
|
7
|
+
else
|
8
|
+
result.shift[1]
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module HumanistErrors
|
2
|
+
class Search
|
3
|
+
attr_accessor :found_error
|
4
|
+
attr_accessor :error_object, :ruby_error_message
|
5
|
+
|
6
|
+
def self.run(error_object, ruby_error_message)
|
7
|
+
searcher = new(error_object, ruby_error_message)
|
8
|
+
searcher.found_error = searcher.find
|
9
|
+
searcher
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(error_object, ruby_error_message)
|
13
|
+
@error_object = error_object
|
14
|
+
@ruby_error_message = ruby_error_message
|
15
|
+
end
|
16
|
+
|
17
|
+
def find
|
18
|
+
error = keyify(error_object)
|
19
|
+
return :no_result unless ERROR_MAPPER.keys.include?(error)
|
20
|
+
ERROR_MAPPER[error][ruby_error_message]
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def keyify(error)
|
26
|
+
error.to_s
|
27
|
+
.gsub(/::/, '__')
|
28
|
+
.gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
|
29
|
+
.gsub(/([a-z\d])([A-Z])/,'\1_\2')
|
30
|
+
.tr("-", "_")
|
31
|
+
.downcase
|
32
|
+
.to_sym
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'humanist_errors/version'
|
3
|
+
require 'humanist_errors/exception_extensions'
|
4
|
+
require 'humanist_errors/regex_hash'
|
5
|
+
require 'humanist_errors/search'
|
6
|
+
require 'humanist_errors/colors'
|
7
|
+
|
8
|
+
module HumanistErrors
|
9
|
+
color = Color.new
|
10
|
+
STARTING_TOKEN = color.green("Hi!\n")
|
11
|
+
ENDING_TOKEN = color.green("Here's the error from Ruby: \n")
|
12
|
+
MESSAGE_DICTIONARY = YAML.load(File.read(File.expand_path('../../dictionaries/humanist_errors.en.yml', __FILE__)))
|
13
|
+
|
14
|
+
def with_human_errors
|
15
|
+
require 'humanist_errors/monkey'
|
16
|
+
yield
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'humanist_errors/error_mapper'
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class NoMethodErrorTest < Minitest::Test
|
4
|
+
include HumanistErrorsSupport
|
5
|
+
|
6
|
+
def test_message_for_random_undefined_word
|
7
|
+
# error = assert_raises(NameError) { eval('asdf') }
|
8
|
+
# expected_message = HumanistErrors::MESSAGE_DICTIONARY[:name_error][:undefined_word]
|
9
|
+
# assert_message(expected_message, error)
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class NameErrorTest < Minitest::Test
|
4
|
+
include HumanistErrorsSupport
|
5
|
+
|
6
|
+
def test_message_for_random_undefined_word
|
7
|
+
assert_error_map("NameError: undefined local variable or method `asdf' for main:Object",
|
8
|
+
:name_error, :undefined_word)
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class NoMethodErrorTest < Minitest::Test
|
4
|
+
include HumanistErrorsSupport
|
5
|
+
|
6
|
+
def test_error_mapper_for_no_method_error
|
7
|
+
assert_error_map("undefined method `nonexistentMethod' for nil:NilClass",
|
8
|
+
:no_method_error, :undefined_method_for_nil)
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class SyntaxErrorTest < Minitest::Test
|
4
|
+
include HumanistErrorsSupport
|
5
|
+
|
6
|
+
def test_error_mapper_for_syntax_error
|
7
|
+
assert_error_map("syntax error, unexpected ';'", :syntax_error, :unexpected_semi_colon)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_message_for_unterminated_string_meets_end_of_file
|
11
|
+
assert_error_map("unterminated string meets end of file", :syntax_error, :open_quote)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_message_for_single_percent_sign
|
15
|
+
assert_error_map("unterminated quoted string meets end of file", :syntax_error, :string_formatter)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_message_for_missing_block_closer
|
19
|
+
assert_error_map(
|
20
|
+
'syntax error, unexpected end-of-input, expecting keyword_end',
|
21
|
+
:syntax_error,
|
22
|
+
:missing_block_closer)
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class SyntaxErrorTest < Minitest::Test
|
4
|
+
def test_message_for_unexpected_semicolon
|
5
|
+
error_message = human_fork(SyntaxError) { eval('1+;') }
|
6
|
+
expected_message = HumanistErrors::MESSAGE_DICTIONARY[:syntax_error][:unexpected_semi_colon]
|
7
|
+
assert_match(expected_message, error_message)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_messge_for_missing_end
|
11
|
+
error_message = human_fork(SyntaxError) do
|
12
|
+
eval(
|
13
|
+
" def stuff
|
14
|
+
opps = 'I did it again'
|
15
|
+
"
|
16
|
+
)
|
17
|
+
end
|
18
|
+
expected_message = HumanistErrors::MESSAGE_DICTIONARY[:syntax_error][:missing_block_closer]
|
19
|
+
assert_match(expected_message, error_message)
|
20
|
+
end
|
21
|
+
end
|
data/test/monkey_test.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class RegexHashTest < Minitest::Test
|
4
|
+
|
5
|
+
def test_a_regex_search_happens_on_key_send
|
6
|
+
magic_string_hash = HumanistErrors::RegexHash[/findme/ => "hurray!"]
|
7
|
+
assert_match(magic_string_hash['findme'], "hurray!")
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_a_failure_when_key_is_not_found
|
11
|
+
magic_string_hash = HumanistErrors::RegexHash[/findme/ => "hurray!"]
|
12
|
+
error = assert_raises(NotImplementedError) { magic_string_hash['1'] }
|
13
|
+
assert(error.message.include?("Could not find Ruby message in dictionary: 1"))
|
14
|
+
end
|
15
|
+
end
|
data/test/search_test.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class SearchTest < Minitest::Test
|
4
|
+
def test_finds_a_human_error
|
5
|
+
searcher = HumanistErrors::Search.run(
|
6
|
+
NameError,
|
7
|
+
"NameError: undefined local variable or method `asdf' for main:Object"
|
8
|
+
)
|
9
|
+
expected_result = HumanistErrors::MESSAGE_DICTIONARY[:name_error][:undefined_word]
|
10
|
+
assert(searcher.found_error == expected_result, "#{searcher.found_error.inspect} does not equal: #{expected_result.inspect}")
|
11
|
+
end
|
12
|
+
|
13
|
+
class DefinatelyNotARealException; end
|
14
|
+
def test_cannot_find_a_error_message
|
15
|
+
searcher = HumanistErrors::Search.run(DefinatelyNotARealException, "blah blah blah")
|
16
|
+
assert(searcher.found_error == :no_result, "#{searcher.found_error.inspect} does not equal: :no_result")
|
17
|
+
end
|
18
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# require "codeclimate-test-reporter"
|
2
|
+
# CodeClimate::TestReporter.start
|
3
|
+
|
4
|
+
require 'humanist_errors'
|
5
|
+
require 'humanist_errors/search'
|
6
|
+
require 'humanist_errors/error_mapper'
|
7
|
+
require 'minitest/focus'
|
8
|
+
require 'minitest/emoji'
|
9
|
+
require 'minitest/autorun'
|
10
|
+
|
11
|
+
module HumanistErrorsSupport
|
12
|
+
|
13
|
+
def assert_result(message)
|
14
|
+
assert(message != :no_result, "no result was found")
|
15
|
+
end
|
16
|
+
|
17
|
+
def assert_error_map(ruby_error, exception_symbol, error_symbol)
|
18
|
+
result = HumanistErrors::ERROR_MAPPER[exception_symbol][ruby_error]
|
19
|
+
assert_result(result)
|
20
|
+
assert_match(result, HumanistErrors::MESSAGE_DICTIONARY[exception_symbol][error_symbol])
|
21
|
+
end
|
22
|
+
|
23
|
+
def human_fork(exception)
|
24
|
+
reader, writer = IO.pipe
|
25
|
+
|
26
|
+
fork do
|
27
|
+
reader.close
|
28
|
+
require 'humanist_errors/monkey'
|
29
|
+
begin
|
30
|
+
yield
|
31
|
+
rescue exception => e
|
32
|
+
writer.puts e.message
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
writer.close
|
37
|
+
reader.gets(nil)
|
38
|
+
ensure
|
39
|
+
reader.close
|
40
|
+
end
|
41
|
+
end
|
metadata
ADDED
@@ -0,0 +1,158 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: humanist-errors
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chester Law
|
8
|
+
- Greg McGuirk
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-09-20 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.7'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.7'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '10.0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '10.0'
|
42
|
+
description: This gem appends on the Ruby error output to give a most likely explanation
|
43
|
+
of the problem, as well as in more understandable terms.
|
44
|
+
email:
|
45
|
+
- chesterlaw@me.com
|
46
|
+
- bgregmc@icloud.com
|
47
|
+
executables: []
|
48
|
+
extensions: []
|
49
|
+
extra_rdoc_files: []
|
50
|
+
files:
|
51
|
+
- ".gitignore"
|
52
|
+
- ".rspec"
|
53
|
+
- ".travis.yml"
|
54
|
+
- Gemfile
|
55
|
+
- LICENSE.txt
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- dictionaries/humanist_errors.en.yml
|
59
|
+
- humanist-errors.gemspec
|
60
|
+
- lib/humanist_errors.rb
|
61
|
+
- lib/humanist_errors/colors.rb
|
62
|
+
- lib/humanist_errors/error_mapper.rb
|
63
|
+
- lib/humanist_errors/exception_extensions.rb
|
64
|
+
- lib/humanist_errors/monkey.rb
|
65
|
+
- lib/humanist_errors/regex_hash.rb
|
66
|
+
- lib/humanist_errors/search.rb
|
67
|
+
- lib/humanist_errors/version.rb
|
68
|
+
- test/backlog/argument_error_test.rb
|
69
|
+
- test/backlog/eof_error_test.rb
|
70
|
+
- test/backlog/fatal_test.rb
|
71
|
+
- test/backlog/float_domain_error_test.rb
|
72
|
+
- test/backlog/index_error_test.rb
|
73
|
+
- test/backlog/interrupt_test.rb
|
74
|
+
- test/backlog/io_error_test.rb
|
75
|
+
- test/backlog/key_error_test.rb
|
76
|
+
- test/backlog/load_error_test.rb
|
77
|
+
- test/backlog/local_jump_error_test.rb
|
78
|
+
- test/backlog/name_error_test.rb
|
79
|
+
- test/backlog/no_method_error_test.rb
|
80
|
+
- test/backlog/not_implemented_error_test.rb
|
81
|
+
- test/backlog/range_error_test.rb
|
82
|
+
- test/backlog/runtime_error_test.rb
|
83
|
+
- test/backlog/script_error_test.rb
|
84
|
+
- test/backlog/security_error_test.rb
|
85
|
+
- test/backlog/signal_exception_test.rb
|
86
|
+
- test/backlog/standard_error_test.rb
|
87
|
+
- test/backlog/system_call_error_test.rb
|
88
|
+
- test/backlog/system_exit_test.rb
|
89
|
+
- test/backlog/system_stack_error_test.rb
|
90
|
+
- test/backlog/thread_error_test.rb
|
91
|
+
- test/backlog/zero_division_error_test.rb
|
92
|
+
- test/error_mapper/name_error_test.rb
|
93
|
+
- test/error_mapper/no_method_error_test.rb
|
94
|
+
- test/error_mapper/syntax_error_test.rb
|
95
|
+
- test/error_mapper/zero_division_error_test.rb
|
96
|
+
- test/features/syntax_error_test.rb
|
97
|
+
- test/monkey_test.rb
|
98
|
+
- test/regex_hash_test.rb
|
99
|
+
- test/search_test.rb
|
100
|
+
- test/test_helper.rb
|
101
|
+
homepage: http://www.gregmcguirk.com
|
102
|
+
licenses:
|
103
|
+
- MIT
|
104
|
+
metadata: {}
|
105
|
+
post_install_message:
|
106
|
+
rdoc_options: []
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: 2.0.0
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
requirements: []
|
120
|
+
rubyforge_project:
|
121
|
+
rubygems_version: 2.4.5.1
|
122
|
+
signing_key:
|
123
|
+
specification_version: 4
|
124
|
+
summary: More readable and friendly errors, for humans.
|
125
|
+
test_files:
|
126
|
+
- test/backlog/argument_error_test.rb
|
127
|
+
- test/backlog/eof_error_test.rb
|
128
|
+
- test/backlog/fatal_test.rb
|
129
|
+
- test/backlog/float_domain_error_test.rb
|
130
|
+
- test/backlog/index_error_test.rb
|
131
|
+
- test/backlog/interrupt_test.rb
|
132
|
+
- test/backlog/io_error_test.rb
|
133
|
+
- test/backlog/key_error_test.rb
|
134
|
+
- test/backlog/load_error_test.rb
|
135
|
+
- test/backlog/local_jump_error_test.rb
|
136
|
+
- test/backlog/name_error_test.rb
|
137
|
+
- test/backlog/no_method_error_test.rb
|
138
|
+
- test/backlog/not_implemented_error_test.rb
|
139
|
+
- test/backlog/range_error_test.rb
|
140
|
+
- test/backlog/runtime_error_test.rb
|
141
|
+
- test/backlog/script_error_test.rb
|
142
|
+
- test/backlog/security_error_test.rb
|
143
|
+
- test/backlog/signal_exception_test.rb
|
144
|
+
- test/backlog/standard_error_test.rb
|
145
|
+
- test/backlog/system_call_error_test.rb
|
146
|
+
- test/backlog/system_exit_test.rb
|
147
|
+
- test/backlog/system_stack_error_test.rb
|
148
|
+
- test/backlog/thread_error_test.rb
|
149
|
+
- test/backlog/zero_division_error_test.rb
|
150
|
+
- test/error_mapper/name_error_test.rb
|
151
|
+
- test/error_mapper/no_method_error_test.rb
|
152
|
+
- test/error_mapper/syntax_error_test.rb
|
153
|
+
- test/error_mapper/zero_division_error_test.rb
|
154
|
+
- test/features/syntax_error_test.rb
|
155
|
+
- test/monkey_test.rb
|
156
|
+
- test/regex_hash_test.rb
|
157
|
+
- test/search_test.rb
|
158
|
+
- test/test_helper.rb
|