jasmine 1.0.1 → 1.0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008-2010 Pivotal Labs
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -3,17 +3,28 @@ $:.unshift(ENV['JASMINE_GEM_PATH']) if ENV['JASMINE_GEM_PATH'] # for gem testing
3
3
  require 'rubygems'
4
4
  require 'jasmine'
5
5
  jasmine_config_overrides = File.expand_path(File.join(File.dirname(__FILE__), 'jasmine_config.rb'))
6
- require jasmine_config_overrides if File.exists?(jasmine_config_overrides)
6
+ require jasmine_config_overrides if File.exist?(jasmine_config_overrides)
7
+ if Jasmine::rspec2?
8
+ require 'rspec'
9
+ else
10
+ require 'spec'
11
+ end
7
12
 
8
13
  jasmine_config = Jasmine::Config.new
9
14
  spec_builder = Jasmine::SpecBuilder.new(jasmine_config)
10
15
 
11
16
  should_stop = false
12
17
 
13
- Spec::Runner.configure do |config|
14
- config.after(:suite) do
18
+ if Jasmine::rspec2?
19
+ RSpec.configuration.after(:suite) do
15
20
  spec_builder.stop if should_stop
16
21
  end
22
+ else
23
+ Spec::Runner.configure do |config|
24
+ config.after(:suite) do
25
+ spec_builder.stop if should_stop
26
+ end
27
+ end
17
28
  end
18
29
 
19
30
  spec_builder.start
@@ -1,6 +1,5 @@
1
1
  require 'socket'
2
2
  require 'erb'
3
- require 'json/pure'
4
3
 
5
4
  module Jasmine
6
5
  def self.root
@@ -56,4 +55,12 @@ module Jasmine
56
55
  "#{file_name}?cachebust=#{digest}"
57
56
  end
58
57
  end
58
+
59
+ def self.rspec2?
60
+ Gem.available? "rspec", ">= 2.0"
61
+ end
62
+
63
+ def self.rails3?
64
+ Gem.available? "rails", ">= 3.0"
65
+ end
59
66
  end
@@ -59,9 +59,12 @@ module Jasmine
59
59
  File.open(template_path('INSTALL'), 'r').each_line do |line|
60
60
  puts line
61
61
  end
62
+ elsif argv[0] == "license"
63
+ puts File.new(expand(cwd, "MIT.LICENSE")).read
62
64
  else
63
65
  puts "unknown command #{argv}"
64
66
  puts "Usage: jasmine init"
67
+ puts " license"
65
68
  end
66
69
  end
67
70
  end
@@ -41,7 +41,7 @@ module Jasmine
41
41
 
42
42
  def windows?
43
43
  require 'rbconfig'
44
- ::Config::CONFIG['host_os'] =~ /mswin|mingw/
44
+ ::RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
45
45
  end
46
46
 
47
47
  def start_selenium_server
@@ -76,6 +76,10 @@ module Jasmine
76
76
  @client.eval_js(script)
77
77
  end
78
78
 
79
+ def json_generate(obj)
80
+ @client.json_generate(obj)
81
+ end
82
+
79
83
  def match_files(dir, patterns)
80
84
  dir = File.expand_path(dir)
81
85
  patterns.collect do |pattern|
@@ -1,6 +1,7 @@
1
1
  module Jasmine
2
2
  class SeleniumDriver
3
3
  def initialize(selenium_host, selenium_port, selenium_browser_start_command, http_address)
4
+ require 'json/pure' unless defined?(JSON)
4
5
  require 'selenium/client'
5
6
  @driver = Selenium::Client::Driver.new(
6
7
  selenium_host,
@@ -40,5 +41,9 @@ module Jasmine
40
41
  result = @driver.get_eval("try { eval(#{escaped_script}, window); } catch(err) { window.eval(#{escaped_script}); }")
41
42
  JSON.parse("{\"result\":#{result}}")["result"]
42
43
  end
44
+
45
+ def json_generate(obj)
46
+ JSON.generate(obj)
47
+ end
43
48
  end
44
49
  end
@@ -58,7 +58,7 @@ module Jasmine
58
58
  [
59
59
  200,
60
60
  { 'Content-Type' => 'text/html' },
61
- body
61
+ [body]
62
62
  ]
63
63
  end
64
64
  end
@@ -82,7 +82,7 @@ module Jasmine
82
82
  [
83
83
  200,
84
84
  { 'Content-Type' => 'application/javascript' },
85
- "document.write('<p>Couldn\\'t load #{env["PATH_INFO"]}!</p>');"
85
+ ["document.write('<p>Couldn\\'t load #{env["PATH_INFO"]}!</p>');"]
86
86
  ]
87
87
  end
88
88
  end
@@ -69,7 +69,7 @@ module Jasmine
69
69
  def load_results
70
70
  @spec_results = {}
71
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) { Object.toJSON(result) } else { JSON.stringify(result) }"))
72
+ @spec_results.merge!(eval_js("var result = jsApiReporter.resultsForSpecs(#{json_generate(slice)}); if (window.Prototype && Object.toJSON) { Object.toJSON(result) } else { JSON.stringify(result) }"))
73
73
  end
