jasmine 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -85,7 +85,7 @@ if Jasmine::Dependencies.rspec2?
85
85
  context "when rails 3 is present and the application pipeline is in use" do
86
86
  before do
87
87
  Gem::Specification.should_receive(:find_by_name).with("rails", ">= 3.0").and_return(true)
88
- application.stub(:assets).and_return(rails_application_assets)
88
+ application.stub(:assets).and_return(rails_application_assets)
89
89
  end
90
90
  let(:rails3_present) { true }
91
91
  let(:respond_to_application) { true }
@@ -95,7 +95,7 @@ if Jasmine::Dependencies.rspec2?
95
95
  context "when rails 3 is present and the application pipeline is not in use" do
96
96
  before do
97
97
  Gem::Specification.should_receive(:find_by_name).with("rails", ">= 3.0").and_return(true)
98
- application.stub(:assets).and_return(rails_application_assets)
98
+ application.stub(:assets).and_return(rails_application_assets)
99
99
  end
100
100
  let(:rails3_present) { true }
101
101
  let(:respond_to_application) { true }
@@ -105,7 +105,7 @@ if Jasmine::Dependencies.rspec2?
105
105
  context "when rails 3 is present but not loaded" do
106
106
  before do
107
107
  Gem::Specification.should_receive(:find_by_name).with("rails", ">= 3.0").and_return(true)
108
- application.stub(:assets).and_return(rails_application_assets)
108
+ application.stub(:assets).and_return(rails_application_assets)
109
109
  end
110
110
  let(:rails3_present) { true }
111
111
  let(:respond_to_application) { false }
@@ -232,5 +232,16 @@ if Jasmine::Dependencies.rspec2?
232
232
  end
233
233
  end
234
234
 
235
+ describe "legacy_rack?" do
236
+ it "should return false if Rack::Server exists" do
237
+ Rack.stub(:constants).and_return([:Server])
238
+ Jasmine::Dependencies.legacy_rack?.should be_false
239
+ end
240
+ it "should return true if Rack::Server does not exist" do
241
+ Rack.stub(:constants).and_return([])
242
+ Jasmine::Dependencies.legacy_rack?.should be_true
243
+ end
244
+ end
235
245
  end
246
+
236
247
  end
@@ -1,23 +1,23 @@
1
1
  require 'spec_helper'
2
2
  require 'jasmine_self_test_config'
3
3
 
4
- jasmine_config = JasmineSelfTestConfig.new
5
- spec_builder = Jasmine::SpecBuilder.new(jasmine_config)
4
+ jasmine_runner_config = Jasmine::RunnerConfig.new(JasmineSelfTestConfig.new)
5
+ server = Jasmine::Server.new(jasmine_runner_config.port, Jasmine::Application.app(jasmine_runner_config))
6
+ client = Jasmine::SeleniumDriver.new(jasmine_runner_config.browser,
7
+ "#{jasmine_runner_config.jasmine_host}:#{jasmine_runner_config.port}/")
6
8
 
7
- should_stop = false
8
-
9
- if Jasmine::Dependencies.rspec2?
10
- RSpec.configuration.after(:suite) do
11
- spec_builder.stop if should_stop
12
- end
13
- else
14
- Spec::Runner.configure do |config|
15
- config.after(:suite) do
16
- spec_builder.stop if should_stop
17
- end
9
+ t = Thread.new do
10
+ begin
11
+ server.start
12
+ rescue ChildProcess::TimeoutError
18
13
  end
14
+ # # ignore bad exits
19
15
  end
16
+ t.abort_on_exception = true
17
+ Jasmine::wait_for_listener(jasmine_runner_config.port, "jasmine server")
18
+ puts "jasmine server started."
20
19
 
21
- spec_builder.start
22
- should_stop = true
23
- spec_builder.declare_suites
20
+ results_processor = Jasmine::ResultsProcessor.new(jasmine_runner_config)
21
+ results = Jasmine::Runners::HTTP.new(client, results_processor).run
22
+ formatter = Jasmine::RspecFormatter.new
23
+ formatter.format_results(results)
@@ -10,7 +10,7 @@ describe Jasmine::Page do
10
10
  :css_files => ["file1.css", "file2.css"],
