Merge branch 'master' into qt-cleanup
This commit is contained in:
commit
f1318a5223
1
Gemfile
1
Gemfile
@ -14,3 +14,4 @@ gem 'rake', '0.8.7'
|
||||
gem 'mocha', '0.9.12'
|
||||
gem 'guard-jasmine-headless-webkit'
|
||||
gem 'facter'
|
||||
|
||||
|
1
Rakefile
1
Rakefile
@ -9,6 +9,7 @@ RSpec::Core::RakeTask.new(:spec)
|
||||
|
||||
$: << File.expand_path('../lib', __FILE__)
|
||||
|
||||
require 'jasmine-headless-webkit'
|
||||
require 'jasmine/headless/task'
|
||||
|
||||
Jasmine::Headless::Task.new
|
||||
|
@ -8,6 +8,8 @@ def gem_dir
|
||||
end
|
||||
|
||||
$:.unshift(File.join(gem_dir, 'lib'))
|
||||
require 'jasmine-headless-webkit'
|
||||
|
||||
require 'jasmine/headless/errors'
|
||||
require 'jasmine/headless/runner'
|
||||
require 'jasmine/headless/options'
|
||||
|
5
ext/jasmine-webkit-specrunner/Makefile.dummy
Normal file
5
ext/jasmine-webkit-specrunner/Makefile.dummy
Normal file
@ -0,0 +1,5 @@
|
||||
build:
|
||||
true
|
||||
install:
|
||||
true
|
||||
|
@ -7,3 +7,4 @@ require 'qt/qmake'
|
||||
system %{make clean}
|
||||
Qt::Qmake.make!('jasmine-headless-webkit', 'specrunner.pro')
|
||||
|
||||
FileUtils.cp File.expand_path('../Makefile.dummy', __FILE__), File.expand_path('../Makefile', __FILE__)
|
||||
|
@ -1,10 +1,10 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
$:.push File.expand_path("../lib", __FILE__)
|
||||
require "jasmine-headless-webkit/version"
|
||||
require "jasmine/headless/version"
|
||||
|
||||
Gem::Specification.new do |s|
|
||||
s.name = "jasmine-headless-webkit"
|
||||
s.version = Jasmine::Headless::Webkit::VERSION
|
||||
s.version = Jasmine::Headless::VERSION
|
||||
s.platform = Gem::Platform::RUBY
|
||||
s.authors = ["John Bintz", "Sencha Inc.", "Pivotal Labs"]
|
||||
s.email = ["john@coswellproductions.com"]
|
||||
|
@ -1,9 +1,19 @@
|
||||
module Jasmine
|
||||
autoload :FilesList, 'jasmine/files_list'
|
||||
autoload :TemplateWriter, 'jasmine/template_writer'
|
||||
|
||||
module Headless
|
||||
module Webkit
|
||||
end
|
||||
autoload :CoffeeScriptCache, 'jasmine/headless/coffee_script_cache'
|
||||
autoload :SpecFileAnalyzer, 'jasmine/headless/spec_file_analyzer'
|
||||
autoload :CacheableAction, 'jasmine/headless/cacheable_action'
|
||||
autoload :VERSION, 'jasmine/headless/version'
|
||||
autoload :Runner, 'jasmine/headless/runner'
|
||||
autoload :Options, 'jasmine/headless/options'
|
||||
autoload :Task, 'jasmine/headless/task'
|
||||
end
|
||||
end
|
||||
|
||||
require 'jasmine/headless/errors'
|
||||
|
||||
require 'jasmine/headless/railtie' if defined?(Rails) && Rails::VERSION::MAJOR >= 3
|
||||
|
||||
|
@ -1,7 +0,0 @@
|
||||
module Jasmine
|
||||
module Headless
|
||||
module Webkit
|
||||
VERSION = "0.6.4"
|
||||
end
|
||||
end
|
||||
end
|
@ -1,5 +1,6 @@
|
||||
require 'jasmine-core'
|
||||
require 'iconv'
|
||||
require 'time'
|
||||
|
||||
module Jasmine
|
||||
class FilesList
|
||||
@ -11,21 +12,7 @@ module Jasmine
|
||||
File.expand_path('../../../jasmine/jasmine.headless-reporter.js', __FILE__)
|
||||
]
|
||||
|
||||
class << self
|
||||
def get_spec_line_numbers(file)
|
||||
line_numbers = {}
|
||||
|
||||
ic = Iconv.new('UTF-8//IGNORE', 'UTF-8')
|
||||
file.lines.each_with_index.each { |line, index|
|
||||
line = ic.iconv(line + ' ')[0..-2]
|
||||
if description = line[%r{(describe|context|it)[( ]*(["'])(.*)\2}, 3]
|
||||
(line_numbers[description] ||= []) << (index + 1)
|
||||
end
|
||||
}
|
||||
|
||||
line_numbers
|
||||
end
|
||||
end
|
||||
PLEASE_WAIT_IM_WORKING_TIME = 2
|
||||
|
||||
def initialize(options = {})
|
||||
@options = options
|
||||
@ -55,7 +42,7 @@ module Jasmine
|
||||
def spec_file_line_numbers
|
||||
@spec_file_line_numbers ||= Hash[@spec_files.collect { |file|
|
||||
if File.exist?(file)
|
||||
if !(lines = self.class.get_spec_line_numbers(File.read(file))).empty?
|
||||
if !(lines = Jasmine::Headless::SpecFileAnalyzer.for(file)).empty?
|
||||
[ file, lines ]
|
||||
end
|
||||
else
|
||||
@ -66,51 +53,31 @@ module Jasmine
|
||||
|
||||
private
|
||||
def to_html(files)
|
||||
coffeescript_run = []
|
||||
alert_time = Time.now + PLEASE_WAIT_IM_WORKING_TIME
|
||||
|
||||
files.collect { |file|
|
||||
coffeescript_run << file if (ext = File.extname(file)) == '.coffee'
|
||||
|
||||
output = []
|
||||
if (files.last == file or ext != '.coffee') and !coffeescript_run.empty?
|
||||
output << ensure_coffeescript_run!(coffeescript_run)
|
||||
if alert_time && alert_time < Time.now
|
||||
puts "Rebuilding cache, please wait..."
|
||||
alert_time = nil
|
||||
end
|
||||
|
||||
if ext != '.coffee'
|
||||
output << case File.extname(file)
|
||||
when '.js'
|
||||
%{<script type="text/javascript" src="#{file}"></script>}
|
||||
when '.css'
|
||||
%{<link rel="stylesheet" href="#{file}" type="text/css" />}
|
||||
case File.extname(file)
|
||||
when '.coffee'
|
||||
begin
|
||||
%{<script type="text/javascript">#{Jasmine::Headless::CoffeeScriptCache.for(file)}</script>}
|
||||
rescue CoffeeScript::CompilationError => ne
|
||||
puts "[%s] %s: %s" % [ 'coffeescript'.color(:red), file.color(:yellow), ne.message.to_s.color(:white) ]
|
||||
raise ne
|
||||
rescue StandardError => e
|
||||
puts "[%s] Error in compiling one of the followng: %s" % [ 'coffeescript'.color(:red), files.join(' ').color(:yellow) ]
|
||||
raise e
|
||||
end
|
||||
when '.js'
|
||||
%{<script type="text/javascript" src="#{file}"></script>}
|
||||
when '.css'
|
||||
%{<link rel="stylesheet" href="#{file}" type="text/css" />}
|
||||
end
|
||||
|
||||
output
|
||||
}.flatten.reject(&:empty?)
|
||||
end
|
||||
|
||||
def ensure_coffeescript_run!(files)
|
||||
data = StringIO.new
|
||||
files.each { |file| data << File.read(file) << "\n" }
|
||||
data.rewind
|
||||
|
||||
%{<script type="text/javascript">#{CoffeeScript.compile(data)}</script>}
|
||||
rescue CoffeeScript::CompilationError => e
|
||||
files.each do |file|
|
||||
begin
|
||||
CoffeeScript.compile(fh = File.open(file))
|
||||
rescue CoffeeScript::CompilationError => ne
|
||||
puts "[%s] %s: %s" % [ 'coffeescript'.color(:red), file.color(:yellow), ne.message.to_s.color(:white) ]
|
||||
raise ne
|
||||
ensure
|
||||
fh.close
|
||||
end
|
||||
end
|
||||
rescue StandardError => e
|
||||
puts "[%s] Error in compiling one of the followng: %s" % [ 'coffeescript'.color(:red), files.join(' ').color(:yellow) ]
|
||||
raise e
|
||||
ensure
|
||||
files.clear
|
||||
}.flatten.compact.reject(&:empty?)
|
||||
end
|
||||
|
||||
def spec_filter
|
||||
@ -131,7 +98,7 @@ module Jasmine
|
||||
@files += found_files
|
||||
|
||||
if searches == 'spec_files'
|
||||
@spec_files = @files + spec_filter
|
||||
@spec_files += spec_filter
|
||||
end
|
||||
|
||||
@filtered_files += (if searches == 'spec_files'
|
||||
|
77
lib/jasmine/headless/cacheable_action.rb
Normal file
77
lib/jasmine/headless/cacheable_action.rb
Normal file
@ -0,0 +1,77 @@
|
||||
module Jasmine::Headless
|
||||
class CacheableAction
|
||||
class << self
|
||||
def enabled=(bool)
|
||||
@enabled = bool
|
||||
end
|
||||
|
||||
def enabled?
|
||||
@enabled = true if @enabled == nil
|
||||
@enabled
|
||||
end
|
||||
|
||||
def cache_type
|
||||
raise ArgumentError.new("No cache type defined for #{self.name}") if @cache_type == nil
|
||||
@cache_type
|
||||
end
|
||||
|
||||
def cache_type=(type)
|
||||
@cache_type = type
|
||||
end
|
||||
|
||||
def cache_dir=(dir)
|
||||
@cache_dir = dir
|
||||
end
|
||||
|
||||
def cache_dir
|
||||
@cache_dir ||= '.jhw-cache'
|
||||
end
|
||||
|
||||
def for(file)
|
||||
new(file).handle
|
||||
end
|
||||
end
|
||||
|
||||
attr_reader :file
|
||||
|
||||
def initialize(file)
|
||||
@file = file
|
||||
end
|
||||
|
||||
def handle
|
||||
if CacheableAction.enabled?
|
||||
if fresh?
|
||||
unserialize(File.read(cache_file))
|
||||
else
|
||||
result = action
|
||||
FileUtils.mkdir_p File.split(cache_file).first
|
||||
File.open(cache_file, 'wb') { |fh| fh.print serialize(result) }
|
||||
result
|
||||
end
|
||||
else
|
||||
action
|
||||
end
|
||||
end
|
||||
|
||||
def cache_file
|
||||
@cache_file ||= File.join(self.class.cache_dir, self.class.cache_type, Digest::SHA1.hexdigest(file))
|
||||
end
|
||||
|
||||
def fresh?
|
||||
File.exist?(cache_file) && (File.mtime(file) < File.mtime(cache_file))
|
||||
end
|
||||
|
||||
def action
|
||||
raise StandardError.new("Override action")
|
||||
end
|
||||
|
||||
def serialize(data)
|
||||
data
|
||||
end
|
||||
|
||||
def unserialize(data)
|
||||
data
|
||||
end
|
||||
end
|
||||
end
|
||||
|
20
lib/jasmine/headless/coffee_script_cache.rb
Normal file
20
lib/jasmine/headless/coffee_script_cache.rb
Normal file
@ -0,0 +1,20 @@
|
||||
require 'coffee_script'
|
||||
require 'digest/sha1'
|
||||
require 'fileutils'
|
||||
|
||||
module Jasmine
|
||||
module Headless
|
||||
class CoffeeScriptCache < CacheableAction
|
||||
class << self
|
||||
def cache_type
|
||||
"coffee_script"
|
||||
end
|
||||
end
|
||||
|
||||
def action
|
||||
CoffeeScript.compile(File.read(file))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -15,6 +15,7 @@ module Jasmine
|
||||
:report => false,
|
||||
:do_list => false,
|
||||
:full_run => true,
|
||||
:enable_cache => true,
|
||||
:files => []
|
||||
}
|
||||
|
||||
@ -42,6 +43,10 @@ module Jasmine
|
||||
@options[:colors] = true
|
||||
when '--no-colors', '-nc'
|
||||
@options[:colors] = false
|
||||
when '--cache'
|
||||
@options[:enable_cache] = true
|
||||
when '--no-cache'
|
||||
@options[:enable_cache] = false
|
||||
when '--keep'
|
||||
@options[:remove_html_file] = false
|
||||
when '--report'
|
||||
@ -67,6 +72,8 @@ module Jasmine
|
||||
command_line_args = GetoptLong.new(
|
||||
[ '--colors', '-c', GetoptLong::NO_ARGUMENT ],
|
||||
[ '--no-colors', GetoptLong::NO_ARGUMENT ],
|
||||
[ '--cache', GetoptLong::NO_ARGUMENT ],
|
||||
[ '--no-t stcache', GetoptLong::NO_ARGUMENT ],
|
||||
[ '--keep', GetoptLong::NO_ARGUMENT ],
|
||||
[ '--report', GetoptLong::REQUIRED_ARGUMENT ],
|
||||
[ '--jasmine-config', '-j', GetoptLong::REQUIRED_ARGUMENT ],
|
||||
|
@ -1,5 +1,3 @@
|
||||
require 'jasmine/headless/task'
|
||||
|
||||
module Jasmine
|
||||
module Headless
|
||||
class Railtie < Rails::Railtie
|
||||
|
@ -1,14 +1,8 @@
|
||||
require 'jasmine/headless/errors'
|
||||
require 'jasmine/headless/options'
|
||||
|
||||
require 'fileutils'
|
||||
|
||||
require 'coffee-script'
|
||||
require 'rainbow'
|
||||
|
||||
require 'jasmine/files_list'
|
||||
require 'jasmine/template_writer'
|
||||
|
||||
require 'yaml'
|
||||
|
||||
module Jasmine
|
||||
@ -61,6 +55,8 @@ module Jasmine
|
||||
end
|
||||
|
||||
def run
|
||||
Jasmine::Headless::CacheableAction.enabled = @options[:enable_cache]
|
||||
|
||||
files_list = Jasmine::FilesList.new(
|
||||
:config => jasmine_config,
|
||||
:only => @options[:files]
|
||||
|
37
lib/jasmine/headless/spec_file_analyzer.rb
Normal file
37
lib/jasmine/headless/spec_file_analyzer.rb
Normal file
@ -0,0 +1,37 @@
|
||||
require 'iconv'
|
||||
require 'multi_json'
|
||||
|
||||
module Jasmine::Headless
|
||||
class SpecFileAnalyzer < CacheableAction
|
||||
class << self
|
||||
def cache_type
|
||||
"spec_file_analysis"
|
||||
end
|
||||
end
|
||||
|
||||
def action
|
||||
line_numbers = {}
|
||||
|
||||
ic = Iconv.new('UTF-8//IGNORE', 'US-ASCII')
|
||||
data = ic.iconv(File.read(file) + ' ')[0..-2]
|
||||
data.force_encoding('US-ASCII') if data.respond_to?(:force_encoding)
|
||||
|
||||
data.lines.each_with_index.each { |line, index|
|
||||
if description = line[%r{(describe|context|it)[( ]*(["'])(.*)\2}, 3]
|
||||
(line_numbers[description] ||= []) << (index + 1)
|
||||
end
|
||||
}
|
||||
|
||||
line_numbers
|
||||
end
|
||||
|
||||
def serialize(data)
|
||||
MultiJson.encode(data)
|
||||
end
|
||||
|
||||
def unserialize(data)
|
||||
MultiJson.decode(data)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,5 +1,3 @@
|
||||
require 'jasmine/headless/runner'
|
||||
|
||||
module Digest
|
||||
class JasmineTest
|
||||
def self.file(file)
|
||||
|
5
lib/jasmine/headless/version.rb
Normal file
5
lib/jasmine/headless/version.rb
Normal file
@ -0,0 +1,5 @@
|
||||
module Jasmine
|
||||
module Headless
|
||||
VERSION = "0.6.4"
|
||||
end
|
||||
end
|
@ -120,7 +120,6 @@ describe "jasmine-headless-webkit" do
|
||||
describe 'files' do
|
||||
it 'should list all the files that will be found' do
|
||||
files = %x{bin/jasmine-headless-webkit -l -j spec/jasmine/success/success.yml}
|
||||
p files
|
||||
$?.exitstatus.should == 0
|
||||
|
||||
files.lines.to_a.should include("./spec/jasmine/success/success.js\n")
|
||||
|
@ -147,127 +147,38 @@ describe Jasmine::FilesList do
|
||||
describe '#.*files_to_html' do
|
||||
include FakeFS::SpecHelpers
|
||||
|
||||
context 'one coffeescript file' do
|
||||
before do
|
||||
files_list.instance_variable_set(:@files, [
|
||||
'test.js',
|
||||
'test.coffee',
|
||||
'test.css'
|
||||
])
|
||||
before do
|
||||
files_list.instance_variable_set(:@files, [
|
||||
'test.js',
|
||||
'test.coffee',
|
||||
'test.whatever',
|
||||
'test.css'
|
||||
])
|
||||
|
||||
files_list.instance_variable_set(:@filtered_files, [
|
||||
'test.js',
|
||||
'test.coffee'
|
||||
])
|
||||
files_list.instance_variable_set(:@filtered_files, [
|
||||
'test.js',
|
||||
'test.coffee'
|
||||
])
|
||||
|
||||
File.open('test.coffee', 'w') { |fh| fh.print "first" }
|
||||
Jasmine::Headless::CoffeeScriptCache.stubs(:for).with('test.coffee').returns("i compiled")
|
||||
end
|
||||
|
||||
CoffeeScript.stubs(:compile).with() { |field| field.read == "first\n" }.returns("i compiled")
|
||||
end
|
||||
|
||||
context '#files_to_html' do
|
||||
it "should create the right HTML" do
|
||||
files_list.files_to_html.should == [
|
||||
%{<script type="text/javascript" src="test.js"></script>},
|
||||
%{<script type="text/javascript">i compiled</script>},
|
||||
%{<link rel="stylesheet" href="test.css" type="text/css" />}
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
context '#filtered_files_to_html' do
|
||||
it "should create the right HTML" do
|
||||
files_list.filtered_files_to_html.should == [
|
||||
%{<script type="text/javascript" src="test.js"></script>},
|
||||
%{<script type="text/javascript">i compiled</script>}
|
||||
]
|
||||
end
|
||||
context '#files_to_html' do
|
||||
it "should create the right HTML" do
|
||||
files_list.files_to_html.should == [
|
||||
%{<script type="text/javascript" src="test.js"></script>},
|
||||
%{<script type="text/javascript">i compiled</script>},
|
||||
%{<link rel="stylesheet" href="test.css" type="text/css" />}
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
context 'two coffeescript files' do
|
||||
before do
|
||||
files_list.instance_variable_set(:@files, [
|
||||
'test.js',
|
||||
'test.coffee',
|
||||
'test2.coffee',
|
||||
'test.css'
|
||||
])
|
||||
|
||||
files_list.instance_variable_set(:@filtered_files, [
|
||||
'test.js',
|
||||
'test.coffee'
|
||||
])
|
||||
|
||||
File.open('test.coffee', 'w') { |fh| fh.print "first" }
|
||||
File.open('test2.coffee', 'w') { |fh| fh.print "second" }
|
||||
end
|
||||
|
||||
context '#files_to_html' do
|
||||
it "should create the right HTML" do
|
||||
CoffeeScript.stubs(:compile).with() { |field| field.read == "first\nsecond\n" }.returns("i compiled")
|
||||
|
||||
files_list.files_to_html.should == [
|
||||
%{<script type="text/javascript" src="test.js"></script>},
|
||||
%{<script type="text/javascript">i compiled</script>},
|
||||
%{<link rel="stylesheet" href="test.css" type="text/css" />}
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
context '#filtered_files_to_html' do
|
||||
it "should create the right HTML" do
|
||||
CoffeeScript.stubs(:compile).with() { |field| field.read == "first\n" }.returns("i compiled")
|
||||
|
||||
files_list.filtered_files_to_html.should == [
|
||||
%{<script type="text/javascript" src="test.js"></script>},
|
||||
%{<script type="text/javascript">i compiled</script>}
|
||||
]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '.get_spec_line_numbers' do
|
||||
let(:line_numbers) do
|
||||
described_class.get_spec_line_numbers(file)
|
||||
end
|
||||
|
||||
context 'coffeescript' do
|
||||
let(:file) do
|
||||
<<-SPEC
|
||||
describe 'test', ->
|
||||
context 'yes', ->
|
||||
it 'should do something', ->
|
||||
"yes"
|
||||
"PR.registerLangHandler(PR.createSimpleLexer([[\"com\",/^#[^\\n\\r]*/,null,\"#\"],[\"pln\",/^[\\t\\n\\r \\xa0]+/,null,\"\\t\\n\\r \xC2\\xa0\"],[\"str\",/^\"(?:[^\"\\\\]|\\\\[\\S\\s])*(?:\"|$)/,null,'\"']],[[\"kwd\",/^(?:ADS|AD|AUG|BZF|BZMF|CAE|CAF|CA|CCS|COM|CS|DAS|DCA|DCOM|DCS|DDOUBL|DIM|DOUBLE|DTCB|DTCF|DV|DXCH|EDRUPT|EXTEND|INCR|INDEX|NDX|INHINT|LXCH|MASK|MSK|MP|MSU|NOOP|OVSK|QXCH|RAND|READ|RELINT|RESUME|RETURN|ROR|RXOR|SQUARE|SU|TCR|TCAA|OVSK|TCF|TC|TS|WAND|WOR|WRITE|XCH|XLQ|XXALQ|ZL|ZQ|ADD|ADZ|SUB|SUZ|MPY|MPR|MPZ|DVP|COM|ABS|CLA|CLZ|LDQ|STO|STQ|ALS|LLS|LRS|TRA|TSQ|TMI|TOV|AXT|TIX|DLY|INP|OUT)\\s/,\n"
|
||||
SPEC
|
||||
end
|
||||
|
||||
it 'should get the line numbers' do
|
||||
line_numbers['test'].should == [ 1 ]
|
||||
line_numbers['yes'].should == [ 2 ]
|
||||
line_numbers['should do something'].should == [ 3 ]
|
||||
end
|
||||
end
|
||||
|
||||
context 'javascript' do
|
||||
let(:file) do
|
||||
<<-SPEC
|
||||
describe('test', function() {
|
||||
context('yes', function() {
|
||||
it('should do something', function() {
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
SPEC
|
||||
end
|
||||
|
||||
it 'should get the line numbers' do
|
||||
line_numbers['test'].should == [ 1 ]
|
||||
line_numbers['yes'].should == [ 2 ]
|
||||
line_numbers['should do something'].should == [ 3 ]
|
||||
context '#filtered_files_to_html' do
|
||||
it "should create the right HTML" do
|
||||
files_list.filtered_files_to_html.should == [
|
||||
%{<script type="text/javascript" src="test.js"></script>},
|
||||
%{<script type="text/javascript">i compiled</script>}
|
||||
]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
88
spec/lib/jasmine/headless/cacheable_action_spec.rb
Normal file
88
spec/lib/jasmine/headless/cacheable_action_spec.rb
Normal file
@ -0,0 +1,88 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Jasmine::Headless::CacheableAction do
|
||||
include FakeFS::SpecHelpers
|
||||
|
||||
let(:file) { 'file.whatever' }
|
||||
let(:data) { 'data' }
|
||||
let(:compiled) { 'compiled' }
|
||||
|
||||
before do
|
||||
File.open(file, 'wb') { |fh| fh.print(data) }
|
||||
described_class.cache_dir = cache_dir
|
||||
described_class.cache_type = cache_type
|
||||
end
|
||||
|
||||
let(:action_runs!) do
|
||||
described_class.any_instance.expects(:action).returns(compiled)
|
||||
end
|
||||
|
||||
let(:cache_type) { 'action' }
|
||||
let(:cache_dir) { 'cache' }
|
||||
let(:cache_file) { File.join(cache_dir, cache_type, Digest::SHA1.hexdigest(file)) }
|
||||
let(:cache_file_data) { YAML.load(File.read(cache_file)) }
|
||||
|
||||
describe '.for' do
|
||||
context 'cache disabled' do
|
||||
before do
|
||||
described_class.enabled = false
|
||||
end
|
||||
|
||||
it 'should compile' do
|
||||
action_runs!
|
||||
described_class.for(file).should == compiled
|
||||
cache_file.should_not be_a_file
|
||||
end
|
||||
end
|
||||
|
||||
context 'cache enabled' do
|
||||
before do
|
||||
described_class.enabled = true
|
||||
FileUtils.mkdir_p(cache_dir)
|
||||
|
||||
File.stubs(:mtime).with(file).returns(Time.at(10))
|
||||
File.stubs(:mtime).with(cache_file).returns(Time.at(cache_file_mtime))
|
||||
end
|
||||
|
||||
context 'cache empty' do
|
||||
let(:cache_file_mtime) { 0 }
|
||||
|
||||
it 'should compile' do
|
||||
action_runs!
|
||||
described_class.for(file).should == compiled
|
||||
|
||||
cache_file_data.should == compiled
|
||||
end
|
||||
end
|
||||
|
||||
context 'cache fresh' do
|
||||
let(:cache_file_mtime) { 15 }
|
||||
|
||||
before do
|
||||
File.open(cache_file, 'wb') { |fh| fh.print compiled }
|
||||
end
|
||||
|
||||
it 'should not compile' do
|
||||
action_runs!.never
|
||||
|
||||
described_class.for(file).should == compiled
|
||||
|
||||
cache_file_data.should == compiled
|
||||
end
|
||||
end
|
||||
|
||||
context 'cache stale' do
|
||||
let(:cache_file_mtime) { 5 }
|
||||
|
||||
it 'should compile' do
|
||||
action_runs!
|
||||
|
||||
described_class.for(file).should == compiled
|
||||
|
||||
cache_file_data.should == compiled
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
21
spec/lib/jasmine/headless/coffee_script_cache_spec.rb
Normal file
21
spec/lib/jasmine/headless/coffee_script_cache_spec.rb
Normal file
@ -0,0 +1,21 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Jasmine::Headless::CoffeeScriptCache do
|
||||
include FakeFS::SpecHelpers
|
||||
|
||||
describe '#action' do
|
||||
let(:file) { 'file' }
|
||||
let(:data) { 'data' }
|
||||
let(:compiled) { 'compiled' }
|
||||
|
||||
before do
|
||||
CoffeeScript.expects(:compile).with(data).returns(compiled)
|
||||
File.open(file, 'wb') { |fh| fh.print(data) }
|
||||
end
|
||||
|
||||
it 'should compile coffeescript' do
|
||||
described_class.new(file).action.should == compiled
|
||||
end
|
||||
end
|
||||
end
|
||||
|
57
spec/lib/jasmine/headless/spec_file_analyzer_spec.rb
Normal file
57
spec/lib/jasmine/headless/spec_file_analyzer_spec.rb
Normal file
@ -0,0 +1,57 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Jasmine::Headless::SpecFileAnalyzer do
|
||||
include FakeFS::SpecHelpers
|
||||
|
||||
let(:file) { 'file' }
|
||||
let(:analyzer) { described_class.new(file) }
|
||||
|
||||
describe '#action' do
|
||||
let(:line_numbers) do
|
||||
analyzer.action
|
||||
end
|
||||
|
||||
before do
|
||||
File.open(file, 'wb') { |fh| fh.print file_data }
|
||||
end
|
||||
|
||||
context 'coffeescript' do
|
||||
let(:file_data) do
|
||||
<<-SPEC
|
||||
describe 'test', ->
|
||||
context 'yes', ->
|
||||
it 'should do something', ->
|
||||
"yes"
|
||||
"PR.registerLangHandler(PR.createSimpleLexer([[\"com\",/^#[^\\n\\r]*/,null,\"#\"],[\"pln\",/^[\\t\\n\\r \\xa0]+/,null,\"\\t\\n\\r \xC2\\xa0\"],[\"str\",/^\"(?:[^\"\\\\]|\\\\[\\S\\s])*(?:\"|$)/,null,'\"']],[[\"kwd\",/^(?:ADS|AD|AUG|BZF|BZMF|CAE|CAF|CA|CCS|COM|CS|DAS|DCA|DCOM|DCS|DDOUBL|DIM|DOUBLE|DTCB|DTCF|DV|DXCH|EDRUPT|EXTEND|INCR|INDEX|NDX|INHINT|LXCH|MASK|MSK|MP|MSU|NOOP|OVSK|QXCH|RAND|READ|RELINT|RESUME|RETURN|ROR|RXOR|SQUARE|SU|TCR|TCAA|OVSK|TCF|TC|TS|WAND|WOR|WRITE|XCH|XLQ|XXALQ|ZL|ZQ|ADD|ADZ|SUB|SUZ|MPY|MPR|MPZ|DVP|COM|ABS|CLA|CLZ|LDQ|STO|STQ|ALS|LLS|LRS|TRA|TSQ|TMI|TOV|AXT|TIX|DLY|INP|OUT)\\s/,\n"
|
||||
SPEC
|
||||
end
|
||||
|
||||
it 'should get the line numbers' do
|
||||
line_numbers['test'].should == [ 1 ]
|
||||
line_numbers['yes'].should == [ 2 ]
|
||||
line_numbers['should do something'].should == [ 3 ]
|
||||
end
|
||||
end
|
||||
|
||||
context 'javascript' do
|
||||
let(:file_data) do
|
||||
<<-SPEC
|
||||
describe('test', function() {
|
||||
context('yes', function() {
|
||||
it('should do something', function() {
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
SPEC
|
||||
end
|
||||
|
||||
it 'should get the line numbers' do
|
||||
line_numbers['test'].should == [ 1 ]
|
||||
line_numbers['yes'].should == [ 2 ]
|
||||
line_numbers['should do something'].should == [ 3 ]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,5 +1,12 @@
|
||||
require 'jasmine-headless-webkit'
|
||||
require 'fakefs/spec_helpers'
|
||||
|
||||
RSpec.configure do |c|
|
||||
c.mock_with :mocha
|
||||
|
||||
c.before(:each) do
|
||||
Jasmine::Headless::CacheableAction.enabled = false
|
||||
end
|
||||
end
|
||||
|
||||
specrunner = 'ext/jasmine-webkit-specrunner/jasmine-webkit-specrunner'
|
||||
@ -10,32 +17,39 @@ if !File.file?(specrunner)
|
||||
end
|
||||
end
|
||||
|
||||
RSpec::Matchers.define :be_a_report_containing do |total, fails, used_console|
|
||||
match do |filename|
|
||||
parts(filename).length.should == 4
|
||||
parts[0].should == total.to_s
|
||||
parts[1].should == fails.to_s
|
||||
parts[2].should == (used_console ? "T" : "F")
|
||||
true
|
||||
module RSpec::Matchers
|
||||
define :be_a_report_containing do |total, fails, used_console|
|
||||
match do |filename|
|
||||
parts(filename).length.should == 4
|
||||
parts[0].should == total.to_s
|
||||
parts[1].should == fails.to_s
|
||||
parts[2].should == (used_console ? "T" : "F")
|
||||
true
|
||||
end
|
||||
|
||||
failure_message_for_should do |filename|
|
||||
parts(filename)
|
||||
"expected #{filename} to be a report containing (#{total}, #{fails}, #{used_console.inspect}), instead it contained (#{parts[0]}, #{parts[1]}, #{(parts[2] == "T").inspect})"
|
||||
end
|
||||
|
||||
def parts(filename = nil)
|
||||
@parts ||= File.readlines(filename).first.strip.split('/')
|
||||
end
|
||||
end
|
||||
|
||||
failure_message_for_should do |filename|
|
||||
parts(filename)
|
||||
"expected #{filename} to be a report containing (#{total}, #{fails}, #{used_console.inspect}), instead it contained (#{parts[0]}, #{parts[1]}, #{(parts[2] == "T").inspect})"
|
||||
define :contain_a_failing_spec do |*parts|
|
||||
match do |filename|
|
||||
report(filename).include?(parts.join("||")).should be_true
|
||||
end
|
||||
|
||||
def report(filename)
|
||||
@report ||= File.readlines(filename)[1..-1].collect(&:strip)
|
||||
end
|
||||
end
|
||||
|
||||
def parts(filename = nil)
|
||||
@parts ||= File.readlines(filename).first.strip.split('/')
|
||||
define :be_a_file do
|
||||
match do |file|
|
||||
File.file?(file)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
RSpec::Matchers.define :contain_a_failing_spec do |*parts|
|
||||
match do |filename|
|
||||
report(filename).include?(parts.join("||")).should be_true
|
||||
end
|
||||
|
||||
def report(filename)
|
||||
@report ||= File.readlines(filename)[1..-1].collect(&:strip)
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user