qunited 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +12 -0
- data/lib/qunited/driver/base.rb +54 -12
- data/lib/qunited/version.rb +1 -1
- data/test/fixtures/coffee_project/app/assets/javascripts/application.coffee +6 -0
- data/test/fixtures/coffee_project/app/assets/javascripts/application.js +6 -0
- data/test/fixtures/coffee_project/test/javascripts/test_basics.coffee +4 -0
- data/test/fixtures/coffee_project/test/javascripts/test_basics.js +6 -0
- data/test/fixtures/coffee_project/test/javascripts/test_math.coffee +10 -0
- data/test/fixtures/coffee_project/test/javascripts/test_math.js +12 -0
- data/test/unit/driver_common_tests.rb +30 -1
- metadata +33 -39
data/README.md
CHANGED
@@ -46,6 +46,18 @@ Source and test files can be configured either as an array of file names or a gl
|
|
46
46
|
|
47
47
|
You can also use an array to configure the test files but a glob pattern might be more convenient since test files usually do not need to be loaded in a particular order.
|
48
48
|
|
49
|
+
|
50
|
+
If you have some extra test helper libraries you would like to include (stubs, mocks) or files with other custom test setup, you can specify them as ```helper_files```.
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
QUnited::RakeTask.new do |t|
|
54
|
+
t.source_files = ['lib/js/jquery.js', 'lib/js/my_app_1.js', 'lib/js/my_app_2.js']
|
55
|
+
t.helper_files = ['test/helpers/sinon-1.6.0.js']
|
56
|
+
t.test_files = 'test/js/**/*.js'
|
57
|
+
end
|
58
|
+
```
|
59
|
+
These will be loaded after source files and before running tests. Separating helpers this way is merely for convenience and has the same effect as just including them last with your source files.
|
60
|
+
|
49
61
|
### Specifying a driver
|
50
62
|
|
51
63
|
QUnited uses various drivers to set up the environment the tests run in (see below for more details). By default it tries to Just Work and find an available driver to use. You may want to lock down the driver (recommended) so your tests are consistent. To do this add a bit more configuration to the Rake task.
|
data/lib/qunited/driver/base.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'tempfile'
|
2
|
+
|
1
3
|
module QUnited
|
2
4
|
module Driver
|
3
5
|
class Base
|
@@ -8,6 +10,8 @@ module QUnited
|
|
8
10
|
TEST_RESULT_END_TOKEN = 'QUNITED_TEST_RESULT_END_TOKEN'
|
9
11
|
TEST_RESULT_REGEX = /#{TEST_RESULT_START_TOKEN}(.*?)#{TEST_RESULT_END_TOKEN}/m
|
10
12
|
|
13
|
+
COFFEESCRIPT_EXTENSIONS = ['coffee', 'cs']
|
14
|
+
|
11
15
|
attr_reader :results, :source_files, :test_files
|
12
16
|
attr_accessor :formatter
|
13
17
|
|
@@ -24,19 +28,11 @@ module QUnited
|
|
24
28
|
return nil
|
25
29
|
end
|
26
30
|
|
27
|
-
#
|
31
|
+
# Initialize the driver with source and test files. The files can be described either with
|
32
|
+
# glob patterns or arrays of file names.
|
28
33
|
def initialize(source_files, test_files)
|
29
|
-
@source_files =
|
30
|
-
|
31
|
-
elsif source_files.is_a? Array
|
32
|
-
source_files
|
33
|
-
end
|
34
|
-
|
35
|
-
@test_files = if test_files.is_a? String
|
36
|
-
Dir.glob(test_files)
|
37
|
-
elsif test_files.is_a? Array
|
38
|
-
test_files
|
39
|
-
end
|
34
|
+
@source_files = normalize_files source_files
|
35
|
+
@test_files = normalize_files test_files
|
40
36
|
end
|
41
37
|
|
42
38
|
def run
|
@@ -60,6 +56,52 @@ module QUnited
|
|
60
56
|
def send_to_formatter(method, *args)
|
61
57
|
formatter.send(method, *args) if formatter
|
62
58
|
end
|
59
|
+
|
60
|
+
# Hash that maps CoffeeScript file paths to temporary compiled JavaScript files. This is
|
61
|
+
# used partially because we need to keep around references to the temporary files or else
|
62
|
+
# they could be deleted.
|
63
|
+
def compiled_coffeescript_files
|
64
|
+
@compiled_coffeescript_files ||= {}
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
# Produces an array of JavaScript filenames from either a glob pattern or an array of
|
70
|
+
# JavaScript or CoffeeScript filenames. Files with CoffeeScript extensions will be
|
71
|
+
# compiled and replaced in the produced array with temp files of compiled JavaScript.
|
72
|
+
def normalize_files(files)
|
73
|
+
files = Dir.glob(files) if files.is_a? String
|
74
|
+
|
75
|
+
files.map do |file|
|
76
|
+
if COFFEESCRIPT_EXTENSIONS.include? File.extname(file).sub(/^\./, '')
|
77
|
+
compile_coffeescript file
|
78
|
+
else
|
79
|
+
file
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
# Compile the CoffeeScript file with the given filename to JavaScript. Returns the full
|
85
|
+
# path of the compiled JavaScript file. The file is created in a temporary directory.
|
86
|
+
def compile_coffeescript(file)
|
87
|
+
begin
|
88
|
+
require 'coffee-script'
|
89
|
+
rescue LoadError
|
90
|
+
msg = <<-ERROR_MSG
|
91
|
+
You must install an additional gem to use CoffeeScript source or test files.
|
92
|
+
Run the following command (with sudo if necessary): gem install coffee-script
|
93
|
+
ERROR_MSG
|
94
|
+
raise UsageError, msg
|
95
|
+
end
|
96
|
+
|
97
|
+
compiled_js_file = Tempfile.new(["compiled_#{File.basename(file).gsub('.', '_')}", '.js'])
|
98
|
+
compiled_js_file.write CoffeeScript.compile(File.read(file))
|
99
|
+
compiled_js_file.close
|
100
|
+
|
101
|
+
compiled_coffeescript_files[file] = compiled_js_file
|
102
|
+
|
103
|
+
compiled_js_file.path
|
104
|
+
end
|
63
105
|
end
|
64
106
|
end
|
65
107
|
end
|
data/lib/qunited/version.rb
CHANGED
@@ -0,0 +1,12 @@
|
|
1
|
+
module("Math");
|
2
|
+
|
3
|
+
test("Addition works", function() {
|
4
|
+
expect(2);
|
5
|
+
equal(1 + 1, 2, "One plus one does equal two");
|
6
|
+
equal(2 + 2, 4, "Two plus two does equal four");
|
7
|
+
});
|
8
|
+
|
9
|
+
test("Subtraction works", function() {
|
10
|
+
expect(1);
|
11
|
+
equal(2 - 1, 1, "Two minus one equals one");
|
12
|
+
});
|
@@ -73,6 +73,32 @@ module QUnited::DriverCommonTests
|
|
73
73
|
run_tests_for_project 'basic_project', :formatter => mock_formatter
|
74
74
|
end
|
75
75
|
|
76
|
+
def test_can_test_coffeescript
|
77
|
+
@results = run_tests_for_project 'coffee_project', :source_files => 'app/assets/javascripts/*.coffee'
|
78
|
+
assert_equal 3, total_tests, 'Correct number of tests run'
|
79
|
+
assert_equal 4, total_assertions, 'Correct number of assertions executed'
|
80
|
+
assert_equal 0, total_failed_tests, 'Correct number of failures given'
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_can_run_coffeescript_tests
|
84
|
+
@results = run_tests_for_project 'coffee_project', :test_files => 'test/javascripts/*.coffee'
|
85
|
+
assert_equal 3, total_tests, 'Correct number of tests run'
|
86
|
+
assert_equal 4, total_assertions, 'Correct number of assertions executed'
|
87
|
+
if total_failed_tests == 1
|
88
|
+
STDOUT.puts @results.first.inspect
|
89
|
+
STDOUT.puts File.read(@results.first.data[:file])
|
90
|
+
end
|
91
|
+
assert_equal 0, total_failed_tests, 'Correct number of failures given'
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_can_test_coffeescript_with_coffeescript_tests
|
95
|
+
@results = run_tests_for_project 'coffee_project',
|
96
|
+
:source_files => 'app/assets/javascripts/*.coffee', :test_files => 'test/javascripts/*.coffee'
|
97
|
+
assert_equal 3, total_tests, 'Correct number of tests run'
|
98
|
+
assert_equal 4, total_assertions, 'Correct number of assertions executed'
|
99
|
+
assert_equal 0, total_failed_tests, 'Correct number of failures given'
|
100
|
+
end
|
101
|
+
|
76
102
|
protected
|
77
103
|
|
78
104
|
def driver_class
|
@@ -86,7 +112,10 @@ module QUnited::DriverCommonTests
|
|
86
112
|
|
87
113
|
def driver_for_project(project_name, opts={})
|
88
114
|
Dir.chdir File.join(FIXTURES_DIR, project_name)
|
89
|
-
driver = driver_class.new(
|
115
|
+
driver = driver_class.new(
|
116
|
+
opts[:source_files] || 'app/assets/javascripts/*.js',
|
117
|
+
opts[:test_files] || 'test/javascripts/*.js'
|
118
|
+
)
|
90
119
|
driver.formatter = opts[:formatter] if opts[:formatter]
|
91
120
|
driver
|
92
121
|
end
|
metadata
CHANGED
@@ -1,33 +1,24 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: qunited
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.2
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 4
|
9
|
-
- 1
|
10
|
-
version: 0.4.1
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Aaron Royer
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
date: 2013-03-23 00:00:00 Z
|
12
|
+
date: 2013-04-12 00:00:00.000000000 Z
|
19
13
|
dependencies: []
|
20
|
-
|
21
14
|
description: QUnited runs headless QUnit tests as part of your normal build
|
22
|
-
email:
|
15
|
+
email:
|
23
16
|
- aaronroyer@gmail.com
|
24
|
-
executables:
|
17
|
+
executables:
|
25
18
|
- qunited
|
26
19
|
extensions: []
|
27
|
-
|
28
20
|
extra_rdoc_files: []
|
29
|
-
|
30
|
-
files:
|
21
|
+
files:
|
31
22
|
- .gitignore
|
32
23
|
- Gemfile
|
33
24
|
- MIT-LICENSE
|
@@ -63,6 +54,12 @@ files:
|
|
63
54
|
- test/fixtures/basic_project/app/assets/javascripts/application.js
|
64
55
|
- test/fixtures/basic_project/test/javascripts/test_basics.js
|
65
56
|
- test/fixtures/basic_project/test/javascripts/test_math.js
|
57
|
+
- test/fixtures/coffee_project/app/assets/javascripts/application.coffee
|
58
|
+
- test/fixtures/coffee_project/app/assets/javascripts/application.js
|
59
|
+
- test/fixtures/coffee_project/test/javascripts/test_basics.coffee
|
60
|
+
- test/fixtures/coffee_project/test/javascripts/test_basics.js
|
61
|
+
- test/fixtures/coffee_project/test/javascripts/test_math.coffee
|
62
|
+
- test/fixtures/coffee_project/test/javascripts/test_math.js
|
66
63
|
- test/fixtures/dom_project/app/assets/javascripts/application.js
|
67
64
|
- test/fixtures/dom_project/test/javascripts/test_misc.js
|
68
65
|
- test/fixtures/errors_project/app/assets/javascripts/no_error.js
|
@@ -84,41 +81,38 @@ files:
|
|
84
81
|
- test/unit/test_runner.rb
|
85
82
|
homepage: https://github.com/aaronroyer/qunited
|
86
83
|
licenses: []
|
87
|
-
|
88
84
|
post_install_message:
|
89
85
|
rdoc_options: []
|
90
|
-
|
91
|
-
require_paths:
|
86
|
+
require_paths:
|
92
87
|
- lib
|
93
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
89
|
none: false
|
95
|
-
requirements:
|
96
|
-
- -
|
97
|
-
- !ruby/object:Gem::Version
|
98
|
-
|
99
|
-
|
100
|
-
- 0
|
101
|
-
version: "0"
|
102
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
95
|
none: false
|
104
|
-
requirements:
|
105
|
-
- -
|
106
|
-
- !ruby/object:Gem::Version
|
107
|
-
|
108
|
-
segments:
|
109
|
-
- 0
|
110
|
-
version: "0"
|
96
|
+
requirements:
|
97
|
+
- - ! '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
111
100
|
requirements: []
|
112
|
-
|
113
101
|
rubyforge_project: qunited
|
114
|
-
rubygems_version: 1.8.
|
102
|
+
rubygems_version: 1.8.23
|
115
103
|
signing_key:
|
116
104
|
specification_version: 3
|
117
105
|
summary: QUnit tests in your build
|
118
|
-
test_files:
|
106
|
+
test_files:
|
119
107
|
- test/fixtures/basic_project/app/assets/javascripts/application.js
|
120
108
|
- test/fixtures/basic_project/test/javascripts/test_basics.js
|
121
109
|
- test/fixtures/basic_project/test/javascripts/test_math.js
|
110
|
+
- test/fixtures/coffee_project/app/assets/javascripts/application.coffee
|
111
|
+
- test/fixtures/coffee_project/app/assets/javascripts/application.js
|
112
|
+
- test/fixtures/coffee_project/test/javascripts/test_basics.coffee
|
113
|
+
- test/fixtures/coffee_project/test/javascripts/test_basics.js
|
114
|
+
- test/fixtures/coffee_project/test/javascripts/test_math.coffee
|
115
|
+
- test/fixtures/coffee_project/test/javascripts/test_math.js
|
122
116
|
- test/fixtures/dom_project/app/assets/javascripts/application.js
|
123
117
|
- test/fixtures/dom_project/test/javascripts/test_misc.js
|
124
118
|
- test/fixtures/errors_project/app/assets/javascripts/no_error.js
|