|
| 1 | +require "test_helper" |
| 2 | +require 'pry' |
| 3 | + |
| 4 | +class AcronymTest < Minitest::Test |
| 5 | + def test_method_chaining_passes |
| 6 | + source = %q{ |
| 7 | + class Acronym |
| 8 | + def self.abbreviate(words) |
| 9 | + words.tr('-', ' ').split.map(&:chr).join.upcase |
| 10 | + end |
| 11 | + end |
| 12 | + } |
| 13 | + results = Acronym::Analyze.(source) |
| 14 | + assert_equal :approve, results[:status] |
| 15 | + assert_equal [], results[:comments] |
| 16 | + end |
| 17 | + |
| 18 | + def test_lvar_name_not_tightly_coupled |
| 19 | + source = %q{ |
| 20 | + class Acronym |
| 21 | + def self.abbreviate(sentence) |
| 22 | + sentence.tr('-', ' ').split.map(&:chr).join.upcase |
| 23 | + end |
| 24 | + end |
| 25 | + } |
| 26 | + results = Acronym::Analyze.(source) |
| 27 | + assert_equal :approve, results[:status] |
| 28 | + assert_equal [], results[:comments] |
| 29 | + end |
| 30 | + |
| 31 | + def test_method_chaining_with_block_syntax_passes_with_comment |
| 32 | + source = %q{ |
| 33 | + class Acronym |
| 34 | + def self.abbreviate(words) |
| 35 | + words.tr('-', ' ').split.map { |word| word.chr }.join.upcase |
| 36 | + end |
| 37 | + end |
| 38 | + } |
| 39 | + results = Acronym::Analyze.(source) |
| 40 | + assert_equal :approve, results[:status] |
| 41 | + assert_equal ["ruby.acronym.block_syntax.shorthand"], results[:comments] |
| 42 | + end |
| 43 | + |
| 44 | + def test_method_chaining_with_block_syntax_with_arbitrary_arg_passes |
| 45 | + source = %q{ |
| 46 | + class Acronym |
| 47 | + def self.abbreviate(words) |
| 48 | + words.tr('-', ' ').split.map { |term| term.chr }.join.upcase |
| 49 | + end |
| 50 | + end |
| 51 | + } |
| 52 | + results = Acronym::Analyze.(source) |
| 53 | + assert_equal :approve, results[:status] |
| 54 | + assert_equal ["ruby.acronym.block_syntax.shorthand"], results[:comments] |
| 55 | + end |
| 56 | + |
| 57 | + def test_module_method_passes |
| 58 | + source = %q{ |
| 59 | + module Acronym |
| 60 | + def self.abbreviate(words) |
| 61 | + words.tr('-', ' ').split.map(&:chr).join.upcase |
| 62 | + end |
| 63 | + end |
| 64 | + } |
| 65 | + results = Acronym::Analyze.(source) |
| 66 | + assert_equal :approve, results[:status] |
| 67 | + assert_equal [], results[:comments] |
| 68 | + end |
| 69 | + |
| 70 | + def test_refers_to_mentor_with_method_not_matching |
| 71 | + source = %q{ |
| 72 | + class Acronym |
| 73 | + def self.abbreviate(words) |
| 74 | + test.words.tr('-', ' ').split.map(&:chr).join.upcase |
| 75 | + end |
| 76 | + end |
| 77 | + } |
| 78 | + results = Acronym::Analyze.(source) |
| 79 | + assert_equal :refer_to_mentor, results[:status] |
| 80 | + end |
| 81 | + |
| 82 | + def test_refers_to_mentor_with_random_method_body |
| 83 | + source = %q{ |
| 84 | + class Acronym |
| 85 | + def self.abbreviate(words) |
| 86 | + anything_here.123.456.test_method |
| 87 | + end |
| 88 | + end |
| 89 | + } |
| 90 | + results = Acronym::Analyze.(source) |
| 91 | + assert_equal :refer_to_mentor, results[:status] |
| 92 | + end |
| 93 | + |
| 94 | + def test_scan_with_any_regex_passes |
| 95 | + source = %q{ |
| 96 | + class Acronym |
| 97 | + def self.abbreviate(words) |
| 98 | + words.scan(/any/).join.upcase |
| 99 | + end |
| 100 | + end |
| 101 | + } |
| 102 | + results = Acronym::Analyze.(source) |
| 103 | + assert_equal :approve, results[:status] |
| 104 | + assert_equal [], results[:comments] |
| 105 | + end |
| 106 | + |
| 107 | + def test_split_with_any_regex_passes |
| 108 | + source = %q{ |
| 109 | + class Acronym |
| 110 | + def self.abbreviate(words) |
| 111 | + words.split(/[ -]/).map(&:chr).join.upcase |
| 112 | + end |
| 113 | + end |
| 114 | + } |
| 115 | + results = Acronym::Analyze.(source) |
| 116 | + assert_equal :approve, results[:status] |
| 117 | + assert_equal [], results[:comments] |
| 118 | + end |
| 119 | +end |
0 commit comments