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,7 @@
|
|
1
|
+
Then /^the report file "(.*)" should have (\d+) total, (\d+) failures?, (no|yes) console usage$/ do |file, total, failures, console_usage|
|
2
|
+
report = Jasmine::Headless::Report.load(file)
|
3
|
+
|
4
|
+
report.total.should == total.to_i
|
5
|
+
report.failed.should == failures.to_i
|
6
|
+
report.has_used_console?.should == (console_usage == 'yes')
|
7
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "jasmine/headless/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "jasmine-headless-webkit-firstbanco"
|
7
|
+
s.version = Jasmine::Headless::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["John Bintz", "Sencha Inc.", "Pivotal Labs"]
|
10
|
+
s.email = ["john@coswellproductions.com"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{Run Jasmine specs headlessly in a WebKit browser.}
|
13
|
+
s.description = %q{Run Jasmine specs headlessly. This is a firstbanco gem fork of the originial project, as it appears to be dormant and we want to make our deploys easier.}
|
14
|
+
|
15
|
+
s.rubyforge_project = "jasmine-headless-webkit"
|
16
|
+
|
17
|
+
s.extensions = `git ls-files -- ext/**/extconf.rb`.split("\n")
|
18
|
+
s.files = `git ls-files`.split("\n") + Dir['jasmine/lib/*']
|
19
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
|
+
s.require_paths = ["lib"]
|
22
|
+
|
23
|
+
s.add_runtime_dependency 'jasmine-core'
|
24
|
+
s.add_runtime_dependency 'coffee-script'
|
25
|
+
s.add_runtime_dependency 'rainbow'
|
26
|
+
s.add_runtime_dependency 'multi_json', '>= 1.2.0'
|
27
|
+
s.add_runtime_dependency 'sprockets'
|
28
|
+
s.add_runtime_dependency 'sprockets-vendor_gems'
|
29
|
+
end
|
30
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
Autotest.add_discovery { 'jasmine' if File.file?('./.jasmine-headless-webkit') }
|
@@ -0,0 +1,111 @@
|
|
1
|
+
module JasmineMixin
|
2
|
+
JASMINE_PROGRAM = File.expand_path('../../../bin/jasmine-headless-webkit', __FILE__)
|
3
|
+
|
4
|
+
JAVASCRIPT_EXTENSIONS = %w{js coffee}
|
5
|
+
|
6
|
+
def self.included(klass)
|
7
|
+
klass::ALL_HOOKS << [ :run_jasmine, :ran_jasmine ]
|
8
|
+
end
|
9
|
+
|
10
|
+
attr_accessor :is_jasmine_running, :jasmine_to_run, :jasmine_ran_once
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
super()
|
14
|
+
setup_jasmine_project_mappings
|
15
|
+
jasmine_ran_once = false
|
16
|
+
end
|
17
|
+
|
18
|
+
def get_to_green
|
19
|
+
begin
|
20
|
+
reset_jasmine(:no)
|
21
|
+
super if find_files_to_test
|
22
|
+
|
23
|
+
reset_jasmine(:yes)
|
24
|
+
self.last_mtime = Time.at(0) if !options[:no_full_after_start] && !jasmine_ran_once
|
25
|
+
run_jasmine if find_files_to_test
|
26
|
+
|
27
|
+
self.is_jasmine_running = :all
|
28
|
+
wait_for_changes unless all_jasmine_good
|
29
|
+
end until all_jasmine_good
|
30
|
+
|
31
|
+
reset_jasmine(:all)
|
32
|
+
end
|
33
|
+
|
34
|
+
def rerun_all_tests
|
35
|
+
reset_jasmine(:no)
|
36
|
+
super
|
37
|
+
|
38
|
+
reset_jasmine(:yes)
|
39
|
+
run_jasmine
|
40
|
+
|
41
|
+
reset_jasmine(:all)
|
42
|
+
end
|
43
|
+
|
44
|
+
def reset_jasmine(method)
|
45
|
+
self.files_to_test = new_hash_of_arrays
|
46
|
+
self.is_jasmine_running = method
|
47
|
+
end
|
48
|
+
|
49
|
+
def run_jasmine
|
50
|
+
hook :run_jasmine
|
51
|
+
|
52
|
+
self.jasmine_to_run = :all
|
53
|
+
|
54
|
+
if mtime = find_files_to_test
|
55
|
+
self.last_mtime = mtime
|
56
|
+
end
|
57
|
+
|
58
|
+
begin
|
59
|
+
system make_jasmine_cmd
|
60
|
+
|
61
|
+
self.jasmine_to_run = ($?.exitstatus == 0) ? :none : :all
|
62
|
+
end
|
63
|
+
|
64
|
+
hook :ran_jasmine
|
65
|
+
|
66
|
+
jasmine_ran_once = true
|
67
|
+
end
|
68
|
+
|
69
|
+
def all_jasmine_good
|
70
|
+
self.jasmine_to_run == :none
|
71
|
+
self.files_to_test = new_hash_of_arrays
|
72
|
+
end
|
73
|
+
|
74
|
+
def find_files
|
75
|
+
Hash[super.find_all { |file, mtime|
|
76
|
+
is_js = (file[%r{\.(#{JAVASCRIPT_EXTENSIONS.join('|')})$}] != nil)
|
77
|
+
|
78
|
+
case self.is_jasmine_running
|
79
|
+
when :all
|
80
|
+
true
|
81
|
+
when :no
|
82
|
+
!is_js
|
83
|
+
when :yes
|
84
|
+
is_js
|
85
|
+
end
|
86
|
+
}]
|
87
|
+
end
|
88
|
+
|
89
|
+
def make_jasmine_cmd
|
90
|
+
self.files_to_test.empty? ? '' :
|
91
|
+
%{#{JASMINE_PROGRAM} #{self.files_to_test.keys.collect { |key| %{'#{key}'} }.join(' ')}}.tap { |o| p o }
|
92
|
+
end
|
93
|
+
|
94
|
+
def setup_jasmine_project_mappings
|
95
|
+
add_mapping(%r{spec/javascripts/.*_spec\.(js|coffee)}) { |filename, _|
|
96
|
+
filename
|
97
|
+
}
|
98
|
+
|
99
|
+
add_mapping(%r{public/javascripts/(.*)\.js}) { |_, m|
|
100
|
+
files_matching(%r{spec/javascripts/#{m[1]}_spec\..*$})
|
101
|
+
}
|
102
|
+
|
103
|
+
add_mapping(%r{app/coffeescripts/(.*)\.coffee}) { |_, m|
|
104
|
+
files_matching(%r{spec/javascripts/#{m[1]}_spec\..*$})
|
105
|
+
}
|
106
|
+
end
|
107
|
+
|
108
|
+
def add_javascript_extensions(*extensions)
|
109
|
+
self.class::JAVASCRIPT_EXTENSIONS << extensions
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
3
|
+
module Jasmine
|
4
|
+
module Headless
|
5
|
+
|
6
|
+
EXCLUDED_FORMATS = %w{less sass scss erb str}
|
7
|
+
|
8
|
+
autoload :CommandLine, 'jasmine/headless/command_line'
|
9
|
+
|
10
|
+
autoload :CoffeeScriptCache, 'jasmine/headless/coffee_script_cache'
|
11
|
+
autoload :SpecFileAnalyzer, 'jasmine/headless/spec_file_analyzer'
|
12
|
+
autoload :CacheableAction, 'jasmine/headless/cacheable_action'
|
13
|
+
autoload :VERSION, 'jasmine/headless/version'
|
14
|
+
autoload :Runner, 'jasmine/headless/runner'
|
15
|
+
autoload :Options, 'jasmine/headless/options'
|
16
|
+
autoload :Task, 'jasmine/headless/task'
|
17
|
+
|
18
|
+
autoload :FilesList, 'jasmine/headless/files_list'
|
19
|
+
autoload :UniqueAssetList, 'jasmine/headless/unique_asset_list'
|
20
|
+
|
21
|
+
autoload :TemplateWriter, 'jasmine/headless/template_writer'
|
22
|
+
|
23
|
+
autoload :FileChecker, 'jasmine/headless/file_checker'
|
24
|
+
|
25
|
+
autoload :CoffeeTemplate, 'jasmine/headless/coffee_template'
|
26
|
+
autoload :JSTemplate, 'jasmine/headless/js_template'
|
27
|
+
autoload :JSTTemplate, 'jasmine/headless/jst_template'
|
28
|
+
autoload :CSSTemplate, 'jasmine/headless/css_template'
|
29
|
+
autoload :NilTemplate, 'jasmine/headless/nil_template'
|
30
|
+
|
31
|
+
autoload :Report, 'jasmine/headless/report'
|
32
|
+
autoload :ReportMessage, 'jasmine/headless/report_message'
|
33
|
+
|
34
|
+
class << self
|
35
|
+
def root
|
36
|
+
@root ||= Pathname(File.expand_path('../../..', __FILE__))
|
37
|
+
end
|
38
|
+
|
39
|
+
def warn(message)
|
40
|
+
output.puts message if show_warnings?
|
41
|
+
end
|
42
|
+
|
43
|
+
def show_warnings=(show)
|
44
|
+
@show_warnings = show
|
45
|
+
end
|
46
|
+
|
47
|
+
def show_warnings?
|
48
|
+
@show_warnings = true if @show_warnings.nil?
|
49
|
+
|
50
|
+
@show_warnings
|
51
|
+
end
|
52
|
+
|
53
|
+
def output
|
54
|
+
$stdout
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
require 'jasmine/headless/errors'
|
61
|
+
|
@@ -0,0 +1,85 @@
|
|
1
|
+
module Jasmine::Headless
|
2
|
+
class CacheableAction
|
3
|
+
class << self
|
4
|
+
def enabled=(bool)
|
5
|
+
@enabled = bool
|
6
|
+
end
|
7
|
+
|
8
|
+
def enabled?
|
9
|
+
@enabled = true if @enabled == nil
|
10
|
+
@enabled
|
11
|
+
end
|
12
|
+
|
13
|
+
def cache_type
|
14
|
+
raise ArgumentError.new("No cache type defined for #{self.name}") if @cache_type == nil
|
15
|
+
@cache_type
|
16
|
+
end
|
17
|
+
|
18
|
+
def cache_type=(type)
|
19
|
+
@cache_type = type
|
20
|
+
end
|
21
|
+
|
22
|
+
def cache_dir=(dir)
|
23
|
+
@cache_dir = dir
|
24
|
+
end
|
25
|
+
|
26
|
+
def cache_dir
|
27
|
+
@cache_dir ||= '.jhw-cache'
|
28
|
+
end
|
29
|
+
|
30
|
+
def for(file)
|
31
|
+
new(file).handle
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
attr_reader :file
|
36
|
+
|
37
|
+
def initialize(file)
|
38
|
+
@file = file
|
39
|
+
end
|
40
|
+
|
41
|
+
def handle
|
42
|
+
if CacheableAction.enabled?
|
43
|
+
if fresh?
|
44
|
+
unserialize(File.read(cache_file))
|
45
|
+
else
|
46
|
+
result = action
|
47
|
+
FileUtils.mkdir_p File.split(cache_file).first
|
48
|
+
File.open(cache_file, 'wb') { |fh| fh.print serialize(result) }
|
49
|
+
result
|
50
|
+
end
|
51
|
+
else
|
52
|
+
action
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def cache_file
|
57
|
+
@cache_file ||= File.expand_path(relative_cache_file) + '.js'
|
58
|
+
end
|
59
|
+
|
60
|
+
def relative_cache_file
|
61
|
+
File.join(self.class.cache_dir, self.class.cache_type, file.gsub(Dir.pwd + '/', ''))
|
62
|
+
end
|
63
|
+
|
64
|
+
def fresh?
|
65
|
+
cached? && (File.mtime(file) < File.mtime(cache_file))
|
66
|
+
end
|
67
|
+
|
68
|
+
def cached?
|
69
|
+
File.exist?(cache_file)
|
70
|
+
end
|
71
|
+
|
72
|
+
def action
|
73
|
+
raise StandardError.new("Override action")
|
74
|
+
end
|
75
|
+
|
76
|
+
def serialize(data)
|
77
|
+
data
|
78
|
+
end
|
79
|
+
|
80
|
+
def unserialize(data)
|
81
|
+
data
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|