Project

fake_io

0.0
There's a lot of open issues
No release in over a year
A mixin module for creating fake IO-like classes.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.0
 Project Readme

fake_io

CI Gem Version

Description

{FakeIO} is a mixin module for creating fake IO-like classes.

Features

  • Supports all of the Ruby 2.x and 3.x IO instance methods.
  • Emulates buffered I/O.
  • UTF-8 aware.
  • Can be included into any Class.
  • Zero dependencies.

Requirements

Install

$ gem install fake_io

gemspec

gem.add_dependency 'fake_io', '~> 1.0'

Gemfile

gem 'fake_io', '~> 1.0'

Examples

require 'fake_io'

class FakeFile

  include FakeIO

  def initialize(chunks=[])
    @index = 0
    @chunks = chunks

    io_initialize
  end

  protected

  def io_read
    unless (block = @chunks[@index])
      raise(EOFError,"end of stream")
    end

    @index += 1
    return block
  end

  def io_write(data)
    @chunks[@index] = data
    @index += 1

    return data.length
  end

end

file = FakeFile.new(["one\ntwo\n", "three\nfour", "\n"])
file.readlines
# => ["one\n", "two\n", "three\n", "four\n"]

Copyright

See {file:LICENSE.txt} for details.