capybara 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,35 @@
1
+ /*
2
+ * jQuery UI 1.7.2
3
+ *
4
+ * Copyright (c) 2009 AUTHORS.txt (http://jqueryui.com/about)
5
+ * Dual licensed under the MIT (MIT-LICENSE.txt)
6
+ * and GPL (GPL-LICENSE.txt) licenses.
7
+ *
8
+ * http://docs.jquery.com/UI
9
+ */
10
+ jQuery.ui||(function(c){var i=c.fn.remove,d=c.browser.mozilla&&(parseFloat(c.browser.version)<1.9);c.ui={version:"1.7.2",plugin:{add:function(k,l,n){var m=c.ui[k].prototype;for(var j in n){m.plugins[j]=m.plugins[j]||[];m.plugins[j].push([l,n[j]])}},call:function(j,l,k){var n=j.plugins[l];if(!n||!j.element[0].parentNode){return}for(var m=0;m<n.length;m++){if(j.options[n[m][0]]){n[m][1].apply(j.element,k)}}}},contains:function(k,j){return document.compareDocumentPosition?k.compareDocumentPosition(j)&16:k!==j&&k.contains(j)},hasScroll:function(m,k){if(c(m).css("overflow")=="hidden"){return false}var j=(k&&k=="left")?"scrollLeft":"scrollTop",l=false;if(m[j]>0){return true}m[j]=1;l=(m[j]>0);m[j]=0;return l},isOverAxis:function(k,j,l){return(k>j)&&(k<(j+l))},isOver:function(o,k,n,m,j,l){return c.ui.isOverAxis(o,n,j)&&c.ui.isOverAxis(k,m,l)},keyCode:{BACKSPACE:8,CAPS_LOCK:20,COMMA:188,CONTROL:17,DELETE:46,DOWN:40,END:35,ENTER:13,ESCAPE:27,HOME:36,INSERT:45,LEFT:37,NUMPAD_ADD:107,NUMPAD_DECIMAL:110,NUMPAD_DIVIDE:111,NUMPAD_ENTER:108,NUMPAD_MULTIPLY:106,NUMPAD_SUBTRACT:109,PAGE_DOWN:34,PAGE_UP:33,PERIOD:190,RIGHT:39,SHIFT:16,SPACE:32,TAB:9,UP:38}};if(d){var f=c.attr,e=c.fn.removeAttr,h="http://www.w3.org/2005/07/aaa",a=/^aria-/,b=/^wairole:/;c.attr=function(k,j,l){var m=l!==undefined;return(j=="role"?(m?f.call(this,k,j,"wairole:"+l):(f.apply(this,arguments)||"").replace(b,"")):(a.test(j)?(m?k.setAttributeNS(h,j.replace(a,"aaa:"),l):f.call(this,k,j.replace(a,"aaa:"))):f.apply(this,arguments)))};c.fn.removeAttr=function(j){return(a.test(j)?this.each(function(){this.removeAttributeNS(h,j.replace(a,""))}):e.call(this,j))}}c.fn.extend({remove:function(){c("*",this).add(this).each(function(){c(this).triggerHandler("remove")});return i.apply(this,arguments)},enableSelection:function(){return this.attr("unselectable","off").css("MozUserSelect","").unbind("selectstart.ui")},disableSelection:function(){return this.attr("unselectable","on").css("MozUserSelect","none").bind("selectstart.ui",function(){return false})},scrollParent:function(){var j;if((c.browser.msie&&(/(static|relative)/).test(this.css("position")))||(/absolute/).test(this.css("position"))){j=this.parents().filter(function(){return(/(relative|absolute|fixed)/).test(c.curCSS(this,"position",1))&&(/(auto|scroll)/).test(c.curCSS(this,"overflow",1)+c.curCSS(this,"overflow-y",1)+c.curCSS(this,"overflow-x",1))}).eq(0)}else{j=this.parents().filter(function(){return(/(auto|scroll)/).test(c.curCSS(this,"overflow",1)+c.curCSS(this,"overflow-y",1)+c.curCSS(this,"overflow-x",1))}).eq(0)}return(/fixed/).test(this.css("position"))||!j.length?c(document):j}});c.extend(c.expr[":"],{data:function(l,k,j){return !!c.data(l,j[3])},focusable:function(k){var l=k.nodeName.toLowerCase(),j=c.attr(k,"tabindex");return(/input|select|textarea|button|object/.test(l)?!k.disabled:"a"==l||"area"==l?k.href||!isNaN(j):!isNaN(j))&&!c(k)["area"==l?"parents":"closest"](":hidden").length},tabbable:function(k){var j=c.attr(k,"tabindex");return(isNaN(j)||j>=0)&&c(k).is(":focusable")}});function g(m,n,o,l){function k(q){var p=c[m][n][q]||[];return(typeof p=="string"?p.split(/,?\s+/):p)}var j=k("getter");if(l.length==1&&typeof l[0]=="string"){j=j.concat(k("getterSetter"))}return(c.inArray(o,j)!=-1)}c.widget=function(k,j){var l=k.split(".")[0];k=k.split(".")[1];c.fn[k]=function(p){var n=(typeof p=="string"),o=Array.prototype.slice.call(arguments,1);if(n&&p.substring(0,1)=="_"){return this}if(n&&g(l,k,p,o)){var m=c.data(this[0],k);return(m?m[p].apply(m,o):undefined)}return this.each(function(){var q=c.data(this,k);(!q&&!n&&c.data(this,k,new c[l][k](this,p))._init());(q&&n&&c.isFunction(q[p])&&q[p].apply(q,o))})};c[l]=c[l]||{};c[l][k]=function(o,n){var m=this;this.namespace=l;this.widgetName=k;this.widgetEventPrefix=c[l][k].eventPrefix||k;this.widgetBaseClass=l+"-"+k;this.options=c.extend({},c.widget.defaults,c[l][k].defaults,c.metadata&&c.metadata.get(o)[k],n);this.element=c(o).bind("setData."+k,function(q,p,r){if(q.target==o){return m._setData(p,r)}}).bind("getData."+k,function(q,p){if(q.target==o){return m._getData(p)}}).bind("remove",function(){return m.destroy()})};c[l][k].prototype=c.extend({},c.widget.prototype,j);c[l][k].getterSetter="option"};c.widget.prototype={_init:function(){},destroy:function(){this.element.removeData(this.widgetName).removeClass(this.widgetBaseClass+"-disabled "+this.namespace+"-state-disabled").removeAttr("aria-disabled")},option:function(l,m){var k=l,j=this;if(typeof l=="string"){if(m===undefined){return this._getData(l)}k={};k[l]=m}c.each(k,function(n,o){j._setData(n,o)})},_getData:function(j){return this.options[j]},_setData:function(j,k){this.options[j]=k;if(j=="disabled"){this.element[k?"addClass":"removeClass"](this.widgetBaseClass+"-disabled "+this.namespace+"-state-disabled").attr("aria-disabled",k)}},enable:function(){this._setData("disabled",false)},disable:function(){this._setData("disabled",true)},_trigger:function(l,m,n){var p=this.options[l],j=(l==this.widgetEventPrefix?l:this.widgetEventPrefix+l);m=c.Event(m);m.type=j;if(m.originalEvent){for(var k=c.event.props.length,o;k;){o=c.event.props[--k];m[o]=m.originalEvent[o]}}this.element.trigger(m,n);return !(c.isFunction(p)&&p.call(this.element[0],m,n)===false||m.isDefaultPrevented())}};c.widget.defaults={disabled:false};c.ui.mouse={_mouseInit:function(){var j=this;this.element.bind("mousedown."+this.widgetName,function(k){return j._mouseDown(k)}).bind("click."+this.widgetName,function(k){if(j._preventClickEvent){j._preventClickEvent=false;k.stopImmediatePropagation();return false}});if(c.browser.msie){this._mouseUnselectable=this.element.attr("unselectable");this.element.attr("unselectable","on")}this.started=false},_mouseDestroy:function(){this.element.unbind("."+this.widgetName);(c.browser.msie&&this.element.attr("unselectable",this._mouseUnselectable))},_mouseDown:function(l){l.originalEvent=l.originalEvent||{};if(l.originalEvent.mouseHandled){return}(this._mouseStarted&&this._mouseUp(l));this._mouseDownEvent=l;var k=this,m=(l.which==1),j=(typeof this.options.cancel=="string"?c(l.target).parents().add(l.target).filter(this.options.cancel).length:false);if(!m||j||!this._mouseCapture(l)){return true}this.mouseDelayMet=!this.options.delay;if(!this.mouseDelayMet){this._mouseDelayTimer=setTimeout(function(){k.mouseDelayMet=true},this.options.delay)}if(this._mouseDistanceMet(l)&&this._mouseDelayMet(l)){this._mouseStarted=(this._mouseStart(l)!==false);if(!this._mouseStarted){l.preventDefault();return true}}this._mouseMoveDelegate=function(n){return k._mouseMove(n)};this._mouseUpDelegate=function(n){return k._mouseUp(n)};c(document).bind("mousemove."+this.widgetName,this._mouseMoveDelegate).bind("mouseup."+this.widgetName,this._mouseUpDelegate);(c.browser.safari||l.preventDefault());l.originalEvent.mouseHandled=true;return true},_mouseMove:function(j){if(c.browser.msie&&!j.button){return this._mouseUp(j)}if(this._mouseStarted){this._mouseDrag(j);return j.preventDefault()}if(this._mouseDistanceMet(j)&&this._mouseDelayMet(j)){this._mouseStarted=(this._mouseStart(this._mouseDownEvent,j)!==false);(this._mouseStarted?this._mouseDrag(j):this._mouseUp(j))}return !this._mouseStarted},_mouseUp:function(j){c(document).unbind("mousemove."+this.widgetName,this._mouseMoveDelegate).unbind("mouseup."+this.widgetName,this._mouseUpDelegate);if(this._mouseStarted){this._mouseStarted=false;this._preventClickEvent=(j.target==this._mouseDownEvent.target);this._mouseStop(j)}return false},_mouseDistanceMet:function(j){return(Math.max(Math.abs(this._mouseDownEvent.pageX-j.pageX),Math.abs(this._mouseDownEvent.pageY-j.pageY))>=this.options.distance)},_mouseDelayMet:function(j){return this.mouseDelayMet},_mouseStart:function(j){},_mouseDrag:function(j){},_mouseStop:function(j){},_mouseCapture:function(j){return true}};c.ui.mouse.defaults={cancel:null,distance:1,delay:0}})(jQuery);;/*
11
+ * jQuery UI Draggable 1.7.2
12
+ *
13
+ * Copyright (c) 2009 AUTHORS.txt (http://jqueryui.com/about)
14
+ * Dual licensed under the MIT (MIT-LICENSE.txt)
15
+ * and GPL (GPL-LICENSE.txt) licenses.
16
+ *
17
+ * http://docs.jquery.com/UI/Draggables
18
+ *
19
+ * Depends:
20
+ * ui.core.js
21
+ */
22
+ (function(a){a.widget("ui.draggable",a.extend({},a.ui.mouse,{_init:function(){if(this.options.helper=="original"&&!(/^(?:r|a|f)/).test(this.element.css("position"))){this.element[0].style.position="relative"}(this.options.addClasses&&this.element.addClass("ui-draggable"));(this.options.disabled&&this.element.addClass("ui-draggable-disabled"));this._mouseInit()},destroy:function(){if(!this.element.data("draggable")){return}this.element.removeData("draggable").unbind(".draggable").removeClass("ui-draggable ui-draggable-dragging ui-draggable-disabled");this._mouseDestroy()},_mouseCapture:function(b){var c=this.options;if(this.helper||c.disabled||a(b.target).is(".ui-resizable-handle")){return false}this.handle=this._getHandle(b);if(!this.handle){return false}return true},_mouseStart:function(b){var c=this.options;this.helper=this._createHelper(b);this._cacheHelperProportions();if(a.ui.ddmanager){a.ui.ddmanager.current=this}this._cacheMargins();this.cssPosition=this.helper.css("position");this.scrollParent=this.helper.scrollParent();this.offset=this.element.offset();this.offset={top:this.offset.top-this.margins.top,left:this.offset.left-this.margins.left};a.extend(this.offset,{click:{left:b.pageX-this.offset.left,top:b.pageY-this.offset.top},parent:this._getParentOffset(),relative:this._getRelativeOffset()});this.originalPosition=this._generatePosition(b);this.originalPageX=b.pageX;this.originalPageY=b.pageY;if(c.cursorAt){this._adjustOffsetFromHelper(c.cursorAt)}if(c.containment){this._setContainment()}this._trigger("start",b);this._cacheHelperProportions();if(a.ui.ddmanager&&!c.dropBehaviour){a.ui.ddmanager.prepareOffsets(this,b)}this.helper.addClass("ui-draggable-dragging");this._mouseDrag(b,true);return true},_mouseDrag:function(b,d){this.position=this._generatePosition(b);this.positionAbs=this._convertPositionTo("absolute");if(!d){var c=this._uiHash();this._trigger("drag",b,c);this.position=c.position}if(!this.options.axis||this.options.axis!="y"){this.helper[0].style.left=this.position.left+"px"}if(!this.options.axis||this.options.axis!="x"){this.helper[0].style.top=this.position.top+"px"}if(a.ui.ddmanager){a.ui.ddmanager.drag(this,b)}return false},_mouseStop:function(c){var d=false;if(a.ui.ddmanager&&!this.options.dropBehaviour){d=a.ui.ddmanager.drop(this,c)}if(this.dropped){d=this.dropped;this.dropped=false}if((this.options.revert=="invalid"&&!d)||(this.options.revert=="valid"&&d)||this.options.revert===true||(a.isFunction(this.options.revert)&&this.options.revert.call(this.element,d))){var b=this;a(this.helper).animate(this.originalPosition,parseInt(this.options.revertDuration,10),function(){b._trigger("stop",c);b._clear()})}else{this._trigger("stop",c);this._clear()}return false},_getHandle:function(b){var c=!this.options.handle||!a(this.options.handle,this.element).length?true:false;a(this.options.handle,this.element).find("*").andSelf().each(function(){if(this==b.target){c=true}});return c},_createHelper:function(c){var d=this.options;var b=a.isFunction(d.helper)?a(d.helper.apply(this.element[0],[c])):(d.helper=="clone"?this.element.clone():this.element);if(!b.parents("body").length){b.appendTo((d.appendTo=="parent"?this.element[0].parentNode:d.appendTo))}if(b[0]!=this.element[0]&&!(/(fixed|absolute)/).test(b.css("position"))){b.css("position","absolute")}return b},_adjustOffsetFromHelper:function(b){if(b.left!=undefined){this.offset.click.left=b.left+this.margins.left}if(b.right!=undefined){this.offset.click.left=this.helperProportions.width-b.right+this.margins.left}if(b.top!=undefined){this.offset.click.top=b.top+this.margins.top}if(b.bottom!=undefined){this.offset.click.top=this.helperProportions.height-b.bottom+this.margins.top}},_getParentOffset:function(){this.offsetParent=this.helper.offsetParent();var b=this.offsetParent.offset();if(this.cssPosition=="absolute"&&this.scrollParent[0]!=document&&a.ui.contains(this.scrollParent[0],this.offsetParent[0])){b.left+=this.scrollParent.scrollLeft();b.top+=this.scrollParent.scrollTop()}if((this.offsetParent[0]==document.body)||(this.offsetParent[0].tagName&&this.offsetParent[0].tagName.toLowerCase()=="html"&&a.browser.msie)){b={top:0,left:0}}return{top:b.top+(parseInt(this.offsetParent.css("borderTopWidth"),10)||0),left:b.left+(parseInt(this.offsetParent.css("borderLeftWidth"),10)||0)}},_getRelativeOffset:function(){if(this.cssPosition=="relative"){var b=this.element.position();return{top:b.top-(parseInt(this.helper.css("top"),10)||0)+this.scrollParent.scrollTop(),left:b.left-(parseInt(this.helper.css("left"),10)||0)+this.scrollParent.scrollLeft()}}else{return{top:0,left:0}}},_cacheMargins:function(){this.margins={left:(parseInt(this.element.css("marginLeft"),10)||0),top:(parseInt(this.element.css("marginTop"),10)||0)}},_cacheHelperProportions:function(){this.helperProportions={width:this.helper.outerWidth(),height:this.helper.outerHeight()}},_setContainment:function(){var e=this.options;if(e.containment=="parent"){e.containment=this.helper[0].parentNode}if(e.containment=="document"||e.containment=="window"){this.containment=[0-this.offset.relative.left-this.offset.parent.left,0-this.offset.relative.top-this.offset.parent.top,a(e.containment=="document"?document:window).width()-this.helperProportions.width-this.margins.left,(a(e.containment=="document"?document:window).height()||document.body.parentNode.scrollHeight)-this.helperProportions.height-this.margins.top]}if(!(/^(document|window|parent)$/).test(e.containment)&&e.containment.constructor!=Array){var c=a(e.containment)[0];if(!c){return}var d=a(e.containment).offset();var b=(a(c).css("overflow")!="hidden");this.containment=[d.left+(parseInt(a(c).css("borderLeftWidth"),10)||0)+(parseInt(a(c).css("paddingLeft"),10)||0)-this.margins.left,d.top+(parseInt(a(c).css("borderTopWidth"),10)||0)+(parseInt(a(c).css("paddingTop"),10)||0)-this.margins.top,d.left+(b?Math.max(c.scrollWidth,c.offsetWidth):c.offsetWidth)-(parseInt(a(c).css("borderLeftWidth"),10)||0)-(parseInt(a(c).css("paddingRight"),10)||0)-this.helperProportions.width-this.margins.left,d.top+(b?Math.max(c.scrollHeight,c.offsetHeight):c.offsetHeight)-(parseInt(a(c).css("borderTopWidth"),10)||0)-(parseInt(a(c).css("paddingBottom"),10)||0)-this.helperProportions.height-this.margins.top]}else{if(e.containment.constructor==Array){this.containment=e.containment}}},_convertPositionTo:function(f,h){if(!h){h=this.position}var c=f=="absolute"?1:-1;var e=this.options,b=this.cssPosition=="absolute"&&!(this.scrollParent[0]!=document&&a.ui.contains(this.scrollParent[0],this.offsetParent[0]))?this.offsetParent:this.scrollParent,g=(/(html|body)/i).test(b[0].tagName);return{top:(h.top+this.offset.relative.top*c+this.offset.parent.top*c-(a.browser.safari&&this.cssPosition=="fixed"?0:(this.cssPosition=="fixed"?-this.scrollParent.scrollTop():(g?0:b.scrollTop()))*c)),left:(h.left+this.offset.relative.left*c+this.offset.parent.left*c-(a.browser.safari&&this.cssPosition=="fixed"?0:(this.cssPosition=="fixed"?-this.scrollParent.scrollLeft():g?0:b.scrollLeft())*c))}},_generatePosition:function(e){var h=this.options,b=this.cssPosition=="absolute"&&!(this.scrollParent[0]!=document&&a.ui.contains(this.scrollParent[0],this.offsetParent[0]))?this.offsetParent:this.scrollParent,i=(/(html|body)/i).test(b[0].tagName);if(this.cssPosition=="relative"&&!(this.scrollParent[0]!=document&&this.scrollParent[0]!=this.offsetParent[0])){this.offset.relative=this._getRelativeOffset()}var d=e.pageX;var c=e.pageY;if(this.originalPosition){if(this.containment){if(e.pageX-this.offset.click.left<this.containment[0]){d=this.containment[0]+this.offset.click.left}if(e.pageY-this.offset.click.top<this.containment[1]){c=this.containment[1]+this.offset.click.top}if(e.pageX-this.offset.click.left>this.containment[2]){d=this.containment[2]+this.offset.click.left}if(e.pageY-this.offset.click.top>this.containment[3]){c=this.containment[3]+this.offset.click.top}}if(h.grid){var g=this.originalPageY+Math.round((c-this.originalPageY)/h.grid[1])*h.grid[1];c=this.containment?(!(g-this.offset.click.top<this.containment[1]||g-this.offset.click.top>this.containment[3])?g:(!(g-this.offset.click.top<this.containment[1])?g-h.grid[1]:g+h.grid[1])):g;var f=this.originalPageX+Math.round((d-this.originalPageX)/h.grid[0])*h.grid[0];d=this.containment?(!(f-this.offset.click.left<this.containment[0]||f-this.offset.click.left>this.containment[2])?f:(!(f-this.offset.click.left<this.containment[0])?f-h.grid[0]:f+h.grid[0])):f}}return{top:(c-this.offset.click.top-this.offset.relative.top-this.offset.parent.top+(a.browser.safari&&this.cssPosition=="fixed"?0:(this.cssPosition=="fixed"?-this.scrollParent.scrollTop():(i?0:b.scrollTop())))),left:(d-this.offset.click.left-this.offset.relative.left-this.offset.parent.left+(a.browser.safari&&this.cssPosition=="fixed"?0:(this.cssPosition=="fixed"?-this.scrollParent.scrollLeft():i?0:b.scrollLeft())))}},_clear:function(){this.helper.removeClass("ui-draggable-dragging");if(this.helper[0]!=this.element[0]&&!this.cancelHelperRemoval){this.helper.remove()}this.helper=null;this.cancelHelperRemoval=false},_trigger:function(b,c,d){d=d||this._uiHash();a.ui.plugin.call(this,b,[c,d]);if(b=="drag"){this.positionAbs=this._convertPositionTo("absolute")}return a.widget.prototype._trigger.call(this,b,c,d)},plugins:{},_uiHash:function(b){return{helper:this.helper,position:this.position,absolutePosition:this.positionAbs,offset:this.positionAbs}}}));a.extend(a.ui.draggable,{version:"1.7.2",eventPrefix:"drag",defaults:{addClasses:true,appendTo:"parent",axis:false,cancel:":input,option",connectToSortable:false,containment:false,cursor:"auto",cursorAt:false,delay:0,distance:1,grid:false,handle:false,helper:"original",iframeFix:false,opacity:false,refreshPositions:false,revert:false,revertDuration:500,scope:"default",scroll:true,scrollSensitivity:20,scrollSpeed:20,snap:false,snapMode:"both",snapTolerance:20,stack:false,zIndex:false}});a.ui.plugin.add("draggable","connectToSortable",{start:function(c,e){var d=a(this).data("draggable"),f=d.options,b=a.extend({},e,{item:d.element});d.sortables=[];a(f.connectToSortable).each(function(){var g=a.data(this,"sortable");if(g&&!g.options.disabled){d.sortables.push({instance:g,shouldRevert:g.options.revert});g._refreshItems();g._trigger("activate",c,b)}})},stop:function(c,e){var d=a(this).data("draggable"),b=a.extend({},e,{item:d.element});a.each(d.sortables,function(){if(this.instance.isOver){this.instance.isOver=0;d.cancelHelperRemoval=true;this.instance.cancelHelperRemoval=false;if(this.shouldRevert){this.instance.options.revert=true}this.instance._mouseStop(c);this.instance.options.helper=this.instance.options._helper;if(d.options.helper=="original"){this.instance.currentItem.css({top:"auto",left:"auto"})}}else{this.instance.cancelHelperRemoval=false;this.instance._trigger("deactivate",c,b)}})},drag:function(c,f){var e=a(this).data("draggable"),b=this;var d=function(i){var n=this.offset.click.top,m=this.offset.click.left;var g=this.positionAbs.top,k=this.positionAbs.left;var j=i.height,l=i.width;var p=i.top,h=i.left;return a.ui.isOver(g+n,k+m,p,h,j,l)};a.each(e.sortables,function(g){this.instance.positionAbs=e.positionAbs;this.instance.helperProportions=e.helperProportions;this.instance.offset.click=e.offset.click;if(this.instance._intersectsWith(this.instance.containerCache)){if(!this.instance.isOver){this.instance.isOver=1;this.instance.currentItem=a(b).clone().appendTo(this.instance.element).data("sortable-item",true);this.instance.options._helper=this.instance.options.helper;this.instance.options.helper=function(){return f.helper[0]};c.target=this.instance.currentItem[0];this.instance._mouseCapture(c,true);this.instance._mouseStart(c,true,true);this.instance.offset.click.top=e.offset.click.top;this.instance.offset.click.left=e.offset.click.left;this.instance.offset.parent.left-=e.offset.parent.left-this.instance.offset.parent.left;this.instance.offset.parent.top-=e.offset.parent.top-this.instance.offset.parent.top;e._trigger("toSortable",c);e.dropped=this.instance.element;e.currentItem=e.element;this.instance.fromOutside=e}if(this.instance.currentItem){this.instance._mouseDrag(c)}}else{if(this.instance.isOver){this.instance.isOver=0;this.instance.cancelHelperRemoval=true;this.instance.options.revert=false;this.instance._trigger("out",c,this.instance._uiHash(this.instance));this.instance._mouseStop(c,true);this.instance.options.helper=this.instance.options._helper;this.instance.currentItem.remove();if(this.instance.placeholder){this.instance.placeholder.remove()}e._trigger("fromSortable",c);e.dropped=false}}})}});a.ui.plugin.add("draggable","cursor",{start:function(c,d){var b=a("body"),e=a(this).data("draggable").options;if(b.css("cursor")){e._cursor=b.css("cursor")}b.css("cursor",e.cursor)},stop:function(b,c){var d=a(this).data("draggable").options;if(d._cursor){a("body").css("cursor",d._cursor)}}});a.ui.plugin.add("draggable","iframeFix",{start:function(b,c){var d=a(this).data("draggable").options;a(d.iframeFix===true?"iframe":d.iframeFix).each(function(){a('<div class="ui-draggable-iframeFix" style="background: #fff;"></div>').css({width:this.offsetWidth+"px",height:this.offsetHeight+"px",position:"absolute",opacity:"0.001",zIndex:1000}).css(a(this).offset()).appendTo("body")})},stop:function(b,c){a("div.ui-draggable-iframeFix").each(function(){this.parentNode.removeChild(this)})}});a.ui.plugin.add("draggable","opacity",{start:function(c,d){var b=a(d.helper),e=a(this).data("draggable").options;if(b.css("opacity")){e._opacity=b.css("opacity")}b.css("opacity",e.opacity)},stop:function(b,c){var d=a(this).data("draggable").options;if(d._opacity){a(c.helper).css("opacity",d._opacity)}}});a.ui.plugin.add("draggable","scroll",{start:function(c,d){var b=a(this).data("draggable");if(b.scrollParent[0]!=document&&b.scrollParent[0].tagName!="HTML"){b.overflowOffset=b.scrollParent.offset()}},drag:function(d,e){var c=a(this).data("draggable"),f=c.options,b=false;if(c.scrollParent[0]!=document&&c.scrollParent[0].tagName!="HTML"){if(!f.axis||f.axis!="x"){if((c.overflowOffset.top+c.scrollParent[0].offsetHeight)-d.pageY<f.scrollSensitivity){c.scrollParent[0].scrollTop=b=c.scrollParent[0].scrollTop+f.scrollSpeed}else{if(d.pageY-c.overflowOffset.top<f.scrollSensitivity){c.scrollParent[0].scrollTop=b=c.scrollParent[0].scrollTop-f.scrollSpeed}}}if(!f.axis||f.axis!="y"){if((c.overflowOffset.left+c.scrollParent[0].offsetWidth)-d.pageX<f.scrollSensitivity){c.scrollParent[0].scrollLeft=b=c.scrollParent[0].scrollLeft+f.scrollSpeed}else{if(d.pageX-c.overflowOffset.left<f.scrollSensitivity){c.scrollParent[0].scrollLeft=b=c.scrollParent[0].scrollLeft-f.scrollSpeed}}}}else{if(!f.axis||f.axis!="x"){if(d.pageY-a(document).scrollTop()<f.scrollSensitivity){b=a(document).scrollTop(a(document).scrollTop()-f.scrollSpeed)}else{if(a(window).height()-(d.pageY-a(document).scrollTop())<f.scrollSensitivity){b=a(document).scrollTop(a(document).scrollTop()+f.scrollSpeed)}}}if(!f.axis||f.axis!="y"){if(d.pageX-a(document).scrollLeft()<f.scrollSensitivity){b=a(document).scrollLeft(a(document).scrollLeft()-f.scrollSpeed)}else{if(a(window).width()-(d.pageX-a(document).scrollLeft())<f.scrollSensitivity){b=a(document).scrollLeft(a(document).scrollLeft()+f.scrollSpeed)}}}}if(b!==false&&a.ui.ddmanager&&!f.dropBehaviour){a.ui.ddmanager.prepareOffsets(c,d)}}});a.ui.plugin.add("draggable","snap",{start:function(c,d){var b=a(this).data("draggable"),e=b.options;b.snapElements=[];a(e.snap.constructor!=String?(e.snap.items||":data(draggable)"):e.snap).each(function(){var g=a(this);var f=g.offset();if(this!=b.element[0]){b.snapElements.push({item:this,width:g.outerWidth(),height:g.outerHeight(),top:f.top,left:f.left})}})},drag:function(u,p){var g=a(this).data("draggable"),q=g.options;var y=q.snapTolerance;var x=p.offset.left,w=x+g.helperProportions.width,f=p.offset.top,e=f+g.helperProportions.height;for(var v=g.snapElements.length-1;v>=0;v--){var s=g.snapElements[v].left,n=s+g.snapElements[v].width,m=g.snapElements[v].top,A=m+g.snapElements[v].height;if(!((s-y<x&&x<n+y&&m-y<f&&f<A+y)||(s-y<x&&x<n+y&&m-y<e&&e<A+y)||(s-y<w&&w<n+y&&m-y<f&&f<A+y)||(s-y<w&&w<n+y&&m-y<e&&e<A+y))){if(g.snapElements[v].snapping){(g.options.snap.release&&g.options.snap.release.call(g.element,u,a.extend(g._uiHash(),{snapItem:g.snapElements[v].item})))}g.snapElements[v].snapping=false;continue}if(q.snapMode!="inner"){var c=Math.abs(m-e)<=y;var z=Math.abs(A-f)<=y;var j=Math.abs(s-w)<=y;var k=Math.abs(n-x)<=y;if(c){p.position.top=g._convertPositionTo("relative",{top:m-g.helperProportions.height,left:0}).top-g.margins.top}if(z){p.position.top=g._convertPositionTo("relative",{top:A,left:0}).top-g.margins.top}if(j){p.position.left=g._convertPositionTo("relative",{top:0,left:s-g.helperProportions.width}).left-g.margins.left}if(k){p.position.left=g._convertPositionTo("relative",{top:0,left:n}).left-g.margins.left}}var h=(c||z||j||k);if(q.snapMode!="outer"){var c=Math.abs(m-f)<=y;var z=Math.abs(A-e)<=y;var j=Math.abs(s-x)<=y;var k=Math.abs(n-w)<=y;if(c){p.position.top=g._convertPositionTo("relative",{top:m,left:0}).top-g.margins.top}if(z){p.position.top=g._convertPositionTo("relative",{top:A-g.helperProportions.height,left:0}).top-g.margins.top}if(j){p.position.left=g._convertPositionTo("relative",{top:0,left:s}).left-g.margins.left}if(k){p.position.left=g._convertPositionTo("relative",{top:0,left:n-g.helperProportions.width}).left-g.margins.left}}if(!g.snapElements[v].snapping&&(c||z||j||k||h)){(g.options.snap.snap&&g.options.snap.snap.call(g.element,u,a.extend(g._uiHash(),{snapItem:g.snapElements[v].item})))}g.snapElements[v].snapping=(c||z||j||k||h)}}});a.ui.plugin.add("draggable","stack",{start:function(b,c){var e=a(this).data("draggable").options;var d=a.makeArray(a(e.stack.group)).sort(function(g,f){return(parseInt(a(g).css("zIndex"),10)||e.stack.min)-(parseInt(a(f).css("zIndex"),10)||e.stack.min)});a(d).each(function(f){this.style.zIndex=e.stack.min+f});this[0].style.zIndex=e.stack.min+d.length}});a.ui.plugin.add("draggable","zIndex",{start:function(c,d){var b=a(d.helper),e=a(this).data("draggable").options;if(b.css("zIndex")){e._zIndex=b.css("zIndex")}b.css("zIndex",e.zIndex)},stop:function(b,c){var d=a(this).data("draggable").options;if(d._zIndex){a(c.helper).css("zIndex",d._zIndex)}}})})(jQuery);;/*
23
+ * jQuery UI Droppable 1.7.2
24
+ *
25
+ * Copyright (c) 2009 AUTHORS.txt (http://jqueryui.com/about)
26
+ * Dual licensed under the MIT (MIT-LICENSE.txt)
27
+ * and GPL (GPL-LICENSE.txt) licenses.
28
+ *
29
+ * http://docs.jquery.com/UI/Droppables
30
+ *
31
+ * Depends:
32
+ * ui.core.js
33
+ * ui.draggable.js
34
+ */
35
+ (function(a){a.widget("ui.droppable",{_init:function(){var c=this.options,b=c.accept;this.isover=0;this.isout=1;this.options.accept=this.options.accept&&a.isFunction(this.options.accept)?this.options.accept:function(e){return e.is(b)};this.proportions={width:this.element[0].offsetWidth,height:this.element[0].offsetHeight};a.ui.ddmanager.droppables[this.options.scope]=a.ui.ddmanager.droppables[this.options.scope]||[];a.ui.ddmanager.droppables[this.options.scope].push(this);(this.options.addClasses&&this.element.addClass("ui-droppable"))},destroy:function(){var b=a.ui.ddmanager.droppables[this.options.scope];for(var c=0;c<b.length;c++){if(b[c]==this){b.splice(c,1)}}this.element.removeClass("ui-droppable ui-droppable-disabled").removeData("droppable").unbind(".droppable")},_setData:function(b,c){if(b=="accept"){this.options.accept=c&&a.isFunction(c)?c:function(e){return e.is(c)}}else{a.widget.prototype._setData.apply(this,arguments)}},_activate:function(c){var b=a.ui.ddmanager.current;if(this.options.activeClass){this.element.addClass(this.options.activeClass)}(b&&this._trigger("activate",c,this.ui(b)))},_deactivate:function(c){var b=a.ui.ddmanager.current;if(this.options.activeClass){this.element.removeClass(this.options.activeClass)}(b&&this._trigger("deactivate",c,this.ui(b)))},_over:function(c){var b=a.ui.ddmanager.current;if(!b||(b.currentItem||b.element)[0]==this.element[0]){return}if(this.options.accept.call(this.element[0],(b.currentItem||b.element))){if(this.options.hoverClass){this.element.addClass(this.options.hoverClass)}this._trigger("over",c,this.ui(b))}},_out:function(c){var b=a.ui.ddmanager.current;if(!b||(b.currentItem||b.element)[0]==this.element[0]){return}if(this.options.accept.call(this.element[0],(b.currentItem||b.element))){if(this.options.hoverClass){this.element.removeClass(this.options.hoverClass)}this._trigger("out",c,this.ui(b))}},_drop:function(c,d){var b=d||a.ui.ddmanager.current;if(!b||(b.currentItem||b.element)[0]==this.element[0]){return false}var e=false;this.element.find(":data(droppable)").not(".ui-draggable-dragging").each(function(){var f=a.data(this,"droppable");if(f.options.greedy&&a.ui.intersect(b,a.extend(f,{offset:f.element.offset()}),f.options.tolerance)){e=true;return false}});if(e){return false}if(this.options.accept.call(this.element[0],(b.currentItem||b.element))){if(this.options.activeClass){this.element.removeClass(this.options.activeClass)}if(this.options.hoverClass){this.element.removeClass(this.options.hoverClass)}this._trigger("drop",c,this.ui(b));return this.element}return false},ui:function(b){return{draggable:(b.currentItem||b.element),helper:b.helper,position:b.position,absolutePosition:b.positionAbs,offset:b.positionAbs}}});a.extend(a.ui.droppable,{version:"1.7.2",eventPrefix:"drop",defaults:{accept:"*",activeClass:false,addClasses:true,greedy:false,hoverClass:false,scope:"default",tolerance:"intersect"}});a.ui.intersect=function(q,j,o){if(!j.offset){return false}var e=(q.positionAbs||q.position.absolute).left,d=e+q.helperProportions.width,n=(q.positionAbs||q.position.absolute).top,m=n+q.helperProportions.height;var g=j.offset.left,c=g+j.proportions.width,p=j.offset.top,k=p+j.proportions.height;switch(o){case"fit":return(g<e&&d<c&&p<n&&m<k);break;case"intersect":return(g<e+(q.helperProportions.width/2)&&d-(q.helperProportions.width/2)<c&&p<n+(q.helperProportions.height/2)&&m-(q.helperProportions.height/2)<k);break;case"pointer":var h=((q.positionAbs||q.position.absolute).left+(q.clickOffset||q.offset.click).left),i=((q.positionAbs||q.position.absolute).top+(q.clickOffset||q.offset.click).top),f=a.ui.isOver(i,h,p,g,j.proportions.height,j.proportions.width);return f;break;case"touch":return((n>=p&&n<=k)||(m>=p&&m<=k)||(n<p&&m>k))&&((e>=g&&e<=c)||(d>=g&&d<=c)||(e<g&&d>c));break;default:return false;break}};a.ui.ddmanager={current:null,droppables:{"default":[]},prepareOffsets:function(e,g){var b=a.ui.ddmanager.droppables[e.options.scope];var f=g?g.type:null;var h=(e.currentItem||e.element).find(":data(droppable)").andSelf();droppablesLoop:for(var d=0;d<b.length;d++){if(b[d].options.disabled||(e&&!b[d].options.accept.call(b[d].element[0],(e.currentItem||e.element)))){continue}for(var c=0;c<h.length;c++){if(h[c]==b[d].element[0]){b[d].proportions.height=0;continue droppablesLoop}}b[d].visible=b[d].element.css("display")!="none";if(!b[d].visible){continue}b[d].offset=b[d].element.offset();b[d].proportions={width:b[d].element[0].offsetWidth,height:b[d].element[0].offsetHeight};if(f=="mousedown"){b[d]._activate.call(b[d],g)}}},drop:function(b,c){var d=false;a.each(a.ui.ddmanager.droppables[b.options.scope],function(){if(!this.options){return}if(!this.options.disabled&&this.visible&&a.ui.intersect(b,this,this.options.tolerance)){d=this._drop.call(this,c)}if(!this.options.disabled&&this.visible&&this.options.accept.call(this.element[0],(b.currentItem||b.element))){this.isout=1;this.isover=0;this._deactivate.call(this,c)}});return d},drag:function(b,c){if(b.options.refreshPositions){a.ui.ddmanager.prepareOffsets(b,c)}a.each(a.ui.ddmanager.droppables[b.options.scope],function(){if(this.options.disabled||this.greedyChild||!this.visible){return}var e=a.ui.intersect(b,this,this.options.tolerance);var g=!e&&this.isover==1?"isout":(e&&this.isover==0?"isover":null);if(!g){return}var f;if(this.options.greedy){var d=this.element.parents(":data(droppable):eq(0)");if(d.length){f=a.data(d[0],"droppable");f.greedyChild=(g=="isover"?1:0)}}if(f&&g=="isover"){f.isover=0;f.isout=1;f._out.call(f,c)}this[g]=1;this[g=="isout"?"isover":"isout"]=0;this[g=="isover"?"_over":"_out"].call(this,c);if(f&&g=="isout"){f.isout=0;f.isover=1;f._over.call(f,c)}})}}})(jQuery);;
@@ -5,19 +5,20 @@ describe Capybara::Session do
5
5
  before do
