test/unit/utils_test.rb in hammer_cli-0.14.0 vs test/unit/utils_test.rb in hammer_cli-0.15.0

- old
+ new

@@ -7,45 +7,36 @@ end end end describe String do + context 'formatting' do + let(:str) { 'AA%<a>s BB%<b>s' } + let(:curly_str) { 'AA%{a} BB%{b}' } + let(:pos_str) { 'AA%s BB%s' } + let(:str_with_percent) { 'Error: AA%<a>s BB%<b>s <%# template error %> verify this %>' } - context "formatting" do - - let(:str) { "AA%<a>s BB%<b>s" } - let(:curly_str) { "AA%{a} BB%{b}" } - let(:pos_str) { "AA%s BB%s" } - let(:str_with_percent) { "Error: AA%<a>s BB%<b>s <%# template error %> verify this %>" } - - it "should not fail without expected parameters" do + it 'should not fail without expected parameters' do str.format({}).must_equal 'AA BB' end - - it "should replace positional parameters" do + it 'should replace positional parameters' do pos_str.format(['A', 'B']).must_equal 'AAA BBB' end - - it "should replace named parameters" do + it 'should replace named parameters' do str.format(:a => 'A', :b => 'B').must_equal 'AAA BBB' end - - it "should replace named parameters with string keys" do + it 'should replace named parameters with string keys' do str.format('a' => 'A', 'b' => 'B').must_equal 'AAA BBB' end - - it "should replace named parameters marked with curly brackets" do + it 'should replace named parameters marked with curly brackets' do curly_str.format(:a => 'A', :b => 'B').must_equal 'AAA BBB' end - - it "should not fail due to presence of percent chars in string" do + it 'should not fail due to presence of percent chars in string' do str_with_percent.format({}).must_equal 'Error: AA BB <%# template error %> verify this %>' end - end - context "camelize" do it "should camelize string with underscores" do "one_two_three".camelize.must_equal "OneTwoThree" end @@ -108,12 +99,21 @@ end end end +describe Hash do + context 'transform_keys' do + let(:hash) { { :one => 'one', :two => 'two', 'three' => 3 } } + let(:transformed_hash) { { :ONE => 'one', :TWO => 'two', 'THREE' => 3 } } + it 'should return a new hash with new keys' do + new_hash = hash.transform_keys(&:upcase) + new_hash.must_equal transformed_hash + end + end +end - describe HammerCLI do describe "interactive?" do before :each do @@ -168,6 +168,5 @@ HammerCLI.constant_path("Constant::Test::X").must_equal [Constant, Constant::Test, Constant::Test::X] end end end -