74
74
  @spec_results
75
75
  end
@@ -109,8 +109,14 @@ module Jasmine
109
109
  example_name = spec["name"]
110
110
  @spec_ids << spec["id"]
111
111
  backtrace = @example_locations[parent.description + " " + example_name]
112
- parent.it example_name, {}, backtrace do
113
- me.report_spec(spec["id"])
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
114
120
  end
115
121
  end
116
122
 
@@ -148,5 +154,9 @@ module Jasmine
148
154
  def eval_js(js)
149
155
  @runner.eval_js(js)
150
156
  end
157
+
158
+ def json_generate(obj)
159
+ @runner.json_generate(obj)
160
+ end
151
161
  end
152
162
  end
@@ -5,20 +5,33 @@ namespace :jasmine do
5
5
 
6
6
  desc "Run continuous integration tests"
7
7
  task :ci => "jasmine:require" do
8
- require "spec"
9
- require 'spec/rake/spectask'
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
10
15
 
11
- Spec::Rake::SpecTask.new(:jasmine_continuous_integration_runner) do |t|
12
- t.spec_opts = ["--color", "--format", "specdoc"]
13
- t.verbose = true
14
- t.spec_files = ['spec/javascripts/support/jasmine_runner.rb']
16
+ if Jasmine::rspec2?
17
+ RSpec::Core::RakeTask.new(:jasmine_continuous_integration_runner) do |t|
18
+ t.rspec_opts = ["--color", "--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
15
28
  end
16
29
  Rake::Task["jasmine_continuous_integration_runner"].invoke
17
30
  end
18
31
 
19
32
  task :server => "jasmine:require" do
20
33
  jasmine_config_overrides = 'spec/javascripts/support/jasmine_config.rb'
21
- require jasmine_config_overrides if File.exists?(jasmine_config_overrides)
34
+ require jasmine_config_overrides if File.exist?(jasmine_config_overrides)
22
35
 
23
36
  puts "your tests are here:"
24
37
  puts " http://localhost:8888/"
@@ -0,0 +1,32 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
2
+
3
+ describe "Jasmine bug fixes" do
4
+ before :each do
5
+ temp_dir_before
6
+ Dir::chdir @tmp
7
+
8
+ @bootstrap = "$:.unshift('#{@root}/lib')"
9
+ end
10
+
11
+ after :each do
12
+ temp_dir_after
13
+ end
14
+
15
+ module Foo end
16
+ describe "require 'json_pure'" do
17
+ it "should not happen until SeleniumDriver is initialized, which is late enough that it won't conflict with Rails" do
18
+ json_is_defined = `ruby -e "#{@bootstrap}; require 'jasmine'; puts defined?(JSON)"`
19
+ json_is_defined.chomp.should == "nil"
20
+ end
21
+
22
+ it "should happen when SeleniumDriver is initialized" do
23
+ json_is_defined = `ruby -e "#{@bootstrap}; require 'jasmine'; Jasmine::SeleniumDriver.new(nil, nil, nil, nil); puts defined?(JSON)"`
24
+ json_is_defined.chomp.should == "constant"
25
+ end
26
+
27
+ it "should not happen if another json implementation is already loaded" do
28
+ json_is_defined = `ruby -e "#{@bootstrap}; require 'jasmine'; JSON="123"; Jasmine::SeleniumDriver.new(nil, nil, nil, nil); puts defined?(JSON)"`
29
+ json_is_defined.chomp.should == "constant"
30
+ end
31
+ end
32
+ end
@@ -8,12 +8,16 @@ describe Jasmine::Config do
8
8
  temp_dir_before
9
9
 
10
10
  Dir::chdir @tmp
11
- `rails rails-project`
11
+ create_rails 'rails-project'
12
12
  Dir::chdir 'rails-project'
13
13
 
14
14
  FileUtils.cp_r(File.join(@root, 'generators'), 'vendor')
15
15
 
16
- `./script/generate jasmine`
16
+ if rails3?
17
+ raise Exception.new('rails 3 generators not yet implemented!')
18
+ else
19
+ `./script/generate jasmine`
20
+ end
17
21
 
18
22
  Dir::chdir @old_dir
19
23
 
@@ -73,9 +77,7 @@ describe Jasmine::Config do
73
77
 
74
78
  it "should parse ERB" do
75
79
  @config.stub!(:simple_config_file).and_return(File.expand_path(File.join(File.dirname(__FILE__), 'fixture/jasmine.erb.yml')))
76
- Dir.stub!(:glob).and_return do |glob_string|
77
- glob_string
78
- end
80
+ Dir.stub!(:glob).and_return { |glob_string| [glob_string] }
79
81
  @config.src_files.should == [
80
82
  'file0.js',
81
83
  'file1.js',
@@ -110,10 +112,8 @@ describe Jasmine::Config do
110
112
 
111
113
  describe "should use the first appearance of duplicate filenames" do
112
114
  before(:each) do
113
- Dir.stub!(:glob).and_return do |glob_string|
114
- glob_string
115
- end
116
- fake_config = Hash.new.stub!(:[]).and_return(["file1.ext", "file2.ext", "file1.ext"])
115
+ Dir.stub!(:glob).and_return { |glob_string| [glob_string] }
116
+ fake_config = Hash.new.stub!(:[]).and_return {|x| ["file1.ext", "file2.ext", "file1.ext"]}
117
117
  @config.stub!(:simple_config).and_return(fake_config)
118
118
  end
119
119
 
@@ -154,9 +154,7 @@ describe Jasmine::Config do
154
154
  it "simple_config stylesheets" do
155
155
  @config.stub!(:simple_config_file).and_return(File.join(@template_dir, 'spec/javascripts/support/jasmine.yml'))
156
156
  YAML.stub!(:load).and_return({'stylesheets' => ['foo.css', 'bar.css']})
157
- Dir.stub!(:glob).and_return do |glob_string|
158
- glob_string
159
- end
157
+ Dir.stub!(:glob).and_return { |glob_string| [glob_string] }
160
158
  @config.stylesheets.should == ['foo.css', 'bar.css']
161
159
  end
162
160
 
@@ -11,9 +11,7 @@ describe "Jasmine command line tool" do
11
11
  end
12
12
 
13
13
  it "should create files on init" do
14
- output = capture_stdout do
15
- Jasmine::CommandLineTool.new.process ["init"]
16
- end
14
+ output = capture_stdout { Jasmine::CommandLineTool.new.process ["init"] }
17
15
  output.should =~ /Jasmine has been installed with example specs./
18
16
 
19
17
  my_jasmine_lib = File.expand_path(File.join(@root, "lib"))
@@ -23,4 +21,9 @@ describe "Jasmine command line tool" do
23
21
  ci_output = `rake -E "#{bootstrap}" --trace jasmine:ci`
24
22
  ci_output.should =~ (/[1-9][0-9]* examples, 0 failures/)
25
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
26
29
  end
@@ -7,10 +7,16 @@ spec_builder = Jasmine::SpecBuilder.new(jasmine_config)
7
7
 
8
8
  should_stop = false
9
9
 
10
- Spec::Runner.configure do |config|
11
- config.after(:suite) do
10
+ if rspec2?
11
+ RSpec.configuration.after(:suite) do
12
12
  spec_builder.stop if should_stop
13
13
  end
14
+ else
15
+ Spec::Runner.configure do |config|
16
+ config.after(:suite) do
17
+ spec_builder.stop if should_stop
18
+ end
19
+ end
14
20
  end
15
21
 
16
22
  spec_builder.start
@@ -11,17 +11,21 @@ describe "Jasmine rails generator" do
11
11
  end
12
12
 
13
13
  it "should create files on init" do
14
- `rails rails-project`
15
- Dir::chdir 'rails-project'
14
+ if rails3? # todo -- get this working
15
+ raise Exception.new('rails 3 generators not yet implemented!')
16
+ else
17
+ create_rails 'rails-project'
18
+ Dir::chdir 'rails-project'
16
19
 
17
- FileUtils.cp_r(File.join(@root, 'generators'), 'vendor')
20
+ FileUtils.cp_r(File.join(@root, 'generators'), 'vendor')
18
21
 
19
- output = `./script/generate jasmine`
20
- output.should =~ /Jasmine has been installed with example specs./
22
+ output = `./script/generate jasmine`
23
+ output.should =~ /Jasmine has been installed with example specs./
21
24
 
22
- bootstrap = "$:.unshift('#{@root}/lib')"
23
- ENV['JASMINE_GEM_PATH'] = "#{@root}/lib"
24
- ci_output = `rake -E \"#{bootstrap}\" --trace jasmine:ci`
25
- ci_output.should =~ (/[1-9][0-9]* examples, 0 failures/)
25
+ bootstrap = "$:.unshift('#{@root}/lib')"
26
+ ENV['JASMINE_GEM_PATH'] = "#{@root}/lib"
27
+ ci_output = `rake -E \"#{bootstrap}\" --trace jasmine:ci`
28
+ ci_output.should =~ (/[1-9][0-9]* examples, 0 failures/)
29
+ end
26
30
  end
27
31
  end
@@ -43,9 +43,7 @@ describe "Jasmine.app" do
43
43
  end
44
44
 
45
45
  it "should serve focused suites when prefixing spec files with /__suite__/" do
46
- Dir.stub!(:glob).and_return do |glob_string|
47
- [glob_string]
48
- end
46
+ Dir.stub!(:glob).and_return { |glob_string| [glob_string] }
49
47
  get "/__suite__/file2.js"
50
48
  last_response.status.should == 200
51
49
  last_response.content_type.should == "text/html"
@@ -1,15 +1,36 @@
1
1
  require "rubygems"
2
2
  require "bundler"
3
3
  require 'stringio'
4
+ require 'tmpdir'
4
5
 
5
6
  Bundler.setup(:default, :test)
6
7
 
7
- require 'spec'
8
+ def rspec2?
9
+ Gem.available? "rspec", ">= 2.0"
10
+ end
11
+
12
+ def rails3?
13
+ Gem.available? "rails", ">= 3.0"
14
+ end
15
+
16
+ if rspec2?
17
+ require 'rspec'
18
+ else
19
+ require 'spec'
20
+ end
8
21
 
9
22
  $:.unshift(File.expand_path(File.join(File.dirname(__FILE__), "../lib")))
10
23
 
11
24
  require "jasmine"
12
25
 
26
+ def create_rails(name)
27
+ if rails3?
28
+ `rails new #{name}`
29
+ else
30
+ `rails #{name}`
31
+ end
32
+ end
33
+
13
34
  def create_temp_dir
14
35
  tmp = File.join(Dir.tmpdir, 'jasmine-gem-test')
15
36
  FileUtils.rm_r(tmp, :force => true)
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jasmine
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 89
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
9
  - 1
10
- version: 1.0.1
10
+ - 1
11
+ version: 1.0.1.1
11
12
  platform: ruby
12
13
  authors:
13
14
  - Rajan Agaskar
@@ -17,7 +18,7 @@ autorequire:
17
18
  bindir: bin
18
19
  cert_chain: []
19
20
 
20
- date: 2010-10-05 00:00:00 -07:00
21
+ date: 2010-11-09 00:00:00 -05:00
21
22
  default_executable: jasmine
22
23
  dependencies:
23
24
  - !ruby/object:Gem::Dependency
@@ -125,6 +126,7 @@ extensions: []
125
126
  extra_rdoc_files:
126
127
  - README.markdown
127
128
  files:
129
+ - MIT.LICENSE
128
130
  - generators/jasmine/jasmine_generator.rb
129
131
  - generators/jasmine/templates/INSTALL
130
132
  - generators/jasmine/templates/jasmine-example/SpecRunner.html
@@ -151,6 +153,7 @@ files:
151
153
  - lib/jasmine/spec_builder.rb
152
154
  - lib/jasmine/tasks/jasmine.rake
153
155
  - README.markdown
156
+ - spec/bug_fixes_spec.rb
154
157
  - spec/config_spec.rb
155
158
  - spec/jasmine_command_line_tool_spec.rb
156
159
  - spec/jasmine_self_test_config.rb
@@ -194,6 +197,7 @@ signing_key:
194
197
  specification_version: 3
195
198
  summary: Jasmine Runner for Ruby
196
199
  test_files:
200
+ - spec/bug_fixes_spec.rb
197
201
  - spec/config_spec.rb
198
202
  - spec/jasmine_command_line_tool_spec.rb
199
203
  - spec/jasmine_self_test_config.rb