Sha256: 15ae1ec549493c59946c1316fab90d5175f5744eecafe5ba8da1fae9f7dca932

Contents?: true

Size: 1.76 KB

Versions: 7

Compression:

Stored size: 1.76 KB

Contents

require File.dirname(__FILE__) + '/../spec_helper'

class TestClass
  include FileWriter
end
describe "FileWriter" do
  before(:each) do
    @test = TestClass.new
    @filepath = File.join("nilly.rb")
    @path = File.join(Base.storage_directory, @filepath)
  end
  %w(write_to_file_in_storage_directory copy_file_to_storage_directory write_to_temp_file).each do |method|
    eval <<-EOE
    it "should have a #{method} method" do
      @test.respond_to?(:#{method}).should == true
    end
    EOE
  end
  it "should copy the file to the Base.storage_directory when calling copy_file_to_storage_directory" do
    FileUtils.should_receive(:cp).with("ranger", Base.storage_directory+"/ranger").and_return true
    @test.copy_file_to_storage_directory("ranger")
  end
  describe "write to file in storage directory" do
    it "should try to create the directory if it doesn't exist" do
      FileTest.stub!(:directory?).and_return false
      ::File.stub!(:open).and_return true
      FileUtils.should_receive(:mkdir_p).with(::File.dirname(@path))
    end
    it "should call File.open on the file" do
      ::File.should_receive(:open).with(@path, "w+").and_return true
    end
    it "should call the block if it is given with a block" do
      block = Proc.new do |a|
        "meee: #{a.class}"
      end
      @test.write_to_file_in_storage_directory(@filepath, "STRING TO WRITE", &block)
    end
    it "should write the string in the file" do
      @test.write_to_file_in_storage_directory(@filepath, "STRING TO WRITE")
      open(::File.join( Base.storage_directory, @filepath)).read.should == "STRING TO WRITE"
    end
    after do
      @test.write_to_file_in_storage_directory(@filepath, "STRING TO WRITE")
    end
  end
  after(:all) do
    ::File.unlink @path if ::File.file? @path
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
auser-poolparty-0.2.3 spec/poolparty/modules/file_writer_spec.rb
auser-poolparty-0.2.4 spec/poolparty/modules/file_writer_spec.rb
auser-poolparty-0.2.5 spec/poolparty/modules/file_writer_spec.rb
auser-poolparty-0.2.6 spec/poolparty/modules/file_writer_spec.rb
auser-poolparty-0.2.8 spec/poolparty/modules/file_writer_spec.rb
auser-poolparty-0.2.9 spec/poolparty/modules/file_writer_spec.rb
poolparty-0.2.6 spec/poolparty/modules/file_writer_spec.rb