6
6
  @session = Capybara::Session.new(:culerity, TestApp)
7
7
  end
8
-
8
+
9
9
  describe '#driver' do
10
10
  it "should be a rack test driver" do
11
11
  @session.driver.should be_an_instance_of(Capybara::Driver::Culerity)
12
12
  end
13
13
  end
14
-
14
+
15
15
  describe '#mode' do
16
16
  it "should remember the mode" do
17
17
  @session.mode.should == :culerity
18
18
  end
19
19
  end
20
-
20
+
21
21
  it_should_behave_like "session"
22
+ it_should_behave_like "session with javascript support"
22
23
  end
23
24
  end
@@ -5,19 +5,20 @@ describe Capybara::Session do
5
5
  before do
6
6
  @session = Capybara::Session.new(:rack_test, TestApp)
7
7
  end
8
-
8
+
9
9
  describe '#driver' do
10
10
  it "should be a rack test driver" do
11
11
  @session.driver.should be_an_instance_of(Capybara::Driver::RackTest)
12
12
  end
13
13
  end
14
-
14
+
15
15
  describe '#mode' do
16
16
  it "should remember the mode" do
17
17
  @session.mode.should == :rack_test
18
18
  end
19
19
  end
20
-
20
+
21
21
  it_should_behave_like "session"
