Sha256: e62a26ef7a5bf265dddad8a19d9e9d54b4c08c3c2e2f62603b9f6ebefc3a4cd8

Contents?: true

Size: 1.93 KB

Versions: 5

Compression:

Stored size: 1.93 KB

Contents

require File.dirname(__FILE__) + '/spec_helper'

describe YARD::CodeObjects::MethodObject do
  before do 
    Registry.clear 
    @yard = ModuleObject.new(:root, :YARD)
  end
  
  it "should have a path of testing for an instance method in the root" do
    meth = MethodObject.new(:root, :testing)
    meth.path.should == "#testing"
  end
  
  it "should have a path of YARD#testing for an instance method in YARD" do
    meth = MethodObject.new(@yard, :testing)
    meth.path.should == "YARD#testing"
  end
  
  it "should have a path of YARD.testing for a class method in YARD" do
    meth = MethodObject.new(@yard, :testing, :class)
    meth.path.should == "YARD.testing"
  end
  
  it "should have a path of ::testing (note the ::) for a class method added to root namespace" do
    meth = MethodObject.new(:root, :testing, :class)
    meth.path.should == "::testing"
  end
  
  it "should exist in the registry after successful creation" do
    obj = MethodObject.new(@yard, :something, :class)
    Registry.at("YARD.something").should_not be_nil
    Registry.at("YARD#something").should be_nil
    Registry.at("YARD::something").should be_nil
    obj = MethodObject.new(@yard, :somethingelse)
    Registry.at("YARD#somethingelse").should_not be_nil
  end
  
  it "should allow #scope to be changed after creation" do
    obj = MethodObject.new(@yard, :something, :class)
    Registry.at("YARD.something").should_not be_nil
    obj.scope = :instance
    Registry.at("YARD.something").should be_nil
    Registry.at("YARD#something").should_not be_nil
  end
  
  describe '#name' do
    it "should show a prefix for an instance method when prefix=true" do
      obj = MethodObject.new(nil, :something)
      obj.name(true).should == :"#something"
    end
    
    it "should never show a prefix for a class method" do
      obj = MethodObject.new(nil, :something, :class)
      obj.name.should == :"something"
      obj.name(true).should == :"something"
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
yard-0.2.3.5 spec/code_objects/method_object_spec.rb
yard-0.2.3.4 spec/code_objects/method_object_spec.rb
yard-0.2.3.2 spec/code_objects/method_object_spec.rb
yard-0.2.3.3 spec/code_objects/method_object_spec.rb
yard-0.2.3 spec/code_objects/method_object_spec.rb