Google Apps Script (webapp) ã§ãã°ãè¨é²ãã
Google Apps Script ã¨ãã°
Google Apps Script (GAS) ã§ããã°ãæ¸ãæã«é·å¹´ Logger.log
ã使ã£ã¦ããã
ã¹ã¯ãªãããå®è¡ããã¡ãã¥ã¼ã® 表示
â ãã°
ã§ãã°ã表示ã§ããã
ãã ãããã®ãã°ã¯èªåã§ã¹ã¯ãªãããå®è¡ããæã®ãã°ã表示ã§ããã ãã§ãä¾ãã° webapp ã¨ãã¦ãããã¤ãã¦ããæã®ãã°ãè¦ããã¨ã¯ã§ããªãã£ãã
Stackdriver Logging ã®æå¹å
å®è¡ä¸ã®ãã°ãè¦ãããã«ã¯ Stackdriver Logging ã¨ãããã®ãå©ç¨ããã
ã¡ãã¥ã¼ã® 表示
â Stackdriver Logging
ãã¯ãªãã¯ããã
ç´ä»ããã§ãã¦ããªãå ´åã«ã¯ä»¥ä¸ã®ãã¤ã¢ãã°ã表示ãããã®ã§ã Google Cloud Platform ã§ããã¸ã§ã¯ããä½ã£ã¦ãããå¿ è¦ãããã
https://console.cloud.google.com/ ã«ã¢ã¯ã»ã¹ããå·¦ä¸ã®ããã¸ã§ã¯ãåãã¯ãªãã¯ããæ°ããããã¸ã§ã¯ããã¯ãªãã¯ããã
é©å½ã«ããã¸ã§ã¯ãåãå ¥åãã¦ãä½æãã¯ãªãã¯ããã
ããã¨ããã¸ã§ã¯ããä½æãããã®ã§ãããã¸ã§ã¯ãçªå·
ãã¡ã¢ããã
GAS ã®ã¨ãã£ã¿ã«æ»ããã¡ãã¥ã¼ãã ãªã½ã¼ã¹
â Google Platform ããã¸ã§ã¯ã
ãã¯ãªãã¯ããã
ããã¸ã§ã¯ããç´ä»ãããã¤ã¢ãã°ã表示ãããã®ã§ãããã¸ã§ã¯ãçªå·ãå
¥åã㦠ããã¸ã§ã¯ããè¨å®
ãã¯ãªãã¯ããã
OAuth åæç»é¢ãè¨å®ããå¿
è¦ãããã¨è¡¨ç¤ºãããã®ã§ã ãã¡ã
ãã¯ãªãã¯ããã
User Type 㯠å¤é¨
ããé¸æã§ããªãã®ã§ãå¤é¨ãé¸æããä½æ ãã¯ãªãã¯ããã
OAuth åæç»é¢ã®ä½æç»é¢ã§ ã¢ããªã±ã¼ã·ã§ã³å ã ãå ¥ã㦠ä¿å ãã¯ãªãã¯ãã
GAS ã®å
ç¨ã®ãã¤ã¢ãã°ã«æ»ã£ã¦ãããä¸åº¦ ããã¸ã§ã¯ããè¨å®
ãã¯ãªãã¯ããã¨ãä»åº¦ã¯ç´ä»ãã§ããã
ãã°ãåºåãã
ãã°ãåºåããã¨ã㯠Logger
ã§ã¯ãªã console
ã使ãã
ãããªæãã®ã¹ã¯ãªããã webapp ã¨ãã¦å ¬éãã¦ããã©ã¦ã¶ã§ã¢ã¯ã»ã¹ãã¦ã¿ãã
const doGet = (e) => { console.log(e); return ContentService.createTextOutput('ok'); }
ãã°ã確èªãã
ã¡ãã¥ã¼ã® 表示
â Stackdriver Logging
ãã¯ãªãã¯ãããJSON ãããæãã«å±éããã¦ããã®ããããã
console.log
ã¯ãã°ã¬ãã«ã DEBUG
ã«ãªãã
console.warn
ã console.info
ãconsole.error
ãªããã使ããã
ãã¾ã
clasp ã使ããã« GAS ãä½ãã¨ã Google Apps Script ã®ãã°ã«ãå±éãã¨ãããã¿ã³ã表示ããã¦ããããããã°ãè¦ããããããªæ°ãããã
clasp ã使ãã¨ããã表示ãããªããè¬ãã
åè URL
Node-RED Google Assistant Bridge 使ã£ã¦ã¿ã
ã¯ããã«
æã家ã§ã¯ Node-RED 㨠Node-RED Alexa Home Skill Bridge ã使ã£ã¦ã家ã®å®¶é»ãæä½ãã¦ããã ããã® Google Home çã§ãã Node-RED Google Assistant Bridge ããå ¬éãããã®ã§è¨å®ãã¦ã¿ãã
åºæ¬çã«ã¯ æ´æ°ããã¥ã¡ã³ã ã®éãã«ãã¦ããã
Node-RED Google Assistant Bridge ã®è¨å®
Node-RED Alexa Home Skill Bridge ã«ã¢ã«ã¦ã³ããç»é²ããã ãã®å¾ãé©å½ã«ããã¤ã¹ãç»é²ããã ããã§ã¯ããªãã³ã°ã®é»æ°ãã¨ããããã¤ã¹ãç»é²ãã¦ããã
æ¥æ¬èªä½¿ã£ãããçµµæåã使ãã®ã¯é¢å¿ããªãããã¿ãããªãã¨ãè¨ããããã©ç¡è¦ããã
Google Group ã«åå ãã
Google Assistant ã§ä½¿ã£ã¦ãã Google ã¢ã«ã¦ã³ãã§ä»¥ä¸ã®ã°ã«ã¼ãã«åå ããã
https://groups.google.com/forum/#!forum/node-red-google-home-bridge
ã¢ã«ã¦ã³ãããªã³ã¯ãã
Node-RED Google Assistant Bridge ã«èªåã®ã¢ã«ã¦ã³ããæãã¦ä¸ããå¿ è¦ãããã®ã§ã Google Home ã¢ããªã§ã¢ã«ã¦ã³ããèªè¨¼ããã
ã¢ããªãéãããå·¦ä¸ã®ãï¼ããã¿ã³ãã¿ãããããããã¤ã¹ã®ã»ããã¢ããããã¿ããããã
次ã«ãã»ããã¢ããæ¸ã¿ã®ããã¤ã¹ã®ãªã³ã¯ããã¿ããããã
次ã«ãNR-GABããã¿ããããã
*[test]
ã¦æ¸ãã¦ãããã©å¤§ä¸å¤«ãâ¦ï¼
Node-RED Alexa Home Skill Bridge ã®ç»é¢ãéãã®ã§ã Node-RED Alexa Home Skill Bridge ã®ã¢ã«ã¦ã³ãã§èªè¨¼ããã
ããããã¼ã¸ã«ããªãã³ã°ã®é»æ°ãã追å ãããã
Node-RED ã« node-red-google-home-bridge ã®ã¤ã³ã¹ãã¼ã«
ã¾ãã¯ãã¼ããã¤ã³ã¹ãã¼ã«ããã
æã家ã§ã¯ Node-RED ã IBM Cloud ã§åããã¦ãããGUI ãããã¼ããã¤ã³ã¹ãã¼ã«ãããã¨ãã§ããªãã®ã§ã package.json
ã«è¿½è¨ããã
$ npm install node-red-contrib-googlehome
ãã¾ãï¼ IBM Cloud ã«ãããã¤ããã
$ bx login $ bx target -o çµç¹å -s dev $ bx cf push
Node-RED å´ã®è¨å®
google home ãã¼ããé©å½ã«ç½®ããããã«ã¯ãªãã¯ããã
ãæ°è¦ã« google-home-conf ã追å ...ãã«ãªã£ã¦ãããã¨ã確èªããéçã¢ã¤ã³ã³ãã¯ãªãã¯ããã
Node-RED Google Assistant Bridge ã® ID ã¨ãã¹ã¯ã¼ãã渡ãã¨ãDevice ã®ä¸è¦§ãåå¾ã§ããã
é©å½ã«ãã¼ããé ç½®ããã
google home ãã¼ãã«æ¥ç¶ãã¦ãã switch ã®ä¸èº«ã¯ä»¥ä¸ã®ãããªæãã«ããã
è¨å®å®äº
ãã®ç¶æ ã§ããªãã±ã¼ã°ã¼ã°ã«ããªãã³ã°ã®é»æ°ããªããã¨è¨ãã¨ããªãã³ã°ã®é»æ°ãæ¶ããããã«ãªã£ãã Alexa ã§ã Google Home ã§ã家é»ãæä½ã§ããããã«ãªã£ã¦ã©ã¤ããã§ã³ã¸ã³ã°ã«ãªã£ãï¼
Ruboty 㧠Redash ã®ãã¼ã¿ãéç¥ãã ruboty-redash ä½ã£ã
Ruboty 㧠Redash ã®ãã¼ã¿ãéç¥ããã
Redash ã§æ°å¤ãå¯è¦åãã¦ããç°å¢ã®å ´åããã®ææ°ã®å¤ã Slack ã§éç¥ãããã Ruboty ã使ã£ã¦ bot ãéç¨ãã¦ããã®ã§ã Ruboty ãã©ã°ã¤ã³ã¨ã㦠Redash ã®å¤ãåã£ã¦ãããã®ãä½ã£ãã
ruboty-redash
使ãæ¹
Ruboty ã«ãã©ã°ã¤ã³ã追å ãã¦ã以ä¸ã®2ã¤ã®ç°å¢å¤æ°ã追å ããã
REDASH_ROOT
⦠Ruboty ã« URL ã®ã«ã¼ã (ä¾ï¼https://app.redash.io/
)REDASH_USER_APIKEY
⦠Redash ã®ã¦ã¼ã¶ã® API ãã¼
ãã¨ã¯ãã£ããä¸ã§ä»¥ä¸ã®ãããªã³ãã³ããå®è¡ããã
@ruboty redash show <ã¯ã¨ãªID> <ERB ã¡ãã»ã¼ã¸ãã©ã¼ããã>
<ã¯ã¨ãª ID>
ã¯ãRedash ã®ã¯ã¨ãªã®ç»é¢ãéããæã« URL ã«è¡¨ç¤ºããã ID ã®ãã¨ã
<ERB ã¡ãã»ã¼ã¸ãã©ã¼ããã>
ã¯ãã¡ãã»ã¼ã¸ã®ãã©ã¼ãããã ERB ã§æå®ããã
ä¾ãã°
@ruboty redash show 11 æ¨æ¥ã®çç£æ§ã¹ã³ã¢ã¯ <%= data['rows'][-1]['productivity_pulse'] %> ã§ãã
ã®ããã«ãªãã
ãã® data
ã®ãã¼ã¿æ§é ã®èª¿ã¹æ¹ãå°ããããããã®ã§ã以ä¸ã§è§£èª¬ããã
data
ã®ãã¼ã¿æ§é ã®èª¿ã¹æ¹
Redash ã§è©²å½ã®ã¯ã¨ãªã®ãã¼ã¸ã Google Chrome ã表示ããã
Developer Tools ã® Network ã¿ããéã㦠query_results
ã§ãã£ã«ã¿ããã
ãã®è¿ã£ã¦ãã JSON ã® Preview 㧠query_result
é
ä¸ã® data
ãã£ã¼ã«ãã data
å¤æ°ã«æ ¼ç´ãããã¨ããä»çµã¿ã
query_result
ã®å¤ãè¦ã¦ãããã¨ãããããããã«ãæå¾ã®å®è¡çµæãåå¾ããã¨ããä»çµã¿ã«ãªã£ã¦ããã
ãã®ãããä¸åº¦ãå®è¡ããã¦ããªãã¯ã¨ãªã¯ ruboty-redash ã§åå¾ãããã¨ã¯ã§ããªãã
ã¾ããã¯ã¨ãªã®å®è¡ã¯ Redash å´ã§ã¹ã±ã¸ã¥ã¼ã«åãã¦ããã¦å¸¸ã«å®è¡ãããããã«ãã¦ãããªãã¨å¤ã¯ææ°åãããªãã
ã¾ã¨ã
Ruboty 㧠Redash ã®å¤ãéç¥ã§ãããããªä»çµã¿ãä½ã£ãã æ¬æä¸ã®ãçç£æ§ã¹ã³ã¢ããæ°ã«ãªã£ãæ¹ã¯ Redash で作る「じぶんダッシュボード」 というタイトルで発表した - mallowlabsの備忘録 ã®è¨äºãåèã«ãã¦æ¬²ããã
Global Media Controls 㧠Alexa SPA ãæä½ãã Chrome æ¡å¼µãä½ã£ã
ã¢ããã¼ã·ã§ã³
é³æ¥½ãè´ãã¨ã㯠Amazon Echo ã®ãã«ãã«ã¼ã ãªã¼ãã£ãªã使ã£ã¦ããã ããããªé¨å±ã§åãæ²ãæµããã®ã¯ããçµé¨ã ããæ²åã確èªããããæ²ãã¹ããããããã¨ãã«ã声ãåºããªãã¨ãããªãã ãã㧠https://alexa.amazon.co.jp/spa/index.html#player (ä»¥ä¸ Alexa SPA) ã使ãã¨ãWeb ãã©ã¦ã¶ããæ²åã確èªããããæ²ãã¹ãããã§ãã¦ä¾¿å©ãªã®ã§ãåããã¦ä½¿ã£ã¦ããã
æè¿ Chrome 79 㧠YouTube Music ãè´ãã¦ãããChrome ã®ãã¼ã«ãã¼ã«é³æ¥½ã®ãã¼ã«ãã¼ã表示ãããããã«ãªã£ããã¨ã«æ°ã¥ããã
調ã¹ãã Global Media Controls ã¨ããè¨ãããããChrome 79 æç¹ã§ã¯å®é¨çãªå®è£ ã¨ããã¦ããã ããã Alexa SPA ã§ã使ãããã¨æã£ãã®ã§ã Chrome æ¡å¼µã§å®è£ ãã¦ã¿ã
alexa-spa-global-media-controls
Chrome ã¹ãã¢ã«ã¯ä¸ãã¦ããªãã®ã§ã試ãã¦ã¿ããå ´åã¯ã¯ãã¼ã³ãã¦ãChrome ã«èªã¿è¾¼ãã§æ¬²ããã
æ¡å¼µãã¤ã³ã¹ãã¼ã«ããç¶æ 㧠https://alexa.amazon.co.jp/spa/index.html#player ã«ã¢ã¯ã»ã¹ãã¦ãAlexa ã§é³æ¥½ãæµãã°ãã¼ã«ãã¼ã«ä»¥ä¸ã®ããã«è¡¨ç¤ºãããã
å®è£ ã®è©±
æ¥æ¬èªã®ããã¥ã¡ã³ããä½ããªãã£ãã®ã¨ãç´°ããã¨ããã§çµæ§ããã£ãã®ã§ããããã©ãããã¾ã¨ããã
Chrome 79.0.3945.130
æç¹ã®è©±ãªã®ã§ãä»å¾æ¹åããå¯è½æ§ã¯é«ãã
ãã¼ã«ãã¼ã«è¡¨ç¤ºãããªã
åºæ¬çã«ã¯ MediaSession API ã以ä¸ã®ããã«ä½¿ãã ãã®ã¯ãã§ããã
navigator.mediaSession.metadata = new MediaMetadata({ title: 'æ²å', artist: 'ã¢ã¼ãã£ã¹ãå', album: 'ã¢ã«ãã å', artwork: [ { src:' ã¢ã«ãã ã¢ã¼ãã® URL' } ] });
ãããããããå¼ã³åºãã¦ããã¼ã«ãã¼ã«ãã¿ã³ã表示ãããªãã
調ã¹ã¦ã¿ãã¨å®éã®ã¿ã㧠video
ã¿ã°ã audio
ã¿ã°ã§å®éã«é³å£°ãåçããã¦ããå¿
è¦ããããããã
ãããã 5ç§ä»¥ä¸ã®é³å£°ãã¡ã¤ã«ãåçãã¦ããå¿
è¦ããããããã
Alexa SPA ã§ã¯å®éã®é³ã¯ Amazon Echo ããæµãããããã¿ãã§é³æ¥½ãåçãããã¨ã¯ã§ããªãã
ããã§ãç¡é³ã® ogg ãã¡ã¤ã«ãç¨æãã¦ã DOM ã®ç¶æ
ãè¦ã¦ãåçãããåæ¢ããããã«å®è£
ããã
ã¢ã«ãã åã®è¡¨ç¤ºä½ç½®ãå¤
MediaSession API ã«ç´ ç´ã« album å±æ§ã渡ãã¨ããã¡ã¤ã³ã®æ¨ªã«è¡¨ç¤ºãããã
YouTube Music ã¯ã©ããã¦ãã®ãè¦ã¦ã¿ãã artist
å±æ§ã«ã¢ã«ãã åãå«ããããã«ãã¦ããã
ãªããéç¶ã¨ããªãããä¼¼ããããªæãã§å®è£
ããã
navigator.mediaSession.metadata = new MediaMetadata({ title: 'æ²å - ã¢ã«ãã å', artist: 'ã¢ã¼ãã£ã¹ãå', artwork: [ { src:' ã¢ã«ãã ã¢ã¼ãã® URL' } ] });
ã¢ã«ãã ã¢ã¼ãã表示ãããªã
ã¢ã«ãã ã¢ã¼ãã® URL ã«ç»åã® URL ã渡ãã¦ããã«ãé¢ããããç»åã表示ãããªãã
ã©ããã sizes
å±æ§ãæå®ããªããã°ãªããªããããã
navigator.mediaSession.metadata = new MediaMetadata({ title: 'æ²å - ã¢ã«ãã å', artist: 'ã¢ã¼ãã£ã¹ãå', artwork: [ { sizes: '412x412', src:' ã¢ã«ãã ã¢ã¼ãã® URL' } ] });
artwork
ã«ã¯ type
ãæå®ã§ãããããã£ã¡ã¯ä¸è¦ãããã
ã¾ã¨ã
Global Media Controls å人çã«ã¯ããªãã¢ãªãªã®ã§ãæ®åãã¦æ¬²ããã
åè URL
Redash ã§ä½ãããã¶ãããã·ã¥ãã¼ãã ã¨ããã¿ã¤ãã«ã§çºè¡¨ãã
ã¹ã©ã¤ã
æ¦è¦
Misoca å¬ã®LTå¤§ä¼ - connpass ã§ç§ã®ããã·ã¥ãã¼ãäºæ ã«ã¤ãã¦è©±ãã¦ããã
- Heroku 㨠Google Spreadsheets ã使ããã¨ã§éç¨ãããã¨ã§ãç¶æè²»ç¡æã§ããã·ã¥ãã¼ããä½ãæ¹æ³
- éåéãç¡ç ãèªæ¸éãçç£æ§ã¨ãå¯è¦åããæ¹æ³
ã¿ãããªè©±ã話ãã¦æ¥½ããã£ãã
Misoca ã®ã³ã¼ãã¬ãã¥ã¼ã§æãã¦ããã£ã RSpec ãããã£ã¾ã¨ã
ãã®è¨äºã¯ Misoca+å¼¥ç Advent Calendar 2019 ã®7æ¥ç®ã®è¨äºã§ãã
ã¯ããã«
Misoca ã«å
¥ç¤¾ãã¦1å¹´ã¨ã¡ãã£ã¨ãçµã¡ã¾ããã
Misoca 㯠Ruby ãã¡ã¤ã³ã®ä¼ç¤¾ã§ãã
ç§ã®ãã£ãªã¢ã¯ãã£ã¨ Java ã ã£ãã®ã§ãç¹ã« RSpec ã®ç¥èã貧弱ã§ãRSpec ã¯ãexpect
ã£ã¦æ¸ãã®ã¯ç¥ã£ã¦ãâ¦ããããã®ç¥èã§ããã
RSpec ã®ãããã£ã¯æ°ãå¤ãããã£ããã©ãããåå¼·ãããããã®ãâ¦ã¨ããã¾ã¾ãã¹ãã³ã¼ããæ¸ãããããã³ã¼ãã¬ãã¥ã¼ã§ããããæ¸ãæ¹ãæãã¦ãããã¤ã¤ãã£ã¦ãã¾ããã
ããã§ãåãææãããããªãããã«èªåç¨ã«ã¾ã¨ãã¤ã¤ãåããããªå¢éã®äººã«å°ãã§ãå½¹ã«ç«ã¤ããã«ãMisoca ã®ã³ã¼ãã¬ãã¥ã¼ã§æãã¦ããã£ã RSpec ã®æ¸ãæ¹ãç´¹ä»ãã¾ãã
注æäºé ã¨ãã¦ã以ä¸ã§æ¸ãæãåã¨å¾ã®ã³ã¼ããåºã¦ãã¾ãããã©ã¡ããè¯ãæªãã¨ããæå³ã¯ããã¾ããã å®éãææãããã£ã¦ãæ¸ãæãããã¨ãããã°ãã¡ãªãããããã°ãã®ã¾ã¾ã«ãããã¨ãããã¾ããã
be_xxx
target
ã xxx? ã¨ããã¡ã½ãããæã£ã¦ããå ´åã be_xxx ã¨ãããããã£ã使ãã¾ãã
ä¾ãã°
expect(target.persisted?).to be_truthy
ã¨ãã example ããã£ãã
expect(target).to be_persisted
ã¨æ¸ããã¨ãã§ãã¾ãã
and
and
ãããã£ãã¤ãªãããã¨ã§ expect(target)
ãä½åº¦ãæ¸ããªãã¦ãã¿ã¾ãã
ä¾ãã°
expect(target).to be_cool expect(target).to be_beautiful
ã¨ãã example ããã£ãã
expect(target).to be_cool .and be_beautiful
ã¨æ¸ããã¨ã§ãã¾ãã
have_attributes
have_attributes
ãããã£ã使ããã¨ã§è¤æ°ã®å±æ§ãæã¤ãã¨ãä¸æ°ã«ãã§ãã¯ã§ãã¾ãã
ä¾ãã°
expect(target.name).to eq('mallowlabs') expect(target.company).to eq('Misoca Inc.') expect(target.joined_at).to eq('2018-10-01')
ã¨ãã example ããã£ãã
expect(target).to have_attributes( name: 'mallowlabs', company: 'Misoca Inc.', joined_at: '2018-10-01' )
ã¨æ¸ããã¨ãã§ãã¾ãã
all
all
ãããã£ã使ããã¨ã§ã³ã¬ã¯ã·ã§ã³ã®è¦ç´ ãä¸æ°ã«ãã§ãã¯ã§ãã¾ãã
targets.each do |target| expect(target).to be_ok end
ã¨ãã example ããã£ãã
expect(targets).to all(be_ok)
ã¨æ¸ããã¨ã§ãã¾ãã
satisfy
satisfy
ãããã£ã使ããã¨ã§ãããã¯ããããã£ã«å¤æã㦠all
ãããã£ã«æ¸¡ããã¨ãã§ãã¾ãã
ä¾ãã°
targets.each do |target| expect(target).not_to be_cool end
ã¨ãã example ããã£ãã
expect(targets).to all(satisfy { |t| !t.cool? })
ã¨æ¸ããã¨ãã§ãã¾ãã
contain_exactly
contain_exactly
ãããã£ã使ããã¨ã§ã³ã¬ã¯ã·ã§ã³ã®ä¸ã«è¦ç´ ããã¹ã¦å«ã¾ãã¦ãããã確èªã§ãã¾ãã
ã³ã¬ã¯ã·ã§ã³ã®é·ãã確èªãã¤ã¤ãè¦ç´ ãæå³ãããã®ãå
¥ã£ã¦ãããã®ãã§ãã¯ããéã«
array = ['mallowlabs'] expect(array.size).to eq(1) expect(array.first).to eq('mallowlabs')
ã¨ãã example ãæ¸ãã¦ãã¾ãããããã¯
array = ['mallowlabs'] expect(array).to contain_exactly('mallowlabs')
ã®ããã«æ¸ãã¾ãã
ä»ã«ã
ããããªãããã£ãæãã¦ãããã¾ããããã·ã³ãã«ã«èª¬æã§ããªãã£ãã®ã§å²æãã¾ãã
ã¾ã¨ã
æ´ç·´ããã¦ããªãã³ã¼ããæ¸ãã¦ã dis ããããã¨ãªãã建è¨çãªææ¡ããã¦ããã Misoca ã®éçºã¡ã³ãã¼ã®ã¿ããªã«æè¬ã§ãã
ææ¥ã¯ id:ryotaway ããBrainF***å¦çç³»ãä½ã£ã¦ã¿ã¾ããã¨ããè¨äºãè²·ãã¦ãããããã§ãã楽ãã¿ã§ããã
RSpec ã® contain_exactly ããã㣠㨠match_array ãããã£
contain_exactly ãããã£
`contain_exactly` matcher - Built in matchers - RSpec Expectations - RSpec - Relish
以ä¸ã®ããã«ã³ã¬ã¯ã·ã§ã³ã«å¯¾ãã¦ãé åºã¯åããªãããã¹ã¦ãå«ã¾ãã¦ãããããã§ãã¯ãããã¨ãã§ããã
expect([1, 2, 3]).to contain_exactly(2, 3, 1) # pass expect([:a, :c, :b]).to contain_exactly(:a, :c) # fail
match_array ãããã£
ã»ã¼åããããªãããã£ã¨ã㦠match_array ã¨ããã®ãããã ããã¯å¼æ°ã«é åãåãã®ã§æ³¨æããã
expect([1, 2, 3]).to match_array [2, 3, 1] # pass expect([:a, :c, :b]).to match_array [:a, :c] # fail
ã½ã¼ã¹ã³ã¼ããèªã
ãããã®ãããã£ã®åä½ãç解ããããã«ãã¾ã㯠contain_exactly
ã®ã½ã¼ã¹ã³ã¼ããèªãã§ã¿ãã
def match(_expected, _actual) return false unless convert_actual_to_an_array match_when_sorted? || (extra_items.empty? && missing_items.empty?) end def match_when_sorted? values_match?(safe_sort(expected), safe_sort(actual)) end
å¼æ°ãé åã«å¤æãã¦ãã½ã¼ããããã¨ã§ãããããããããããããã§ãã¯ãã¦ããã
ä¸æ¹ match_array
ã¯ä»¥ä¸ã®ãããªæãã
def match_array(items) contain_exactly(*items) end
contain_exactly
å¼ãã§ãã
ã¨ãããã¨ã§ contain_exactly
㨠match_array
ã¯å¼æ°ã«é
åãåããã©ãã以å¤ã¯åãæåããããã¨ãããã£ãã
ã¾ã¨ã
RSpec ã¯å¥¥ãæ·±ãã