Sha256: 03a23ee9b577f4ff0c6ea07f3b40a3e76801b4a58d4e602c67b7c8478ce82dbf

Contents?: true

Size: 1.6 KB

Versions: 10

Compression:

Stored size: 1.6 KB

Contents

require 'test_helper'

module ACRONYM
end

class Project
  def self.bo0k
    Bo0k
  end
end

class Book
  class TableOfContents; end

  def tableof_contents
    TableofContents
  end

  class Page
    def tableof_contents
      TableofContents
    end

    def self.tableof_contents
      TableofContents
    end
  end
end

class ClassNameTest < Minitest::Test
  def test_corrections
    error = assert_raises(NameError) { ::Bo0k }
    assert_correction "Book", error.corrections
  end

  def test_corrections_include_case_specific_class_name
    error = assert_raises(NameError) { ::Acronym }
    assert_correction "ACRONYM", error.corrections
  end

  def test_corrections_include_top_level_class_name
    error = assert_raises(NameError) { Project.bo0k }
    assert_correction "Book", error.corrections
  end

  def test_names_in_corrections_have_namespaces
    error = assert_raises(NameError) { ::Book::TableofContents }
    assert_correction "Book::TableOfContents", error.corrections
  end

  def test_corrections_candidates_for_names_in_upper_level_scopes
    error = assert_raises(NameError) { Book::Page.tableof_contents }
    assert_correction "Book::TableOfContents", error.corrections
  end

  def test_corrections_should_work_from_within_instance_method
    error = assert_raises(NameError) { ::Book.new.tableof_contents }
    assert_correction "Book::TableOfContents", error.corrections
  end

  def test_corrections_should_work_from_within_instance_method_on_nested_class
    error = assert_raises(NameError) { ::Book::Page.new.tableof_contents }
    assert_correction "Book::TableOfContents", error.corrections
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
did_you_mean-1.0.3 test/spell_checking/class_name_test.rb
did_you_mean-1.1.2 test/spell_checking/class_name_test.rb
ruby-compiler-0.1.1 vendor/ruby/gems/did_you_mean-1.1.0/test/spell_checking/class_name_test.rb
did_you_mean-1.1.0 test/spell_checking/class_name_test.rb
did_you_mean-1.0.2 test/spell_checking/class_name_test.rb
did_you_mean-1.0.1 test/correctable/class_name_test.rb
did_you_mean-1.0.0 test/correctable/class_name_test.rb
did_you_mean-1.0.0.rc1 test/correctable/class_name_test.rb
did_you_mean-1.0.0.beta3 test/correctable/class_name_test.rb
did_you_mean-1.0.0.beta2 test/correctable/class_name_test.rb