11
11
  :jasmine_files => ["jasmine_file1.js", "jasmine_file2.js"])
12
12
  end
13
- let(:context) { fake_config.instance_eval { binding } }
13
+ let(:context) { fake_config }
14
14
  let(:page) { Jasmine::Page.new(context) }
15
15
  it "should render javascript files in the correct order" do
16
16
  js_files = subject.css("script")
@@ -0,0 +1,3 @@
1
+ describe Jasmine::ResultsProcessor do
2
+
3
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe Jasmine::Results do
4
+ it "should be able to return suites" do
5
+ suites = {:some => 'suite'}
6
+ Jasmine::Results.new({}, suites, {}).suites.should == suites
7
+ end
8
+
9
+ it "should return a result for a particular spec id" do
10
+ result1 = {:some => 'result'}
11
+ result2 = {:some => 'other result'}
12
+ raw_results = {'1' => result1, '2' => result2 }
13
+ results = Jasmine::Results.new(raw_results, {}, {})
14
+ results.for_spec_id('1').should == result1
15
+ results.for_spec_id('2').should == result2
16
+ end
17
+
18
+ it "should return an example location for a particular string" do
19
+ example_location1 = {:some => 'spec location'}
20
+ example_location2 = {:some => 'other spec location'}
21
+ example_locations = {'foo bar' => example_location1, 'baz quux' => example_location2 }
22
+ results = Jasmine::Results.new({}, {}, example_locations)
23
+ results.example_location_for('foo bar').should == example_location1
24
+ results.example_location_for('baz quux').should == example_location2
25
+ end
26
+ end
27
+
@@ -0,0 +1,88 @@
1
+ require 'spec_helper'
2
+
3
+ describe Jasmine::RspecFormatter do
4
+ describe "environment variables" do
5
+ def stub_env_hash(hash)
6
+ ENV.stub!(:[]) do |arg|
7
+ hash[arg]
8
+ end
9
+ end
10
+ describe "browser configuration" do
11
+ it "should use firefox by default" do
12
+ pending
13
+ stub_env_hash({"JASMINE_BROWSER" => nil})
14
+ config = double('config')
15
+ formatter = Jasmine::RspecFormatter.new(config)
16
+ Jasmine::SeleniumDriver.should_receive(:new).
17
+ with("firefox", anything).
18
+ and_return(mock(Jasmine::SeleniumDriver, :connect => true))
19
+ formatter.start
20
+ end
21
+
22
+ it "should use ENV['JASMINE_BROWSER'] if set" do
23
+ pending
24
+ stub_env_hash({"JASMINE_BROWSER" => "mosaic"})
25
+
26
+ Jasmine::SeleniumDriver.should_receive(:new).
27
+ with("mosaic", anything).
28
+ and_return(mock(Jasmine::SeleniumDriver, :connect => true))
29
+ formatter.start
30
+ end
31
+ end
32
+
33
+ describe "jasmine host" do
34
+ it "should use http://localhost by default" do
35
+ pending
36
+ stub_env_hash({})
37
+ config = Jasmine::Config.new
38
+ config.instance_variable_set(:@jasmine_server_port, '1234')
39
+ config.stub!(:start_jasmine_server)
40
+
41
+ Jasmine::SeleniumDriver.should_receive(:new).
42
+ with(anything, "http://localhost:1234/").
43
+ and_return(mock(Jasmine::SeleniumDriver, :connect => true))
44
+ config.start
45
+ end
46
+
47
+ it "should use ENV['JASMINE_HOST'] if set" do
48
+ pending
49
+ stub_env_hash({"JASMINE_HOST" => "http://some_host"})
50
+ config = Jasmine::Config.new
51
+ config.instance_variable_set(:@jasmine_server_port, '1234')
52
+ config.stub!(:start_jasmine_server)
53
+
54
+ Jasmine::SeleniumDriver.should_receive(:new).
55
+ with(anything, "http://some_host:1234/").
56
+ and_return(mock(Jasmine::SeleniumDriver, :connect => true))
57
+ config.start
58
+ end
59
+
60
+ it "should use ENV['JASMINE_PORT'] if set" do
61
+ pending
62
+ stub_env_hash({"JASMINE_PORT" => "4321"})
63
+ config = Jasmine::Config.new
64
+ Jasmine.stub!(:wait_for_listener)
65
+ config.stub!(:start_server)
66
+ Jasmine::SeleniumDriver.should_receive(:new).
67
+ with(anything, "http://localhost:4321/").
68
+ and_return(mock(Jasmine::SeleniumDriver, :connect => true))
69
+ config.start
70
+ end
71
+ end
72
+
73
+ describe "external selenium server" do
74
+ it "should use an external selenium server if SELENIUM_SERVER is set" do
75
+ pending
76
+ stub_env_hash({"SELENIUM_SERVER" => "http://myseleniumserver.com:4441"})
77
+ Selenium::WebDriver.should_receive(:for).with(:remote, :url => "http://myseleniumserver.com:4441", :desired_capabilities => :firefox)
78
+ Jasmine::SeleniumDriver.new('firefox', 'http://localhost:8888')
79
+ end
80
+ it "should use an local selenium server with a specific port if SELENIUM_SERVER_PORT is set" do
81
+ pending
82
+ stub_env_hash({"SELENIUM_SERVER_PORT" => "4441"})
83
+ Selenium::WebDriver.should_receive(:for).with(:remote, :url => "http://localhost:4441/wd/hub", :desired_capabilities => :firefox)
84
+ Jasmine::SeleniumDriver.new('firefox', 'http://localhost:8888')
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,131 @@
1
+ require 'spec_helper'
2
+ require 'selenium-webdriver'
3
+
4
+ describe Jasmine::RunnerConfig do
5
+ describe "css_files" do
6
+ it "should return the jasmine stylesheets and any user defined stylesheets" do
7
+ jasmine_stylesheets = ['some/css/file']
8
+ user_stylesheets = ['some/user/file']
9
+ user_config = double("config", :jasmine_stylesheets => jasmine_stylesheets, :user_stylesheets => user_stylesheets)
10
+ Jasmine::RunnerConfig.new(user_config).css_files.should == jasmine_stylesheets + user_stylesheets
11
+ end
12
+ end
13
+
14
+ describe "jasmine_files" do
15
+ it "should return the jasmine files from the config" do
16
+ jasmine_files = ['some/file']
17
+ user_config = double('config', :jasmine_javascripts => jasmine_files)
18
+ Jasmine::RunnerConfig.new(user_config).jasmine_files.should == jasmine_files
19
+ end
20
+ end
21
+
22
+ describe "js_files" do
23
+ it "should return the user js files from the config" do
24
+ js_files = ['some/file']
25
+ user_config = double('config', :js_files => js_files)
26
+ Jasmine::RunnerConfig.new(user_config).js_files.should == js_files
27
+ end
28
+ end
29
+
30
+ describe "spec_files" do
31
+ it "should return the user spec_files from the config" do
32
+ spec_files = ['some/file']
33
+ user_config = double('config', :spec_files => spec_files)
34
+ Jasmine::RunnerConfig.new(user_config).spec_files.should == spec_files
35
+ end
36
+ end
37
+
38
+ describe "spec_files_full_paths" do
39
+ it "should return the user spec_files_full_paths from the config" do
40
+ spec_files_full_paths = ['some/file_path']
41
+ user_config = double('config', :spec_files_full_paths => spec_files_full_paths)
42
+ Jasmine::RunnerConfig.new(user_config).spec_files_full_paths.should == spec_files_full_paths
43
+ end
44
+ end
45
+
46
+ describe "spec_path" do
47
+ it "should return the user spec_path from the config" do
48
+ spec_path = ['some/path']
49
+ user_config = double('config', :spec_path => spec_path)
50
+ Jasmine::RunnerConfig.new(user_config).spec_path.should == spec_path
51
+ end
52
+ end
53
+
54
+ describe "spec_dir" do
55
+ it "should return the user spec_dir from the config" do
56
+ spec_dir = ['some/dir']
57
+ user_config = double('config', :spec_dir => spec_dir)
58
+ Jasmine::RunnerConfig.new(user_config).spec_dir.should == spec_dir
59
+ end
60
+ end
61
+
62
+ describe "src_dir" do
63
+ it "should return the user src_dir from the config" do
64
+ src_dir = ['some/dir']
65
+ user_config = double('config', :src_dir => src_dir)
66
+ Jasmine::RunnerConfig.new(user_config).src_dir.should == src_dir
67
+ end
68
+ end
69
+
70
+ describe "project_root" do
71
+ it "should return the user project_root from the config" do
72
+ project_root = ['some/dir']
73
+ user_config = double('config', :project_root => project_root)
74
+ Jasmine::RunnerConfig.new(user_config).project_root.should == project_root
75
+ end
76
+ end
77
+
78
+ describe "root_path" do
79
+ it "should return the user root_path from the config" do
80
+ root_path = ['some/path']
81
+ user_config = double('config', :root_path => root_path)
82
+ Jasmine::RunnerConfig.new(user_config).root_path.should == root_path
83
+ end
84
+ end
85
+
86
+ describe "browser" do
87
+ it "should default to firefox" do
88
+ Jasmine::RunnerConfig.new.browser.should == 'firefox'
89
+ end
90
+
91
+ it "should use ENV['JASMINE_BROWSER'] if it exists" do
92
+ ENV.stub(:[], "JASMINE_BROWSER").and_return("foo")
93
+ Jasmine::RunnerConfig.new.browser.should == 'foo'
94
+ end
95
+ end
96
+
97
+ describe "jasmine_host" do
98
+ it "should default to localhost" do
99
+ Jasmine::RunnerConfig.new.jasmine_host.should == 'http://localhost'
100
+ end
101
+
102
+ it "should use ENV['JASMINE_HOST'] if it exists" do
103
+ ENV.stub(:[], "JASMINE_HOST").and_return("foo")
104
+ Jasmine::RunnerConfig.new.jasmine_host.should == 'foo'
105
+ end
106
+ end
107
+
108
+ describe "port" do
109
+ it "should find an unused port" do
110
+ Jasmine.should_receive(:find_unused_port).and_return('1234')
111
+ Jasmine::RunnerConfig.new.port.should == '1234'
112
+ end
113
+
114
+ it "should use ENV['JASMINE_PORT'] if it exists" do
115
+ ENV.stub(:[], "JASMINE_PORT").and_return("foo")
116
+ Jasmine::RunnerConfig.new.port.should == 'foo'
117
+ end
118
+
119
+ it "should cache port" do
120
+ config = Jasmine::RunnerConfig.new
121
+ Jasmine.stub(:find_unused_port).and_return('1234')
122
+ config.port.should == '1234'
123
+ Jasmine.stub(:find_unused_port).and_return('4321')
124
+ config.port.should == '1234'
125
+ end
126
+
127
+
128
+ end
129
+
130
+ end
131
+
@@ -1,95 +1,48 @@
1
1
  require 'spec_helper'
