This repository has been archived by the owner on Oct 27, 2021. It is now read-only.
/
file_accessor_spec.rb
38 lines (33 loc) · 1.63 KB
/
file_accessor_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
require File.dirname(__FILE__) + '/spec_helper'
require File.dirname(__FILE__) + '/file_accessor'
require 'stringio'
describe "A FileAccessor" do
# This sequence diagram illustrates what this spec specifies.
#
# +--------------+ +----------+ +-------------+
# | FileAccessor | | Pathname | | IoProcessor |
# +--------------+ +----------+ +-------------+
# | | |
# open_and_handle_with | | |
# -------------------->| | open | |
# | |--------------->| | |
# | | io | | |
# | |<...............| | |
# | | | process(io) |
# | |---------------------------------->| |
# | | | | |
# | |<..................................| |
# | | |
#
it "should open a file and pass it to the processor's process method" do
# This is the primary actor
accessor = FileAccessor.new
# These are the primary actor's neighbours, which we mock.
file = mock "Pathname"
io_processor = mock "IoProcessor"
io = StringIO.new "whatever"
file.should_receive(:open).and_yield io
io_processor.should_receive(:process).with(io)
accessor.open_and_handle_with(file, io_processor)
end
end