jasmine-headless-webkit/spec/lib/jasmine/headless/test_file_spec.rb

131 lines
2.9 KiB
Ruby
Raw Normal View History

2011-11-16 20:28:02 +00:00
require 'spec_helper'
describe Jasmine::Headless::TestFile do
2011-11-18 03:16:04 +00:00
let(:source_root) { File.expand_path('source_root') }
let(:path) { File.join(source_root, 'path.js') }
let(:file) { described_class.new(path, source_root) }
2011-11-16 20:28:02 +00:00
subject { file }
its(:path) { should == path }
describe '#to_html' do
subject { file.to_html }
context '.js' do
let(:path) { 'path.js' }
it { should == %{<script type="text/javascript" src="#{path}"></script>} }
end
context '.css' do
let(:path) { 'path.css' }
2011-11-17 21:18:25 +00:00
it { should == %{<link rel="stylesheet" href="#{path}" type="text/css" />} }
2011-11-16 20:28:02 +00:00
end
context 'with tilt template' do
include FakeFS::SpecHelpers
2011-11-16 20:28:02 +00:00
let(:content) { 'content' }
2011-11-16 20:28:02 +00:00
before do
File.open(path, 'wb') { |fh| fh.print content }
2011-11-16 20:28:02 +00:00
end
let(:klass) do
Class.new(Tilt::Template) do
def prepare ; end
2011-11-16 20:28:02 +00:00
def evaluate(scope, locals, &block)
"#{file} made it #{data}"
2011-11-17 21:18:25 +00:00
end
2011-11-16 20:28:02 +00:00
end
end
2011-11-18 21:00:24 +00:00
2011-11-20 00:15:38 +00:00
let(:other_klass) do
Class.new(Tilt::Template) do
def prepare ; end
def evaluate(scope, locals, &block)
data
end
end
end
2011-11-18 21:00:24 +00:00
before do
Sprockets.stubs(:engines).with('.tilt').returns(klass)
2011-11-20 00:15:38 +00:00
Sprockets.stubs(:engines).with('.jst').returns(other_klass)
2011-11-18 21:00:24 +00:00
end
context '.tilt' do
let(:path) { 'path.tilt' }
2011-11-18 21:00:24 +00:00
2011-11-20 00:15:38 +00:00
it { should == %{#{path} made it #{content}} }
end
2011-11-18 21:00:24 +00:00
context '.tilt.tilt' do
let(:path) { 'path.tilt.tilt' }
2011-11-18 21:00:24 +00:00
2011-11-20 00:15:38 +00:00
it { should == %{path.tilt made it #{path} made it #{content}} }
2011-11-18 21:00:24 +00:00
end
2011-11-20 00:15:38 +00:00
context '.jst.tilt' do
let(:path) { 'path.jst.tilt' }
2011-11-20 00:15:38 +00:00
it { should == %{<script type="text/javascript">#{path} made it #{content}</script>} }
2011-11-18 21:00:24 +00:00
end
end
2011-11-16 20:28:02 +00:00
end
2011-11-18 03:16:04 +00:00
describe '#dependencies' do
include FakeFS::SpecHelpers
2011-11-20 16:56:25 +00:00
let(:directive) { 'require' }
2011-11-18 03:16:04 +00:00
before do
FileUtils.mkdir_p File.dirname(path)
2011-11-20 16:56:25 +00:00
File.open(path, 'wb') { |fh| fh.print "//= #{directive} '#{req}'\njavascript" }
2011-11-18 03:16:04 +00:00
end
context 'absolute' do
let(:req) { 'test' }
subject { file.dependencies }
2011-11-20 16:56:25 +00:00
context 'require' do
it { should == [ [ 'require', req ] ] }
end
context 'require_tree' do
let(:directive) { 'require_tree' }
it 'should raise an error' do
expect { subject }.to raise_error(Sprockets::ArgumentError, /relative/)
end
end
2011-11-18 03:16:04 +00:00
end
context 'relative' do
let(:path) { File.join(source_root, 'subdir/subsubdir/path.js') }
let(:req) { './test' }
subject { file.dependencies }
it { should == [ [ 'require', 'subdir/subsubdir/test' ] ] }
end
context 'dot' do
let(:path) { File.join(source_root, 'subdir/subsubdir/path.js') }
let(:req) { '.' }
subject { file.dependencies }
it { should == [ [ 'require', 'subdir/subsubdir' ] ] }
end
2011-11-18 03:16:04 +00:00
end
2011-11-16 20:28:02 +00:00
end