22
+ it_should_behave_like "session without javascript support"
22
23
  end
23
24
  end
@@ -5,19 +5,20 @@ describe Capybara::Session do
5
5
  before do
6
6
  @session = Capybara::Session.new(:selenium, TestApp)
7
7
  end
8
-
8
+
9
9
  describe '#driver' do
10
- it "should be a rack test driver" do
10
+ it "should be a selenium driver" do
11
11
  @session.driver.should be_an_instance_of(Capybara::Driver::Selenium)
12
12
  end
13
13
  end
14
-
14
+
15
15
  describe '#mode' do
16
16
  it "should remember the mode" do
17
17
  @session.mode.should == :selenium
18
18
  end
19
19
  end
20
-
20
+
21
21
  it_should_behave_like "session"
22
+ it_should_behave_like "session with javascript support"
22
23
  end
23
24
  end
@@ -67,6 +67,14 @@ shared_examples_for "session" do
67
67
  @session.visit('/form')
68
68
  end
69
69
 
70
+ context "with multiple values with the same name" do
71
+ it "should use the latest given value" do
72
+ @session.check('Terms of Use')
73
+ @session.click_button('awesome')
74
+ extract_results(@session)['terms_of_use'].should == '1'
75
+ end
76
+ end
77
+
70
78
  context "with value given on a submit button" do