2
- require 'rack/test'
3
2
 
4
- describe "Jasmine.app" do
5
- include Rack::Test::Methods
6
-
7
- def app
8
- config = Jasmine::Config.new
9
- @root = File.join(File.dirname(__FILE__))
10
- config.stub!(:project_root).and_return(@root)
11
- config.stub!(:spec_dir).and_return(File.join(@root, "fixture", "spec"))
12
- config.stub!(:src_dir).and_return(File.join(@root, "fixture", "src"))
13
- config.stub!(:src_files).and_return(["file1.js"])
14
- config.stub!(:spec_files).and_return(["file2.js"])
15
- Jasmine.app(config)
16
- end
17
-
18
- it "includes no-cache headers for specs" do
19
- get "/__spec__/example_spec.js"
20
- last_response.headers.should have_key("Cache-Control")
21
- last_response.headers["Cache-Control"].should == "max-age=0, private, must-revalidate"
22
- end
23
-
24
- it "should serve static files from spec dir under __spec__" do
25
- get "/__spec__/example_spec.js"
26
- last_response.status.should == 200
27
- last_response.content_type.should == "application/javascript"
28
- last_response.body.should == File.read(File.join(@root, "fixture/spec/example_spec.js"))
3
+ describe Jasmine::Server do
4
+ describe "rack ~> 1.0" do
5
+ before do
6
+ Jasmine::Dependencies.stub(:legacy_rack?).and_return(true)
29
7
  end
