spec/operation_spec.rb in elevate-0.3.3 vs spec/operation_spec.rb in elevate-0.4.0

- old
+ new

@@ -1,9 +1,9 @@ describe Elevate::ElevateOperation do before do - @target = Target.new - @operation = Elevate::ElevateOperation.alloc.initWithTarget(@target) + @target = lambda { @result } + @operation = Elevate::ElevateOperation.alloc.initWithTarget(@target, args: {}) @queue = NSOperationQueue.alloc.init end after do @queue.waitUntilAllOperationsAreFinished() @@ -16,26 +16,26 @@ describe "#on_finished" do it "invokes it after #on_started" do @lock = NSLock.alloc.init @value = [] - @operation.on_started = lambda do + @operation.on_started = lambda do @lock.lock() if @value == [] @value << 1 end @lock.unlock() end - @operation.on_finished = lambda do + @operation.on_finished = lambda do |result, exception| @lock.lock() if @value == [1] @value << 2 end @lock.unlock() - resume + Dispatch::Queue.main.sync { resume } end @queue.addOperation(@operation) wait_max 1.0 do @@ -56,54 +56,25 @@ end end describe "when an exception is raised" do it "returns the exception" do - @target.exception = IndexError.new + @target = lambda { raise IndexError } + @operation = Elevate::ElevateOperation.alloc.initWithTarget(@target, args: {}) @queue.addOperation(@operation) @operation.waitUntilFinished() - @operation.exception.should == @target.exception + @operation.exception.should.not.be.nil end end end - describe "#main" do - describe "when the operation has not been run" do - it "invokes the target" do - @queue.addOperation(@operation) - @operation.waitUntilFinished() - - @target.called.should == 1 - end - end - - describe "when the operation has been cancelled prior to starting" do - it "does not invoke the target" do - @operation.cancel() - - @queue.addOperation(@operation) - @operation.waitUntilFinished() - - @target.called.should == 0 - end - end - - describe "when the operation is running" do - it "allows IO to be cancelled" do - @queue.addOperation(@operation) - @operation.waitUntilFinished() - - @target.io_coordinator.should.not.be.nil - end - end - end - describe "#result" do before do - @target.result = 42 + @target = lambda { 42 } + @operation = Elevate::ElevateOperation.alloc.initWithTarget(@target, args: {}) end describe "before starting the operation" do it "returns nil" do @operation.result.should.be.nil @@ -120,10 +91,10 @@ @operation.result.should.be.nil end end describe "when the operation has finished" do - it "returns the result of the target's #execute method" do + it "returns the result of the lambda" do @queue.addOperation(@operation) @operation.waitUntilFinished() @operation.result.should == 42 end