From f3d69fbc6ee97676801741b74ce4cfe974ad143e Mon Sep 17 00:00:00 2001 From: harttle Date: Sun, 6 Nov 2016 15:33:46 +0800 Subject: [PATCH] refactor fs-mock from before() to .it() --- test/tags/include.js | 120 +++++++++++++++++++++++-------------------- 1 file changed, 64 insertions(+), 56 deletions(-) diff --git a/test/tags/include.js b/test/tags/include.js index d76f9a009..58a5e48bc 100644 --- a/test/tags/include.js +++ b/test/tags/include.js @@ -6,15 +6,76 @@ const ParseError = Liquid.Types.ParseError; chai.use(require("chai-as-promised")); describe('tags/include', function() { - var liquid, ctx; + var liquid; before(function() { liquid = Liquid({ root: '/', extname: '.html' }); }); - beforeEach(function() { - ctx = { + afterEach(function() { + mock.restore(); + }); + it('should support include', function() { + mock({ + '/current.html': 'bar{% include "bar/foo.html" %}bar', + '/bar/foo.html': 'foo' + }); + return expect(liquid.renderFile('/current.html')).to. + eventually.equal('barfoobar'); + }); + + it('should throw when illegal', function() { + mock({ + '/illegal.html': '{%include%}', + }); + return expect(liquid.renderFile('/illegal.html')).to. + be.rejectedWith(ParseError, /illegal token {%include%}/); + }); + + it('should support include with relative path', function() { + mock({ + '/bar/foo.html': 'foo', + '/foo/relative.html': 'bar{% include "../bar/foo.html" %}bar', + }); + return expect(liquid.renderFile('foo/relative.html')).to. + eventually.equal('barfoobar'); + }); + + it('should support include: hash list', function() { + mock({ + '/hash.html': '{% assign name="harttle" %}{% include "user.html", role: "admin", alias: name %}', + '/user.html': '{{name}} : {{role}} : {{alias}}', + }); + return expect(liquid.renderFile('hash.html')).to. + eventually.equal('harttle : admin : harttle'); + }); + + it('should support include: parent scope', function() { + mock({ + '/scope.html': '{% assign shape="triangle" %}{% assign color="yellow" %}{% include "color.html" %}', + '/color.html': 'color:{{color}}, shape:{{shape}}', + }); + return expect(liquid.renderFile('scope.html')).to. + eventually.equal('color:yellow, shape:triangle'); + }); + + it('should support include: with', function() { + mock({ + '/with.html': '{% include "color" with "red", shape: "rect" %}', + '/color.html': 'color:{{color}}, shape:{{shape}}', + }); + return expect(liquid.renderFile('with.html')).to. + eventually.equal('color:red, shape:rect'); + }); + + it('should support nested includes', function() { + mock({ + '/personInfo.html': 'This is a person {% include "card.html" %}', + '/card.html': '

{{person.firstName}} {{person.lastName}}
{% include "address" %}

', + '/address.html': 'City: {{person.address.city}}' + }); + var ctx = { person: { firstName: 'Joe', lastName: 'Shmoe', @@ -23,59 +84,6 @@ describe('tags/include', function() { } } }; - mock({ - '/current.html': 'bar{% include "bar/foo.html" %}bar', - '/bar/foo.html': 'foo', - '/foo/relative.html': 'bar{% include "../bar/foo.html" %}bar', - '/hash.html': '{% assign name="harttle" %}{% include "user.html", role: "admin", alias: name %}', - '/illegal.html': '{%include%}', - - // colors - '/scope.html': '{% assign shape="triangle" %}{% assign color="yellow" %}{% include "color.html" %}', - '/with.html': '{% include "color" with "red", shape: "rect" %}', - '/color.html': 'color:{{color}}, shape:{{shape}}', - - // person info - '/personInfo.html': 'This is a person {% include "card.html" %}', - '/card.html': '

{{person.firstName}} {{person.lastName}}
{% include "address" %}

', - '/user.html': '{{name}} : {{role}} : {{alias}}', - '/address.html': 'City: {{person.address.city}}' - }); - }); - afterEach(function() { - mock.restore(); - }); - it('should support include', function() { - return expect(liquid.renderFile('/current.html', ctx)).to. - eventually.equal('barfoobar'); - }); - - it('should throw when illegal', function() { - return expect(liquid.renderFile('/illegal.html')).to. - be.rejectedWith(ParseError, /illegal token {%include%}/); - }); - - it('should support include with relative path', function() { - return expect(liquid.renderFile('foo/relative.html', ctx)).to. - eventually.equal('barfoobar'); - }); - - it('should support include: hash list', function() { - return expect(liquid.renderFile('hash.html', ctx)).to. - eventually.equal('harttle : admin : harttle'); - }); - - it('should support include: parent scope', function() { - return expect(liquid.renderFile('scope.html', ctx)).to. - eventually.equal('color:yellow, shape:triangle'); - }); - - it('should support include: with', function() { - return expect(liquid.renderFile('with.html', ctx)).to. - eventually.equal('color:red, shape:rect'); - }); - - it('should support nested includes', function() { return expect(liquid.renderFile('personInfo.html', ctx)).to. eventually.equal('This is a person

Joe Shmoe
City: Dallas

'); });