30
8
 
31
- it "should serve static files from root dir under __root__" do
32
- get "/__root__/fixture/src/example.js"
33
- last_response.status.should == 200
34
- last_response.content_type.should == "application/javascript"
35
- last_response.body.should == File.read(File.join(@root, "fixture/src/example.js"))
36
- end
37
-
38
- it "should serve static files from src dir under /" do
39
- get "/example.js"
40
- last_response.status.should == 200
41
- last_response.content_type.should == "application/javascript"
42
- last_response.body.should == File.read(File.join(@root, "fixture/src/example.js"))
43
- end
44
-
45
- it "should serve Jasmine static files under /__JASMINE_ROOT__/" do
46
- get "/__JASMINE_ROOT__/jasmine.css"
47
- last_response.status.should == 200
48
- last_response.content_type.should == "text/css"
49
- last_response.body.should == File.read(File.join(Jasmine::Core.path, "jasmine.css"))
50
- end
51
-
52
- it "should serve focused suites when prefixing spec files with /__suite__/" do
53
- pending "Temporarily removing this feature (maybe permanent)"
54
- Dir.stub!(:glob).and_return { |glob_string| [glob_string] }
55
- get "/__suite__/file2.js"
56
- last_response.status.should == 200
57
- last_response.content_type.should == "text/html"
58
- last_response.body.should include("\"/__spec__/file2.js")
59
- end
60
-
61
- it "should redirect /run.html to /" do
62
- get "/run.html"
63
- last_response.status.should == 302
64
- last_response.location.should == "/"
9
+ it "should run the handler with the application" do
10
+ server = double(:server)
11
+ port = 1234
12
+ application = double(:application)
13
+ Rack::Handler.should_receive(:get).with("webrick").and_return(server)
14
+ server.should_receive(:run).with(application, hash_including(:Port => port))
15
+ Jasmine::Server.new(port, application).start
16
+ end
65
17
  end
