jasmine 1.0.1.1 → 1.0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. data/.gitignore +11 -0
  2. data/.gitmodules +3 -0
  3. data/Gemfile +5 -0
  4. data/HOW_TO_TEST.markdown +11 -0
  5. data/README.markdown +42 -14
  6. data/RELEASE.markdown +22 -0
  7. data/Rakefile +76 -0
  8. data/generators/jasmine/jasmine_generator.rb +15 -13
  9. data/generators/jasmine/templates/spec/javascripts/support/jasmine_config.rb +23 -0
  10. data/install.rb +2 -0
  11. data/jasmine.gemspec +52 -0
  12. data/jasmine/Gemfile +6 -0
  13. data/jasmine/MIT.LICENSE +20 -0
  14. data/jasmine/README.markdown +28 -0
  15. data/jasmine/Rakefile +182 -0
  16. data/jasmine/cruise_config.rb +21 -0
  17. data/jasmine/example/spec/PlayerSpec.js +58 -0
  18. data/jasmine/example/spec/SpecHelper.js +9 -0
  19. data/jasmine/example/src/Player.js +22 -0
  20. data/jasmine/example/src/Song.js +7 -0
  21. data/jasmine/images/fail-16.png +0 -0
  22. data/jasmine/images/fail.png +0 -0
  23. data/jasmine/images/go-16.png +0 -0
  24. data/jasmine/images/go.png +0 -0
  25. data/jasmine/images/pending-16.png +0 -0
  26. data/jasmine/images/pending.png +0 -0
  27. data/jasmine/images/question-bk.png +0 -0
  28. data/jasmine/images/questionbk-16.png +0 -0
  29. data/jasmine/images/spinner.gif +0 -0
  30. data/jasmine/jsdoc-template/allclasses.tmpl +17 -0
  31. data/jasmine/jsdoc-template/allfiles.tmpl +56 -0
  32. data/jasmine/jsdoc-template/class.tmpl +646 -0
  33. data/jasmine/jsdoc-template/index.tmpl +39 -0
  34. data/jasmine/jsdoc-template/publish.js +184 -0
  35. data/jasmine/jsdoc-template/static/default.css +162 -0
  36. data/jasmine/jsdoc-template/static/header.html +2 -0
  37. data/jasmine/jsdoc-template/static/index.html +19 -0
  38. data/jasmine/jsdoc-template/symbol.tmpl +35 -0
  39. data/jasmine/spec/runner.html +80 -0
  40. data/jasmine/spec/suites/BaseSpec.js +27 -0
  41. data/jasmine/spec/suites/CustomMatchersSpec.js +97 -0
  42. data/jasmine/spec/suites/EnvSpec.js +158 -0
  43. data/jasmine/spec/suites/ExceptionsSpec.js +107 -0
  44. data/jasmine/spec/suites/JsApiReporterSpec.js +103 -0
  45. data/jasmine/spec/suites/MatchersSpec.js +795 -0
  46. data/jasmine/spec/suites/MockClockSpec.js +38 -0
  47. data/jasmine/spec/suites/MultiReporterSpec.js +45 -0
  48. data/jasmine/spec/suites/NestedResultsSpec.js +54 -0
  49. data/jasmine/spec/suites/PrettyPrintSpec.js +93 -0
  50. data/jasmine/spec/suites/QueueSpec.js +23 -0
  51. data/jasmine/spec/suites/ReporterSpec.js +56 -0
  52. data/jasmine/spec/suites/RunnerSpec.js +267 -0
  53. data/jasmine/spec/suites/SpecRunningSpec.js +1253 -0
  54. data/jasmine/spec/suites/SpecSpec.js +124 -0
  55. data/jasmine/spec/suites/SpySpec.js +201 -0
  56. data/jasmine/spec/suites/SuiteSpec.js +120 -0
  57. data/jasmine/spec/suites/TrivialReporterSpec.js +238 -0
  58. data/jasmine/spec/suites/UtilSpec.js +40 -0
  59. data/jasmine/spec/suites/WaitsForBlockSpec.js +87 -0
  60. data/jasmine/src/Block.js +22 -0
  61. data/jasmine/src/Env.js +264 -0
  62. data/jasmine/src/JsApiReporter.js +102 -0
  63. data/jasmine/src/Matchers.js +354 -0
  64. data/jasmine/src/MultiReporter.js +35 -0
  65. data/jasmine/src/NestedResults.js +80 -0
  66. data/jasmine/src/PrettyPrinter.js +122 -0
  67. data/jasmine/src/Queue.js +99 -0
  68. data/jasmine/src/Reporter.js +31 -0
  69. data/jasmine/src/Runner.js +77 -0
  70. data/jasmine/src/Spec.js +242 -0
  71. data/jasmine/src/Suite.js +82 -0
  72. data/jasmine/src/WaitsBlock.js +13 -0
  73. data/jasmine/src/WaitsForBlock.js +52 -0
  74. data/jasmine/src/base.js +589 -0
  75. data/jasmine/src/html/TrivialReporter.js +188 -0
  76. data/jasmine/src/html/jasmine.css +166 -0
  77. data/jasmine/src/mock-timeout.js +183 -0
  78. data/jasmine/src/util.js +67 -0
  79. data/jasmine/src/version.json +5 -0
  80. data/lib/generators/jasmine/examples/USAGE +11 -0
  81. data/lib/generators/jasmine/examples/examples_generator.rb +19 -0
  82. data/lib/generators/jasmine/examples/templates/public/javascripts/jasmine_examples/Player.js +22 -0
  83. data/lib/generators/jasmine/examples/templates/public/javascripts/jasmine_examples/Song.js +7 -0
  84. data/lib/generators/jasmine/examples/templates/spec/javascripts/helpers/SpecHelper.js +9 -0
  85. data/lib/generators/jasmine/examples/templates/spec/javascripts/jasmine_examples/PlayerSpec.js +58 -0
  86. data/lib/generators/jasmine/install/USAGE +11 -0
  87. data/lib/generators/jasmine/install/install_generator.rb +18 -0
  88. data/lib/generators/jasmine/install/templates/spec/javascripts/helpers/.gitkeep +0 -0
  89. data/lib/generators/jasmine/install/templates/spec/javascripts/support/jasmine.yml +81 -0
  90. data/lib/generators/jasmine/install/templates/spec/javascripts/support/jasmine_config.rb +23 -0
  91. data/lib/generators/jasmine/install/templates/spec/javascripts/support/jasmine_runner.rb +20 -0
  92. data/lib/generators/jasmine/jasmine_generator.rb +32 -0
  93. data/lib/generators/jasmine/templates/INSTALL +9 -0
  94. data/lib/generators/jasmine/templates/lib/tasks/jasmine.rake +2 -0
  95. data/lib/generators/jasmine/templates/spec/javascripts/support/jasmine-rails.yml +81 -0
  96. data/lib/generators/jasmine/templates/spec/javascripts/support/jasmine.yml +73 -0
  97. data/lib/generators/jasmine/templates/spec/javascripts/support/jasmine_config.rb +23 -0
  98. data/lib/generators/jasmine/templates/spec/javascripts/support/jasmine_runner.rb +32 -0
  99. data/lib/jasmine.rb +31 -6
  100. data/lib/jasmine/command_line_tool.rb +1 -0
  101. data/lib/jasmine/config.rb +16 -44
  102. data/lib/jasmine/generator.rb +9 -0
  103. data/lib/jasmine/selenium_driver.rb +18 -18
  104. data/lib/jasmine/server.rb +0 -24
  105. data/lib/jasmine/spec_builder.rb +4 -4
  106. data/lib/jasmine/tasks/jasmine.rake +2 -2
  107. data/lib/jasmine/version.rb +3 -0
  108. data/spec/config_spec.rb +174 -123
  109. data/spec/fixture/jasmine.erb.yml +4 -0
  110. data/spec/jasmine_pojs_spec.rb +51 -0
  111. data/spec/jasmine_rails2_spec.rb +93 -0
  112. data/spec/jasmine_rails3_spec.rb +71 -0
  113. data/spec/spec_helper.rb +8 -2
  114. metadata +215 -65
  115. data/spec/bug_fixes_spec.rb +0 -32
  116. data/spec/rails_generator_spec.rb +0 -31
