Sha256: 861ca49f3d5e9da57a1ac79aea5199a9c166f31e5147cfa08a66d40b3337d5eb

Contents?: true

Size: 1.94 KB

Versions: 92

Compression:

Stored size: 1.94 KB

Contents

#! /usr/bin/env ruby
require 'spec_helper'

require 'puppet/util/constant_inflector'

describe Puppet::Util::ConstantInflector, "when converting file names to constants" do
  it "should capitalize terms" do
    subject.file2constant("file").should == "File"
  end

  it "should switch all '/' characters to double colons" do
    subject.file2constant("file/other").should == "File::Other"
  end

  it "should remove underscores and capitalize the proceeding letter" do
    subject.file2constant("file_other").should == "FileOther"
  end

  it "should correctly replace as many underscores as exist in the file name" do
    subject.file2constant("two_under_scores/with_some_more_underscores").should == "TwoUnderScores::WithSomeMoreUnderscores"
  end

  it "should collapse multiple underscores" do
    subject.file2constant("many___scores").should == "ManyScores"
  end

  it "should correctly handle file names deeper than two directories" do
    subject.file2constant("one_two/three_four/five_six").should == "OneTwo::ThreeFour::FiveSix"
  end
end

describe Puppet::Util::ConstantInflector, "when converting constnats to file names" do
  it "should convert them to a string if necessary" do
    subject.constant2file(Puppet::Util::ConstantInflector).should be_instance_of(String)
  end

  it "should accept string inputs" do
    subject.constant2file("Puppet::Util::ConstantInflector").should be_instance_of(String)
  end

  it "should downcase all terms" do
    subject.constant2file("Puppet").should == "puppet"
  end

  it "should convert '::' to '/'" do
    subject.constant2file("Puppet::Util::Constant").should == "puppet/util/constant"
  end

  it "should convert mid-word capitalization to an underscore" do
    subject.constant2file("OneTwo::ThreeFour").should == "one_two/three_four"
  end

  it "should correctly handle constants with more than two parts" do
    subject.constant2file("OneTwoThree::FourFiveSixSeven").should == "one_two_three/four_five_six_seven"
  end
end

Version data entries

92 entries across 92 versions & 2 rubygems

Version Path
puppet-3.8.7 spec/unit/util/constant_inflector_spec.rb
puppet-3.8.7-x86-mingw32 spec/unit/util/constant_inflector_spec.rb
puppet-3.8.7-x64-mingw32 spec/unit/util/constant_inflector_spec.rb
puppet-3.8.6 spec/unit/util/constant_inflector_spec.rb
puppet-3.8.6-x86-mingw32 spec/unit/util/constant_inflector_spec.rb
puppet-3.8.6-x64-mingw32 spec/unit/util/constant_inflector_spec.rb
puppet-3.8.5 spec/unit/util/constant_inflector_spec.rb
puppet-3.8.5-x86-mingw32 spec/unit/util/constant_inflector_spec.rb
puppet-3.8.5-x64-mingw32 spec/unit/util/constant_inflector_spec.rb
puppet-3.8.4 spec/unit/util/constant_inflector_spec.rb
puppet-3.8.4-x86-mingw32 spec/unit/util/constant_inflector_spec.rb
puppet-3.8.4-x64-mingw32 spec/unit/util/constant_inflector_spec.rb
puppet-3.8.3 spec/unit/util/constant_inflector_spec.rb
puppet-3.8.3-x86-mingw32 spec/unit/util/constant_inflector_spec.rb
puppet-3.8.3-x64-mingw32 spec/unit/util/constant_inflector_spec.rb
puppet-3.8.2 spec/unit/util/constant_inflector_spec.rb
puppet-3.8.2-x86-mingw32 spec/unit/util/constant_inflector_spec.rb
puppet-3.8.2-x64-mingw32 spec/unit/util/constant_inflector_spec.rb
puppet-3.8.1 spec/unit/util/constant_inflector_spec.rb
puppet-3.8.1-x86-mingw32 spec/unit/util/constant_inflector_spec.rb