Sha256: 828eb91e150f63c51d9d76c707c78ebb3ea5c49abbdf18580e71d1c4508afb21

Contents?: true

Size: 1.94 KB

Versions: 13

Compression:

Stored size: 1.94 KB

Contents

# encoding: UTF-8

require 'spec_helper'

module MyScriptsTest
  module A
    class B
      class C
      end
    end
  end

  describe String do
    context '#snake_case' do
      it 'transforms CamelCase strings' do
        'GetCharWidth32'.snake_case.should == 'get_char_width_32'
      end

      it 'leaves snake_case strings intact' do
        'keybd_event'.snake_case.should == 'keybd_event'
      end
    end

    context '#camel_case' do
      it 'transforms underscore strings to CamelCase' do
        'get_char_width_32'.camel_case.should == 'GetCharWidth32'
      end

      it 'leaves CamelCase strings intact' do
        'GetCharWidth32'.camel_case.should == 'GetCharWidth32'
      end
    end

    context '#to_class' do
      it 'converts string into appropriate Class constant' do
        "Fixnum".to_class.should == Fixnum
        "MyScriptsTest::A::B::C".to_class.should == MyScriptsTest::A::B::C
      end

      it 'returns nil if string is not convertible into class' do
        "Math".to_class.should == nil
        "Math::PI".to_class.should == nil
        "Something".to_class.should == nil
      end

      it 'deals with leading colons' do
        "::MyScriptsTest::A::B::C".to_class.should == MyScriptsTest::A::B::C
      end
    end

    context '#translit!' do
      it 'converts string from Cyrillic to Latin translit' do
        "Широкая электрификация южных губерний даст мощный толчок подъёму сельского хозяйства".translit!.
         should == "SHirokaya elektrifikatsiya yuzhnykh gubernij dast moshchnyj tolchok pod\"emu sel'skogo khozyajstva"
        "ШИРОКАЯ ЭЛЕКТРИФИКАЦИЯ ЮЖНЫХ ГУБЕРНИЙ ДАСТ МОЩНЫЙ ТОЛЧОК ПОДЪЁМУ СЕЛЬСКОГО ХОЗЯЙСТВА".translit!.
         should == "SHIROKAYA ELEKTRIFIKATSIYA YUZHNYKH GUBERNIJ DAST MOSHCHNYJ TOLCHOK POD\"EMU SEL'SKOGO KHOZYAJSTVA"
      end
    end

  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
my_scripts-0.1.13 spec/my_scripts/extensions_spec.rb
my_scripts-0.1.12 spec/my_scripts/extensions_spec.rb
my_scripts-0.1.11 spec/my_scripts/extensions_spec.rb
my_scripts-0.1.10 spec/my_scripts/extensions_spec.rb
my_scripts-0.1.9 spec/my_scripts/extensions_spec.rb
my_scripts-0.1.8 spec/my_scripts/extensions_spec.rb
my_scripts-0.1.7 spec/my_scripts/extensions_spec.rb
my_scripts-0.1.5 spec/my_scripts/extensions_spec.rb
my_scripts-0.1.3 spec/my_scripts/extensions_spec.rb
my_scripts-0.1.0 spec/my_scripts/extensions_spec.rb
my_scripts-0.0.24 spec/my_scripts/extensions_spec.rb
my_scripts-0.0.23 spec/my_scripts/extensions_spec.rb
my_scripts-0.0.22 spec/my_scripts/extensions_spec.rb