Sha256: c6c73d0563637090658566d77f0e199c45884b1c32043d1169d3e7018051088b

Contents?: true

Size: 1.24 KB

Versions: 6

Compression:

Stored size: 1.24 KB

Contents

describe Chicanery::Persistence do
  include Chicanery::Persistence

  let(:file) { stub 'file' }
  let(:state) { stub 'state', to_yaml: :yaml }

  describe '#persist' do
    it 'should write state to disk as yaml' do
      File.should_receive(:open).with('state', 'w').and_yield file
      file.should_receive(:puts).with :yaml
      persist state
    end

    it 'should persist state to where it is told' do
      persist_state_to 'foo'
      File.should_receive(:open).with('foo', 'w').and_yield file
      file.should_receive(:puts).with :yaml
      persist state
    end
  end

  describe '#restore' do
    it 'should return empty hash if state file does not exist' do
      File.should_receive(:exist?).with('state').and_return false
      restore.should == {}
    end

    it 'should read yaml from disk' do
      File.should_receive(:exist?).with('state').and_return true
      YAML.should_receive(:load_file).with('state').and_return state
      restore.should == state
    end

    it 'should read yaml from another location if it is told to do so' do
      persist_state_to 'foo'
      File.should_receive(:exist?).with('foo').and_return true
      YAML.should_receive(:load_file).with('foo').and_return state
      restore.should == state
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
chicanery-0.1.4 spec/chicanery/persistence_spec.rb
chicanery-0.1.3 spec/chicanery/persistence_spec.rb
chicanery-0.1.1 spec/chicanery/persistence_spec.rb
chicanery-0.1.0 spec/chicanery/persistence_spec.rb
chicanery-0.0.9 spec/chicanery/persistence_spec.rb
chicanery-0.0.8 spec/chicanery/persistence_spec.rb