Sha256: 3169e994a8ceb33ba263c55b557368915c22eabf5070242fdb5f1f0637ec20d9

Contents?: true

Size: 1.1 KB

Versions: 3

Compression:

Stored size: 1.1 KB

Contents

require 'spec_helper'

describe Bogus::ConvertsNameToClass do
  FooBarBaz = Class.new

  module Foo
    FooBarBaz = Class.new
  end

  module Bar
    FooBarBaz = Class.new
    Bam = Class.new
  end

  it "finds classes in golbal namespace by default" do
    converts_name_to_class = Bogus::ConvertsNameToClass.new(Bogus.config.search_modules)

    expect(converts_name_to_class.convert(:foo_bar_baz)).to eq FooBarBaz
  end

  it "looks in the modules in the specified order" do
    converts_name_to_class = Bogus::ConvertsNameToClass.new([Foo, Bar])

    expect(converts_name_to_class.convert(:foo_bar_baz)).to eq Foo::FooBarBaz
  end

  it "looks in the next module on the list if the first does not contain the class" do
    converts_name_to_class = Bogus::ConvertsNameToClass.new([Foo, Bar])

    expect(converts_name_to_class.convert(:bam)).to eq Bar::Bam
  end

  it "raises an error if it can't find the class" do
    converts_name_to_class = Bogus::ConvertsNameToClass.new([Foo])

    expect do
      converts_name_to_class.convert(:bam)
    end.to raise_error(Bogus::ConvertsNameToClass::CanNotFindClass)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
bogus-0.1.7 spec/bogus/fakes/converts_name_to_class_spec.rb
bogus-0.1.6 spec/bogus/fakes/converts_name_to_class_spec.rb
bogus-0.1.5 spec/bogus/fakes/converts_name_to_class_spec.rb