New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix running JavaScript (-) to specification. #17

Open
wants to merge 4 commits into
base: master
from
Jump to file or symbol
Failed to load files and symbols.
+164 −0
Diff settings

Always

Just for now

Viewing a subset of changes. View all
Prev

Several rawjs example specs.

  • Loading branch information...
nickl- committed Sep 22, 2013
commit c9a4c134d8a5c59be3f9177b1fdf9dbbc9d8932a
View
@@ -43,6 +43,170 @@ def render haml, file = "file.jst.js.hamljs"
end
end
describe 'rawjs.if.simple' do
let(:choice) { true }
subject do
func = render <<eot, 'myTemplate.js.hamljs'
- if (choice)
%p it is so
eot
ExecJS.compile("var f = #{func};").eval "f({choice: #{choice}})"
end
it { should include '<p>it is so</p>' }
context "changing opinion" do
let(:choice) { false }
it { should_not include '<p>it is so</p>' }
end
end
describe 'rawjs.if.begin' do
let(:choice) { true }
subject do
func = render <<eot, 'myTemplate.js.hamljs'
- if (choice) {
%p it is so
eot
ExecJS.compile("var f = #{func};").eval "f({choice: #{choice}})"
end
it { should include '<p>it is so</p>' }
context "changing opinion" do
let(:choice) { false }
it { should_not include '<p>it is so</p>' }
end
end
describe 'rawjs.for.simple' do
let(:list) { [1,2,3] }
subject do
func = render <<eot, 'myTemplate.js.hamljs'
- for (i=0; i < list.length; i++)
%p= list[i]
eot
ExecJS.compile("var f = #{func};").eval "f({list: #{list}})"
end
it { should include '<p>1</p>' }
it { should include '<p>2</p>' }
it { should include '<p>3</p>' }
end
describe 'rawjs.for.begin' do
let(:list) { [1,2,3] }
subject do
func = render <<eot, 'myTemplate.js.hamljs'
- for (i=0; i < list.length; i++) {
%p= list[i]
eot
ExecJS.compile("var f = #{func};").eval "f({list: #{list}})"
end
it { should include '<p>1</p>' }
it { should include '<p>2</p>' }
it { should include '<p>3</p>' }
end
describe 'rawjs.for.in' do
let(:list) { [1,2,3] }
subject do
func = render <<eot, 'myTemplate.js.hamljs'
- for (i in list)
%p= list[i]
eot
ExecJS.compile("var f = #{func};").eval "f({list: #{list}})"
end
it { should include '<p>1</p>' }
it { should include '<p>2</p>' }
it { should include '<p>3</p>' }
end
describe 'rawjs.assign' do
let(:list) { [1,2,3] }
subject do
func = render <<eot, 'myTemplate.js.hamljs'
- for (i=0; i < list.length; i++) {
- pval = list[i];
%p= pval
eot
ExecJS.compile("var f = #{func};").eval "f({list: #{list}})"
end
it { should include '<p>1</p>' }
it { should include '<p>2</p>' }
it { should include '<p>3</p>' }
end
describe 'rawjs.for.complex' do
let(:list) { [1,2,3] }
subject do
func = render <<eot, 'myTemplate.js.hamljs'
- for (i = 0; i < list.length; i++)
%i= i
- if (list[i] == 1)
%p one
- if (list[i] == 2)
%p two
- if (list[i] == 3)
%p three
%p= list[i]
eot
ExecJS.compile("var f = #{func};").eval "f({list: #{list}})"
end
it { should include '<i>0</i>' }
it { should include '<i>1</i>' }
it { should include '<i>2</i>' }
it { should include '<p>1</p>' }
it { should include '<p>2</p>' }
it { should include '<p>3</p>' }
it { should include '<p>one</p>' }
it { should include '<p>two</p>' }
it { should include '<p>three</p>' }
end
describe 'rawjs.while' do
let(:list) { [1,2,3] }
subject do
func = render <<eot, 'myTemplate.js.hamljs'
- i = 0;
- while (i < list.length) {
%p= list[i]
- i++;
eot
ExecJS.compile("var f = #{func};").eval "f({list: #{list}})"
end
it { should include '<p>1</p>' }
it { should include '<p>2</p>' }
it { should include '<p>3</p>' }
end
describe 'rawjs.async' do
let(:list) { [1,2,3] }
subject do
func = render <<eot, 'myTemplate.js.hamljs'
- list.forEach(function (i) {
%p= i
eot
ExecJS.compile("var f = #{func};").eval "f({list: #{list}})"
end
it { should include '<p>1</p>' }
it { should include '<p>2</p>' }
it { should include '<p>3</p>' }
end
describe 'serving' do
subject { assets }
it { should serve 'sample.js' }
ProTip! Use n and p to navigate between commits in a pull request.