
var
  pipeflow = require('pipeflow'),
  expect = require('chai').expect,
  fs = require('../'),
  Environment = require('./environment');
  
describe('open middleware', () => {
  
  var env = Environment();
  
  beforeEach(env.init({ 'hello.txt': 'hello world!' }));
  afterEach(env.reset);
  
  it('should return a file stream', (done) => {
    // arrange
    var path = env.resolve('hello.txt');
    var app = pipeflow(fs.open).pipe(assert);
       
    // act
    app.start(path);
    
    // assert
    function assert(next, stream) {
      stream.read((er, chunk) => {
        expect(stream.filename()).to.equal(path);
        expect(chunk.toString()).to.equal('hello world!');
      }, () => done());
    }
  });
  
});
