public
Description: IRB Power User Utility Belt
Homepage: http://utilitybelt.rubyforge.org
Clone URL: git://github.com/gilesbowkett/utility-belt.git
gilesbowkett (author)
Tue Feb 26 11:27:51 -0800 2008
utility-belt / spec / convertable_to_file_spec.rb
100644 32 lines (25 sloc) 0.855 kb
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
#!/usr/bin/env ruby
require File.join(File.dirname(__FILE__), "spec_helper")
 
require 'spec'
require 'irb'
require File.join(File.dirname(__FILE__), '..', 'lib', 'utility_belt', 'convertable_to_file')
 
describe ConvertableToFile do
  include ConvertableToFile
 
  before :each do
    @tempfile = stub("temp file", :<< => nil, :path => nil)
    Tempfile.stub!(:open).and_yield(@tempfile)
  end
 
  it "should create a temp file using object id as basename" do
    should_receive(:object_id).and_return(6789)
    Tempfile.should_receive(:open).with("6789").and_yield(@tempfile)
    to_file
  end
 
  it "should dump self to the opened temp file" do
    @tempfile.should_receive(:<<).with(self)
    to_file
  end
 
  it "should return the temp file path" do
    @tempfile.should_receive(:path).and_return("TEMP_PATH")
    to_file.should == "TEMP_PATH"
  end
end