josephholsten-jasmine 1.1.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (135) hide show
  1. data/.gitignore +11 -0
  2. data/.gitmodules +3 -0
  3. data/Gemfile +5 -0
  4. data/HOW_TO_TEST.markdown +9 -0
  5. data/MIT.LICENSE +20 -0
  6. data/README.markdown +71 -0
  7. data/RELEASE.markdown +22 -0
  8. data/Rakefile +76 -0
  9. data/bin/jasmine +6 -0
  10. data/generators/jasmine/jasmine_generator.rb +32 -0
  11. data/generators/jasmine/templates/INSTALL +9 -0
  12. data/generators/jasmine/templates/jasmine-example/SpecRunner.html +27 -0
  13. data/generators/jasmine/templates/jasmine-example/spec/PlayerSpec.js +58 -0
  14. data/generators/jasmine/templates/jasmine-example/spec/SpecHelper.js +9 -0
  15. data/generators/jasmine/templates/jasmine-example/src/Player.js +22 -0
  16. data/generators/jasmine/templates/jasmine-example/src/Song.js +7 -0
  17. data/generators/jasmine/templates/lib/tasks/jasmine.rake +8 -0
  18. data/generators/jasmine/templates/spec/javascripts/support/jasmine-rails.yml +81 -0
  19. data/generators/jasmine/templates/spec/javascripts/support/jasmine.yml +73 -0
  20. data/generators/jasmine/templates/spec/javascripts/support/jasmine_config.rb +23 -0
  21. data/generators/jasmine/templates/spec/javascripts/support/jasmine_runner.rb +32 -0
  22. data/jasmine/Gemfile +6 -0
  23. data/jasmine/Gemfile.lock +33 -0
  24. data/jasmine/HowToRelease.markdown +29 -0
  25. data/jasmine/MIT.LICENSE +20 -0
  26. data/jasmine/README.markdown +50 -0
  27. data/jasmine/Rakefile +166 -0
  28. data/jasmine/cruise_config.rb +21 -0
  29. data/jasmine/example/SpecRunner.html +27 -0
  30. data/jasmine/example/spec/PlayerSpec.js +58 -0
  31. data/jasmine/example/spec/SpecHelper.js +9 -0
  32. data/jasmine/example/src/Player.js +22 -0
  33. data/jasmine/example/src/Song.js +7 -0
  34. data/jasmine/images/jasmine_favicon.png +0 -0
  35. data/jasmine/jsdoc-template/allclasses.tmpl +17 -0
  36. data/jasmine/jsdoc-template/allfiles.tmpl +56 -0
  37. data/jasmine/jsdoc-template/class.tmpl +646 -0
  38. data/jasmine/jsdoc-template/index.tmpl +39 -0
  39. data/jasmine/jsdoc-template/publish.js +184 -0
  40. data/jasmine/jsdoc-template/static/default.css +162 -0
  41. data/jasmine/jsdoc-template/static/header.html +2 -0
  42. data/jasmine/jsdoc-template/static/index.html +19 -0
  43. data/jasmine/jsdoc-template/symbol.tmpl +35 -0
  44. data/jasmine/jshint/jshint.js +5919 -0
  45. data/jasmine/jshint/run.js +98 -0
  46. data/jasmine/lib/jasmine-html.js +190 -0
  47. data/jasmine/lib/jasmine.css +166 -0
  48. data/jasmine/lib/jasmine.js +2445 -0
  49. data/jasmine/lib/json2.js +478 -0
  50. data/jasmine/spec/node_suite.js +233 -0
  51. data/jasmine/spec/runner.html +82 -0
  52. data/jasmine/spec/suites/BaseSpec.js +27 -0
  53. data/jasmine/spec/suites/CustomMatchersSpec.js +97 -0
  54. data/jasmine/spec/suites/EnvSpec.js +158 -0
  55. data/jasmine/spec/suites/ExceptionsSpec.js +107 -0
  56. data/jasmine/spec/suites/JsApiReporterSpec.js +103 -0
  57. data/jasmine/spec/suites/MatchersSpec.js +795 -0
  58. data/jasmine/spec/suites/MockClockSpec.js +38 -0
  59. data/jasmine/spec/suites/MultiReporterSpec.js +45 -0
  60. data/jasmine/spec/suites/NestedResultsSpec.js +54 -0
  61. data/jasmine/spec/suites/PrettyPrintSpec.js +93 -0
  62. data/jasmine/spec/suites/QueueSpec.js +23 -0
  63. data/jasmine/spec/suites/ReporterSpec.js +56 -0
  64. data/jasmine/spec/suites/RunnerSpec.js +267 -0
  65. data/jasmine/spec/suites/SpecRunningSpec.js +1253 -0
  66. data/jasmine/spec/suites/SpecSpec.js +124 -0
  67. data/jasmine/spec/suites/SpySpec.js +201 -0
  68. data/jasmine/spec/suites/SuiteSpec.js +120 -0
  69. data/jasmine/spec/suites/TrivialConsoleReporterSpec.js +431 -0
  70. data/jasmine/spec/suites/TrivialReporterSpec.js +238 -0
  71. data/jasmine/spec/suites/UtilSpec.js +39 -0
  72. data/jasmine/spec/suites/WaitsForBlockSpec.js +118 -0
  73. data/jasmine/src/Block.js +22 -0
  74. data/jasmine/src/Env.js +264 -0
  75. data/jasmine/src/JsApiReporter.js +102 -0
  76. data/jasmine/src/Matchers.js +354 -0
  77. data/jasmine/src/MultiReporter.js +35 -0
  78. data/jasmine/src/NestedResults.js +80 -0
  79. data/jasmine/src/PrettyPrinter.js +123 -0
  80. data/jasmine/src/Queue.js +99 -0
  81. data/jasmine/src/Reporter.js +31 -0
  82. data/jasmine/src/Runner.js +77 -0
  83. data/jasmine/src/Spec.js +242 -0
  84. data/jasmine/src/Suite.js +82 -0
  85. data/jasmine/src/WaitsBlock.js +15 -0
  86. data/jasmine/src/WaitsForBlock.js +54 -0
  87. data/jasmine/src/base.js +608 -0
  88. data/jasmine/src/console/TrivialConsoleReporter.js +144 -0
  89. data/jasmine/src/html/TrivialReporter.js +190 -0
  90. data/jasmine/src/html/jasmine.css +166 -0
  91. data/jasmine/src/mock-timeout.js +183 -0
  92. data/jasmine/src/util.js +67 -0
  93. data/jasmine/src/version.json +5 -0
  94. data/jasmine.gemspec +52 -0
  95. data/lib/generators/jasmine/examples/USAGE +11 -0
  96. data/lib/generators/jasmine/examples/examples_generator.rb +19 -0
  97. data/lib/generators/jasmine/examples/templates/public/javascripts/jasmine_examples/Player.js +22 -0
  98. data/lib/generators/jasmine/examples/templates/public/javascripts/jasmine_examples/Song.js +7 -0
  99. data/lib/generators/jasmine/examples/templates/spec/javascripts/helpers/SpecHelper.js +9 -0
  100. data/lib/generators/jasmine/examples/templates/spec/javascripts/jasmine_examples/PlayerSpec.js +58 -0
  101. data/lib/generators/jasmine/install/USAGE +11 -0
  102. data/lib/generators/jasmine/install/install_generator.rb +18 -0
  103. data/lib/generators/jasmine/install/templates/spec/javascripts/helpers/.gitkeep +0 -0
  104. data/lib/generators/jasmine/install/templates/spec/javascripts/support/jasmine.yml +81 -0
  105. data/lib/generators/jasmine/install/templates/spec/javascripts/support/jasmine_config.rb +23 -0
  106. data/lib/generators/jasmine/install/templates/spec/javascripts/support/jasmine_runner.rb +20 -0
  107. data/lib/generators/jasmine/jasmine_generator.rb +32 -0
  108. data/lib/generators/jasmine/templates/INSTALL +9 -0
  109. data/lib/generators/jasmine/templates/lib/tasks/jasmine.rake +2 -0
  110. data/lib/generators/jasmine/templates/spec/javascripts/support/jasmine-rails.yml +81 -0
  111. data/lib/generators/jasmine/templates/spec/javascripts/support/jasmine.yml +73 -0
  112. data/lib/generators/jasmine/templates/spec/javascripts/support/jasmine_config.rb +23 -0
  113. data/lib/generators/jasmine/templates/spec/javascripts/support/jasmine_runner.rb +32 -0
  114. data/lib/jasmine/base.rb +66 -0
  115. data/lib/jasmine/command_line_tool.rb +72 -0
  116. data/lib/jasmine/config.rb +190 -0
  117. data/lib/jasmine/railtie.rb +20 -0
  118. data/lib/jasmine/run.html.erb +44 -0
  119. data/lib/jasmine/selenium_driver.rb +49 -0
  120. data/lib/jasmine/server.rb +106 -0
  121. data/lib/jasmine/spec_builder.rb +162 -0
  122. data/lib/jasmine/tasks/jasmine.rake +44 -0
  123. data/lib/jasmine/version.rb +3 -0
  124. data/lib/jasmine.rb +14 -0
  125. data/spec/config_spec.rb +308 -0
  126. data/spec/fixture/jasmine.erb.yml +4 -0
  127. data/spec/jasmine_command_line_tool_spec.rb +29 -0
  128. data/spec/jasmine_pojs_spec.rb +51 -0
  129. data/spec/jasmine_rails2_spec.rb +93 -0
  130. data/spec/jasmine_rails3_spec.rb +71 -0
  131. data/spec/jasmine_self_test_config.rb +15 -0
  132. data/spec/jasmine_self_test_spec.rb +24 -0
  133. data/spec/server_spec.rb +80 -0
  134. data/spec/spec_helper.rb +65 -0
  135. metadata +386 -0
