spec/nsisam_spec.rb in nsisam-0.6.2 vs spec/nsisam_spec.rb in nsisam-0.6.3

- old
+ new

@@ -2,17 +2,21 @@ require 'base64' describe NSISam do before :all do fake_options = { user: 'test', password: 'test', host: 'localhost', - port: '8888' } + port: '9888' } @options = integration_options || fake_options @nsisam = NSISam::Client.new(@options) @keys = Array.new - @fake_sam = NSISam::FakeServerManager.new.start_server unless integrating? + @fake_sam = NSISam::FakeServerManager.new.start_server(9888) unless integrating? end + before :each do + @nsisam.expire = false + end + after :all do @fake_sam.stop_server unless integrating? end let(:file_content) { example_file_content } @@ -31,10 +35,18 @@ response = @nsisam.store("something") response.should respond_to("key") response.should respond_to("checksum") end + it "can store a value with an expire time" do + @nsisam.expire = 2 + response = @nsisam.store('teste') + sleep(3) + expect { @nsisam.get(response.key) }.to raise_error(NSISam::Errors::Client::KeyNotFoundError) + @nsisam.expire = false + end + context "file" do it "encodes content before storing" do Base64.should_receive(:encode64).with(file_content). and_return(:dummy_value) @nsisam.should_receive(:store).with(file: :dummy_value, filename: filename). @@ -105,10 +117,18 @@ response.key.should == key response.checksum.should_not be_nil @nsisam.get(key).data.should == 'updated' end + it "can update values with an expire time to the new value" do + response = @nsisam.store('test') + @nsisam.expire = 2 + @nsisam.update(response.key, 'test 2') + sleep(3) + expect { @nsisam.get(response.key) }.to raise_error(NSISam::Errors::Client::KeyNotFoundError) + end + it "raises error when key not found" do expect { @nsisam.update("dont exist ruby is fast", "foo") }.to raise_error(NSISam::Errors::Client::KeyNotFoundError) end context 'file' do @@ -154,25 +174,28 @@ NSISam::Client.configure do user "why" password "chunky" host "localhost" port "8888" + expire false end end it "by configure" do sam = NSISam::Client.new sam.instance_variable_get(:@user).should == "why" sam.instance_variable_get(:@password).should == "chunky" sam.instance_variable_get(:@host).should == "localhost" sam.instance_variable_get(:@port).should == "8888" + sam.instance_variable_get(:@expire).should == false end it "by initialize parameters" do - sam = NSISam::Client.new(user: 'luckystiff', password: 'bacon', host: 'why.com', port: '9999') + sam = NSISam::Client.new(user: 'luckystiff', password: 'bacon', host: 'why.com', port: '9999', expire: 5) sam.instance_variable_get(:@user).should == "luckystiff" sam.instance_variable_get(:@password).should == "bacon" sam.instance_variable_get(:@host).should == "why.com" sam.instance_variable_get(:@port).should == "9999" + sam.instance_variable_get(:@expire).should == 5 end end end