Sha256: b4ab6dd4412a3d5ede454cde2f63de868c09a1bda49002e796f144e4f9871bb5

Contents?: true

Size: 1.71 KB

Versions: 1

Compression:

Stored size: 1.71 KB

Contents

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

describe NSISam do

  before :all do
    @nsisam = NSISam::Client.new 'http://test:test@localhost:8888'
    @keys = Array.new
  end

  after :all do
    @keys.each { |key| @nsisam.delete(key) }
  end

  context "storing" do
    it "can store a value in SAM" do
      response = @nsisam.store("something")
      response.should_not be_nil
      response.should have_key("key")
      response.should have_key("checksum")

      @keys.push(response["key"])
    end
  end

  context "deleting" do
    it "can delete a stored value" do
      key = @nsisam.store("delete this")["key"]
      response = @nsisam.delete(key)
      response["deleted"].should be_true
    end

    it "raises error when key not found" do
      expect { @nsisam.delete("i dont exist") }.to raise_error(NSISam::Errors::Client::KeyNotFoundError)
    end
  end

  context "retrieving" do
    it "can retrieve a stored value" do
      key = @nsisam.store("retrieve this")["key"]
      response = @nsisam.get(key)
      response["data"].should == "retrieve this"

      @keys.push(key)
    end

    it "raises error when key not found" do
      expect { @nsisam.get("non existing key") }.to raise_error(NSISam::Errors::Client::KeyNotFoundError)
    end
  end

  context "updating" do
    it "can update values in keys already stored" do
      key = @nsisam.store("update this")["key"]
      response = @nsisam.update(key, "updated")
      response["key"].should == key
      response.should have_key("checksum")

      @keys.push(key)
    end

    it "raises error when key not found" do
      expect { @nsisam.update("ruby is fast", "foo") }.to raise_error(NSISam::Errors::Client::KeyNotFoundError)
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nsisam-0.1.1 spec/nsisam_spec.rb