Welcome to the Ruby version of the Cotta file API

Introduction

Cotta project is created to provide a lightweight, simple and sensible API to file operation and testing. See Cotta Power for its motivation

Install It

The easiest way to install the install cotta using RubyGems:

sudo gem install cotta

Features

Cotta is just a plain Ruby API, so you can use it wherever you can use Ruby.

To used the new API just require the client driver:

require "rubygems"
require "cotta"

For a fully backward compatible API you can start with:

require "rubygems"
gem "cotta"
require "cotta"

For instance to write a little Ruby script using cotta you could write something like:

#!/usr/bin/env ruby
#
# Sample Ruby script using the Cotta API
#
require "rubygems"
gem "cotta", ">=1.0.0"
require "cotta"
#system implementation is injected here
cotta = Cotta.physical
file = cotta.file('dir/file.txt')
file.should_not be_exists
# parent directories are created automatically
file.save('my content')
file2 = cotta.file('dir/file2.txt')
file2.should_not be_exists
file.copy_to(file2)
file2.should be_exists
file2.load.should == 'my content'
file2.read {|file| puts file.gets}

Writing Tests

To test your code that uses Cotta API, you just need to pass in a Cotta instance that is backed by an in-memory file system:

cotta = Cotta.in_memory

Resources

Reports

Team

  • Shane Duan