71
79
  before do
72
80
  @session.click_button('awesome')
@@ -77,6 +85,10 @@ shared_examples_for "session" do
77
85
  @results['first_name'].should == 'John'
78
86
  end
79
87
 
88
+ it "should escape fields when submitting" do
89
+ @results['phone'].should == '+1 555 7021'
90
+ end
91
+
80
92
  it "should serialize and submit password fields" do
81
93
  @results['password'].should == 'seeekrit'
82
94
  end
@@ -173,7 +185,7 @@ shared_examples_for "session" do
173
185
  end.should raise_error(Capybara::ElementNotFound)
174
186
  end
175
187
  end
176
-
188
+
177
189
  it "should serialize and send GET forms" do
178
190
  @session.visit('/form')
179
191
  @session.click_button('med')
@@ -205,6 +217,12 @@ shared_examples_for "session" do
205
217
  extract_results(@session)['first_name'].should == 'Harry'
206
218
  end
207
219
 
220
+ it "should favour exact label matches over partial matches" do
221
+ @session.fill_in('Name', :with => 'Harry Jones')
222
+ @session.click_button('awesome')
223
+ extract_results(@session)['name'].should == 'Harry Jones'
224
+ end
225
+
208
226
  it "should fill in a textarea by id" do
209
227
  @session.fill_in('form_description', :with => 'Texty text')