@@ -0,0 +1,162 @@
1
+ require 'enumerator'
2
+
3
+ module Jasmine
4
+ class SpecBuilder
5
+ attr_accessor :suites
6
+
7
+ def initialize(config)
8
+ @config = config
9
+ @spec_files = config.spec_files
10
+ @runner = config
11
+ @spec_ids = []
12
+ end
13
+
14
+ def start
15
+ guess_example_locations
16
+
17
+ @runner.start
18
+ load_suite_info
19
+ wait_for_suites_to_finish_running
20
+ end
21
+
22
+ def stop
23
+ @runner.stop
24
+ end
25
+
26
+ def script_path
27
+ File.expand_path(__FILE__)
28
+ end
29
+
30
+ def guess_example_locations
31
+ @example_locations = {}
32
+
33
+ example_name_parts = []
34
+ previous_indent_level = 0
35
+ @config.spec_files_full_paths.each do |filename|
36
+ line_number = 1
37
+ File.open(filename, "r") do |file|
38
+ file.readlines.each do |line|
39
+ match = /^(\s*)(describe|it)\s*\(\s*["'](.*)["']\s*,\s*function/.match(line)
40
+ if (match)
41
+ indent_level = match[1].length / 2
42
+ example_name = match[3]
43
+ example_name_parts[indent_level] = example_name
44
+
45
+ full_example_name = example_name_parts.slice(0, indent_level + 1).join(" ")
46
+ @example_locations[full_example_name] = "#{filename}:#{line_number}: in `it'"
47
+ end
48
+ line_number += 1
49
+ end
50
+ end
51
+ end
52
+ end
53
+
54
+ def load_suite_info
55
+ started = Time.now
56
+ while !eval_js('return jsApiReporter && jsApiReporter.started') do
57
+ raise "couldn't connect to Jasmine after 60 seconds" if (started + 60 < Time.now)
58
+ sleep 0.1
59
+ end
60
+
61
+ @suites = eval_js("var result = jsApiReporter.suites(); if (window.Prototype && Object.toJSON) { return Object.toJSON(result) } else { return JSON.stringify(result) }")
62
+ end
63
+
64
+ def results_for(spec_id)
65
+ @spec_results ||= load_results
66
+ @spec_results[spec_id.to_s]
67
+ end
68
+
69
+ def load_results
70
+ @spec_results = {}
71
+ @spec_ids.each_slice(50) do |slice|
72
+ @spec_results.merge!(eval_js("var result = jsApiReporter.resultsForSpecs(#{json_generate(slice)}); if (window.Prototype && Object.toJSON) { return Object.toJSON(result) } else { return JSON.stringify(result) }"))
73
+ end
74
+ @spec_results
75
+ end
76
+
77
+ def wait_for_suites_to_finish_running
78
+ puts "Waiting for suite to finish in browser ..."
79
+ while !eval_js('return jsApiReporter.finished') do
80
+ sleep 0.1
81
+ end
82
+ end
83
+
84
+ def declare_suites
85
+ me = self
86
+ suites.each do |suite|
87
+ declare_suite(self, suite)
88
+ end
89
+ end
90
+
91
+ def declare_suite(parent, suite)
92
+ me = self
93
+ parent.describe suite["name"] do
94
+ suite["children"].each do |suite_or_spec|
95
+ type = suite_or_spec["type"]
96
+ if type == "suite"
97
+ me.declare_suite(self, suite_or_spec)
98
+ elsif type == "spec"
99
+ me.declare_spec(self, suite_or_spec)
100
+ else
101
+ raise "unknown type #{type} for #{suite_or_spec.inspect}"
102
+ end
103
+ end
104
+ end
105
+ end
106
+
107
+ def declare_spec(parent, spec)
108
+ me = self
109
+ example_name = spec["name"]
110
+ @spec_ids << spec["id"]
111
+ backtrace = @example_locations[parent.description + " " + example_name]
112
+ if Jasmine::rspec2?
113
+ parent.it example_name, {} do
114
+ me.report_spec(spec["id"])
115
+ end
116
+ else
117
+ parent.it example_name, {}, backtrace do
118
+ me.report_spec(spec["id"])
119
+ end
120
+ end
121
+ end
122
+
123
+ def report_spec(spec_id)
124
+ spec_results = results_for(spec_id)
125
+ out = ""
126
+ messages = spec_results['messages'].each do |message|
127
+ case
128
+ when message["type"] == "log"
129
+ puts message["text"]
130
+ puts "\n"
131
+ else
132
+ unless message["message"] =~ /^Passed.$/
133
+ STDERR << message["message"]
134
+ STDERR << "\n"
135
+
136
+ out << message["message"]
137
+ out << "\n"
138
+ end
139
+
140
+ if !message["passed"] && message["trace"]["stack"]
141
+ stack_trace = message["trace"]["stack"].gsub(/<br \/>/, "\n").gsub(/<\/?b>/, " ")
142
+ STDERR << stack_trace.gsub(/\(.*\)@http:\/\/localhost:[0-9]+\/specs\//, "/spec/")
143
+ STDERR << "\n"
144
+ end
145
+ end
146
+
147
+ end
148
+ fail out unless spec_results['result'] == 'passed'
149
+ puts out unless out.empty?
150
+ end
151
+
152
+ private
153
+
154
+ def eval_js(js)
155
+ @runner.eval_js(js)
156
+ end
157
+
158
+ def json_generate(obj)
159
+ @runner.json_generate(obj)
160
+ end
161
+ end
162
+ end
@@ -0,0 +1,44 @@
1
+ namespace :jasmine do
2
+ task :require do
3
+ require 'jasmine'
4
+ end
5
+
6
+ desc "Run continuous integration tests"
7
+ task :ci => "jasmine:require" do
8
+ if Jasmine::rspec2?
9
+ require "rspec"
10
+ require "rspec/core/rake_task"
11
+ else
12
+ require "spec"
13
+ require 'spec/rake/spectask'
14
+ end
15
+
16
+ if Jasmine::rspec2?
17
+ RSpec::Core::RakeTask.new(:jasmine_continuous_integration_runner) do |t|
18
+ t.rspec_opts = ["--colour", "--format", "progress"]
19
+ t.verbose = true
20
+ t.pattern = ['spec/javascripts/support/jasmine_runner.rb']
21
+ end
22
+ else
23
+ Spec::Rake::SpecTask.new(:jasmine_continuous_integration_runner) do |t|
24
+ t.spec_opts = ["--color", "--format", "specdoc"]
25
+ t.verbose = true
26
+ t.spec_files = ['spec/javascripts/support/jasmine_runner.rb']
27
+ end
28
+ end
29
+ Rake::Task["jasmine_continuous_integration_runner"].invoke
30
+ end
31
+
32
+ task :server => "jasmine:require" do
33
+ jasmine_config_overrides = './spec/javascripts/support/jasmine_config.rb'
34
+ require jasmine_config_overrides if File.exist?(jasmine_config_overrides)
35
+
36
+ puts "your tests are here:"
37
+ puts " http://localhost:8888/"
38
+
39
+ Jasmine::Config.new.start_server
40
+ end
41
+ end
42
+
43
+ desc "Run specs via server"
44
+ task :jasmine => ['jasmine:server']
@@ -0,0 +1,3 @@
1
+ module Jasmine
2
+ VERSION = "1.1.0.pre.1"
3
+ end
data/lib/jasmine.rb ADDED
@@ -0,0 +1,14 @@
1
+ jasmine_files = ['base',
2
+ 'config',
3
+ 'server',
4
+ 'selenium_driver',
5
+ 'spec_builder',
6
+ 'command_line_tool']
7
+
8
+ jasmine_files.each do |file|
9
+ require File.join('jasmine', file)
10
+ end
11
+
12
+ require File.join('jasmine', "railtie") if Jasmine.rails3?
13
+
14
+
@@ -0,0 +1,308 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
2
+ require 'selenium-webdriver'
3
+
4
+ describe Jasmine::Config do
5
+ describe "configuration" do
6
+ before :each do
7
+ temp_dir_before
8
+
9
+ Dir::chdir @tmp
10
+ dir_name = "test_js_project"
11
+ `mkdir -p #{dir_name}`
12
+ Dir::chdir dir_name
13
+ `#{@root}/bin/jasmine init .`
14
+
15
+ @project_dir = Dir.pwd
16
+
17
+ @template_dir = File.expand_path(File.join(@root, "generators/jasmine/templates"))
18
+ @config = Jasmine::Config.new
19
+ end
20
+
21
+ after(:each) do
22
+ temp_dir_after
23
+ end
24
+
25
+ describe "defaults" do
26
+ it "src_dir uses root when src dir is blank" do
27
+ @config.stub!(:project_root).and_return('some_project_root')
28
+ @config.stub!(:simple_config_file).and_return(File.join(@template_dir, 'spec/javascripts/support/jasmine.yml'))
29
+ YAML.stub!(:load).and_return({'src_dir' => nil})
30
+ @config.src_dir.should == 'some_project_root'
31
+ end
32
+
33
+ it "should use correct default yaml config" do
34
+ @config.stub!(:project_root).and_return('some_project_root')
35
+ @config.simple_config_file.should == (File.join('some_project_root', 'spec/javascripts/support/jasmine.yml'))
36
+ end
37
+ end
38
+
39
+ describe "simple_config" do
40
+ before(:each) do
41
+ @config.stub!(:src_dir).and_return(File.join(@project_dir, "."))
42
+ @config.stub!(:spec_dir).and_return(File.join(@project_dir, "spec/javascripts"))
43
+ end
44
+
45
+ describe "using default jasmine.yml" do
46
+ before(:each) do
47
+ @config.stub!(:simple_config_file).and_return(File.join(@template_dir, 'spec/javascripts/support/jasmine.yml'))
48
+ end
49
+
50
+ it "should find the source files" do
51
+ @config.src_files.should =~ ['public/javascripts/Player.js', 'public/javascripts/Song.js']
52
+ end
53
+
54
+ it "should find the stylesheet files" do
55
+ @config.stylesheets.should == []
56
+ end
57
+
58
+ it "should find the spec files" do
59
+ @config.spec_files.should == ['PlayerSpec.js']
60
+ end
61
+
62
+ it "should find any helpers" do
63
+ @config.helpers.should == ['helpers/SpecHelper.js']
64
+ end
65
+
66
+ it "should build an array of all the JavaScript files to include, source files then spec files" do
67
+ @config.js_files.should == [
68
+ '/public/javascripts/Player.js',
69
+ '/public/javascripts/Song.js',
70
+ '/__spec__/helpers/SpecHelper.js',
71
+ '/__spec__/PlayerSpec.js'
72
+ ]
73
+ end
74
+
75
+ it "should allow the js_files to be filtered" do
76
+ @config.js_files("PlayerSpec.js").should == [
77
+ '/public/javascripts/Player.js',
78
+ '/public/javascripts/Song.js',
79
+ '/__spec__/helpers/SpecHelper.js',
80
+ '/__spec__/PlayerSpec.js'
81
+ ]
82
+ end
83
+
84
+ it "should report the full paths of the spec files" do
85
+ @config.spec_files_full_paths.should == [File.join(@project_dir, 'spec/javascripts/PlayerSpec.js')]
86
+ end
87
+ end
88
+
89
+ it "should parse ERB" do
90
+ @config.stub!(:simple_config_file).and_return(File.expand_path(File.join(@root, 'spec', 'fixture','jasmine.erb.yml')))
91
+ Dir.stub!(:glob).and_return { |glob_string| [glob_string] }
92
+ @config.src_files.should == ['file0.js', 'file1.js', 'file2.js',]
93
+ end
94
+
95
+ describe "if jasmine.yml not found" do
96
+ before(:each) do
97
+ File.stub!(:exist?).and_return(false)
98
+ end
99
+
100
+ it "should default to loading no source files" do
101
+ @config.src_files.should be_empty
102
+ end
103
+
104
+ it "should default to loading no stylesheet files" do
105
+ @config.stylesheets.should be_empty
106
+ end
107
+
108
+ end
109
+
110
+ describe "if jasmine.yml is empty" do
111
+ before(:each) do
112
+ @config.stub!(:simple_config_file).and_return(File.join(@template_dir, 'spec/javascripts/support/jasmine.yml'))
113
+ YAML.stub!(:load).and_return(false)
114
+ end
115
+
116
+ it "should default to loading no source files" do
117
+ @config.src_files.should be_empty
118
+ end
119
+
120
+ it "should default to loading no stylesheet files" do
121
+ @config.stylesheets.should be_empty
122
+ end
123
+ end
124
+
125
+ describe "should use the first appearance of duplicate filenames" do
126
+ before(:each) do
127
+ Dir.stub!(:glob).and_return { |glob_string| [glob_string] }
128
+ fake_config = Hash.new.stub!(:[]).and_return { |x| ["file1.ext", "file2.ext", "file1.ext"] }
129
+ @config.stub!(:simple_config).and_return(fake_config)
130
+ end
131
+
132
+ it "src_files" do
133
+ @config.src_files.should == ['file1.ext', 'file2.ext']
134
+ end
135
+
136
+ it "stylesheets" do
137
+ @config.stylesheets.should == ['file1.ext', 'file2.ext']
138
+ end
139
+
140
+ it "spec_files" do
141
+ @config.spec_files.should == ['file1.ext', 'file2.ext']
142
+ end
143
+
144
+ it "helpers" do
145
+ @config.spec_files.should == ['file1.ext', 'file2.ext']
146
+ end
147
+
148
+ it "js_files" do
149
+ @config.js_files.should == ["/file1.ext",
150
+ "/file2.ext",
151
+ "/__spec__/file1.ext",
152
+ "/__spec__/file2.ext",
153
+ "/__spec__/file1.ext",
154
+ "/__spec__/file2.ext"]
155
+ end
156
+
157
+ it "spec_files_full_paths" do
158
+ @config.spec_files_full_paths.should == [
159
+ File.expand_path("spec/javascripts/file1.ext", @project_dir),
160
+ File.expand_path("spec/javascripts/file2.ext", @project_dir)
161
+ ]
162
+ end
163
+ end
164
+
165
+ describe "should allow .gitignore style negation (!pattern)" do
166
+ before(:each) do
167
+ Dir.stub!(:glob).and_return { |glob_string| [glob_string] }
168
+ fake_config = Hash.new.stub!(:[]).and_return { |x| ["file1.ext", "!file1.ext", "file2.ext"] }
169
+ @config.stub!(:simple_config).and_return(fake_config)
170
+ end
171
+
172
+ it "should not contain negated files" do
173
+ @config.src_files.should == ["file2.ext"]
174
+ end
175
+ end
176
+
177
+ it "simple_config stylesheets" do
178
+ @config.stub!(:simple_config_file).and_return(File.join(@template_dir, 'spec/javascripts/support/jasmine.yml'))
179
+
180
+ YAML.stub!(:load).and_return({'stylesheets' => ['foo.css', 'bar.css']})
181
+ Dir.stub!(:glob).and_return { |glob_string| [glob_string] }
182
+
183
+ @config.stylesheets.should == ['foo.css', 'bar.css']
184
+ end
185
+
186
+ it "using rails jasmine.yml" do
187
+ ['public/javascripts/prototype.js',
188
+ 'public/javascripts/effects.js',
189
+ 'public/javascripts/controls.js',
190
+ 'public/javascripts/dragdrop.js',
191
+ 'public/javascripts/application.js'].each { |f| `touch #{f}` }
192
+
193
+ @config.stub!(:simple_config_file).and_return(File.join(@template_dir, 'spec/javascripts/support/jasmine-rails.yml'))
194
+
195
+ @config.spec_files.should == ['PlayerSpec.js']
196
+ @config.helpers.should == ['helpers/SpecHelper.js']
197
+ @config.src_files.should == ['public/javascripts/prototype.js',
198
+ 'public/javascripts/effects.js',
199
+ 'public/javascripts/controls.js',
200
+ 'public/javascripts/dragdrop.js',
201
+ 'public/javascripts/application.js',
202
+ 'public/javascripts/Player.js',
203
+ 'public/javascripts/Song.js']
204
+ @config.js_files.should == [
205
+ '/public/javascripts/prototype.js',
206
+ '/public/javascripts/effects.js',
207
+ '/public/javascripts/controls.js',
208
+ '/public/javascripts/dragdrop.js',
209
+ '/public/javascripts/application.js',
210
+ '/public/javascripts/Player.js',
211
+ '/public/javascripts/Song.js',
212
+ '/__spec__/helpers/SpecHelper.js',
213
+ '/__spec__/PlayerSpec.js',
214
+ ]
215
+ @config.js_files("PlayerSpec.js").should == [
216
+ '/public/javascripts/prototype.js',
217
+ '/public/javascripts/effects.js',
218
+ '/public/javascripts/controls.js',
219
+ '/public/javascripts/dragdrop.js',
220
+ '/public/javascripts/application.js',
221
+ '/public/javascripts/Player.js',
222
+ '/public/javascripts/Song.js',
223
+ '/__spec__/helpers/SpecHelper.js',
224
+ '/__spec__/PlayerSpec.js'
225
+ ]
226
+ end
227
+ end
228
+ end
229
+
230
+ describe "environment variables" do
231
+ def stub_env_hash(hash)
232
+ ENV.stub!(:[]) do |arg|
233
+ hash[arg]
234
+ end
235
+ end
236
+ describe "browser configuration" do
237
+ it "should use firefox by default" do
238
+ stub_env_hash({"JASMINE_BROWSER" => nil})
239
+ config = Jasmine::Config.new
240
+ config.stub!(:start_jasmine_server)
241
+ Jasmine::SeleniumDriver.should_receive(:new).
242
+ with("firefox", anything).
243
+ and_return(mock(Jasmine::SeleniumDriver, :connect => true))
244
+ config.start
245
+ end
246
+
247
+ it "should use ENV['JASMINE_BROWSER'] if set" do
248
+ stub_env_hash({"JASMINE_BROWSER" => "mosaic"})
249
+ config = Jasmine::Config.new
250
+ config.stub!(:start_jasmine_server)
251
+ Jasmine::SeleniumDriver.should_receive(:new).
252
+ with("mosaic", anything).
253
+ and_return(mock(Jasmine::SeleniumDriver, :connect => true))
254
+ config.start
255
+ end
256
+ end
257
+
258
+ describe "jasmine host" do
259
+ it "should use http://localhost by default" do
260
+ stub_env_hash({})
261
+ config = Jasmine::Config.new
262
+ config.instance_variable_set(:@jasmine_server_port, '1234')
263
+ config.stub!(:start_jasmine_server)
264
+
265
+ Jasmine::SeleniumDriver.should_receive(:new).
266
+ with(anything, "http://localhost:1234/").
267
+ and_return(mock(Jasmine::SeleniumDriver, :connect => true))
268
+ config.start
269
+ end
270
+
271
+ it "should use ENV['JASMINE_HOST'] if set" do
272
+ stub_env_hash({"JASMINE_HOST" => "http://some_host"})
273
+ config = Jasmine::Config.new
274
+ config.instance_variable_set(:@jasmine_server_port, '1234')
275
+ config.stub!(:start_jasmine_server)
276
+
277
+ Jasmine::SeleniumDriver.should_receive(:new).
278
+ with(anything, "http://some_host:1234/").
279
+ and_return(mock(Jasmine::SeleniumDriver, :connect => true))
280
+ config.start
281
+ end
282
+
283
+ it "should use ENV['JASMINE_PORT'] if set" do
284
+ stub_env_hash({"JASMINE_PORT" => "4321"})
285
+ config = Jasmine::Config.new
286
+ Jasmine.stub!(:wait_for_listener)
287
+ config.stub!(:start_server)
288
+ Jasmine::SeleniumDriver.should_receive(:new).
289
+ with(anything, "http://localhost:4321/").
290
+ and_return(mock(Jasmine::SeleniumDriver, :connect => true))
291
+ config.start
292
+ end
293
+ end
294
+
295
+ describe "external selenium server" do
296
+ it "should use an external selenium server if SELENIUM_SERVER is set" do
297
+ stub_env_hash({"SELENIUM_SERVER" => "http://myseleniumserver.com:4441"})
298
+ Selenium::WebDriver.should_receive(:for).with(:remote, :url => "http://myseleniumserver.com:4441", :desired_capabilities => :firefox)
299
+ Jasmine::SeleniumDriver.new('firefox', 'http://localhost:8888')
300
+ end
301
+ it "should use an local selenium server with a specific port if SELENIUM_SERVER_PORT is set" do
302
+ stub_env_hash({"SELENIUM_SERVER_PORT" => "4441"})
303
+ Selenium::WebDriver.should_receive(:for).with(:remote, :url => "http://localhost:4441/wd/hub", :desired_capabilities => :firefox)
304
+ Jasmine::SeleniumDriver.new('firefox', 'http://localhost:8888')
305
+ end
306
+ end
307
+ end
308
+ end
@@ -0,0 +1,4 @@
1
+ src_files:
2
+ <% 3.times do |i| %>
3
+ - <%= "file#{i}.js" %>
4
+ <% end %>
@@ -0,0 +1,29 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
2
+
3
+ describe "Jasmine command line tool" do
4
+ before :each do
5
+ temp_dir_before
6
+ Dir::chdir @tmp
7
+ end
8
+
9
+ after :each do
10
+ temp_dir_after
11
+ end
12
+
13
+ it "should create files on init" do
14
+ output = capture_stdout { Jasmine::CommandLineTool.new.process ["init"] }
15
+ output.should =~ /Jasmine has been installed with example specs./
16
+
17
+ my_jasmine_lib = File.expand_path(File.join(@root, "lib"))
18
+ bootstrap = "$:.unshift('#{my_jasmine_lib}')"
19
+
20
+ ENV['JASMINE_GEM_PATH'] = "#{@root}/lib"
21
+ ci_output = `rake -E "#{bootstrap}" --trace jasmine:ci`
22
+ ci_output.should =~ (/[1-9][0-9]* examples, 0 failures/)
23
+ end
24
+
25
+ it "should include license info" do
26
+ output = capture_stdout { Jasmine::CommandLineTool.new.process ["license"] }
27
+ output.should =~ /Copyright/
28
+ end
29
+ end
@@ -0,0 +1,51 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
2
+
3
+ describe "POJS jasmine install" do
4
+
5
+ before :each do
6
+ temp_dir_before
7
+ Dir::chdir @tmp
8
+ @install_directory = 'pojs-example'
9
+ Dir::mkdir @install_directory
10
+ Dir::chdir @install_directory
11
+ end
12
+
13
+ after :each do
14
+ temp_dir_after
15
+ end
16
+
17
+ context "when the Jasmine generators are available" do
18
+ before :each do
19
+ `jasmine init`
20
+ end
21
+
22
+ it "should find the Jasmine configuration files" do
23
+ File.exists?("spec/javascripts/support/jasmine.yml").should == true
24
+ File.exists?("spec/javascripts/support/jasmine_runner.rb").should == true
25
+ File.exists?("spec/javascripts/support/jasmine_config.rb").should == true
26
+ end
27
+
28
+ it "should find the Jasmine example files" do
29
+ File.exists?("public/javascripts/Player.js").should == true
30
+ File.exists?("public/javascripts/Song.js").should == true
31
+
32
+ File.exists?("spec/javascripts/PlayerSpec.js").should == true
33
+ File.exists?("spec/javascripts/helpers/SpecHelper.js").should == true
34
+
35
+ File.exists?("spec/javascripts/support/jasmine.yml").should == true
36
+ File.exists?("spec/javascripts/support/jasmine_runner.rb").should == true
37
+ File.exists?("spec/javascripts/support/jasmine_config.rb").should == true
38
+ end
39
+
40
+ it "should show jasmine rake task" do
41
+ output = `rake -T`
42
+ output.should include("jasmine ")
43
+ output.should include("jasmine:ci")
44
+ end
45
+
46
+ it "should successfully run rake jasmine:ci" do
47
+ output = `rake jasmine:ci`
48
+ end
49
+
50
+ end
51
+ end