66
18
 
67
- it "should 404 non-existent files" do
68
- get "/some-non-existent-file"
69
- last_response.should be_not_found
70
- end
19
+ describe "rack >= 1.1" do
20
+ before do
21
+ Jasmine::Dependencies.stub(:legacy_rack?).and_return(false)
22
+ if !Rack.constants.include?(:Server)
23
+ Rack::Server = double("Rack::Server")
24
+ end
25
+ end
71
26
 
72
- describe "/ page" do
73
- it "should load each js file in order" do
74
- get "/"
75
- last_response.status.should == 200
76
- last_response.body.should include("\"/file1.js")
77
- last_response.body.should include("\"/__spec__/file2.js")
78
- last_response.body.should satisfy {|s| s.index("/file1.js") < s.index("/__spec__/file2.js") }
27
+ it "should create a Rack::Server with the correct port when passed" do
28
+ port = 1234
29
+ Rack::Server.should_receive(:new).with(hash_including(:Port => port)).and_return(double(:server).as_null_object)
30
+ Jasmine::Server.new(port).start
79
31
  end
80
32
 
81
- it "should return an empty 200 for HEAD requests to /" do
82
- head "/"
83
- last_response.status.should == 200
84
- last_response.headers['Content-Type'].should == 'text/html'
85
- last_response.body.should == ''
33
+ it "should start the server" do
34
+ server = double(:server)
35
+ Rack::Server.should_receive(:new) { server.as_null_object }
36
+ server.should_receive(:start)
37
+ Jasmine::Server.new.start
86
38
  end
87
39
 
88
- it "should tell the browser not to cache any assets" do
89
- head "/"
90
- ['Pragma'].each do |key|
91
- last_response.headers[key].should == 'no-cache'
92
- end
40
+ it "should set the app as the instance variable on the rack server" do
41
+ app = double('application')
42
+ server = double(:server)
43
+ Rack::Server.should_receive(:new) { server.as_null_object }
44
+ Jasmine::Server.new(1234, app).start
45
+ server.instance_variable_get(:@app).should == app
93
46
  end
94
47
  end
95
48
  end