jasmine-headless-webkit-firstbanco 0.9.0.rc.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/.rspec +1 -0
- data/CHANGELOG.md +89 -0
- data/Gemfile +30 -0
- data/Guardfile +41 -0
- data/README.md +44 -0
- data/Rakefile +65 -0
- data/bin/jasmine-headless-webkit +11 -0
- data/config/cucumber.yml +2 -0
- data/ext/jasmine-webkit-specrunner/Info.plist +22 -0
- data/ext/jasmine-webkit-specrunner/Makefile.dummy +5 -0
- data/ext/jasmine-webkit-specrunner/Page.cpp +15 -0
- data/ext/jasmine-webkit-specrunner/Page.h +20 -0
- data/ext/jasmine-webkit-specrunner/Runner.cpp +208 -0
- data/ext/jasmine-webkit-specrunner/Runner.h +73 -0
- data/ext/jasmine-webkit-specrunner/common.pri +8 -0
- data/ext/jasmine-webkit-specrunner/extconf.rb +10 -0
- data/ext/jasmine-webkit-specrunner/specrunner.cpp +79 -0
- data/ext/jasmine-webkit-specrunner/specrunner.pro +5 -0
- data/features/bin/failure.feature +7 -0
- data/features/bin/files.feature +7 -0
- data/features/bin/filtered_run/both_runs.feature +18 -0
- data/features/bin/filtered_run/no_full_run.feature +14 -0
- data/features/bin/help.feature +7 -0
- data/features/bin/quiet_messages.feature +8 -0
- data/features/bin/runner_out.feature +8 -0
- data/features/bin/spec_files_with_same_basename.feature +7 -0
- data/features/bin/success.feature +20 -0
- data/features/bin/success_with_js_error.feature +5 -0
- data/features/bin/tries_to_leave_page.feature +7 -0
- data/features/bin/try_to_click_a_button.feature +7 -0
- data/features/bin/two_files_from_src_files.feature +11 -0
- data/features/bin/with_coffeescript_error.feature +7 -0
- data/features/bin/with_console_log.feature +7 -0
- data/features/bin/with_server.feature +7 -0
- data/features/bin/with_window_prompt.feature +7 -0
- data/features/reporters.feature +24 -0
- data/features/runner.feature +34 -0
- data/features/steps/given/i_have_test_suite.rb +2 -0
- data/features/steps/given/no_existing_file.rb +4 -0
- data/features/steps/given/options/i_have_defaults.rb +4 -0
- data/features/steps/given/options/i_have_reporters.rb +10 -0
- data/features/steps/given/options/i_have_runner_options.rb +3 -0
- data/features/steps/then/bin/exit_status_should_be.rb +3 -0
- data/features/steps/then/bin/file_should_contain_runner.rb +4 -0
- data/features/steps/then/bin/following_files_loaded_in_order.rb +10 -0
- data/features/steps/then/bin/i_should_get_help_output.rb +4 -0
- data/features/steps/then/bin/output_should_include.rb +3 -0
- data/features/steps/then/bin/output_should_not_include.rb +4 -0
- data/features/steps/then/reporting/report_does_not_exist.rb +4 -0
- data/features/steps/then/reporting/report_should_exist.rb +3 -0
- data/features/steps/then/reporting/report_should_have.rb +7 -0
- data/features/steps/then/reporting/report_should_have_seed.rb +4 -0
- data/features/steps/then/runner/it_should_have_exit_status.rb +3 -0
- data/features/steps/then/runner/it_should_include_report_file.rb +4 -0
- data/features/steps/then/runner/it_should_not_include_report_file.rb +3 -0
- data/features/steps/then/templates/it_should_use_reporter.rb +6 -0
- data/features/steps/when/i_delete_file.rb +3 -0
- data/features/steps/when/i_get_runner.rb +4 -0
- data/features/steps/when/i_get_template_writer.rb +4 -0
- data/features/steps/when/i_run_executable.rb +4 -0
- data/features/steps/when/i_run_runner.rb +4 -0
- data/features/support/env.rb +7 -0
- data/jasmine-headless-webkit-firstbanco.gemspec +30 -0
- data/lib/autotest/discover.rb +1 -0
- data/lib/autotest/jasmine.rb +7 -0
- data/lib/autotest/jasmine_mixin.rb +111 -0
- data/lib/autotest/jasmine_rspec2.rb +7 -0
- data/lib/jasmine-headless-webkit.rb +3 -0
- data/lib/jasmine/headless.rb +61 -0
- data/lib/jasmine/headless/cacheable_action.rb +85 -0
- data/lib/jasmine/headless/coffee_script_cache.rb +20 -0
- data/lib/jasmine/headless/coffee_template.rb +36 -0
- data/lib/jasmine/headless/command_line.rb +31 -0
- data/lib/jasmine/headless/css_template.rb +19 -0
- data/lib/jasmine/headless/errors.rb +16 -0
- data/lib/jasmine/headless/file_checker.rb +25 -0
- data/lib/jasmine/headless/files_list.rb +332 -0
- data/lib/jasmine/headless/js_template.rb +23 -0
- data/lib/jasmine/headless/jst_template.rb +15 -0
- data/lib/jasmine/headless/nil_template.rb +14 -0
- data/lib/jasmine/headless/options.rb +206 -0
- data/lib/jasmine/headless/railtie.rb +12 -0
- data/lib/jasmine/headless/report.rb +81 -0
- data/lib/jasmine/headless/report_message.rb +12 -0
- data/lib/jasmine/headless/report_message/console.rb +18 -0
- data/lib/jasmine/headless/report_message/error.rb +20 -0
- data/lib/jasmine/headless/report_message/fail.rb +5 -0
- data/lib/jasmine/headless/report_message/pass.rb +5 -0
- data/lib/jasmine/headless/report_message/seed.rb +14 -0
- data/lib/jasmine/headless/report_message/spec.rb +28 -0
- data/lib/jasmine/headless/report_message/total.rb +31 -0
- data/lib/jasmine/headless/runner.rb +264 -0
- data/lib/jasmine/headless/spec_file_analyzer.rb +44 -0
- data/lib/jasmine/headless/task.rb +39 -0
- data/lib/jasmine/headless/template_writer.rb +65 -0
- data/lib/jasmine/headless/unique_asset_list.rb +16 -0
- data/lib/jasmine/headless/version.rb +5 -0
- data/lib/qt/qmake.rb +155 -0
- data/script/gemfile +11 -0
- data/script/hooks/post-commit +4 -0
- data/script/hooks/pre-commit +15 -0
- data/script/initialize-environment +35 -0
- data/script/install-git-hooks +6 -0
- data/skel/template.html.erb +77 -0
- data/spec/files/UTF-8-test.txt +0 -0
- data/spec/integration/randomization_spec.rb +13 -0
- data/spec/integration/specify_runner_file_spec.rb +22 -0
- data/spec/integration/sprockets_spec.rb +23 -0
- data/spec/jasmine/click_button/click_button.js +5 -0
- data/spec/jasmine/click_button/click_button.yml +12 -0
- data/spec/jasmine/click_button/click_button_spec.js +11 -0
- data/spec/jasmine/coffeescript_error/coffeescript_error.yml +10 -0
- data/spec/jasmine/coffeescript_error/spec.coffee +2 -0
- data/spec/jasmine/coffeescript_error/src.coffee +2 -0
- data/spec/jasmine/console_log/console_log.js +1 -0
- data/spec/jasmine/console_log/console_log.yml +10 -0
- data/spec/jasmine/console_log/console_log_spec.js +7 -0
- data/spec/jasmine/failure/failure.js +1 -0
- data/spec/jasmine/failure/failure.yml +9 -0
- data/spec/jasmine/failure/failure_spec.js +6 -0
- data/spec/jasmine/filtered_failure/failure_spec.js +6 -0
- data/spec/jasmine/filtered_failure/filtered_failure.yml +10 -0
- data/spec/jasmine/filtered_failure/src.js +0 -0
- data/spec/jasmine/filtered_failure/success_spec.js +6 -0
- data/spec/jasmine/filtered_success/filtered_success.yml +10 -0
- data/spec/jasmine/filtered_success/src.js +0 -0
- data/spec/jasmine/filtered_success/success_one_spec.js +6 -0
- data/spec/jasmine/filtered_success/success_other_file.js +7 -0
- data/spec/jasmine/filtered_success/success_two_spec.js +6 -0
- data/spec/jasmine/filtered_success_with_console/filtered_success.yml +10 -0
- data/spec/jasmine/filtered_success_with_console/src.js +0 -0
- data/spec/jasmine/filtered_success_with_console/success_one_spec.js +7 -0
- data/spec/jasmine/filtered_success_with_console/success_two_spec.js +6 -0
- data/spec/jasmine/leave_page/leave_page.js +4 -0
- data/spec/jasmine/leave_page/leave_page.yml +9 -0
- data/spec/jasmine/leave_page/leave_page_spec.js +11 -0
- data/spec/jasmine/noisy/file.js.erb +0 -0
- data/spec/jasmine/noisy/noisy.yml +8 -0
- data/spec/jasmine/noisy/other_file.js +2 -0
- data/spec/jasmine/runner_out_in_jasmine_yml/jasmine.yml +11 -0
- data/spec/jasmine/runner_out_in_jasmine_yml/test.js +2 -0
- data/spec/jasmine/runner_out_in_jasmine_yml/test_spec.coffee +4 -0
- data/spec/jasmine/success/success.js +1 -0
- data/spec/jasmine/success/success.yml +9 -0
- data/spec/jasmine/success/success_spec.js +6 -0
- data/spec/jasmine/success_with_error/success_with_error.js +3 -0
- data/spec/jasmine/success_with_error/success_with_error.yml +9 -0
- data/spec/jasmine/success_with_error/success_with_error_spec.js +6 -0
- data/spec/jasmine/two_files_from_src_files/app/app-file.js +0 -0
- data/spec/jasmine/two_files_from_src_files/app/app.js +2 -0
- data/spec/jasmine/two_files_from_src_files/jasmine.yml +7 -0
- data/spec/jasmine/two_files_from_src_files/vendor/vendor-file.js +0 -0
- data/spec/jasmine/two_files_from_src_files/vendor/vendor.js +2 -0
- data/spec/jasmine/two_spec_files_same_basename/jasmine.yml +6 -0
- data/spec/jasmine/two_spec_files_same_basename/spec.coffee +4 -0
- data/spec/jasmine/two_spec_files_same_basename/spec.js +6 -0
- data/spec/jasmine/window_prompt/source.js +2 -0
- data/spec/jasmine/window_prompt/window_prompt.yml +4 -0
- data/spec/jasmine/with_sprockets_includes/assets/application.js.erb +2 -0
- data/spec/jasmine/with_sprockets_includes/assets/things/code.js +6 -0
- data/spec/jasmine/with_sprockets_includes/assets/things/jquery.string.js +0 -0
- data/spec/jasmine/with_sprockets_includes/assets/things/required.js +3 -0
- data/spec/jasmine/with_sprockets_includes/assets/things/subcode/more_code.js +2 -0
- data/spec/jasmine/with_sprockets_includes/assets/things/templates/that.jst.ejs +1 -0
- data/spec/jasmine/with_sprockets_includes/assets/things/templates/this.jst +2 -0
- data/spec/jasmine/with_sprockets_includes/spec/spec_helper.js +1 -0
- data/spec/jasmine/with_sprockets_includes/spec/things/code_spec.js +9 -0
- data/spec/jasmine/with_sprockets_includes/with_sprockets_includes.yml +12 -0
- data/spec/javascripts/console.log_spec.coffee +15 -0
- data/spec/javascripts/headless_reporter_result_spec.coffee +30 -0
- data/spec/javascripts/helpers/spec_helper.coffee +2 -0
- data/spec/javascripts/jasmine-extensions_spec.coffee +80 -0
- data/spec/javascripts/jasmine.HeadlessReporter.ConsoleBase_spec.coffee +35 -0
- data/spec/javascripts/jasmine.HeadlessReporter.Console_spec.coffee +3 -0
- data/spec/javascripts/jasmine.HeadlessReporter.Tap_spec.coffee +19 -0
- data/spec/javascripts/jasmine.HeadlessReporter_spec.coffee +27 -0
- data/spec/javascripts/support/jasmine.yml +9 -0
- data/spec/lib/jasmine/headless/cacheable_action_spec.rb +122 -0
- data/spec/lib/jasmine/headless/coffee_script_cache_spec.rb +21 -0
- data/spec/lib/jasmine/headless/coffee_template_spec.rb +55 -0
- data/spec/lib/jasmine/headless/css_template_spec.rb +25 -0
- data/spec/lib/jasmine/headless/file_checker_spec.rb +41 -0
- data/spec/lib/jasmine/headless/files_list_spec.rb +194 -0
- data/spec/lib/jasmine/headless/js_template_spec.rb +31 -0
- data/spec/lib/jasmine/headless/jst_template_spec.rb +21 -0
- data/spec/lib/jasmine/headless/nil_template_spec.rb +31 -0
- data/spec/lib/jasmine/headless/options_spec.rb +194 -0
- data/spec/lib/jasmine/headless/report_message/seed_spec.rb +18 -0
- data/spec/lib/jasmine/headless/report_message/spec_spec.rb +20 -0
- data/spec/lib/jasmine/headless/report_spec.rb +95 -0
- data/spec/lib/jasmine/headless/runner_spec.rb +247 -0
- data/spec/lib/jasmine/headless/spec_file_analyzer_spec.rb +68 -0
- data/spec/lib/jasmine/headless/task_spec.rb +92 -0
- data/spec/lib/jasmine/headless/template_writer_spec.rb +92 -0
- data/spec/lib/jasmine/headless/unique_asset_list_spec.rb +22 -0
- data/spec/lib/jasmine/headless_spec.rb +38 -0
- data/spec/lib/qt/qmake_spec.rb +142 -0
- data/spec/skel/template.html.erb_spec.rb +8 -0
- data/spec/spec_helper.rb +113 -0
- data/vendor/assets/coffeescripts/headless_reporter_result.coffee +49 -0
- data/vendor/assets/coffeescripts/prolog.coffee +100 -0
- data/vendor/assets/javascripts/beautify-html.js +463 -0
- data/vendor/assets/javascripts/headless_reporter_result.js +79 -0
- data/vendor/assets/javascripts/intense.coffee +28 -0
- data/vendor/assets/javascripts/jasmine-extensions.coffee +97 -0
- data/vendor/assets/javascripts/jasmine.HeadlessReporter.Console.coffee +8 -0
- data/vendor/assets/javascripts/jasmine.HeadlessReporter.ConsoleBase.coffee +92 -0
- data/vendor/assets/javascripts/jasmine.HeadlessReporter.File.coffee +24 -0
- data/vendor/assets/javascripts/jasmine.HeadlessReporter.Tap.coffee +28 -0
- data/vendor/assets/javascripts/jasmine.HeadlessReporter.Verbose.coffee +64 -0
- data/vendor/assets/javascripts/jasmine.HeadlessReporter.coffee +58 -0
- data/vendor/assets/javascripts/jsDump.js +209 -0
- data/vendor/assets/javascripts/prolog.js +108 -0
- metadata +347 -0
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'coffee_script'
|
2
|
+
require 'digest/sha1'
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
module Jasmine
|
6
|
+
module Headless
|
7
|
+
class CoffeeScriptCache < CacheableAction
|
8
|
+
class << self
|
9
|
+
def cache_type
|
10
|
+
"coffee_script"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def action
|
15
|
+
CoffeeScript.compile(File.read(file))
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'tilt/template'
|
2
|
+
require 'rainbow'
|
3
|
+
|
4
|
+
module Jasmine::Headless
|
5
|
+
class CoffeeTemplate < Tilt::Template
|
6
|
+
include Jasmine::Headless::FileChecker
|
7
|
+
|
8
|
+
self.default_mime_type = 'application/javascript'
|
9
|
+
|
10
|
+
def prepare ; end
|
11
|
+
|
12
|
+
def evaluate(scope, locals, &block)
|
13
|
+
if bad_format?(file)
|
14
|
+
alert_bad_format(file)
|
15
|
+
return ''
|
16
|
+
end
|
17
|
+
begin
|
18
|
+
cache = Jasmine::Headless::CoffeeScriptCache.new(file)
|
19
|
+
source = cache.handle
|
20
|
+
if cache.cached?
|
21
|
+
%{<script type="text/javascript" src="#{cache.cache_file}"></script>
|
22
|
+
<script type="text/javascript">window.CSTF['#{File.split(cache.cache_file).last}'] = '#{file}';</script>}
|
23
|
+
else
|
24
|
+
%{<script type="text/javascript">#{source}</script>}
|
25
|
+
end
|
26
|
+
rescue CoffeeScript::CompilationError => ne
|
27
|
+
puts "[%s] %s: %s" % [ 'coffeescript'.color(:red), file.color(:yellow), "#{ne.message}".color(:white) ]
|
28
|
+
raise ne
|
29
|
+
rescue StandardError => e
|
30
|
+
puts "[%s] Error in compiling file: %s" % [ 'coffeescript'.color(:red), file.color(:yellow) ]
|
31
|
+
raise e
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Jasmine::Headless
|
2
|
+
class CommandLine
|
3
|
+
class << self
|
4
|
+
def run!
|
5
|
+
require 'coffee-script'
|
6
|
+
require 'rainbow'
|
7
|
+
|
8
|
+
begin
|
9
|
+
options = Options.from_command_line
|
10
|
+
runner = Runner.new(options)
|
11
|
+
|
12
|
+
if options[:do_list]
|
13
|
+
FilesList.reset!
|
14
|
+
|
15
|
+
files_list = FilesList.new(:config => runner.jasmine_config)
|
16
|
+
files_list.files.each { |file| puts file }
|
17
|
+
else
|
18
|
+
exit runner.run
|
19
|
+
end
|
20
|
+
rescue CoffeeScript::CompilationError
|
21
|
+
exit 1
|
22
|
+
rescue StandardError => e
|
23
|
+
$stderr.puts "[%s] %s (%s)" % [ "jasmine-headless-webkit".color(:red), e.message.color(:white), e.class.name.color(:yellow) ]
|
24
|
+
$stderr.puts e.backtrace.collect { |line| " #{line}" }.join("\n")
|
25
|
+
exit 1
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'tilt/template'
|
2
|
+
|
3
|
+
module Jasmine::Headless
|
4
|
+
class CSSTemplate < Tilt::Template
|
5
|
+
include Jasmine::Headless::FileChecker
|
6
|
+
self.default_mime_type = 'text/css'
|
7
|
+
|
8
|
+
def prepare ; end
|
9
|
+
|
10
|
+
def evaluate(scope, locals, &block)
|
11
|
+
if bad_format?(file)
|
12
|
+
alert_bad_format(file)
|
13
|
+
return ''
|
14
|
+
end
|
15
|
+
file ? %{<link rel="stylesheet" href="#{file}" type="text/css" />} : data
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Jasmine
|
2
|
+
module Headless
|
3
|
+
class NoRunnerError < StandardError
|
4
|
+
def message
|
5
|
+
"The jasmine-headless-webkit specrunner (jasmine-webkit-specrunner) could not be found! Try reinstalling the gem."
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class TestFailure < StandardError; end
|
10
|
+
class ConsoleLogUsage < StandardError ; end
|
11
|
+
|
12
|
+
class JasmineConfigNotFound < Errno::ENOENT ; end
|
13
|
+
class InvalidReport < StandardError ; end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Jasmine::Headless::FileChecker
|
2
|
+
def excluded_formats
|
3
|
+
::Jasmine::Headless::EXCLUDED_FORMATS
|
4
|
+
end
|
5
|
+
|
6
|
+
def bad_format?(file)
|
7
|
+
return if file.nil?
|
8
|
+
|
9
|
+
excluded_formats.any? do |format|
|
10
|
+
file[%r{\.#{format}(\.|$)}]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def alert_bad_format(file)
|
15
|
+
Jasmine::Headless.warn("[%s] %s: %s" % [ 'Skipping File'.color(:red), file.color(:yellow), "unsupported format".color(:white) ])
|
16
|
+
end
|
17
|
+
|
18
|
+
def alert_if_bad_format?(file)
|
19
|
+
if result = bad_format?(file)
|
20
|
+
alert_bad_format(file)
|
21
|
+
end
|
22
|
+
|
23
|
+
result
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,332 @@
|
|
1
|
+
require 'jasmine-core'
|
2
|
+
require 'time'
|
3
|
+
require 'multi_json'
|
4
|
+
require 'set'
|
5
|
+
require 'sprockets'
|
6
|
+
require 'sprockets/engines'
|
7
|
+
require 'sprockets-vendor_gems'
|
8
|
+
|
9
|
+
module Jasmine::Headless
|
10
|
+
class FilesList
|
11
|
+
include FileChecker
|
12
|
+
|
13
|
+
class << self
|
14
|
+
def asset_paths
|
15
|
+
@asset_paths ||= Sprockets.find_gem_vendor_paths(:for => 'javascripts')
|
16
|
+
end
|
17
|
+
|
18
|
+
def reset!
|
19
|
+
@asset_paths = nil
|
20
|
+
@registered_engines = {}
|
21
|
+
|
22
|
+
# register haml-sprockets and handlebars_assets if it's available...
|
23
|
+
%w{haml-sprockets handlebars_assets}.each do |library|
|
24
|
+
begin
|
25
|
+
require library
|
26
|
+
rescue LoadError
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
if ENV['JHW_ENV']
|
31
|
+
begin
|
32
|
+
require 'bundler'
|
33
|
+
|
34
|
+
Bundler.require(ENV['JHW_ENV'].to_sym)
|
35
|
+
rescue LoadError
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
@sprockets_environment = nil
|
40
|
+
end
|
41
|
+
|
42
|
+
def registered_engines
|
43
|
+
@registered_engines ||= {}
|
44
|
+
end
|
45
|
+
|
46
|
+
def register_engine(file_extension, template_class)
|
47
|
+
registered_engines[file_extension] = template_class
|
48
|
+
end
|
49
|
+
|
50
|
+
def register_engines!
|
51
|
+
registered_engines.each do |file_extension, template_class|
|
52
|
+
Sprockets.register_engine file_extension, template_class
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def default_files
|
57
|
+
%w{jasmine.js jasmine-html jasmine.css jasmine-extensions
|
58
|
+
intense headless_reporter_result jasmine.HeadlessReporter
|
59
|
+
jasmine.HeadlessReporter.ConsoleBase
|
60
|
+
jsDump beautify-html}
|
61
|
+
end
|
62
|
+
|
63
|
+
def extension_filter
|
64
|
+
extensions = (%w{.js .css} + Sprockets.engine_extensions)
|
65
|
+
|
66
|
+
%r{(#{extensions.join('|')})$}
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
PLEASE_WAIT_IM_WORKING_TIME = 2
|
71
|
+
|
72
|
+
attr_reader :options, :required_files, :potential_files_to_filter
|
73
|
+
|
74
|
+
def initialize(options = {})
|
75
|
+
@options = options
|
76
|
+
|
77
|
+
Kernel.srand(options[:seed]) if options[:seed]
|
78
|
+
|
79
|
+
@required_files = UniqueAssetList.new
|
80
|
+
@potential_files_to_filter = []
|
81
|
+
|
82
|
+
register_engines!
|
83
|
+
|
84
|
+
load_initial_assets
|
85
|
+
|
86
|
+
use_config if config?
|
87
|
+
end
|
88
|
+
|
89
|
+
def register_engines!
|
90
|
+
begin
|
91
|
+
require spec_helper
|
92
|
+
rescue LoadError
|
93
|
+
end
|
94
|
+
self.class.register_engines!
|
95
|
+
end
|
96
|
+
|
97
|
+
def load_initial_assets
|
98
|
+
self.class.default_files.each do |file|
|
99
|
+
begin
|
100
|
+
add_path(file)
|
101
|
+
rescue InvalidUniqueAsset => e
|
102
|
+
raise StandardError.new("Not an asset: #{file}")
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
(options[:reporters] || []).each do |reporter, identifier, file|
|
107
|
+
add_path("jasmine.HeadlessReporter.#{reporter}")
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def files
|
112
|
+
required_files.flatten.collect { |asset| asset.pathname.to_s }.uniq
|
113
|
+
end
|
114
|
+
|
115
|
+
def spec_files
|
116
|
+
filter_for_requested_specs(
|
117
|
+
files.find_all { |file| spec_dir.any? { |dir| file[dir] } }
|
118
|
+
)
|
119
|
+
end
|
120
|
+
|
121
|
+
def filtered_files
|
122
|
+
filter_for_requested_specs(files)
|
123
|
+
end
|
124
|
+
|
125
|
+
def search_paths
|
126
|
+
return @search_paths if @search_paths
|
127
|
+
|
128
|
+
@search_paths = [ Jasmine::Core.path, Jasmine::Headless.root.join('vendor/assets/javascripts').to_s ]
|
129
|
+
@search_paths += self.class.asset_paths
|
130
|
+
@search_paths += src_dir.collect { |dir| File.expand_path(dir) }
|
131
|
+
@search_paths += asset_paths.collect { |dir| File.expand_path(dir) }
|
132
|
+
@search_paths += spec_dir.collect { |dir| File.expand_path(dir) }
|
133
|
+
|
134
|
+
@search_paths.uniq!
|
135
|
+
@search_paths
|
136
|
+
end
|
137
|
+
|
138
|
+
def sprockets_environment
|
139
|
+
return @sprockets_environment if @sprockets_environment
|
140
|
+
|
141
|
+
@sprockets_environment = Sprockets::Environment.new
|
142
|
+
search_paths.each { |path| @sprockets_environment.append_path(path) }
|
143
|
+
|
144
|
+
@sprockets_environment.unregister_postprocessor('application/javascript', Sprockets::SafetyColons)
|
145
|
+
|
146
|
+
# ...and unregister ones we don't want/need
|
147
|
+
@sprockets_environment.instance_eval do
|
148
|
+
EXCLUDED_FORMATS.each do |extension|
|
149
|
+
register_engine ".#{extension}", Jasmine::Headless::NilTemplate
|
150
|
+
end
|
151
|
+
|
152
|
+
register_engine '.coffee', Jasmine::Headless::CoffeeTemplate
|
153
|
+
register_engine '.js', Jasmine::Headless::JSTemplate
|
154
|
+
register_engine '.css', Jasmine::Headless::CSSTemplate
|
155
|
+
register_engine '.jst', Jasmine::Headless::JSTTemplate
|
156
|
+
end
|
157
|
+
|
158
|
+
@sprockets_environment
|
159
|
+
end
|
160
|
+
|
161
|
+
def has_spec_outside_scope?
|
162
|
+
if is_outside_scope = !spec_filter.empty?
|
163
|
+
is_outside_scope = spec_dir.any? do |dir|
|
164
|
+
spec_file_searches.any? do |search|
|
165
|
+
!spec_files.any? do |file|
|
166
|
+
target = File.join(dir, search)
|
167
|
+
File.fnmatch?(target, file) || File.fnmatch?(target.gsub(%{^**/}, ''), file)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
is_outside_scope
|
174
|
+
end
|
175
|
+
|
176
|
+
def filtered?
|
177
|
+
files != filtered_files
|
178
|
+
end
|
179
|
+
|
180
|
+
def files_to_html
|
181
|
+
to_html(files)
|
182
|
+
end
|
183
|
+
|
184
|
+
def filtered_files_to_html
|
185
|
+
to_html(filtered_files)
|
186
|
+
end
|
187
|
+
|
188
|
+
def spec_file_line_numbers
|
189
|
+
@spec_file_line_numbers ||= Hash[spec_files.collect { |file|
|
190
|
+
if File.exist?(file)
|
191
|
+
if !(lines = Jasmine::Headless::SpecFileAnalyzer.for(file)).empty?
|
192
|
+
[ file, lines ]
|
193
|
+
end
|
194
|
+
else
|
195
|
+
nil
|
196
|
+
end
|
197
|
+
}.compact]
|
198
|
+
end
|
199
|
+
|
200
|
+
private
|
201
|
+
def to_html(files)
|
202
|
+
alert_time = Time.now + PLEASE_WAIT_IM_WORKING_TIME
|
203
|
+
|
204
|
+
files.collect do |file|
|
205
|
+
if alert_time && alert_time < Time.now
|
206
|
+
puts "Rebuilding cache, please wait..."
|
207
|
+
alert_time = nil
|
208
|
+
end
|
209
|
+
|
210
|
+
sprockets_environment.find_asset(file, :bundle => false).body
|
211
|
+
end.compact.reject(&:empty?)
|
212
|
+
end
|
213
|
+
|
214
|
+
def spec_filter
|
215
|
+
@spec_filter ||= (@options[:only] && @options[:only].collect { |path| expanded_dir(path) }.flatten) || []
|
216
|
+
end
|
217
|
+
|
218
|
+
SEARCH_ROOTS = {
|
219
|
+
'src_files' => 'src_dir',
|
220
|
+
'stylesheets' => 'src_dir',
|
221
|
+
'helpers' => 'spec_dir',
|
222
|
+
'spec_files' => 'spec_dir'
|
223
|
+
}
|
224
|
+
|
225
|
+
def use_config
|
226
|
+
@config = @options[:config].dup
|
227
|
+
@searches = {}
|
228
|
+
@potential_files_to_filter = []
|
229
|
+
|
230
|
+
%w{src_files stylesheets helpers spec_files}.each do |type|
|
231
|
+
if data = @config[type]
|
232
|
+
add_files(@searches[type] = data.flatten, type, send(SEARCH_ROOTS[type]))
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
def add_files(patterns, type, dirs)
|
238
|
+
patterns.each do |pattern|
|
239
|
+
dirs.collect { |dir| expanded_dir(File.join(dir, pattern)) }.each do |files|
|
240
|
+
files.sort! { |a, b| Kernel.rand(3) - 1 } if type == 'spec_files'
|
241
|
+
|
242
|
+
files.each do |path|
|
243
|
+
add_path(path, type)
|
244
|
+
end
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
if type == 'spec_files'
|
249
|
+
spec_filter.each { |path| add_path(path, type) }
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
def config?
|
254
|
+
@options[:config]
|
255
|
+
end
|
256
|
+
|
257
|
+
def expanded_dir(path)
|
258
|
+
file_list = Dir.glob(path).sort
|
259
|
+
file_list.find_all { |file|
|
260
|
+
file[extension_filter] && !alert_if_bad_format?(file)
|
261
|
+
}.collect {
|
262
|
+
|file| File.expand_path(file)
|
263
|
+
}.find_all {
|
264
|
+
|path| File.file?(path)
|
265
|
+
}
|
266
|
+
end
|
267
|
+
|
268
|
+
def extension_filter
|
269
|
+
self.class.extension_filter
|
270
|
+
end
|
271
|
+
|
272
|
+
def add_path(path, type = nil)
|
273
|
+
asset = sprockets_environment.find_asset(path)
|
274
|
+
|
275
|
+
@required_files << asset
|
276
|
+
|
277
|
+
if type == 'spec_files'
|
278
|
+
@potential_files_to_filter << path
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
282
|
+
def src_dir
|
283
|
+
@src_dir ||= config_dir_or_pwd('src_dir') + asset_paths
|
284
|
+
end
|
285
|
+
|
286
|
+
def spec_dir
|
287
|
+
@spec_dir ||= config_dir_or_pwd('spec_dir')
|
288
|
+
end
|
289
|
+
|
290
|
+
def asset_paths
|
291
|
+
@asset_paths ||= config_dir('asset_paths')
|
292
|
+
end
|
293
|
+
|
294
|
+
def spec_file_searches
|
295
|
+
@searches['spec_files']
|
296
|
+
end
|
297
|
+
|
298
|
+
def config_dir_or_pwd(dir)
|
299
|
+
if (found = config_dir(dir)).empty?
|
300
|
+
found = [ Dir.pwd ]
|
301
|
+
end
|
302
|
+
|
303
|
+
found
|
304
|
+
end
|
305
|
+
|
306
|
+
def config_dir(dir)
|
307
|
+
[ @options[:config] && @options[:config][dir] ].flatten.compact.collect { |dir| File.expand_path(dir) }
|
308
|
+
end
|
309
|
+
|
310
|
+
def filter_for_requested_specs(files)
|
311
|
+
files.find_all do |file|
|
312
|
+
if potential_files_to_filter.include?(file)
|
313
|
+
spec_filter.empty? || spec_filter.any? { |pattern| File.fnmatch?(pattern, file) }
|
314
|
+
else
|
315
|
+
true
|
316
|
+
end
|
317
|
+
end
|
318
|
+
end
|
319
|
+
|
320
|
+
def spec_helper
|
321
|
+
File.join(spec_dir, "helpers", "spec_helper")
|
322
|
+
end
|
323
|
+
end
|
324
|
+
end
|
325
|
+
|
326
|
+
module Jasmine::Headless
|
327
|
+
extend self
|
328
|
+
|
329
|
+
def register_engine(file_extension, template_class)
|
330
|
+
Jasmine::Headless::FilesList.register_engine(file_extension, template_class)
|
331
|
+
end
|
332
|
+
end
|