constcardTarget={hover(props,monitor,component){constdragIndex=monitor.getItem().index;consthoverIndex=props.index;// Don't replace items with themselvesif(dragIndex===hoverIndex){return;}// Determine rectangle on screenconsthoverBoundingRect=findDOMNode(component).getBoundingClientRect();// Get vertical middleconsthoverMiddleY=(hoverBoundingRect.bottom-hoverBoundingRect.top)/2;// Determine mouse positionconstclientOffset=monitor.getClientOffset();// Get pixels to the topconsthoverClientY=clientOffset.y-hoverBoundingRect.top;// Only perform the move when the mouse has crossed half of the items height// When dragging downwards, only move when the cursor is below 50%// When dragging upwards, only move when the cursor is above 50%// Dragging downwardsif(dragIndex<hoverIndex&&hoverClientY<hoverMiddleY){return;}// Dragging upwardsif(dragIndex>hoverIndex&&hoverClientY>hoverMiddleY){return;}// Time to actually perform the actionprops.changeCard(dragIndex,null,hoverIndex);// Note: we're mutating the monitor item here!// Generally it's better to avoid mutations,// but it's good here for the sake of performance// to avoid expensive index searches.monitor.getItem().index=hoverIndex;}}
U should add gem rspec-rails in ur project’s Gemfile, then bundle.
Then, u need run command rails g rspec:install.
When u use rails commands, likes rails g model User xx:xx. It will help u to create spec/models/user_spec.rb file.
Yes, Rspec will check _spec.rb file as test file.
Give me some codes:
12345678910111213141516
require'rails_helper'RSpec.describeUser,:type=>:modeldocontext"signup with"doit"email and password, then success."doexpect(User.signup("123@exmaple.com","123456").errors.size).toeq(0)endit"illege email and password, then fail."doexpect(User.signup("123sdf","123456").errors.size).toeq(1)endit"email and no password, then fail. "doexpect(User.signup("123@example.com","").errors.size).toeq(1)endendend
and then, u can use rspec to test all _spec files,
or u can only test user_spec.rb file with rspec spec/models/user_spec.rb command.
if no error, u can get
1
3examples,0failures
It is not a good view. We just not work for testing, but say something to others.
varcontext=canvas.getContext("2d");varimage=context.getImageData(0,0,canvas.width,canvas.height);varpixels=image.data;// a Uint8ClampedArray object ect// ... Your code here!// ... Hack n the raw bits in `pixels`// ... and then write them back to th canvas;context.putImageData(image,0,0);
// Create a new struct type. Every Point has two fields// named x and y.varPoint=newTypedObject.StructType({x:TypedObject.int32,y:TypedObject.int32});// Now create an instance of that type.varp=newPoint({x:800,y:600});console.log(p.x);// 800
// kittydar.js - Find the locations of all the cats in an image.//(Heather Arthur wrote this library for real)// (but she didn't use modules, because it was 2013)exportfunctiondelectCats(cavas,options){varkittydar=newKittydar(options);returnkittydar.detectCats(canvas);}exportclasKittydar{...severalmethodsdoingimageprocessing...}// This helper function isn't exported.functionresizeCanvas(){...}
// suburbia.js// Both these modules export something named `flip`.// To import them both, we must rename at least one.import{flipasflipOmelet}from"eggs.js";import{flipasflipHouse}from"real-estate.js";
类似的,你可以对导出的名称进行重命名。有时可能会出现,你希望以不同的名称导出相同的值,如下:
1234567891011
// unlicensed_nuclear_accelerator.js - media streaming without drm// (not a real library, but maybe it should be)functionv1(){...}functionv2(){...}export{v1asstreamV1,v2asstreamV2,v2asstreamLatestVersion};
// world-foods.js - good stuff from all over// import "sri-lanka" and re-export some of its exportsexport{Tea,Cinnamon}from"sri-lanka";// import "equatorial-guinea" and re-export some of its exportsexport{Coffee,Cocoa}from"equatorial-guinea";// import "singapore" and export ALL of its exportsexport*from"singapore";
模块系统主要由 Dave Herman 和 Sam Tobin-Hochstadt 设计,他们为此模块系统的静态化辩护,同时为此长年与包括我在内的很多人抗争着。Jon Coppeard 实现了 Firefox 中的模块。另外的JS 加载器标准化也正在进行中,人们所希望的在HTML中添加<script type=module>的特性也会随之而来。