210
228
  @session.click_button('awesome')
@@ -254,6 +272,12 @@ shared_examples_for "session" do
254
272
  @session.click_button('awesome')
255
273
  extract_results(@session)['gender'].should == 'both'
256
274
  end
275
+
276
+ context "with a locator that doesn't exist" do
277
+ it "should raise an error" do
278
+ running { @session.choose('does not exist') }.should raise_error(Capybara::ElementNotFound)
279
+ end
280
+ end
257
281
  end
258
282
 
259
283
  describe "#check" do
@@ -272,6 +296,12 @@ shared_examples_for "session" do
272
296
  @session.click_button('awesome')
273
297
  extract_results(@session)['pets'].should include('dog', 'cat', 'hamster')
274
298
  end
299
+
300
+ context "with a locator that doesn't exist" do
301
+ it "should raise an error" do
302
+ running { @session.check('does not exist') }.should raise_error(Capybara::ElementNotFound)
303
+ end
304
+ end
275
305
  end
276
306
 
277
307
  describe "#uncheck" do
@@ -292,6 +322,12 @@ shared_examples_for "session" do
292
322
  extract_results(@session)['pets'].should include('dog')
293
323
  extract_results(@session)['pets'].should_not include('hamster')
294
324
  end
325
+
326
+ context "with a locator that doesn't exist" do
327
+ it "should raise an error" do
328
+ running { @session.uncheck('does not exist') }.should raise_error(Capybara::ElementNotFound)
329
+ end
330
+ end
295
331
  end
