Sha256: 0a19e82167b12d46a959a63f5c725e1219a351f5fc3839525e10c43a2469466d

Contents?: true

Size: 1.01 KB

Versions: 12

Compression:

Stored size: 1.01 KB

Contents

#!/usr/bin/env ruby

#---
# Copyright 2003 by Jim Weirich (jweirich@one.net).
# All rights reserved.

# Permission is granted for use, copying, modification, distribution,
# and distribution of modified versions of this work as long as the
# above copyright notice is included.
#+++

require 'test/unit'

# Sample FlexMock Usage.

class TestSamples < Test::Unit::TestCase

  # This is a basic example where we setup a mock object to mimic an
  # IO object.  We know that the +count_lines+ method uses gets, so we
  # tell the mock object to handle +gets+ by returning successive
  # elements of an array (just as the real +gets+ returns successive
  # elements of a file.
  def test_file_io
    file = FlexMock.new
    filedata = ["line 1", "line 2"]
    file.mock_handle(:gets) { filedata.shift }
    assert_equal 2, count_lines(file)
  end

  # Count the number of lines in a file.  Used in the test_file_io
  # test.
  def count_lines(file)
    n = 0
    while file.gets
      n += 1
    end
    n
  end

  def test_x
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
flexmock-0.1.2 test/test_samples.rb
flexmock-0.1.3 test/test_samples.rb
flexmock-0.1.1 test/test_samples.rb
flexmock-0.1.5 test/test_samples.rb
flexmock-0.1.4 test/test_samples.rb
flexmock-0.2.1 test/test_samples.rb
flexmock-0.3.0 test/test_samples.rb
flexmock-0.3.2 test/test_samples.rb
flexmock-0.1.6 test/test_samples.rb
flexmock-0.3.1 test/test_samples.rb
flexmock-0.1.7 test/test_samples.rb
flexmock-0.2.0 test/test_samples.rb