# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/spec_helper') describe String do describe "word_count" do it "should return 2" do "two words".word_count.should == 2 end it "should handle hypenated words" do "one-way street".word_count.should == 2 end it "should handle possessive apostrophe" do "this is max's ball".word_count.should == 4 end context "when string is a different encoding" do it "should not blow up" do str = "two ¢words".force_encoding("ISO-8859-1") str.valid_encoding?.should == true str.word_count.should == 2 end end end end