Sha256: d0a149463b68b25fe81d06868ecf59008e879f52303fd37a847be094764e99ef

Contents?: true

Size: 1.83 KB

Versions: 13

Compression:

Stored size: 1.83 KB

Contents

require "test_helper"
require "rubycritic/analysers/helpers/modules_locator"
require "rubycritic/core/analysed_module"
require "pathname"

describe Rubycritic::ModulesLocator do
  describe "#names" do
    context "when a file contains Ruby code" do
      it "returns the names of all the classes and modules inside the file" do
        analysed_module = Rubycritic::AnalysedModule.new(
          :pathname => Pathname.new("test/samples/module_names.rb"),
          :methods_count => 1
        )
        Rubycritic::ModulesLocator.new(analysed_module).names
          .must_equal ["Foo", "Foo::Bar", "Foo::Baz", "Foo::Qux", "Foo::Quux::Corge"]
      end
    end

    context "when a file is empty" do
      it "returns the name of the file titleized" do
        analysed_module = Rubycritic::AnalysedModule.new(
          :pathname => Pathname.new("test/samples/empty.rb"),
          :methods_count => 1
        )
        Rubycritic::ModulesLocator.new(analysed_module).names.must_equal ["Empty"]
      end
    end

    context "when a file is unparsable" do
      it "does not blow up and returns the name of the file titleized" do
        analysed_module = Rubycritic::AnalysedModule.new(
          :pathname => Pathname.new("test/samples/unparsable.rb"),
          :methods_count => 1
        )
        capture_output_streams do
          Rubycritic::ModulesLocator.new(analysed_module).names.must_equal ["Unparsable"]
        end
      end
    end

    context "when a file has no methods" do
      it "returns the name of the file titleized" do
        analysed_module = Rubycritic::AnalysedModule.new(
          :pathname => Pathname.new("test/samples/no_methods.rb"),
          :methods_count => 0
        )
        capture_output_streams do
          Rubycritic::ModulesLocator.new(analysed_module).names.must_equal ["NoMethods"]
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
rubycritic-2.5.0 test/lib/rubycritic/analysers/helpers/modules_locator_test.rb
rubycritic-2.4.1 test/lib/rubycritic/analysers/helpers/modules_locator_test.rb
rubycritic-2.4.0 test/lib/rubycritic/analysers/helpers/modules_locator_test.rb
rubycritic-2.3.0 test/lib/rubycritic/analysers/helpers/modules_locator_test.rb
rubycritic-2.2.0 test/lib/rubycritic/analysers/helpers/modules_locator_test.rb
rubycritic-2.1.0 test/lib/rubycritic/analysers/helpers/modules_locator_test.rb
rubycritic-2.0.0 test/lib/rubycritic/analysers/helpers/modules_locator_test.rb
rubycritic-1.4.0 test/lib/rubycritic/analysers/helpers/modules_locator_test.rb
rubycritic-1.3.0 test/lib/rubycritic/analysers/helpers/modules_locator_test.rb
rubycritic-1.2.1 test/lib/rubycritic/analysers/helpers/modules_locator_test.rb
rubycritic-1.2.0 test/lib/rubycritic/analysers/helpers/modules_locator_test.rb
rubycritic-1.1.1 test/lib/rubycritic/analysers/helpers/modules_locator_test.rb
rubycritic-1.1.0 test/lib/rubycritic/analysers/helpers/modules_locator_test.rb