1+ var fs = require ( 'fs' ) ;
2+ var expect = require ( 'chai' ) . expect ;
3+ var proxyquire = require ( 'proxyquire' ) ;
4+ var quickTemp = require ( 'quick-temp' ) ;
5+ var functionCalls = [ ] ;
6+
7+ /**
8+ * Used to push any function calls and their
9+ * arguments to the funcitonCalls array. We
10+ * can use this function to replace any
11+ * function calls that we aren't trying to
12+ * test.
13+ * @param {String } functionName name of the function being called
14+ * @param {Object } [returnObject] object to return after recording the funciton call
15+ * @return {Function } function that when called will record functionName and it's arguments
16+ */
17+ var recordFunctionCalls = function ( functionName , returnObject ) {
18+ return function ( ) {
19+ var callRecorder = { functionName : functionName } ;
20+ for ( var i = 0 ; i < arguments . length ; i ++ ) {
21+ callRecorder [ i ] = arguments [ i ] ;
22+ }
23+ functionCalls . push ( callRecorder ) ;
24+ return returnObject ;
25+ } ;
26+ } ;
27+
28+ var directories , experimentData , ExperimentTwo , experiment ;
29+ var folder = 'new-experiment' ;
30+ var description = 'My new experiment' ;
31+ var edit_url = 'http://www.example.com' ;
32+
33+ var createExperimentWithDefaults = function ( ) {
34+ directories = { }
35+ quickTemp . makeOrRemake ( directories , 'experiment' ) ;
36+ experimentData = {
37+ description : description ,
38+ edit_url : edit_url
39+ } ;
40+ ExperimentTwo = require ( '../lib/experiment.js' ) ;
41+ ExperimentTwo . create ( experimentData , directories . experiment ) ;
42+ } ;
43+
44+
45+ describe ( 'Experiment' , function ( ) {
46+
47+ describe ( '#create()' , function ( ) {
48+ var Experiment ;
49+ before ( function ( done ) {
50+ var fileUtil = {
51+ writeDir : recordFunctionCalls ( 'writeDir' ) ,
52+ writeText : recordFunctionCalls ( 'writeText' ) ,
53+ writeJSON : recordFunctionCalls ( 'writeJSON' )
54+ } ;
55+ var optcliBase = require ( '../lib/optcli-base.js' ) ;
56+ optcliBase . prototype
57+ Experiment = proxyquire ( '../lib/experiment.js' , {
58+ './file-util' : fileUtil
59+ } ) ;
60+ functionCalls = [ ] ;
61+ experiment = Experiment . create ( {
62+ description : description ,
63+ edit_url : edit_url
64+ } , folder ) ;
65+ done ( ) ;
66+ } ) ;
67+ after ( function ( ) {
68+ console . log ( functionCalls . length ) ;
69+ } )
70+ it ( 'Should create an experiment directory' , function ( ) {
71+ expect ( functionCalls [ 0 ] ) . to . deep . equal ( { 'functionName' :'writeDir' , 0 : folder } ) ;
72+ } ) ;
73+ it ( 'Should create a global.css file' , function ( ) {
74+ expect ( functionCalls [ 1 ] ) . to . deep . equal ( { 'functionName' :'writeText' , 0 : folder + '/global.css' } ) ;
75+ } ) ;
76+ it ( 'Should create a global.js file' , function ( ) {
77+ expect ( functionCalls [ 2 ] ) . to . deep . equal ( { 'functionName' :'writeText' , 0 : folder + '/global.js' } ) ;
78+ } ) ;
79+ it ( 'Should create an experiment.json file' , function ( ) {
80+ expect ( functionCalls [ 3 ] ) . to . deep . equal ( {
81+ 'functionName' :'writeJSON' ,
82+ 0 : folder + '/experiment.json' ,
83+ 1 : {
84+ 'description' : description ,
85+ 'edit_url' : edit_url
86+ }
87+ } ) ;
88+ } ) ;
89+ it ( 'Should return an experiment object' , function ( ) {
90+ expect ( experiment ) . to . be . an . instanceOf ( Experiment ) ;
91+ } ) ;
92+ } ) ;
93+ describe ( '#locateAndLoad()' , function ( ) {
94+ before ( function ( done ) {
95+ createExperimentWithDefaults ( ) ;
96+ console . log ( functionCalls . length ) ;
97+ experiment = ExperimentTwo . locateAndLoad ( directories . experiment ) ;
98+ done ( ) ;
99+ } ) ;
100+ after ( function ( done ) {
101+ quickTemp . remove ( directories , 'experiment' ) ;
102+ done ( ) ;
103+ } )
104+ it ( 'Should locate the experiment.json' , function ( ) {
105+ //expect(experiment).to.be.an.instanceOf(Experiment);
106+ } ) ;
107+ it ( 'Should load the experiment.json' , function ( ) {
108+ //expect(experiment.attributes).to.deep.equal(experimentData);
109+ } ) ;
110+ } ) ;
111+ describe ( '#getCSS' , function ( ) { } )
112+ } ) ;
0 commit comments