spec/kestrel/client/envelope_spec.rb in kestrel-client-0.4.1 vs spec/kestrel/client/envelope_spec.rb in kestrel-client-0.5.0
- old
+ new
@@ -1,26 +1,38 @@
require 'spec/spec_helper'
-class Envelope; end
+class Envelope
+ class << self; attr_accessor :unwraps end
+ def initialize(item); @item = item end
+ def unwrap; self.class.unwraps += 1; @item end
+end
+
describe Kestrel::Client::Envelope do
describe "Instance Methods" do
before do
+ Envelope.unwraps = 0
@raw_kestrel_client = Kestrel::Client.new(*Kestrel::Config.default)
@kestrel = Kestrel::Client::Envelope.new(Envelope, @raw_kestrel_client)
end
describe "#get and #set" do
describe "envelopes" do
+ it "integrates" do
+ @kestrel.set("a_queue", :mcguffin)
+ @kestrel.get("a_queue").should == :mcguffin
+ Envelope.unwraps.should == 1
+ end
+
it "creates an envelope on a set" do
mock(Envelope).new(:mcguffin)
@kestrel.set('a_queue', :mcguffin)
end
it "unwraps an envelope on a get" do
- envelope = Envelope.new
+ envelope = Envelope.new(:mcguffin)
mock(@raw_kestrel_client).get('a_queue') { envelope }
- mock(envelope).unwrap { :mcguffin }
+ mock.proxy(envelope).unwrap
@kestrel.get('a_queue').should == :mcguffin
end
it "does not unwrap a nil get" do
mock(@raw_kestrel_client).get('a_queue') { nil }