Ruby: mocking file writes with Flexmock
===

Apologies if this was asked before.

A simple class:

    class AskSO

      def initialize( filehandle )
        @filehandle   = filehandle
      end

      def library_start
        @filehandle << '<plist version="1.0">'
      end
    end

A simple unit test using Flex mock

    require 'rubygems'
    require 'flexmock/test_unit'
    require 'AskSO'
    require 'test/unit'

    class AskSOTest < Test::Unit::TestCase

      def setup
        @filehandle = flexmock( "filehandle", "<<" => "" )
      end

      def test_library_start
        @filehandle.should_receive( "<<" ).with( '<plist version="1.0">' ).once
        @AskSOInstance = AskSO.new( @filehandle )
        @AskSOInstance.library_start
      end
    end

When I run it with `ruby AskSO-test.rb` I get

      1) Failure:
    test_library_start(AskSOTest)
        [/Library/Ruby/Gems/1.8/gems/flexmock-0.9.0/lib/flexmock/validators.rb:40:in `validate'
         /Library/Ruby/Gems/1.8/gems/flexmock-0.9.0/lib/flexmock/expectation.rb:123:in `flexmock_verify'
         /Library/Ruby/Gems/1.8/gems/flexmock-0.9.0/lib/flexmock/expectation.rb:122:in `each'
         /Library/Ruby/Gems/1.8/gems/flexmock-0.9.0/lib/flexmock/expectation.rb:122:in `flexmock_verify'
         /Library/Ruby/Gems/1.8/gems/flexmock-0.9.0/lib/flexmock/expectation_director.rb:64:in `flexmock_verify'
         /Library/Ruby/Gems/1.8/gems/flexmock-0.9.0/lib/flexmock/expectation_director.rb:63:in `each'
         /Library/Ruby/Gems/1.8/gems/flexmock-0.9.0/lib/flexmock/expectation_director.rb:63:in `flexmock_verify'
         /Library/Ruby/Gems/1.8/gems/flexmock-0.9.0/lib/flexmock/core.rb:76:in `flexmock_verify'
         /Library/Ruby/Gems/1.8/gems/flexmock-0.9.0/lib/flexmock/core.rb:75:in `each'
         /Library/Ruby/Gems/1.8/gems/flexmock-0.9.0/lib/flexmock/core.rb:75:in `flexmock_verify'
         /Library/Ruby/Gems/1.8/gems/flexmock-0.9.0/lib/flexmock/core.rb:191:in `flexmock_wrap'
         /Library/Ruby/Gems/1.8/gems/flexmock-0.9.0/lib/flexmock/core.rb:74:in `flexmock_verify'
         /Library/Ruby/Gems/1.8/gems/flexmock-0.9.0/lib/flexmock/mock_container.rb:40:in `flexmock_verify'
         /Library/Ruby/Gems/1.8/gems/flexmock-0.9.0/lib/flexmock/mock_container.rb:39:in `each'
         /Library/Ruby/Gems/1.8/gems/flexmock-0.9.0/lib/flexmock/mock_container.rb:39:in `flexmock_verify'
         /Library/Ruby/Gems/1.8/gems/flexmock-0.9.0/lib/flexmock/mock_container.rb:32:in `flexmock_teardown'
         /Library/Ruby/Gems/1.8/gems/flexmock-0.9.0/lib/flexmock/test_unit.rb:26:in `teardown']:
    in mock 'filehandle': method '<<("<plist version=\"1.0\">")' called incorrect number of times.
    <1> expected but was
    <0>.

What am I doing wrong? thanks in advance
    