Sha256: c51589fe334df83183fd8a4fdbf517e421db136b579a3e2aa66c33a75011a423

Contents?: true

Size: 1.01 KB

Versions: 3

Compression:

Stored size: 1.01 KB

Contents

require "spec_helper"

describe String do

  describe "#snakecase" do
    it "lowercases one word CamelCase" do
      expect("Merb".snakecase).to eq("merb")
    end

    it "makes one underscore snakecase two word CamelCase" do
      expect("MerbCore".snakecase).to eq("merb_core")
    end

    it "handles CamelCase with more than 2 words" do
      expect("SoYouWantContributeToMerbCore".snakecase).to eq("so_you_want_contribute_to_merb_core")
    end

    it "handles CamelCase with more than 2 capital letter in a row" do
      expect("CNN".snakecase).to eq("cnn")
      expect("CNNNews".snakecase).to eq("cnn_news")
      expect("HeadlineCNNNews".snakecase).to eq("headline_cnn_news")
    end

    it "does NOT change one word lowercase" do
      expect("merb".snakecase).to eq("merb")
    end

    it "leaves snake_case as is" do
      expect("merb_core".snakecase).to eq("merb_core")
    end

    it "converts period characters to underscores" do
      expect("User.GetEmail".snakecase).to eq("user_get_email")
    end
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
wasabi-3.5.0 spec/wasabi/core_ext/string_spec.rb
wasabi-3.4.0 spec/wasabi/core_ext/string_spec.rb
wasabi-3.3.1 spec/wasabi/core_ext/string_spec.rb