296
332
 
297
333
  describe "#select" do
@@ -310,6 +346,12 @@ shared_examples_for "session" do
310
346
  @session.click_button('awesome')
311
347
  extract_results(@session)['locale'].should == 'fi'
312
348
  end
349
+
350
+ context "with a locator that doesn't exist" do
351
+ it "should raise an error" do
352
+ running { @session.select('foo', :from => 'does not exist') }.should raise_error(Capybara::ElementNotFound)
353
+ end
354
+ end
313
355
  end
314
356
 
315
357
  describe '#has_content?' do
@@ -320,6 +362,13 @@ shared_examples_for "session" do
320
362
  @session.should have_content('Redirect')
321
363
  end
322
364
 
365
+ it "should be true if scoped to an element which has the content" do
366
+ @session.visit('/with_html')
367
+ @session.within("//a[@title='awesome title']") do
368
+ @session.should have_content('labore')
369
+ end
370
+ end
371
+
323
372
  it "should be false if the given content is not on the page" do
324
373
  @session.visit('/with_html')
325
374
  @session.should_not have_content('xxxxyzzz')
@@ -358,7 +407,7 @@ shared_examples_for "session" do
358
407
  @session.should_not have_xpath("//p//a[@id='doesnotexist']")
359
408
  @session.should_not have_xpath("//p[contains(.,'thisstringisnotonpage')]")