@@ -0,0 +1,67 @@
1
+ /**
2
+ * @namespace
3
+ */
4
+ jasmine.util = {};
5
+
6
+ /**
7
+ * Declare that a child class inherit it's prototype from the parent class.
8
+ *
9
+ * @private
10
+ * @param {Function} childClass
11
+ * @param {Function} parentClass
12
+ */
13
+ jasmine.util.inherit = function(childClass, parentClass) {
14
+ /**
15
+ * @private
16
+ */
17
+ var subclass = function() {
18
+ };
19
+ subclass.prototype = parentClass.prototype;
20
+ childClass.prototype = new subclass;
21
+ };
22
+
23
+ jasmine.util.formatException = function(e) {
24
+ var lineNumber;
25
+ if (e.line) {
26
+ lineNumber = e.line;
27
+ }
28
+ else if (e.lineNumber) {
29
+ lineNumber = e.lineNumber;
30
+ }
31
+
32
+ var file;
33
+
34
+ if (e.sourceURL) {
35
+ file = e.sourceURL;
36
+ }
37
+ else if (e.fileName) {
38
+ file = e.fileName;
39
+ }
40
+
41
+ var message = (e.name && e.message) ? (e.name + ': ' + e.message) : e.toString();
42
+
43
+ if (file && lineNumber) {
44
+ message += ' in ' + file + ' (line ' + lineNumber + ')';
45
+ }
46
+
47
+ return message;
48
+ };
49
+
50
+ jasmine.util.htmlEscape = function(str) {
51
+ if (!str) return str;
52
+ return str.replace(/&/g, '&')
53
+ .replace(/</g, '&lt;')
54
+ .replace(/>/g, '&gt;');
55
+ };
56
+
57
+ jasmine.util.argsToArray = function(args) {
58
+ var arrayOfArgs = [];
59
+ for (var i = 0; i < args.length; i++) arrayOfArgs.push(args[i]);
60
+ return arrayOfArgs;
61
+ };
62
+
63
+ jasmine.util.extend = function(destination, source) {
64
+ for (var property in source) destination[property] = source[property];
65
+ return destination;
66
+ };
67
+
@@ -0,0 +1,5 @@
1
+ {
2
+ "major": 1,
3
+ "minor": 0,
4
+ "build": 1
5
+ }
@@ -0,0 +1,11 @@
1
+ Description:
2
+ Install jasmine examples
3
+
4
+ Example:
5
+ rails generate jasmine:examples
6
+
7
+ This will create:
8
+ public/javascripts/jasmine_examples/PlayerSpec.js
9
+ public/javascripts/jasmine_examples/SpecHelper.js
10
+ spec/javascripts/jasmine_examples/PlayerSpec.js
11
+ spec/javascripts/jasmine_examples/SpecHelper.js
@@ -0,0 +1,19 @@
1
+ module Jasmine
2
+ module Generators
3
+ class ExamplesGenerator < Rails::Generators::Base
4
+
5
+ def self.source_root
6
+ @source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
7
+ end
8
+
9
+ def copy_example_files
10
+ directory 'public'
11
+ directory 'spec'
12
+ end
13
+
14
+ def app_name
15
+ Rails.application.class.name
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,22 @@
1
+ function Player() {
2
+ }
3
+ Player.prototype.play = function(song) {
4
+ this.currentlyPlayingSong = song;
5
+ this.isPlaying = true;
6
+ };
7
+
8
+ Player.prototype.pause = function() {
9
+ this.isPlaying = false;
10
+ };
11
+
12
+ Player.prototype.resume = function() {
13
+ if (this.isPlaying) {
14
+ throw new Error("song is already playing");
15
+ }
16
+
17
+ this.isPlaying = true;
18
+ };
19
+
20
+ Player.prototype.makeFavorite = function() {
21
+ this.currentlyPlayingSong.persistFavoriteStatus(true);
22
+ };
@@ -0,0 +1,7 @@
1
+ function Song() {
2
+ }
3
+
4
+ Song.prototype.persistFavoriteStatus = function(value) {
5
+ // something complicated
6
+ throw new Error("not yet implemented");
7
+ };
@@ -0,0 +1,9 @@
1
+ beforeEach(function() {
2
+ this.addMatchers({
3
+ toBePlaying: function(expectedSong) {
4
+ var player = this.actual;
5
+ return player.currentlyPlayingSong === expectedSong
6
+ && player.isPlaying;
7
+ }
8
+ })
9
+ });
@@ -0,0 +1,58 @@
1
+ describe("Player", function() {
2
+ var player;
3
+ var song;
4
+
5
+ beforeEach(function() {
6
+ player = new Player();
7
+ song = new Song();
8
+ });
9
+
10
+ it("should be able to play a Song", function() {
11
+ player.play(song);
12
+ expect(player.currentlyPlayingSong).toEqual(song);
13
+
14
+ //demonstrates use of custom matcher
15
+ expect(player).toBePlaying(song);
16
+ });
17
+
18
+ describe("when song has been paused", function() {
19
+ beforeEach(function() {
20
+ player.play(song);
21
+ player.pause();
22
+ });
23
+
24
+ it("should indicate that the song is currently paused", function() {
25
+ expect(player.isPlaying).toBeFalsy();
26
+
27
+ // demonstrates use of 'not' with a custom matcher
28
+ expect(player).not.toBePlaying(song);
29
+ });
30
+
31
+ it("should be possible to resume", function() {
32
+ player.resume();
33
+ expect(player.isPlaying).toBeTruthy();
34
+ expect(player.currentlyPlayingSong).toEqual(song);
35
+ });
36
+ });
37
+
38
+ // demonstrates use of spies to intercept and test method calls
39
+ it("tells the current song if the user has made it a favorite", function() {
40
+ spyOn(song, 'persistFavoriteStatus');
41
+
42
+ player.play(song);
43
+ player.makeFavorite();
44
+
45
+ expect(song.persistFavoriteStatus).toHaveBeenCalledWith(true);
46
+ });
47
+
48
+ //demonstrates use of expected exceptions
49
+ describe("#resume", function() {
50
+ it("should throw an exception if song is already playing", function() {
51
+ player.play(song);
52
+
53
+ expect(function() {
54
+ player.resume();
55
+ }).toThrow("song is already playing");
56
+ });
57
+ });
58
+ });
@@ -0,0 +1,11 @@
1
+ Description:
2
+ Install jasmine
3
+
4
+ Example:
5
+ rails generate jasmine:install
6
+
7
+ This will create:
8
+ spec/javascripts/support/jasmine.yml
9
+ spec/javascripts/support/jasmine_config.rb
10
+ spec/javascripts/support/jasmine_runner.rb
11
+ spec/javascripts/helpers/.gitkeep
@@ -0,0 +1,18 @@
1
+ module Jasmine
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+
5
+ def self.source_root
6
+ @source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
7
+ end
8
+
9
+ def copy_spec_files
10
+ directory 'spec'
11
+ end
12
+
13
+ def app_name
14
+ Rails.application.class.name
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,81 @@
1
+ # src_files
2
+ #
3
+ # Return an array of filepaths relative to src_dir to include before jasmine specs.
4
+ # Default: []
5
+ #
6
+ # EXAMPLE:
7
+ #
8
+ # src_files:
9
+ # - lib/source1.js
10
+ # - lib/source2.js
11
+ # - dist/**/*.js
12
+ #
13
+ src_files:
14
+ - public/javascripts/prototype.js
15
+ - public/javascripts/effects.js
16
+ - public/javascripts/controls.js
17
+ - public/javascripts/dragdrop.js
18
+ - public/javascripts/application.js
19
+ - public/javascripts/**/*.js
20
+
21
+ # stylesheets
22
+ #
23
+ # Return an array of stylesheet filepaths relative to src_dir to include before jasmine specs.
24
+ # Default: []
25
+ #
26
+ # EXAMPLE:
27
+ #
28
+ # stylesheets:
29
+ # - css/style.css
30
+ # - stylesheets/*.css
31
+ #
32
+ stylesheets:
33
+ - stylesheets/**/*.css
34
+
35
+ # helpers
36
+ #
37
+ # Return an array of filepaths relative to spec_dir to include before jasmine specs.
38
+ # Default: ["helpers/**/*.js"]
39
+ #
40
+ # EXAMPLE:
41
+ #
42
+ # helpers:
43
+ # - helpers/**/*.js
44
+ #
45
+ helpers:
46
+ - helpers/**/*.js
47
+
48
+ # spec_files
49
+ #
50
+ # Return an array of filepaths relative to spec_dir to include.
51
+ # Default: ["**/*[sS]pec.js"]
52
+ #
53
+ # EXAMPLE:
54
+ #
55
+ # spec_files:
56
+ # - **/*[sS]pec.js
57
+ #
58
+ spec_files:
59
+ - **/*[sS]pec.js
60
+
61
+ # src_dir
62
+ #
63
+ # Source directory path. Your src_files must be returned relative to this path. Will use root if left blank.
64
+ # Default: project root
65
+ #
66
+ # EXAMPLE:
67
+ #
68
+ # src_dir: public
69
+ #
70
+ src_dir:
71
+
72
+ # spec_dir
73
+ #
74
+ # Spec directory path. Your spec_files must be returned relative to this path.
75
+ # Default: spec/javascripts
76
+ #
77
+ # EXAMPLE:
78
+ #
79
+ # spec_dir: spec/javascripts
80
+ #
81
+ spec_dir: spec/javascripts
@@ -0,0 +1,23 @@
1
+ module Jasmine
2
+ class Config
3
+
4
+ # Add your overrides or custom config code here
5
+
6
+ end
7
+ end
8
+
9
+
10
+ # Note - this is necessary for rspec2, which has removed the backtrace
11
+ module Jasmine
12
+ class SpecBuilder
13
+ def declare_spec(parent, spec)
14
+ me = self
15
+ example_name = spec["name"]
16
+ @spec_ids << spec["id"]
17
+ backtrace = @example_locations[parent.description + " " + example_name]
18
+ parent.it example_name, {} do
19
+ me.report_spec(spec["id"])
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,20 @@
1
+ $:.unshift(ENV['JASMINE_GEM_PATH']) if ENV['JASMINE_GEM_PATH'] # for gem testing purposes
2
+
3
+ require 'rubygems'
4
+ require 'jasmine'
5
+ require 'rspec'
6
+ jasmine_config_overrides = File.expand_path(File.join(File.dirname(__FILE__), 'jasmine_config.rb'))
7
+ require jasmine_config_overrides if File.exists?(jasmine_config_overrides)
8
+
9
+ jasmine_config = Jasmine::Config.new
10
+ spec_builder = Jasmine::SpecBuilder.new(jasmine_config)
11
+
12
+ should_stop = false
13
+
14
+ RSpec.configuration.after(:suite) do
15
+ spec_builder.stop if should_stop
16
+ end
17
+
18
+ spec_builder.start
19
+ should_stop = true
20
+ spec_builder.declare_suites
@@ -0,0 +1,32 @@
1
+ class JasmineGenerator < Rails::Generator::Base
2
+ def manifest
3
+ m = ::Rails::Generator::Manifest.new
4
+
5
+ m.directory "public/javascripts"
6
+ m.file "jasmine-example/src/Player.js", "public/javascripts/Player.js"
7
+ m.file "jasmine-example/src/Song.js", "public/javascripts/Song.js"
8
+
9
+ m.directory "spec/javascripts"
10
+ m.file "jasmine-example/spec/PlayerSpec.js", "spec/javascripts/PlayerSpec.js"
11
+
12
+ m.directory "spec/javascripts/helpers"
13
+ m.file "jasmine-example/spec/SpecHelper.js", "spec/javascripts/helpers/SpecHelper.js"
14
+
15
+ m.directory "spec/javascripts/support"
16
+ m.file "spec/javascripts/support/jasmine_runner.rb", "spec/javascripts/support/jasmine_runner.rb"
17
+ m.file "spec/javascripts/support/jasmine_config.rb", "spec/javascripts/support/jasmine_config.rb"
18
+ m.file "spec/javascripts/support/jasmine-rails.yml", "spec/javascripts/support/jasmine.yml"
19
+ m.readme "INSTALL"
20
+
21
+ unless ::Rails::VERSION::STRING[0,1] == "3"
22
+ m.directory "lib/tasks"
23
+ m.file "lib/tasks/jasmine.rake", "lib/tasks/jasmine.rake"
24
+ end
25
+ m
26
+ end
27
+
28
+ def file_name
29
+ "create_blog"
30
+ end
31
+
32
+ end
@@ -0,0 +1,9 @@
1
+ Jasmine has been installed with example specs.
2
+
3
+ To run the server:
4
+
5
+ rake jasmine
6
+
7
+ To run the automated CI task with Selenium:
8
+
9
+ rake jasmine:ci
@@ -0,0 +1,2 @@
1
+ require 'jasmine'
2
+ load 'jasmine/tasks/jasmine.rake'
@@ -0,0 +1,81 @@
1
+ # src_files
2
+ #
3
+ # Return an array of filepaths relative to src_dir to include before jasmine specs.
4
+ # Default: []
5
+ #
6
+ # EXAMPLE:
7
+ #
8
+ # src_files:
9
+ # - lib/source1.js
10
+ # - lib/source2.js
11
+ # - dist/**/*.js
12
+ #
13
+ src_files:
14
+ - public/javascripts/prototype.js
15
+ - public/javascripts/effects.js
16
+ - public/javascripts/controls.js
17
+ - public/javascripts/dragdrop.js
18
+ - public/javascripts/application.js
19
+ - public/javascripts/**/*.js
20
+
21
+ # stylesheets
22
+ #
23
+ # Return an array of stylesheet filepaths relative to src_dir to include before jasmine specs.
24
+ # Default: []
25
+ #
26
+ # EXAMPLE:
27
+ #
28
+ # stylesheets:
29
+ # - css/style.css
30
+ # - stylesheets/*.css
31
+ #
32
+ stylesheets:
33
+ - stylesheets/**/*.css
34
+
35
+ # helpers
36
+ #
37
+ # Return an array of filepaths relative to spec_dir to include before jasmine specs.
38
+ # Default: ["helpers/**/*.js"]
39
+ #
40
+ # EXAMPLE:
41
+ #
42
+ # helpers:
43
+ # - helpers/**/*.js
44
+ #
45
+ helpers:
46
+ - helpers/**/*.js
47
+
48
+ # spec_files
49
+ #
50
+ # Return an array of filepaths relative to spec_dir to include.
51
+ # Default: ["**/*[sS]pec.js"]
52
+ #
53
+ # EXAMPLE:
54
+ #
55
+ # spec_files:
56
+ # - **/*[sS]pec.js
57
+ #
58
+ spec_files:
59
+ - **/*[sS]pec.js
60
+
61
+ # src_dir
62
+ #
63
+ # Source directory path. Your src_files must be returned relative to this path. Will use root if left blank.
64
+ # Default: project root
65
+ #
66
+ # EXAMPLE:
67
+ #
68
+ # src_dir: public
69
+ #
70
+ src_dir:
71
+
72
+ # spec_dir
73
+ #
74
+ # Spec directory path. Your spec_files must be returned relative to this path.
75
+ # Default: spec/javascripts
76
+ #
77
+ # EXAMPLE:
78
+ #
79
+ # spec_dir: spec/javascripts
80
+ #
81
+ spec_dir: spec/javascripts