Sha256: ed899dfc517929557276d29098d891e6b1acc5b54265e6e4f401ee0fab319d0e

Contents?: true

Size: 1.09 KB

Versions: 11

Compression:

Stored size: 1.09 KB

Contents

require 'spec_helper'

describe Virtus::Coercion::String, '.to_constant' do
  subject { object.to_constant(string) }

  let(:object) { described_class }

  context 'with a non-namespaced name' do
    let(:string) { 'String' }

    it { should be(String) }
  end

  context 'with a non-namespaced qualified name' do
    let(:string) { '::String' }

    it { should be(String) }
  end

  context 'with a namespaced name' do
    let(:string) { 'Virtus::Coercion::String' }

    it { should be(Virtus::Coercion::String) }
  end

  context 'with a namespaced qualified name' do
    let(:string) { '::Virtus::Coercion::String' }

    it { should be(Virtus::Coercion::String) }
  end

  context 'with a name outside of the namespace' do
    let(:string) { 'Virtus::Object' }

    specify { expect { subject }.to raise_error(NameError) }
  end

  context 'when the name is unknown' do
    let(:string) { 'Unknown' }

    specify { expect { subject }.to raise_error(NameError) }
  end

  context 'when the name is invalid' do
    let(:string) { 'invalid' }

    specify { expect { subject }.to raise_error(NameError) }
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
virtus-0.5.5 spec/unit/virtus/coercion/string/class_methods/to_constant_spec.rb
virtus-0.5.4 spec/unit/virtus/coercion/string/class_methods/to_constant_spec.rb
virtus-0.5.3 spec/unit/virtus/coercion/string/class_methods/to_constant_spec.rb
fragrant-0.0.5 vendor/bundle/ruby/1.9.1/gems/virtus-0.5.2/spec/unit/virtus/coercion/string/class_methods/to_constant_spec.rb
virtus-0.5.2 spec/unit/virtus/coercion/string/class_methods/to_constant_spec.rb
virtus-0.5.1 spec/unit/virtus/coercion/string/class_methods/to_constant_spec.rb
virtus-0.5.0 spec/unit/virtus/coercion/string/class_methods/to_constant_spec.rb
virtus-0.4.2 spec/unit/virtus/coercion/string/class_methods/to_constant_spec.rb
virtus-0.4.1 spec/unit/virtus/coercion/string/class_methods/to_constant_spec.rb
virtus-0.4.0 spec/unit/virtus/coercion/string/class_methods/to_constant_spec.rb
virtus-0.3.0 spec/unit/virtus/coercion/string/class_methods/to_constant_spec.rb