360
409
  end
361
-
410
+
362
411
  it "should respect scopes" do
363
412
  @session.within "//p[@id='first']" do
364
413
  @session.should have_xpath("//a[@id='foo']")
@@ -384,20 +433,20 @@ shared_examples_for "session" do
384
433
  @session.should_not have_xpath("//p//a[@id='doesnotexist']", :count => 1)
385
434
  end
386
435
  end
387
-
436
+
388
437
  context "with text" do
389
438
  it "should discard all matches where the given string is not contained" do
390
439
  @session.should have_xpath("//p//a", :text => "Redirect", :count => 1)
391
440
  @session.should_not have_xpath("//p", :text => "Doesnotexist")
392
441
  end
393
-
442
+
394
443
  it "should discard all matches where the given regexp is not matched" do
395
444
  @session.should have_xpath("//p//a", :text => /re[dab]i/i, :count => 1)
396
445
  @session.should_not have_xpath("//p//a", :text => /Red$/)
397
446
  end
398
447
  end
399
448
  end
400
-
449
+
401
450
  describe '#has_css?' do
402
451
  before do
403
452
  @session.visit('/with_html')
@@ -413,7 +462,7 @@ shared_examples_for "session" do
413
462
  @session.should_not have_css("p a#doesnotexist")
414
463
  @session.should_not have_css("p.nosuchclass")
415
464
  end
416
-
465
+
417
466
  it "should respect scopes" do
418
467
  @session.within "//p[@id='first']" do
419
468
  @session.should have_css("a#foo")
@@ -437,13 +486,13 @@ shared_examples_for "session" do
437
486
  @session.should_not have_css("p a.doesnotexist", :count => 1)
438
487
  end
439
488
  end
440
-
489
+
441
490
  context "with text" do
442
491
  it "should discard all matches where the given string is not contained" do
443
492
  @session.should have_css("p a", :text => "Redirect", :count => 1)
444
493
  @session.should_not have_css("p a", :text => "Doesnotexist")
445
494
  end
446
-
495
+
447
496
  it "should discard all matches where the given regexp is not matched" do
448
497
  @session.should have_css("p a", :text => /re[dab]i/i, :count => 1)
449
498
  @session.should_not have_css("p a", :text => /Red$/)
@@ -486,10 +535,19 @@ shared_examples_for "session" do
486
535
  @session.click_button('Upload')
487
536
  @session.body.should include(File.read(@test_file_path))
488
537
  end
538
+
539
+ it "should not break if no file is submitted" do
540
+ @session.click_button('Upload')
541
+ end
489
542
  end
490
543
 
544
+ context "with a locator that doesn't exist" do
545
+ it "should raise an error" do
546
+ running { @session.attach_file('does not exist', 'foo.txt') }.should raise_error(Capybara::ElementNotFound)
547
+ end
548
+ end
491
549
  end
492
-
550
+
493
551
  describe '#find_field' do
494
552
  before do
495
553
  @session.visit('/form')
@@ -500,28 +558,17 @@ shared_examples_for "session" do
500
558
  @session.find_field('form_description').text.should == 'Descriptive text goes here'
501
559
  @session.find_field('Region')[:name].should == 'form[region]'
502
560
  end
503
-
504
- it "should raise an error if the field doesn't exist" do
505
- running {
506
- @session.find_field('Does not exist')
507
- }.should raise_error(Capybara::ElementNotFound)
508
- end
509
-
510
- it "should find only given kind of field" do
511
- @session.find_field('form_description', :text_field, :text_area).text.should == 'Descriptive text goes here'
512
- running {
513
- @session.find_field('form_description', :password_field)
514
- }.should raise_error(Capybara::ElementNotFound)
561
+
562
+ it "should be nil if the field doesn't exist" do
563
+ @session.find_field('Does not exist').should be_nil
515
564
  end
516
-
565
+
517
566
  it "should be aliased as 'field_labeled' for webrat compatibility" do
518
567
  @session.field_labeled('Dog').value.should == 'dog'
519
- running {
520
- @session.field_labeled('Does not exist')
521
- }.should raise_error(Capybara::ElementNotFound)
568
+ @session.field_labeled('Does not exist').should be_nil
522
569
  end
523
570
  end
524
-
571
+
525
572
  describe '#find_link' do
526
573
  before do
527
574
  @session.visit('/with_html')
@@ -531,14 +578,12 @@ shared_examples_for "session" do
531
578
  @session.find_link('foo').text.should == "ullamco"
532
579
  @session.find_link('labore')[:href].should == "/with_simple_html"
533
580
  end
534
-
535
- it "should raise an error if the field doesn't exist" do
536
- running {
537
- @session.find_link('Does not exist')
538
- }.should raise_error(Capybara::ElementNotFound)
581
+
582
+ it "should return nil if the field doesn't exist" do
583
+ @session.find_link('Does not exist').should be_nil
539
584
  end
540
585
  end
541
-
586
+
542
587
  describe '#find_button' do
543
588
  before do
544
589
  @session.visit('/form')
@@ -548,11 +593,110 @@ shared_examples_for "session" do
548
593
  @session.find_button('med')[:id].should == "mediocre"
549
594
  @session.find_button('crap321').value.should == "crappy"
550
595
  end
596
+
597
+ it "should return nil if the field doesn't exist" do
598
+ @session.find_button('Does not exist').should be_nil
599
+ end
600
+ end
601
+
602
+ describe '#all' do
603
+ before do
604
+ @session.visit('/with_html')
605
+ end
606
+
607
+ it "should find all elements using the given locator" do
608
+ @session.all('//p').should have(3).elements
609
+ @session.all('//h1').first.text.should == 'This is a test'
610
+ @session.all("//input[@id='test_field']").first[:value].should == 'monkey'
611
+ end
612
+
613
+ it "should return an empty array when nothing was found" do
614
+ @session.all('//div').should be_empty
615
+ end
616
+
617
+ it "should accept an XPath instance" do
618
+ @session.visit('/form')
619
+ @xpath = Capybara::XPath.text_field('Name')
620
+ @result = @session.all(@xpath)
621
+ @result.map(&:value).should include('Smith', 'John', 'John Smith')
622
+ end
623
+
624
+ context "within a scope" do
625
+ before do
626
+ @session.visit('/with_scope')
627
+ end
628
+
629
+ it "should find any element using the given locator" do
630
+ @session.within(:xpath, "//div[@id='for_bar']") do
631
+ @session.all('//li').should have(2).elements
632
+ end
633
+ end
634
+ end
635
+ end
636
+
637
+ describe '#find' do
638
+ before do
639
+ @session.visit('/with_html')
640
+ end
641
+
642
+ it "should find the first element using the given locator" do
643
+ @session.find('//h1').text.should == 'This is a test'
644
+ @session.find("//input[@id='test_field']")[:value].should == 'monkey'
645
+ end
646
+
647
+ it "should return nil when nothing was found" do
648
+ @session.find('//div').should be_nil
649
+ end
650
+
651
+ it "should accept an XPath instance and respect the order of paths" do
652
+ @session.visit('/form')
653
+ @xpath = Capybara::XPath.text_field('Name')
654
+ @session.find(@xpath).value.should == 'John Smith'
655
+ end
656
+
657
+ context "within a scope" do
658
+ before do
659
+ @session.visit('/with_scope')
660
+ end
661
+
662
+ it "should find the first element using the given locator" do
663
+ @session.within(:xpath, "//div[@id='for_bar']") do
664
+ @session.find('//li').text.should =~ /With Simple HTML/
665
+ end
666
+ end
667
+ end
668
+ end
669
+
670
+ describe '#wait_for' do
671
+ before do
672
+ @session.visit('/with_html')
673
+ end
674
+
675
+ it "should find the first element using the given locator" do
676
+ @session.wait_for('//h1').text.should == 'This is a test'
677
+ @session.wait_for("//input[@id='test_field']")[:value].should == 'monkey'
678
+ end
551
679
 
