did_you_mean 1.2.1 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +39 -0
- data/CHANGELOG.md +172 -57
- data/Gemfile +2 -0
- data/README.md +79 -28
- data/Rakefile +38 -12
- data/appveyor.yml +25 -0
- data/benchmark/jaro_winkler/memory_usage.rb +4 -4
- data/benchmark/jaro_winkler/speed.rb +14 -6
- data/benchmark/levenshtein/memory_usage.rb +4 -4
- data/benchmark/levenshtein/speed.rb +13 -8
- data/benchmark/require_path_checker.rb +47 -0
- data/benchmark/speed.yml +13 -0
- data/did_you_mean.gemspec +6 -4
- data/documentation/CHANGELOG.md.erb +8 -0
- data/documentation/changelog_generator.rb +34 -0
- data/documentation/human_typo_api.md +20 -0
- data/documentation/tree_spell_algorithm.md +82 -0
- data/documentation/tree_spell_checker_api.md +24 -0
- data/lib/did_you_mean.rb +95 -52
- data/lib/did_you_mean/core_ext/name_error.rb +4 -6
- data/lib/did_you_mean/experimental.rb +2 -2
- data/lib/did_you_mean/formatters/plain_formatter.rb +24 -0
- data/lib/did_you_mean/formatters/verbose_formatter.rb +36 -0
- data/lib/did_you_mean/levenshtein.rb +1 -1
- data/lib/did_you_mean/spell_checker.rb +8 -14
- data/lib/did_you_mean/spell_checkers/key_error_checker.rb +8 -2
- data/lib/did_you_mean/spell_checkers/method_name_checker.rb +48 -6
- data/lib/did_you_mean/spell_checkers/name_error_checkers.rb +2 -2
- data/lib/did_you_mean/spell_checkers/name_error_checkers/class_name_checker.rb +5 -5
- data/lib/did_you_mean/spell_checkers/name_error_checkers/variable_name_checker.rb +56 -4
- data/lib/did_you_mean/spell_checkers/require_path_checker.rb +35 -0
- data/lib/did_you_mean/tree_spell_checker.rb +109 -0
- data/lib/did_you_mean/verbose.rb +2 -2
- data/lib/did_you_mean/version.rb +1 -1
- data/test/core_ext/test_name_error_extension.rb +48 -0
- data/test/edit_distance/{jaro_winkler_test.rb → test_jaro_winkler.rb} +2 -2
- data/test/fixtures/book.rb +1 -1
- data/test/fixtures/mini_dir.yml +15 -0
- data/test/fixtures/rspec_dir.yml +112 -0
- data/test/helper.rb +29 -0
- data/test/spell_checking/{class_name_check_test.rb → test_class_name_check.rb} +15 -11
- data/test/spell_checking/{key_name_check_test.rb → test_key_name_check.rb} +18 -8
- data/test/spell_checking/{method_name_check_test.rb → test_method_name_check.rb} +41 -13
- data/test/spell_checking/test_require_path_check.rb +32 -0
- data/test/spell_checking/{uncorrectable_name_check_test.rb → test_uncorrectable_name_check.rb} +3 -3
- data/test/spell_checking/{variable_name_check_test.rb → test_variable_name_check.rb} +36 -18
- data/test/{spell_checker_test.rb → test_spell_checker.rb} +2 -2
- data/test/test_tree_spell_checker.rb +170 -0
- data/test/test_verbose_formatter.rb +23 -0
- data/test/tree_spell/change_word.rb +61 -0
- data/test/tree_spell/human_typo.rb +69 -0
- data/test/tree_spell/test_change_word.rb +38 -0
- data/test/tree_spell/test_explore.rb +128 -0
- data/test/tree_spell/test_human_typo.rb +24 -0
- metadata +53 -66
- data/.ruby-version +0 -1
- data/.travis.yml +0 -14
- data/lib/did_you_mean/experimental/initializer_name_correction.rb +0 -20
- data/lib/did_you_mean/experimental/ivar_name_correction.rb +0 -74
- data/lib/did_you_mean/verbose_formatter.rb +0 -7
- data/test/core_ext/name_error_extension_test.rb +0 -47
- data/test/deprecated_formatter_test.rb +0 -9
- data/test/experimental/initializer_name_correction_test.rb +0 -15
- data/test/experimental/method_name_checker_test.rb +0 -13
- data/test/test_helper.rb +0 -13
- data/test/verbose_formatter_test.rb +0 -23
@@ -0,0 +1,112 @@
|
|
1
|
+
---
|
2
|
+
- spec/spec_helper.rb
|
3
|
+
- spec/integration/suite_hooks_errors_spec.rb
|
4
|
+
- spec/integration/filtering_spec.rb
|
5
|
+
- spec/integration/spec_file_load_errors_spec.rb
|
6
|
+
- spec/integration/failed_line_detection_spec.rb
|
7
|
+
- spec/integration/persistence_failures_spec.rb
|
8
|
+
- spec/integration/bisect_runners_spec.rb
|
9
|
+
- spec/integration/order_spec.rb
|
10
|
+
- spec/integration/fail_if_no_examples_spec.rb
|
11
|
+
- spec/integration/bisect_spec.rb
|
12
|
+
- spec/integration/output_stream_spec.rb
|
13
|
+
- spec/support/sandboxing.rb
|
14
|
+
- spec/support/spec_files.rb
|
15
|
+
- spec/support/fake_libs/json.rb
|
16
|
+
- spec/support/fake_libs/open3.rb
|
17
|
+
- spec/support/fake_libs/drb/acl.rb
|
18
|
+
- spec/support/fake_libs/drb/drb.rb
|
19
|
+
- spec/support/fake_libs/mocha/api.rb
|
20
|
+
- spec/support/fake_libs/test/unit/assertions.rb
|
21
|
+
- spec/support/fake_libs/flexmock/rspec.rb
|
22
|
+
- spec/support/fake_libs/rake/tasklib.rb
|
23
|
+
- spec/support/fake_libs/coderay.rb
|
24
|
+
- spec/support/fake_libs/rr.rb
|
25
|
+
- spec/support/fake_libs/rake.rb
|
26
|
+
- spec/support/fake_libs/erb.rb
|
27
|
+
- spec/support/fake_libs/rspec/mocks.rb
|
28
|
+
- spec/support/fake_libs/rspec/expectations.rb
|
29
|
+
- spec/support/fake_libs/minitest/assertions.rb
|
30
|
+
- spec/support/fake_libs/minitest.rb
|
31
|
+
- spec/support/matchers.rb
|
32
|
+
- spec/support/runner_support.rb
|
33
|
+
- spec/support/isolated_home_directory.rb
|
34
|
+
- spec/support/config_options_helper.rb
|
35
|
+
- spec/support/mathn_integration_support.rb
|
36
|
+
- spec/support/helper_methods.rb
|
37
|
+
- spec/support/formatter_support.rb
|
38
|
+
- spec/support/fake_bisect_runner.rb
|
39
|
+
- spec/support/shared_example_groups.rb
|
40
|
+
- spec/support/aruba_support.rb
|
41
|
+
- spec/rspec/core/runner_spec.rb
|
42
|
+
- spec/rspec/core/did_you_mean_spec.rb
|
43
|
+
- spec/rspec/core/drb_spec.rb
|
44
|
+
- spec/rspec/core/metadata_spec.rb
|
45
|
+
- spec/rspec/core/example_group_spec.rb
|
46
|
+
- spec/rspec/core/configuration/only_failures_support_spec.rb
|
47
|
+
- spec/rspec/core/rake_task_spec.rb
|
48
|
+
- spec/rspec/core/memoized_helpers_spec.rb
|
49
|
+
- spec/rspec/core/ordering_spec.rb
|
50
|
+
- spec/rspec/core/option_parser_spec.rb
|
51
|
+
- spec/rspec/core/example_execution_result_spec.rb
|
52
|
+
- spec/rspec/core/suite_hooks_spec.rb
|
53
|
+
- spec/rspec/core/set_spec.rb
|
54
|
+
- spec/rspec/core/configuration_spec.rb
|
55
|
+
- spec/rspec/core/rspec_matchers_spec.rb
|
56
|
+
- spec/rspec/core/hooks_filtering_spec.rb
|
57
|
+
- spec/rspec/core/bisect/shell_command_spec.rb
|
58
|
+
- spec/rspec/core/bisect/server_spec.rb
|
59
|
+
- spec/rspec/core/bisect/example_minimizer_spec.rb
|
60
|
+
- spec/rspec/core/bisect/shell_runner_spec.rb
|
61
|
+
- spec/rspec/core/bisect/utilities_spec.rb
|
62
|
+
- spec/rspec/core/bisect/coordinator_spec.rb
|
63
|
+
- spec/rspec/core/resources/a_foo.rb
|
64
|
+
- spec/rspec/core/resources/formatter_specs.rb
|
65
|
+
- spec/rspec/core/resources/inconsistently_ordered_specs.rb
|
66
|
+
- spec/rspec/core/resources/a_bar.rb
|
67
|
+
- spec/rspec/core/resources/utf8_encoded.rb
|
68
|
+
- spec/rspec/core/resources/a_spec.rb
|
69
|
+
- spec/rspec/core/resources/acceptance/bar.rb
|
70
|
+
- spec/rspec/core/resources/acceptance/foo_spec.rb
|
71
|
+
- spec/rspec/core/resources/custom_example_group_runner.rb
|
72
|
+
- spec/rspec/core/failed_example_notification_spec.rb
|
73
|
+
- spec/rspec/core/hooks_spec.rb
|
74
|
+
- spec/rspec/core/formatters/profile_formatter_spec.rb
|
75
|
+
- spec/rspec/core/formatters/deprecation_formatter_spec.rb
|
76
|
+
- spec/rspec/core/formatters/syntax_highlighter_spec.rb
|
77
|
+
- spec/rspec/core/formatters/base_text_formatter_spec.rb
|
78
|
+
- spec/rspec/core/formatters/snippet_extractor_spec.rb
|
79
|
+
- spec/rspec/core/formatters/progress_formatter_spec.rb
|
80
|
+
- spec/rspec/core/formatters/html_snippet_extractor_spec.rb
|
81
|
+
- spec/rspec/core/formatters/helpers_spec.rb
|
82
|
+
- spec/rspec/core/formatters/html_formatter_spec.rb
|
83
|
+
- spec/rspec/core/formatters/json_formatter_spec.rb
|
84
|
+
- spec/rspec/core/formatters/documentation_formatter_spec.rb
|
85
|
+
- spec/rspec/core/formatters/exception_presenter_spec.rb
|
86
|
+
- spec/rspec/core/formatters/console_codes_spec.rb
|
87
|
+
- spec/rspec/core/formatters/fallback_message_formatter_spec.rb
|
88
|
+
- spec/rspec/core/invocations_spec.rb
|
89
|
+
- spec/rspec/core/configuration_options_spec.rb
|
90
|
+
- spec/rspec/core/pending_spec.rb
|
91
|
+
- spec/rspec/core/profiler_spec.rb
|
92
|
+
- spec/rspec/core/project_initializer_spec.rb
|
93
|
+
- spec/rspec/core/aggregate_failures_spec.rb
|
94
|
+
- spec/rspec/core/dsl_spec.rb
|
95
|
+
- spec/rspec/core/ruby_project_spec.rb
|
96
|
+
- spec/rspec/core/formatters_spec.rb
|
97
|
+
- spec/rspec/core/metadata_filter_spec.rb
|
98
|
+
- spec/rspec/core/example_group_constants_spec.rb
|
99
|
+
- spec/rspec/core/world_spec.rb
|
100
|
+
- spec/rspec/core/shared_context_spec.rb
|
101
|
+
- spec/rspec/core/pending_example_spec.rb
|
102
|
+
- spec/rspec/core/filter_manager_spec.rb
|
103
|
+
- spec/rspec/core/shared_example_group_spec.rb
|
104
|
+
- spec/rspec/core/example_status_persister_spec.rb
|
105
|
+
- spec/rspec/core/backtrace_formatter_spec.rb
|
106
|
+
- spec/rspec/core/output_wrapper_spec.rb
|
107
|
+
- spec/rspec/core/example_spec.rb
|
108
|
+
- spec/rspec/core/reporter_spec.rb
|
109
|
+
- spec/rspec/core/filterable_item_repository_spec.rb
|
110
|
+
- spec/rspec/core/notifications_spec.rb
|
111
|
+
- spec/rspec/core/warnings_spec.rb
|
112
|
+
- spec/rspec/core_spec.rb
|
data/test/helper.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
|
3
|
+
module DidYouMean
|
4
|
+
module TestHelper
|
5
|
+
class << self
|
6
|
+
attr_reader :root
|
7
|
+
end
|
8
|
+
|
9
|
+
if File.file?(File.expand_path('../lib/did_you_mean.rb', __dir__))
|
10
|
+
# In this case we're being run from inside the gem, so we just want to
|
11
|
+
# require the root of the library
|
12
|
+
|
13
|
+
@root = File.expand_path('../lib/did_you_mean', __dir__)
|
14
|
+
require_relative @root
|
15
|
+
else
|
16
|
+
# In this case we're being run from inside ruby core, and we want to
|
17
|
+
# include the experimental features in the test suite
|
18
|
+
|
19
|
+
@root = File.expand_path('../../lib/did_you_mean', __dir__)
|
20
|
+
require_relative @root
|
21
|
+
# We are excluding experimental features for now.
|
22
|
+
# require_relative File.join(@root, 'experimental')
|
23
|
+
end
|
24
|
+
|
25
|
+
def assert_correction(expected, array)
|
26
|
+
assert_equal Array(expected), array, "Expected #{array.inspect} to only include #{expected.inspect}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require_relative '../helper'
|
2
2
|
|
3
3
|
module ACRONYM
|
4
4
|
end
|
@@ -27,48 +27,52 @@ class Book
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
class ClassNameCheckTest <
|
30
|
+
class ClassNameCheckTest < Test::Unit::TestCase
|
31
|
+
include DidYouMean::TestHelper
|
32
|
+
|
31
33
|
def test_corrections
|
32
|
-
error =
|
34
|
+
error = assert_raise(NameError) { ::Bo0k }
|
33
35
|
assert_correction "Book", error.corrections
|
34
36
|
end
|
35
37
|
|
36
38
|
def test_corrections_include_case_specific_class_name
|
37
|
-
error =
|
39
|
+
error = assert_raise(NameError) { ::Acronym }
|
38
40
|
assert_correction "ACRONYM", error.corrections
|
39
41
|
end
|
40
42
|
|
41
43
|
def test_corrections_include_top_level_class_name
|
42
|
-
error =
|
44
|
+
error = assert_raise(NameError) { Project.bo0k }
|
43
45
|
assert_correction "Book", error.corrections
|
44
46
|
end
|
45
47
|
|
46
48
|
def test_names_in_corrections_have_namespaces
|
47
|
-
error =
|
49
|
+
error = assert_raise(NameError) { ::Book::TableofContents }
|
48
50
|
assert_correction "Book::TableOfContents", error.corrections
|
49
51
|
end
|
50
52
|
|
51
53
|
def test_corrections_candidates_for_names_in_upper_level_scopes
|
52
|
-
error =
|
54
|
+
error = assert_raise(NameError) { Book::Page.tableof_contents }
|
53
55
|
assert_correction "Book::TableOfContents", error.corrections
|
54
56
|
end
|
55
57
|
|
56
58
|
def test_corrections_should_work_from_within_instance_method
|
57
|
-
error =
|
59
|
+
error = assert_raise(NameError) { ::Book.new.tableof_contents }
|
58
60
|
assert_correction "Book::TableOfContents", error.corrections
|
59
61
|
end
|
60
62
|
|
61
63
|
def test_corrections_should_work_from_within_instance_method_on_nested_class
|
62
|
-
error =
|
64
|
+
error = assert_raise(NameError) { ::Book::Page.new.tableof_contents }
|
63
65
|
assert_correction "Book::TableOfContents", error.corrections
|
64
66
|
end
|
65
67
|
|
66
68
|
def test_does_not_suggest_user_input
|
67
|
-
|
69
|
+
Book.send(:remove_const, :Spine) if Book.constants.include?(:Spine)
|
70
|
+
|
71
|
+
error = assert_raise(NameError) { ::Book::Spine }
|
68
72
|
|
69
73
|
# This is a weird require, but in a multi-threaded condition, a constant may
|
70
74
|
# be loaded between when a NameError occurred and when the spell checker
|
71
|
-
#
|
75
|
+
# attempts to find a possible suggestion. The manual require here simulates
|
72
76
|
# a race condition a single test.
|
73
77
|
require_relative '../fixtures/book'
|
74
78
|
|
@@ -1,14 +1,16 @@
|
|
1
|
-
|
1
|
+
require_relative '../helper'
|
2
|
+
|
3
|
+
class KeyNameCheckTest < Test::Unit::TestCase
|
4
|
+
include DidYouMean::TestHelper
|
2
5
|
|
3
|
-
class KeyNameCheckTest < Minitest::Test
|
4
6
|
def test_corrects_hash_key_name_with_fetch
|
5
7
|
hash = { "foo" => 1, bar: 2 }
|
6
8
|
|
7
|
-
error =
|
9
|
+
error = assert_raise(KeyError) { hash.fetch(:bax) }
|
8
10
|
assert_correction ":bar", error.corrections
|
9
11
|
assert_match "Did you mean? :bar", error.to_s
|
10
12
|
|
11
|
-
error =
|
13
|
+
error = assert_raise(KeyError) { hash.fetch("fooo") }
|
12
14
|
assert_correction %("foo"), error.corrections
|
13
15
|
assert_match %(Did you mean? "foo"), error.to_s
|
14
16
|
end
|
@@ -16,17 +18,25 @@ class KeyNameCheckTest < Minitest::Test
|
|
16
18
|
def test_corrects_hash_key_name_with_fetch_values
|
17
19
|
hash = { "foo" => 1, bar: 2 }
|
18
20
|
|
19
|
-
error =
|
21
|
+
error = assert_raise(KeyError) { hash.fetch_values("foo", :bar, :bax) }
|
20
22
|
assert_correction ":bar", error.corrections
|
21
23
|
assert_match "Did you mean? :bar", error.to_s
|
22
24
|
|
23
|
-
error =
|
25
|
+
error = assert_raise(KeyError) { hash.fetch_values("foo", :bar, "fooo") }
|
24
26
|
assert_correction %("foo"), error.corrections
|
25
27
|
assert_match %(Did you mean? "foo"), error.to_s
|
26
28
|
end
|
27
29
|
|
30
|
+
def test_correct_symbolized_hash_keys_with_string_value
|
31
|
+
hash = { foo_1: 1, bar_2: 2 }
|
32
|
+
|
33
|
+
error = assert_raise(KeyError) { hash.fetch('foo_1') }
|
34
|
+
assert_correction %(:foo_1), error.corrections
|
35
|
+
assert_match %(Did you mean? :foo_1), error.to_s
|
36
|
+
end
|
37
|
+
|
28
38
|
def test_corrects_sprintf_key_name
|
29
|
-
error =
|
39
|
+
error = assert_raise(KeyError) { sprintf("%<foo>d", {fooo: 1}) }
|
30
40
|
assert_correction ":fooo", error.corrections
|
31
41
|
assert_match "Did you mean? :fooo", error.to_s
|
32
42
|
end
|
@@ -34,7 +44,7 @@ class KeyNameCheckTest < Minitest::Test
|
|
34
44
|
def test_corrects_env_key_name
|
35
45
|
ENV["FOO"] = "1"
|
36
46
|
ENV["BAR"] = "2"
|
37
|
-
error =
|
47
|
+
error = assert_raise(KeyError) { ENV.fetch("BAX") }
|
38
48
|
assert_correction %("BAR"), error.corrections
|
39
49
|
assert_match %(Did you mean? "BAR"), error.to_s
|
40
50
|
ensure
|
@@ -1,6 +1,8 @@
|
|
1
|
-
|
1
|
+
require_relative '../helper'
|
2
|
+
|
3
|
+
class MethodNameCheckTest < Test::Unit::TestCase
|
4
|
+
include DidYouMean::TestHelper
|
2
5
|
|
3
|
-
class MethodNameCheckTest < Minitest::Test
|
4
6
|
class User
|
5
7
|
def friends; end
|
6
8
|
def first_name; end
|
@@ -36,50 +38,50 @@ class MethodNameCheckTest < Minitest::Test
|
|
36
38
|
end
|
37
39
|
|
38
40
|
def test_corrections_include_instance_method
|
39
|
-
error =
|
41
|
+
error = assert_raise(NoMethodError){ @user.flrst_name }
|
40
42
|
|
41
43
|
assert_correction :first_name, error.corrections
|
42
44
|
assert_match "Did you mean? first_name", error.to_s
|
43
45
|
end
|
44
46
|
|
45
47
|
def test_corrections_include_private_method
|
46
|
-
error =
|
48
|
+
error = assert_raise(NoMethodError){ @user.friend }
|
47
49
|
|
48
50
|
assert_correction :friends, error.corrections
|
49
51
|
assert_match "Did you mean? friends", error.to_s
|
50
52
|
end
|
51
53
|
|
52
54
|
def test_corrections_include_method_from_module
|
53
|
-
error =
|
55
|
+
error = assert_raise(NoMethodError){ @user.fr0m_module }
|
54
56
|
|
55
57
|
assert_correction :from_module, error.corrections
|
56
58
|
assert_match "Did you mean? from_module", error.to_s
|
57
59
|
end
|
58
60
|
|
59
61
|
def test_corrections_include_class_method
|
60
|
-
error =
|
62
|
+
error = assert_raise(NoMethodError){ User.l0ad }
|
61
63
|
|
62
64
|
assert_correction :load, error.corrections
|
63
65
|
assert_match "Did you mean? load", error.to_s
|
64
66
|
end
|
65
67
|
|
66
68
|
def test_private_methods_should_not_be_suggested
|
67
|
-
error =
|
69
|
+
error = assert_raise(NoMethodError){ User.new.the_protected_method }
|
68
70
|
refute_includes error.corrections, :the_protected_method
|
69
71
|
|
70
|
-
error =
|
72
|
+
error = assert_raise(NoMethodError){ User.new.the_private_method }
|
71
73
|
refute_includes error.corrections, :the_private_method
|
72
74
|
end
|
73
75
|
|
74
76
|
def test_corrections_when_private_method_is_called_with_args
|
75
|
-
error =
|
77
|
+
error = assert_raise(NoMethodError){ @user.call_incorrect_private_method }
|
76
78
|
|
77
79
|
assert_correction :raise, error.corrections
|
78
80
|
assert_match "Did you mean? raise", error.to_s
|
79
81
|
end
|
80
82
|
|
81
83
|
def test_exclude_methods_on_nil
|
82
|
-
error =
|
84
|
+
error = assert_raise(NoMethodError){ nil.map }
|
83
85
|
assert_empty error.corrections
|
84
86
|
end
|
85
87
|
|
@@ -87,14 +89,14 @@ class MethodNameCheckTest < Minitest::Test
|
|
87
89
|
def nil.empty?
|
88
90
|
end
|
89
91
|
|
90
|
-
error =
|
92
|
+
error = assert_raise(NoMethodError){ nil.empty }
|
91
93
|
assert_correction :empty?, error.corrections
|
92
94
|
ensure
|
93
95
|
NilClass.class_eval { undef empty? }
|
94
96
|
end
|
95
97
|
|
96
98
|
def test_does_not_append_suggestions_twice
|
97
|
-
error =
|
99
|
+
error = assert_raise NoMethodError do
|
98
100
|
begin
|
99
101
|
@user.firstname
|
100
102
|
rescue NoMethodError => e
|
@@ -106,7 +108,7 @@ class MethodNameCheckTest < Minitest::Test
|
|
106
108
|
end
|
107
109
|
|
108
110
|
def test_does_not_append_suggestions_three_times
|
109
|
-
error =
|
111
|
+
error = assert_raise NoMethodError do
|
110
112
|
begin
|
111
113
|
@user.raise_no_method_error
|
112
114
|
rescue NoMethodError => e
|
@@ -116,4 +118,30 @@ class MethodNameCheckTest < Minitest::Test
|
|
116
118
|
|
117
119
|
assert_equal 1, error.to_s.scan(/Did you mean/).count
|
118
120
|
end
|
121
|
+
|
122
|
+
def test_suggests_corrections_on_nested_error
|
123
|
+
error = assert_raise NoMethodError do
|
124
|
+
begin
|
125
|
+
@user.firstname
|
126
|
+
rescue NoMethodError
|
127
|
+
@user.firstname
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
assert_equal 1, error.to_s.scan(/Did you mean/).count
|
132
|
+
end
|
133
|
+
|
134
|
+
def test_suggests_yield
|
135
|
+
error = assert_raise(NoMethodError) { yeild(1) }
|
136
|
+
|
137
|
+
assert_correction :yield, error.corrections
|
138
|
+
assert_match "Did you mean? yield", error.to_s
|
139
|
+
end
|
140
|
+
|
141
|
+
def test_does_not_suggest_yield
|
142
|
+
error = assert_raise(NoMethodError) { 1.yeild }
|
143
|
+
|
144
|
+
assert_correction [], error.corrections
|
145
|
+
assert_not_match(/Did you mean\? +yield/, error.to_s)
|
146
|
+
end if RUBY_ENGINE != "jruby"
|
119
147
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require_relative '../helper'
|
2
|
+
|
3
|
+
return if !(RUBY_VERSION >= '2.8.0')
|
4
|
+
|
5
|
+
class RequirePathCheckTest < Test::Unit::TestCase
|
6
|
+
include DidYouMean::TestHelper
|
7
|
+
|
8
|
+
def test_load_error_from_require_has_suggestions
|
9
|
+
error = assert_raise LoadError do
|
10
|
+
require 'open_struct'
|
11
|
+
end
|
12
|
+
|
13
|
+
assert_correction 'ostruct', error.corrections
|
14
|
+
assert_match "Did you mean? ostruct", error.to_s
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_load_error_from_require_for_nested_files_has_suggestions
|
18
|
+
error = assert_raise LoadError do
|
19
|
+
require 'net/htt'
|
20
|
+
end
|
21
|
+
|
22
|
+
assert_correction 'net/http', error.corrections
|
23
|
+
assert_match "Did you mean? net/http", error.to_s
|
24
|
+
|
25
|
+
error = assert_raise LoadError do
|
26
|
+
require 'net-http'
|
27
|
+
end
|
28
|
+
|
29
|
+
assert_correction ['net/http', 'net/https'], error.corrections
|
30
|
+
assert_match "Did you mean? net/http", error.to_s
|
31
|
+
end
|
32
|
+
end
|
data/test/spell_checking/{uncorrectable_name_check_test.rb → test_uncorrectable_name_check.rb}
RENAMED
@@ -1,10 +1,10 @@
|
|
1
|
-
|
1
|
+
require_relative '../helper'
|
2
2
|
|
3
|
-
class UncorrectableNameCheckTest <
|
3
|
+
class UncorrectableNameCheckTest < Test::Unit::TestCase
|
4
4
|
class FirstNameError < NameError; end
|
5
5
|
|
6
6
|
def setup
|
7
|
-
@error =
|
7
|
+
@error = assert_raise(FirstNameError) do
|
8
8
|
raise FirstNameError, "Other name error"
|
9
9
|
end
|
10
10
|
end
|
@@ -1,6 +1,8 @@
|
|
1
|
-
|
1
|
+
require_relative '../helper'
|
2
|
+
|
3
|
+
class VariableNameCheckTest < Test::Unit::TestCase
|
4
|
+
include DidYouMean::TestHelper
|
2
5
|
|
3
|
-
class VariableNameCheckTest < Minitest::Test
|
4
6
|
class User
|
5
7
|
def initialize
|
6
8
|
@email_address = 'email_address@address.net'
|
@@ -27,7 +29,7 @@ class VariableNameCheckTest < Minitest::Test
|
|
27
29
|
end
|
28
30
|
|
29
31
|
def test_corrections_include_instance_method
|
30
|
-
error =
|
32
|
+
error = assert_raise(NameError) do
|
31
33
|
@user.instance_eval { flrst_name }
|
32
34
|
end
|
33
35
|
|
@@ -41,7 +43,7 @@ class VariableNameCheckTest < Minitest::Test
|
|
41
43
|
end
|
42
44
|
|
43
45
|
def test_corrections_include_method_from_module
|
44
|
-
error =
|
46
|
+
error = assert_raise(NameError) do
|
45
47
|
@user.instance_eval { fr0m_module }
|
46
48
|
end
|
47
49
|
|
@@ -50,26 +52,32 @@ class VariableNameCheckTest < Minitest::Test
|
|
50
52
|
end
|
51
53
|
|
52
54
|
def test_corrections_include_local_variable_name
|
53
|
-
|
54
|
-
|
55
|
+
if RUBY_ENGINE != "jruby"
|
56
|
+
person = person = nil
|
57
|
+
error = (eprson rescue $!) # Do not use @assert_raise here as it changes a scope.
|
55
58
|
|
56
|
-
|
57
|
-
|
59
|
+
assert_correction :person, error.corrections
|
60
|
+
assert_match "Did you mean? person", error.to_s
|
61
|
+
end
|
58
62
|
end
|
59
63
|
|
60
64
|
def test_corrections_include_ruby_predefined_objects
|
61
|
-
some_var = nil
|
65
|
+
some_var = some_var = nil
|
62
66
|
|
63
|
-
false_error =
|
67
|
+
false_error = assert_raise(NameError) do
|
64
68
|
some_var = fals
|
65
69
|
end
|
66
70
|
|
67
|
-
true_error =
|
71
|
+
true_error = assert_raise(NameError) do
|
68
72
|
some_var = treu
|
69
73
|
end
|
70
74
|
|
71
|
-
nil_error =
|
72
|
-
some_var =
|
75
|
+
nil_error = assert_raise(NameError) do
|
76
|
+
some_var = nul
|
77
|
+
end
|
78
|
+
|
79
|
+
file_error = assert_raise(NameError) do
|
80
|
+
__FIEL__
|
73
81
|
end
|
74
82
|
|
75
83
|
assert_correction :false, false_error.corrections
|
@@ -80,17 +88,27 @@ class VariableNameCheckTest < Minitest::Test
|
|
80
88
|
|
81
89
|
assert_correction :nil, nil_error.corrections
|
82
90
|
assert_match "Did you mean? nil", nil_error.to_s
|
91
|
+
|
92
|
+
assert_correction :__FILE__, file_error.corrections
|
93
|
+
assert_match "Did you mean? __FILE__", file_error.to_s
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_suggests_yield
|
97
|
+
error = assert_raise(NameError) { yeild }
|
98
|
+
|
99
|
+
assert_correction :yield, error.corrections
|
100
|
+
assert_match "Did you mean? yield", error.to_s
|
83
101
|
end
|
84
102
|
|
85
103
|
def test_corrections_include_instance_variable_name
|
86
|
-
error =
|
104
|
+
error = assert_raise(NameError){ @user.to_s }
|
87
105
|
|
88
106
|
assert_correction :@email_address, error.corrections
|
89
107
|
assert_match "Did you mean? @email_address", error.to_s
|
90
108
|
end
|
91
109
|
|
92
110
|
def test_corrections_include_private_method
|
93
|
-
error =
|
111
|
+
error = assert_raise(NameError) do
|
94
112
|
@user.instance_eval { cia_code_name }
|
95
113
|
end
|
96
114
|
|
@@ -101,7 +119,7 @@ class VariableNameCheckTest < Minitest::Test
|
|
101
119
|
@@does_exist = true
|
102
120
|
|
103
121
|
def test_corrections_include_class_variable_name
|
104
|
-
error =
|
122
|
+
error = assert_raise(NameError){ @@doesnt_exist }
|
105
123
|
|
106
124
|
assert_correction :@@does_exist, error.corrections
|
107
125
|
assert_match "Did you mean? @@does_exist", error.to_s
|
@@ -109,14 +127,14 @@ class VariableNameCheckTest < Minitest::Test
|
|
109
127
|
|
110
128
|
def test_struct_name_error
|
111
129
|
value = Struct.new(:does_exist).new
|
112
|
-
error =
|
130
|
+
error = assert_raise(NameError){ value[:doesnt_exist] }
|
113
131
|
|
114
132
|
assert_correction [:does_exist, :does_exist=], error.corrections
|
115
133
|
assert_match "Did you mean? does_exist", error.to_s
|
116
134
|
end
|
117
135
|
|
118
136
|
def test_exclude_typical_incorrect_suggestions
|
119
|
-
error =
|
137
|
+
error = assert_raise(NameError){ foo }
|
120
138
|
assert_empty error.corrections
|
121
139
|
end
|
122
140
|
end
|