Sha256: 713b7083b27b32a6a8d133bcc12c186484107cf7bc810d8f6c7117420ec8a26e

Contents?: true

Size: 1.33 KB

Versions: 11

Compression:

Stored size: 1.33 KB

Contents

require 'spec_helper'

describe ::Object do
  before(:all) do
    class SomeFakeClass < OpenStruct
    end
  end

  subject do
    SomeFakeClass
  end

  describe ".try_chain" do
    it "wraps multiple calls to try and calls try on return value" do
      subject.try_chain(:name, :underscore).should eq "some_fake_class"
    end

    it "handles return if nil is in chain" do
      subject.try_chain(:name, :somefakemethod).should be_nil
    end

    it "handles instances of class" do
      SomeFakeClass.new.try_chain(:class, :name, :underscore).should eq "some_fake_class"
    end
  end

  describe ".set_fully_qualified_constant" do
    it "sets a fully qualified constant" do
      result = Object.set_fully_qualified_constant("SomeFakeClass::SomeFakeNestedClass", Class.new)
      result.name.should eq "SomeFakeClass::SomeFakeNestedClass"
    end

    it "raises error if no valid namespace to set constant upon is passed" do
      expect{Object.set_fully_qualified_constant("SomeFakeNestedClass", Class.new)}.to raise_error(StandardError)
    end
  end

  describe ".remove_instance_variables" do
    it "reset instance variables by symbol names" do
      obj = SomeFakeClass.new
      obj.instance_variable_set(:@someivar, "anything")
      obj.reset_instance_variables(:someivar)
      obj.instance_variable_get(:@someivar).should be nil
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
trax_core-0.0.84 spec/trax/core/ext/object_spec.rb
trax_core-0.0.83 spec/trax/core/ext/object_spec.rb
trax_core-0.0.82 spec/trax/core/ext/object_spec.rb
trax_core-0.0.81 spec/trax/core/ext/object_spec.rb
trax_core-0.0.80 spec/trax/core/ext/object_spec.rb
trax_core-0.0.79 spec/trax/core/ext/object_spec.rb
trax_core-0.0.78 spec/trax/core/ext/object_spec.rb
trax_core-0.0.77 spec/trax/core/ext/object_spec.rb
trax_core-0.0.76 spec/trax/core/ext/object_spec.rb
trax_core-0.0.74 spec/trax/core/ext/object_spec.rb
trax_core-0.0.73 spec/trax/core/ext/object_spec.rb