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

108 lines
2.3 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
before do
Sprockets.stubs(:engines).with('.tilt').returns(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
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
it { should == "path.tilt made it #{path} made it #{content}" }
2011-11-18 21:00:24 +00:00
end
context '.js.tilt' do
let(:path) { 'path.js.tilt' }
it { should == "#{path} made it #{content}" }
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
before do
FileUtils.mkdir_p File.dirname(path)
File.open(path, 'wb') { |fh| fh.print "//= require '#{req}'\njavascript" }
end
context 'absolute' do
let(:req) { 'test' }
subject { file.dependencies }
it { should == [ [ 'require', req ] ] }
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