552
- it "should raise an error if the field doesn't exist" do
553
- running {
554
- @session.find_button('Does not exist')
555
- }.should raise_error(Capybara::ElementNotFound)
680
+ it "should return nil when nothing was found" do
681
+ @session.wait_for('//div').should be_nil
682
+ end
683
+
684
+ it "should accept an XPath instance and respect the order of paths" do
685
+ @session.visit('/form')
686
+ @xpath = Capybara::XPath.text_field('Name')
687
+ @session.wait_for(@xpath).value.should == 'John Smith'
688
+ end
689
+
690
+ context "within a scope" do
691
+ before do
692
+ @session.visit('/with_scope')
693
+ end
694
+
695
+ it "should find the first element using the given locator" do
696
+ @session.within(:xpath, "//div[@id='for_bar']") do
697
+ @session.wait_for('//li').text.should =~ /With Simple HTML/
698
+ end
699
+ end
556
700
  end
557
701
  end
558
702
 
@@ -560,7 +704,7 @@ shared_examples_for "session" do
560
704
  before do
561
705
  @session.visit('/with_scope')
562
706
  end
563
-
707
+
564
708
  context "with CSS selector" do
565
709
  it "should click links in the given scope" do
566
710
  @session.within(:css, "ul li[contains('With Simple HTML')]") do
@@ -569,7 +713,7 @@ shared_examples_for "session" do
569
713
  @session.body.should include('<h1>Bar</h1>')
570
714
  end
571
715
  end
572
-
716
+
573
717
  context "with XPath selector" do
574
718
  it "should click links in the given scope" do
575
719
  @session.within(:xpath, "//li[contains(.,'With Simple HTML')]") do
@@ -578,7 +722,7 @@ shared_examples_for "session" do
578
722
  @session.body.should include('<h1>Bar</h1>')
579
723
  end
580
724
  end
581
-
725
+
582
726
  context "with the default selector" do
583
727
  it "should use XPath" do
584
728
  @session.within("//li[contains(., 'With Simple HTML')]") do
@@ -587,12 +731,12 @@ shared_examples_for "session" do
587
731
  @session.body.should include('<h1>Bar</h1>')
588
732
  end
589
733
  end
590
-
734
+
591
735
  context "with the default selector set to CSS" do
592
736
  after do
593
737
  Capybara.default_selector = :xpath
594
738
  end
595
-
739
+
596
740
  it "should use CSS" do
597
741
  Capybara.default_selector = :css
598
742
  @session.within("ul li[contains('With Simple HTML')]") do
@@ -601,7 +745,7 @@ shared_examples_for "session" do
601
745
  @session.body.should include('<h1>Bar</h1>')
602
746
  end
603
747
  end
604
-
748
+
605
749
  context "with click_link" do
606
750
  it "should click links in the given scope" do
607
751
  @session.within("//li[contains(.,'With Simple HTML')]") do
@@ -629,7 +773,7 @@ shared_examples_for "session" do
629
773
  @session.body.should include('Hello world')
630
774
  end
631
775
  end
632
-
776
+
633
777
  it "should raise an error if the scope is not found on the page" do
634
778
  running {
635
779
  @session.within("//div[@id='doesnotexist']") do
@@ -653,12 +797,12 @@ shared_examples_for "session" do
653
797
  end
654
798
  end
655
799
  end
656
-
800
+
657
801
  describe '#within_fieldset' do
658
802
  before do
659
803
  @session.visit('/fieldsets')
660
804
  end
661
-
805
+
662
806
  it "should restrict scope to a fieldset given by id" do
663
807
  @session.within_fieldset("villain_fieldset") do
664
808
  @session.fill_in("Name", :with => 'Goldfinger')
@@ -666,7 +810,7 @@ shared_examples_for "session" do
666
810
  end
667
811
  extract_results(@session)['villain_name'].should == 'Goldfinger'
668
812
  end
669
-
813
+
670
814
  it "should restrict scope to a fieldset given by legend" do
671
815
  @session.within_fieldset("Villain") do
672
816
  @session.fill_in("Name", :with => 'Goldfinger')
@@ -675,12 +819,12 @@ shared_examples_for "session" do
675
819
  extract_results(@session)['villain_name'].should == 'Goldfinger'
676
820
  end
677
821
  end
678
-
822
+
679
823
  describe '#within_table' do
680
824
  before do
681
825
  @session.visit('/tables')
682
826
  end
683
-
827
+
684
828
  it "should restrict scope to a fieldset given by id" do
685
829
  @session.within_table("girl_table") do
686
830
  @session.fill_in("Name", :with => 'Christmas')
@@ -688,7 +832,7 @@ shared_examples_for "session" do
688
832
  end
689
833
  extract_results(@session)['girl_name'].should == 'Christmas'
690
834
  end
691
-
835
+
692
836
  it "should restrict scope to a fieldset given by legend" do
693
837
  @session.within_table("Villain") do
694
838
  @session.fill_in("Name", :with => 'Quantum')
@@ -697,6 +841,60 @@ shared_examples_for "session" do
697
841
  extract_results(@session)['villain_name'].should == 'Quantum'
698
842
  end
699
843
  end
844
+
845
+ end
846
+
847
+ shared_examples_for "session without javascript support" do
848
+ describe "#evaluate_script" do
849
+ before{ @session.visit('/with_js') }
850
+ it "should raise an error" do
851
+ running {
852
+ @session.evaluate_script("1+5")
853
+ }.should raise_error(Capybara::NotSupportedByDriverError)
854
+ end
855
+ end
856
+ end
857
+
858
+ shared_examples_for "session with javascript support" do
859
+ describe "#evaluate_script" do
860
+ before{ @session.visit('/with_js') }
861
+ it "should return the evaluated script" do
862
+ @session.evaluate_script("1+3").should == 4
863
+ end
864
+ end
865
+
866
+ describe '#wait_for' do
867
+ it "should wait for asynchronous load" do
868
+ @session.visit('/with_js')
869
+ @session.click_link('Click me')
870
+ @session.wait_for("//a[contains(.,'Has been clicked')]")[:href].should == '#'
871
+ end
872
+ end
873
+
874
+ describe '#click_link' do
875
+ it "should wait for asynchronous load" do
876
+ @session.visit('/with_js')
877
+ @session.click_link('Click me')
878
+ @session.click_link('Has been clicked')
879
+ end
880
+ end
881
+
882
+ describe '#click_button' do
883
+ it "should wait for asynchronous load" do
884
+ @session.visit('/with_js')
885
+ @session.click_link('Click me')
886
+ @session.click_button('New Here')
887
+ end
888
+ end
889
+
890
+ describe '#fill_in' do
891
+ it "should wait for asynchronous load" do
892
+ @session.visit('/with_js')
893
+ @session.click_link('Click me')
894
+ @session.fill_in('new_field', :with => 'Testing...')
895
+ end
896
+ end
897
+
700
898
  end
701
899
 
702
900
  describe Capybara::Session do
@@ -708,3 +906,4 @@ describe Capybara::Session do
708
906
  end
709
907
  end
710
908
  end
909
+