require File.expand_path(File.dirname(__FILE__) + '/spec_helper') require 'em-http' def compiler_test file, ext, src, &test File.open(file, "w+"){|f| f.write(src)} cf = Slinky::Compilers.cfile_for_file(file) called_back = false $stdout.should_receive(:puts).with("Compiled #{file}".foreground(:green)) cf.compile{|cpath, _, _, error| error.should == nil cpath.nil?.should == false cpath.end_with?(ext).should == true test.call(File.open(cpath).read).should == true called_back = true } called_back.should == true end describe "Compilers" do before :each do FileUtils.rm_rf("/compilers") rescue nil FileUtils.mkdir("/compilers") end context "SassCompiler" do it "should be able to compile SASS files" do src = < console.log(x)} test.do("Hello, world") eos compiler_test("/compilers/test.coffee", ".js", src){|s| s.include?("function(x) {") } end end context "HamlCompiler" do it "should be able to compile .haml files" do src = <Hello!") } end end context "JSXCompiler" do it "should be able to compile .jsx files" do src = <<-EOF /** @jsx React.DOM */ React.renderComponent(

Hello, world!

, document.getElementById('example') ); EOF compiler_test("/compilers/test.jsx", ".js", src){|s| s.include?("Hello, world!") } end end end