Skip to content

Instantly share code, notes, and snippets.

@cantino
Last active August 29, 2015 14:14
Show Gist options
  • Save cantino/17cf8b7345c244b28d6b to your computer and use it in GitHub Desktop.
Save cantino/17cf8b7345c244b28d6b to your computer and use it in GitHub Desktop.
diff --git a/.gitignore b/.gitignore
index ae3fdc2..681170a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,3 +12,4 @@
*.o
*.a
mkmf.log
+.idea
diff --git a/lib/humanist_errors.rb b/lib/humanist_errors.rb
index 324f0a8..27384ce 100644
--- a/lib/humanist_errors.rb
+++ b/lib/humanist_errors.rb
@@ -1,5 +1,5 @@
require 'humanist_errors/version'
-require 'humanist_errors/human'
+require 'humanist_errors/exception_extensions'
require 'humanist_errors/monkey'
require 'humanist_errors/regex_hash'
diff --git a/test/humanist_test.rb b/test/humanist_test.rb
index a629c64..0e6a456 100644
--- a/test/humanist_test.rb
+++ b/test/humanist_test.rb
@@ -1,11 +1,6 @@
require_relative '../test_helper'
class HumanistTest < Minitest::Test
- def setup
- @starting_token = HumanistErrors::STARTING_TOKEN
- @ending_token = HumanistErrors::ENDING_TOKEN
- end
-
def test_error_mapper_for_syntax_error
humanist_message = HumanistErrors::ERROR_MAPPER[:syntax_error]["syntax error, unexpected ';'"]
real_humanist_message = HumanistErrors::MESSAGE_DICTIONARY[:syntax_error][:unexpected_semi_colon]
diff --git a/test/name_error_test.rb b/test/name_error_test.rb
index c98edf2..9b843ca 100644
--- a/test/name_error_test.rb
+++ b/test/name_error_test.rb
@@ -1,18 +1,13 @@
require_relative '../test_helper'
class NoMethodErrorTest < Minitest::Test
-
- def setup
- @starting_token = HumanistErrors::STARTING_TOKEN
- @ending_token = HumanistErrors::ENDING_TOKEN
- end
+ include HumanistErrorsSupport
def test_message_for_random_undefined_word
error = assert_raises(NameError) {
eval('asdf')
}
expected_message = HumanistErrors::MESSAGE_DICTIONARY[:name_error][:undefined_word]
- assert_match /#{@starting_token} #{expected_message} #{@ending_token}/, error.message
+ assert_message expected_message, error
end
-
end
diff --git a/test/no_method_error_test.rb b/test/no_method_error_test.rb
index 87b434b..e3a0981 100644
--- a/test/no_method_error_test.rb
+++ b/test/no_method_error_test.rb
@@ -1,18 +1,13 @@
require_relative '../test_helper'
class NoMethodErrorTest < Minitest::Test
-
- def setup
- @starting_token = HumanistErrors::STARTING_TOKEN
- @ending_token = HumanistErrors::ENDING_TOKEN
- end
+ include HumanistErrorsSupport
def test_message_for_undefined_method_on_nil
error = assert_raises(NoMethodError) {
eval('nil.nonexistentMethod')
}
expected_message = HumanistErrors::MESSAGE_DICTIONARY[:no_method_error][:undefined_method_for_nil]
- assert_match /#{@starting_token} #{expected_message} #{@ending_token}/, error.message
- end
-
+ assert_message expected_message, error
+ end
end
diff --git a/test/syntax_error_test.rb b/test/syntax_error_test.rb
index aa6f8a8..e693bfb 100644
--- a/test/syntax_error_test.rb
+++ b/test/syntax_error_test.rb
@@ -1,33 +1,30 @@
require_relative '../test_helper'
class SyntaxErrorTest < Minitest::Test
- def setup
- @starting_token = HumanistErrors::STARTING_TOKEN
- @ending_token = HumanistErrors::ENDING_TOKEN
- end
+ include HumanistErrorsSupport
def test_message_for_unexpected_semicolon
error = assert_raises(SyntaxError) { eval('1+;') }
expected_message = HumanistErrors::MESSAGE_DICTIONARY[:syntax_error][:unexpected_semi_colon]
- assert_match /#{@starting_token} #{expected_message} #{@ending_token}/, error.message
+ assert_message expected_message, error
end
def test_message_for_unterminated_string_meets_end_of_file
error = assert_raises(SyntaxError) { eval('"') }
expected_message = HumanistErrors::MESSAGE_DICTIONARY[:syntax_error][:open_quote]
- assert_match /#{@starting_token} #{expected_message} #{@ending_token}/, error.message
+ assert_message expected_message, error
end
def test_message_for_single_percent_sign
error = assert_raises(SyntaxError) { eval('%') }
expected_message = HumanistErrors::MESSAGE_DICTIONARY[:syntax_error][:string_formatter]
- assert_match /#{@starting_token} #{expected_message} #{@ending_token}/, error.message
+ assert_message expected_message, error
end
def test_message_for_missing_argument
error = assert_raises(SyntaxError) { eval('puts "foo", ') }
expected_message = HumanistErrors::MESSAGE_DICTIONARY[:syntax_error][:missing_argument]
- assert_match /#{@starting_token} #{expected_message} #{@ending_token}/, error.message
+ assert_message expected_message, error
end
def test_message_for_missing_block_closer
@@ -39,6 +36,6 @@ class SyntaxErrorTest < Minitest::Test
')
}
expected_message = HumanistErrors::MESSAGE_DICTIONARY[:syntax_error][:missing_block_closer]
- assert_match /#{@starting_token} #{expected_message} #{@ending_token}/, error.message
+ assert_message expected_message, error
end
end
diff --git a/test_helper.rb b/test_helper.rb
index dafe788..5c9c8d8 100644
--- a/test_helper.rb
+++ b/test_helper.rb
@@ -2,3 +2,10 @@ require 'humanist_errors'
require 'humanist_errors/search'
require 'minitest/autorun'
require 'minitest/emoji'
+
+module HumanistErrorsSupport
+ def assert_message(message, error)
+ string = [HumanistErrors::STARTING_TOKEN, message, HumanistErrors::ENDING_TOKEN].join(' ')
+ assert error.message.include?(string)
+ end
+end
\ No newline at end of file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment