I am still interested in a real solution, but I For now I am working around the problem. Perhaps interesting for other people running into the same problem.
I decided to fake the UIGestures and send them to delegate functions of the DraggableView. In this way I can still test the correct working of the function, without a drag of the simulator. I have stubbed three gestures: a start gesture, a change gesture and an end gesture.
before do
@drag = DragableView.alloc.initWithFrame [[10,200],[100,100]]
@drag.backgroundColor = UIColor.redColor
@start_gesture = Object.new
@start_gesture.stub!(:setTranslation) {|v1,v2|}
@start_gesture.stub!(:state, :return=> UIGestureRecognizerStateBegan)
@start_gesture.stub!("translationInView") {|v| [0,0]}
@end_gesture = Object.new
@end_gesture.stub!(:state, :return=> UIGestureRecognizerStateEnded)
@end_gesture.stub!("translationInView") {|v| [100,100]}
@end_gesture.stub!(:setTranslation) {|v1,v2|}
controller.view.addSubview @drag
end
it "should not accept wrong drop" do
@wrong_gesture = Object.new
@wrong_gesture.stub!(:state, :return=> UIGestureRecognizerStateChanged)
@wrong_gesture.stub!("translationInView") {|v| CGPointMake(100,100)}
@wrong_gesture.stub!(:setTranslation) {|v1,v2|}
delegate = Object.new
delegate.mock! (:draggableViewStartedDragging) {|view|}
delegate.mock!(:draggableViewHasBeenDroppedAtWrongLocation) {|view|
view.should == @drag
}
@drag.delegate = delegate
@drag.send :dragGesture, @start_gesture
@drag.send :dragGesture, @wrong_gesture
@drag.send :dragGesture, @end_gesture
CGRectEqualToRect(@drag.frame, [[10,200], [100,100]]).should.be.true
end