jasmine-headless-webkit 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -5,4 +5,4 @@ gemspec
5
5
 
6
6
  gem 'rspec'
7
7
  gem 'autotest'
8
-
8
+ gem 'fakefs', :require => nil
data/README.md CHANGED
@@ -39,9 +39,27 @@ Current supported options:
39
39
 
40
40
  * `-c`/`--colors` enables color output
41
41
  * `--no-colors` disables color output
42
+ * `--keep` preserves the temporary HTML document if an error occurs in testing
42
43
 
43
44
  These options can also be placed into a `.jasmine-headless-webkit` file in your project root.
44
45
 
46
+ ### CoffeeScript Support
47
+
48
+ `jasmine-headless-webkit` brings in the `coffee-script` gem and compiles & injects all CoffeeScript into the
49
+ generated HTML page. All you need to do is configure your `jasmine.yml` file to look for .coffee files:
50
+
51
+ src_files:
52
+ - app/assets/javascripts/**/*.coffee
53
+ spec_files:
54
+ - **/*[sS]pec.coffee
55
+
56
+ *(This will probably make it difficult to test your code in an official Jasmine server for now. You can try
57
+ [a technique like this](https://github.com/jbaudanza/rack-asset-compiler/blob/master/examples/jasmine_config.rb) for compiling CoffeeScript when it's requested from the server
58
+ or use [this fork of jasmine-gem](https://github.com/johnbintz/jasmine-gem/tree/coffeescript-inline-support) which
59
+ is thoroughly untested.)*
60
+
61
+ You will get line numbers on compile errors, but not logic errors. This is a CoffeeScript thing, and they're working on it. :)
62
+
45
63
  ### JavaScript Dialogs
46
64
 
47
65
  You can call `alert()` and `confirm()` in your code. `alert()` will print the message to the console, and
@@ -1,53 +1,58 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ require 'rubygems'
4
+
5
+ gem_dir = File.expand_path('../..', __FILE__)
6
+ $:.unshift(File.join(gem_dir, 'lib'))
7
+
3
8
  require 'yaml'
4
9
  require 'fileutils'
5
10
  require 'getoptlong'
6
11
 
12
+ gem 'jasmine'
13
+ gem 'coffee-script'
14
+ gem 'rainbow'
15
+
16
+ require 'jasmine'
17
+ require 'coffee-script'
18
+ require 'rainbow'
19
+
20
+ require 'jasmine/cli'
21
+ include Jasmine::CLI
22
+
7
23
  opts = GetoptLong.new(
8
24
  [ '--colors', '-c', GetoptLong::NO_ARGUMENT ],
9
- [ '--no-colors', GetoptLong::NO_ARGUMENT ]
25
+ [ '--no-colors', GetoptLong::NO_ARGUMENT ],
26
+ [ '--keep', GetoptLong::NO_ARGUMENT ]
10
27
  )
11
28
 
12
- options = { :colors => false }
29
+ options = { :colors => false, :remove_html_file => true }
13
30
 
14
- process_options = lambda { |*args|
15
- opt = args.shift
31
+ @process_options = lambda { |*args|
32
+ opt = args.flatten.shift
16
33
  case opt
17
34
  when '--colors', '-c'
18
35
  options[:colors] = true
19
36
  when '--no-colors', '-nc'
20
37
  options[:colors] = false
38
+ when '--keep', '-k'
39
+ options[:remove_html_file] = false
21
40
  end
22
41
  }
23
42
 
24
- if File.file?('.jasmine-headless-webkit')
25
- File.readlines('.jasmine-headless-webkit').collect { |line| line.strip.split(' ', 2) }.flatten(1).each(&process_options)
26
- end
27
-
28
- opts.each(&process_options)
43
+ read_defaults_file if defaults_file?
44
+ opts.each(&@process_options)
29
45
 
30
46
  data = YAML.load_file(ARGV.shift || 'spec/javascripts/support/jasmine.yml')
31
- gem_dir = File.expand_path('../..', __FILE__)
32
47
 
33
- if !File.file?(File.join(gem_dir, 'ext/jasmine-webkit-specrunner/jasmine-webkit-specrunner'))
48
+ if !File.file?(File.join(gem_dir, RUNNER))
34
49
  puts "The Qt WebKit widget is not compiled! Try re-installing this gem."
35
50
  exit 1
36
51
  end
37
52
 
38
53
  puts "Running Jasmine specs..."
39
54
 
40
- files = [
41
- 'file://' + File.join(gem_dir, 'jasmine/lib/jasmine.js'),
42
- 'file://' + File.join(gem_dir, 'jasmine/lib/jasmine-html.js'),
43
- 'file://' + File.join(gem_dir, 'jasmine/lib/jasmine.css')
44
- ]
45
-
46
- DEFAULTS = {
47
- 'spec_files' => [ '**/*[sS]pec.js' ],
48
- 'helpers' => [ 'helpers/**/*.js' ],
49
- 'spec_dir' => 'spec/javascripts'
50
- }
55
+ files = %w{jasmine jasmine-html}.collect { |name| File.join(Jasmine.root, "lib/#{name}.js") }
51
56
 
