On Mar 22, 2008, at 4:17 pm, Dave wrote:
> Anyone have any ideas on how to make this (simple!) test pass with
> flying colors?

You will need to use a unicode library.  Judging by the length of the  
strings being compared, I think what is happening is the ý and í  
characters are being entered in different ways. URI is encoding them  
as letter+accent (total length 84) whereas your test string is  
encoding them as single character (total length 82).  (Actual length  
of the string is 80, I counted by hand).

I'm no unicode expert but I do know that some characters can be  
encoded either the form <é> or the form <e + ´>

Without resorting to a unicode library you would have to do

   URI.should_receive(:unescape).with("...")

to test it, which is more of a unit test than a functional test.

Hope this helps.

Ashley

#####

Here's the code I wrote as a test:

Error:
Song when location= has been sanitized dealing with foreign character  
expected: 82, got: 84 (using ==)

   $KCODE = "u"

   require 'uri'

   class Song
     attr_reader :location

     def location=(location)
      @location = URI.unescape(location).gsub!("file://localhost", "")
     end
   end

   describe Song do
     before(:each) do
       @song = Song.new
     end

     it "when location= has been sanitized dealing with foreign  
characters" do
       location = 
"file://localhost/Users/dave/Music/iTunes/iTunes%20Music/Sigur%20Ros/Agaetis%20Byrjun/05%20Ny%CC%81%20batteri%CC%81.m4a
 
"
       @song.location = location

       expected_sanitized_location = "/Users/dave/Music/iTunes/iTunes  
Music/Sigur Ros/Agaetis Byrjun/05 Ný batterí.m4a"
       @song.location.length.should ==  
expected_sanitized_location.length
       @song.location.should == expected_sanitized_location
     end

      it "when location= has been sanitized dealing with non-foreign  
characters" do
        location = 
"file://localhost/Users/dave/Music/iTunes/iTunes%20Music/Mogwai/Mr.%20Beast/Travel%20Is%20Dangerous.mp3
 
"
        @song.location = location

        expected_sanitized_location = "/Users/dave/Music/iTunes/iTunes  
Music/Mogwai/Mr. Beast/Travel Is Dangerous.mp3"
        @song.location.length.should ==  
expected_sanitized_location.length
        @song.location.should eql(expected_sanitized_location)
      end
   end
_______________________________________________
rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to