52
57
  files += [ [ 'src_files', 'src_dir' ], [ 'stylesheets', 'src_dir' ], [ 'helpers', 'spec_dir' ], [ 'spec_files', 'spec_dir' ] ].collect do |searches, root|
53
58
  data[searches] ||= DEFAULTS[searches]
@@ -66,37 +71,26 @@ files = files.flatten.compact.collect { |file|
66
71
  case File.extname(file)
67
72
  when '.js'
68
73
  %{<script type="text/javascript" src="#{file}"></script>}
74
+ when '.coffee'
75
+ begin
76
+ %{<script type="text/javascript">#{CoffeeScript.compile(fh = File.open(file))}</script>}
77
+ rescue CoffeeScript::CompilationError => e
78
+ puts "[%s] %s: %s" % [ 'coffeescript'.color(:red), file.color(:yellow), e.message.color(:white) ]
79
+ exit 1
80
+ ensure
81
+ fh.close
82
+ end
69
83
  when '.css'
70
84
  %{<link rel="stylesheet" href="#{file}" type="text/css" />}
71
85
  end
72
86
  }
73
87
 
74
- output = <<-HTML
75
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
76
- "http://www.w3.org/TR/html4/loose.dtd">
77
- <html>
78
- <head>
79
- <title>Jasmine Test Runner</title>
80
- <script type="text/javascript">
81
- window.console = { log: function(data) { debug.log(JSON.stringify(data)); } };
82
- </script>
83
- #{files.join("\n")}
84
- </head>
85
- <body>
86
-
87
- <script type="text/javascript">
88
- jasmine.getEnv().addReporter(new jasmine.TrivialReporter());
89
- jasmine.getEnv().execute();
90
- </script>
91
-
92
- </body>
93
- </html>
94
- HTML
88
+ output = jasmine_html_template(files)
95
89
 
96
90
  File.open(target = "specrunner.#{$$}.html", 'w') { |fh| fh.print output }
97
- system %{#{File.join(gem_dir, 'ext/jasmine-webkit-specrunner/jasmine-webkit-specrunner')} #{options[:colors] ? '-c' : ''} #{target}}
91
+ system %{#{File.join(gem_dir, RUNNER)} #{options[:colors] ? '-c' : ''} #{target}}
98
92
  status = $?.exitstatus
99
- FileUtils.rm_f target
93
+ FileUtils.rm_f target if options[:remove_html_file] || (status == 0)
100
94
 
101
95
  exit status
102
96
 
@@ -112,7 +112,9 @@ void HeadlessSpecRunner::load(const QString &spec)
112
112
  void HeadlessSpecRunner::watch(bool ok)
113
113
  {
114
114
  if (!ok) {
115
- std::cerr << "Can't load' " << qPrintable(m_page.mainFrame()->url().toString()) << std::endl;
115
+ std::cerr << "Can't load " << qPrintable(m_page.mainFrame()->url().toString()) << ", the file may be broken." << std::endl;
116
+ std::cerr << "Out of curiosity, did your tests try to submit a form and you haven't prevented that?" << std::endl;
117
+ std::cerr << "Try running your tests in your browser with the Jasmine server and see what happens." << std::endl;
116
118
  QApplication::instance()->exit(1);
117
119
  return;
118
120
  }
@@ -21,4 +21,6 @@ Gem::Specification.new do |s|
21
21
  s.require_paths = ["lib"]
22
22
 
23
23
  s.add_dependency 'jasmine'
24
+ s.add_dependency 'coffee-script'
25
+ s.add_dependency 'rainbow'
24
26
  end
@@ -1,17 +1,18 @@
1
1
  module JasmineMixin
2
2
  JASMINE_PROGRAM = File.expand_path('../../../bin/jasmine-headless-webkit', __FILE__)
3
3
 
4
- JAVASCRIPT_EXTENSIONS = %w{js}
4
+ JAVASCRIPT_EXTENSIONS = %w{js coffee}
5
5
 
6
6
  def self.included(klass)
7
7
  klass::ALL_HOOKS << [ :run_jasmine, :ran_jasmine ]
8
8
  end
9
9
 
10
- attr_accessor :is_jasmine_running, :jasmine_to_run
10
+ attr_accessor :is_jasmine_running, :jasmine_to_run, :jasmine_ran_once
11
11
 
12
12
  def initialize
13
13
  super()
14
14
  setup_jasmine_project_mappings
15
+ jasmine_ran_once = false
15
16
  end
16
17
 
17
18
  def get_to_green
@@ -20,6 +21,7 @@ module JasmineMixin
20
21
  super if find_files_to_test
21
22
 
22
23
  reset_jasmine(:yes)
24
+ self.last_mtime = Time.at(0) if !options[:no_full_after_start] && !jasmine_ran_once
23
25
  run_jasmine if find_files_to_test
24
26
 
25
27
  self.is_jasmine_running = :all
@@ -29,6 +31,16 @@ module JasmineMixin
29
31
  reset_jasmine(:all)
30
32
  end
31
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
+
32
44
  def reset_jasmine(method)
33
45
  self.files_to_test = new_hash_of_arrays
34
46
  self.is_jasmine_running = method
@@ -50,6 +62,8 @@ module JasmineMixin
50
62
  end
51
63
 
52
64
  hook :ran_jasmine
65
+
66
+ jasmine_ran_once = true
53
67
  end
54
68
 
55
69
  def all_jasmine_good
@@ -77,12 +91,16 @@ module JasmineMixin
77
91
  end
78
92
 
79
93
  def setup_jasmine_project_mappings
80
- add_mapping(%r{spec/javascripts/.*_spec\.js}) { |filename, _|
94
+ add_mapping(%r{spec/javascripts/.*_spec\.(js|coffee)}) { |filename, _|
81
95
  filename
82
96
  }
83
97
 
84
98
  add_mapping(%r{public/javascripts/(.*)\.js}) { |_, m|
85
- [ "spec/javascripts/#{m[1]}_spec.js" ]
99
+ files_matching(%r{spec/javascripts/#{m[1]}_spec\..*$})
100
+ }
101
+
102
+ add_mapping(%r{app/coffeescripts/(.*)\.coffee}) { |_, m|
103
+ files_matching(%r{spec/javascripts/#{m[1]}_spec\..*$})
86
104
  }
87
105
  end
88
106
 
@@ -1,7 +1,7 @@
1
1
  module Jasmine
2
2
  module Headless
3
3
  module Webkit
4
- VERSION = "0.0.3"
4
+ VERSION = "0.1.0"
5
5
  end
6
6
  end
7
7
  end
@@ -0,0 +1,51 @@
1
+ module Jasmine
2
+ module CLI
3
+ DEFAULTS = {
4
+ 'spec_files' => [ '**/*[sS]pec.js' ],
5
+ 'helpers' => [ 'helpers/**/*.js' ],
6
+ 'spec_dir' => 'spec/javascripts',
7
+ 'src_dir' => nil,
8
+ 'stylesheets' => [],
9
+ 'src_files' => []
10
+ }
11
+
12
+ RUNNER = 'ext/jasmine-webkit-specrunner/jasmine-webkit-specrunner'
13
+ DEFAULTS_FILE = '.jasmine-headless-webkit'
14
+
15
+ def process_jasmine_config(overrides = {})
16
+ DEFAULTS.merge(overrides)
17
+ end
18
+
19
+ def read_defaults_file
20
+ File.readlines(DEFAULTS_FILE).collect { |line| line.strip.split(' ', 2) }.each(&@process_options)
21
+ end
22
+
23
+ def defaults_file?
24
+ File.file?(DEFAULTS_FILE)
25
+ end
26
+
27
+ def jasmine_html_template(files)
28
+ <<-HTML
29
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
30
+ <html>
31
+ <head>
32
+ <title>Jasmine Test Runner</title>
33
+ <script type="text/javascript">
34
+ window.console = { log: function(data) { debug.log(JSON.stringify(data)); } };
35
+ </script>
36
+ #{files.join("\n")}
37
+ </head>
38
+ <body>
39
+
40
+ <script type="text/javascript">
41
+ jasmine.getEnv().addReporter(new jasmine.TrivialReporter());
42
+ jasmine.getEnv().execute();
43
+ </script>
44
+
45
+ </body>
46
+ </html>
47
+ HTML
48
+ end
49
+ end
50
+ end
51
+
@@ -0,0 +1,62 @@
1
+ require 'spec_helper'
2
+ require 'jasmine/cli'
3
+ require 'fakefs/spec_helpers'
4
+
5
+ describe Jasmine::CLI do
6
+ include Jasmine::CLI
7
+ include FakeFS::SpecHelpers
8
+
9
+ describe '#process_jasmine_config' do
10
+ context 'without overrides' do
11
+ let(:config) { {} }
12
+
13
+ it "should just return the defaults" do
14
+ process_jasmine_config(config).should == {
15
+ 'src_files' => [],
16
+ 'stylesheets' => [],
17
+ 'helpers' => [ 'helpers/**/*.js' ],
18
+ 'spec_files' => [ '**/*[sS]pec.js' ],
19
+ 'src_dir' => nil,
20
+ 'spec_dir' => 'spec/javascripts'
21
+ }
22
+ end
23
+ end
24
+
25
+ context 'with overrides' do
26
+ let(:config) {
27
+ {
28
+ 'src_files' => [ 'one', 'two' ],
29
+ 'src_dir' => 'this-dir',
30
+ 'stylesheets' => [ 'three', 'four' ],
31
+ 'helpers' => [ 'five', 'six' ],
32
+ 'spec_files' => [ 'seven', 'eight' ],
33
+ 'spec_dir' => 'that-dir'
34
+ }
35
+ }
36
+
37
+ it "should return the merged data" do
38
+ process_jasmine_config(config).should == config
39
+ end
40
+ end
41
+ end
42
+
43
+ describe '#read_defaults_file' do
44
+ let(:test_data) { %w{first second} }
45
+
46
+ before do
47
+ File.open(DEFAULTS_FILE, 'w') { |fh| fh.puts test_data.join(' ') }
48
+ end
49
+
50
+ it "should read the options" do
51
+ found = false
52
+
53
+ @process_options = lambda { |*args|
54
+ found = true if args.flatten == test_data
55
+ }
56
+
57
+ read_defaults_file
58
+
59
+ found.should be_true
60
+ end
61
+ end
62
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: jasmine-headless-webkit
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.3
5
+ version: 0.1.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - John Bintz
@@ -12,7 +12,7 @@ autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
14
 
15
- date: 2011-05-04 00:00:00 -04:00
15
+ date: 2011-05-10 00:00:00 -04:00
16
16
  default_executable:
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
@@ -26,6 +26,28 @@ dependencies:
26
26
  version: "0"
27
27
  type: :runtime
28
28
  version_requirements: *id001
29
+ - !ruby/object:Gem::Dependency
30
+ name: coffee-script
31
+ prerelease: false
32
+ requirement: &id002 !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: "0"
38
+ type: :runtime
39
+ version_requirements: *id002
40
+ - !ruby/object:Gem::Dependency
41
+ name: rainbow
42
+ prerelease: false
43
+ requirement: &id003 !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: "0"
49
+ type: :runtime
50
+ version_requirements: *id003
29
51
  description: Run Jasmine specs headlessly
30
52
  email:
31
53
  - john@coswellproductions.com
@@ -38,7 +60,6 @@ extra_rdoc_files: []
38
60
  files:
39
61
  - .autotest
40
62
  - .gitignore
41
- - .gitmodules
42
63
  - .rspec
43
64
  - Gemfile
44
65
  - README.md
@@ -55,6 +76,7 @@ files:
55
76
  - lib/autotest/jasmine_rspec2.rb
56
77
  - lib/jasmine-headless-webkit.rb
57
78
  - lib/jasmine-headless-webkit/version.rb
79
+ - lib/jasmine/cli.rb
58
80
  - spec/bin/jasmine-headless-webkit_spec.rb
59
81
  - spec/jasmine/console_log/console_log.js
60
82
  - spec/jasmine/console_log/console_log.yml
@@ -65,11 +87,8 @@ files:
65
87
  - spec/jasmine/success/success.js
66
88
  - spec/jasmine/success/success.yml
67
89
  - spec/jasmine/success/success_spec.js
90
+ - spec/lib/jasmine/cli_spec.rb
68
91
  - spec/spec_helper.rb
69
- - jasmine/lib/jasmine-html.js
70
- - jasmine/lib/jasmine.css
71
- - jasmine/lib/jasmine.js
72
- - jasmine/lib/json2.js
73
92
  has_rdoc: true
74
93
  homepage: ""
75
94
  licenses: []
@@ -109,4 +128,5 @@ test_files:
109
128
  - spec/jasmine/success/success.js
110
129
  - spec/jasmine/success/success.yml
111
130
  - spec/jasmine/success/success_spec.js
131
+ - spec/lib/jasmine/cli_spec.rb
112
132
  - spec/spec_helper.rb