jasmine 0.4.5 → 0.4.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/jasmine/config.rb +23 -13
- data/spec/config_spec.rb +125 -85
- metadata +2 -2
data/lib/jasmine/config.rb
CHANGED
@@ -5,9 +5,8 @@ module Jasmine
|
|
5
5
|
def initialize(options = {})
|
6
6
|
require 'selenium_rc'
|
7
7
|
@selenium_jar_path = SeleniumRC::Server.allocate.jar_path
|
8
|
-
@options = options
|
9
8
|
|
10
|
-
@browser =
|
9
|
+
@browser = ENV["JASMINE_BROWSER"] || 'firefox'
|
11
10
|
@selenium_pid = nil
|
12
11
|
@jasmine_server_pid = nil
|
13
12
|
end
|
@@ -27,27 +26,38 @@ module Jasmine
|
|
27
26
|
stop_servers
|
28
27
|
end
|
29
28
|
|
30
|
-
def
|
29
|
+
def start_jasmine_server
|
31
30
|
@jasmine_server_port = Jasmine::find_unused_port
|
32
|
-
@selenium_server_port = Jasmine::find_unused_port
|
33
|
-
|
34
31
|
server = Jasmine::Server.new(@jasmine_server_port, self)
|
35
|
-
|
36
|
-
@selenium_pid = fork do
|
37
|
-
Process.setpgrp
|
38
|
-
exec "java -jar #{@selenium_jar_path} -port #{@selenium_server_port} > /dev/null 2>&1"
|
39
|
-
end
|
40
|
-
puts "selenium started. pid is #{@selenium_pid}"
|
41
|
-
|
42
32
|
@jasmine_server_pid = fork do
|
43
33
|
Process.setpgrp
|
44
34
|
server.start
|
45
35
|
exit! 0
|
46
36
|
end
|
47
37
|
puts "jasmine server started. pid is #{@jasmine_server_pid}"
|
38
|
+
Jasmine::wait_for_listener(@jasmine_server_port, "jasmine server")
|
39
|
+
end
|
48
40
|
|
41
|
+
def external_selenium_server_port
|
42
|
+
ENV['SELENIUM_SERVER_PORT'] && ENV['SELENIUM_SERVER_PORT'].to_i > 0 ? ENV['SELENIUM_SERVER_PORT'].to_i : nil
|
43
|
+
end
|
44
|
+
|
45
|
+
def start_selenium_server
|
46
|
+
@selenium_server_port = external_selenium_server_port
|
47
|
+
if @selenium_server_port.nil?
|
48
|
+
@selenium_server_port = Jasmine::find_unused_port
|
49
|
+
@selenium_pid = fork do
|
50
|
+
Process.setpgrp
|
51
|
+
exec "java -jar #{@selenium_jar_path} -port #{@selenium_server_port} > /dev/null 2>&1"
|
52
|
+
end
|
53
|
+
puts "selenium started. pid is #{@selenium_pid}"
|
54
|
+
end
|
49
55
|
Jasmine::wait_for_listener(@selenium_server_port, "selenium server")
|
50
|
-
|
56
|
+
end
|
57
|
+
|
58
|
+
def start_servers
|
59
|
+
start_jasmine_server
|
60
|
+
start_selenium_server
|
51
61
|
end
|
52
62
|
|
53
63
|
def stop_servers
|
data/spec/config_spec.rb
CHANGED
@@ -1,113 +1,153 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
|
2
2
|
|
3
3
|
describe Jasmine::Config do
|
4
|
-
before(:each) do
|
5
|
-
@template_dir = File.expand_path(File.join(File.dirname(__FILE__), "../generators/jasmine/templates"))
|
6
|
-
@config = Jasmine::Config.new
|
7
|
-
end
|
8
4
|
|
9
5
|
describe "configuration" do
|
6
|
+
|
10
7
|
before(:each) do
|
11
|
-
@
|
12
|
-
@config.
|
8
|
+
@template_dir = File.expand_path(File.join(File.dirname(__FILE__), "../generators/jasmine/templates"))
|
9
|
+
@config = Jasmine::Config.new
|
13
10
|
end
|
14
11
|
|
15
|
-
|
16
|
-
File.stub!(:exist?).and_return(false)
|
17
|
-
@config.src_files.should == []
|
18
|
-
@config.stylesheets.should == []
|
19
|
-
@config.spec_files.should == ['javascripts/ExampleSpec.js', 'javascripts/SpecHelper.js']
|
20
|
-
@config.mappings.should == {
|
21
|
-
'/__root__' => @config.project_root,
|
22
|
-
'/__spec__' => @config.spec_dir
|
23
|
-
}
|
24
|
-
end
|
12
|
+
describe "defaults" do
|
25
13
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
@config.mappings.should == {
|
33
|
-
'/__root__' => @config.project_root,
|
34
|
-
'/__spec__' => @config.spec_dir
|
35
|
-
}
|
36
|
-
end
|
14
|
+
it "src_dir uses root when src dir is blank" do
|
15
|
+
@config.stub!(:project_root).and_return('some_project_root')
|
16
|
+
@config.stub!(:simple_config_file).and_return(File.join(@template_dir, 'spec/javascripts/support/jasmine.yml'))
|
17
|
+
YAML.stub!(:load).and_return({'src_dir' => nil})
|
18
|
+
@config.src_dir.should == 'some_project_root'
|
19
|
+
end
|
37
20
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
@config.mappings.should == {
|
43
|
-
'/__root__' => @config.project_root,
|
44
|
-
'/__spec__' => @config.spec_dir
|
45
|
-
}
|
46
|
-
end
|
21
|
+
it "should use correct default yaml config" do
|
22
|
+
@config.stub!(:project_root).and_return('some_project_root')
|
23
|
+
@config.simple_config_file.should == (File.join('some_project_root', 'spec/javascripts/support/jasmine.yml'))
|
24
|
+
end
|
47
25
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
26
|
+
|
27
|
+
it "should provide dir mappings" do
|
28
|
+
@config.mappings.should == {
|
29
|
+
'/__root__' => @config.project_root,
|
30
|
+
'/__spec__' => @config.spec_dir
|
31
|
+
}
|
53
32
|
end
|
54
|
-
@config.stylesheets.should == ['foo.css', 'bar.css']
|
55
33
|
end
|
56
34
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
35
|
+
|
36
|
+
describe "simple_config" do
|
37
|
+
before(:each) do
|
38
|
+
@config.stub!(:src_dir).and_return(File.join(@template_dir, "public"))
|
39
|
+
@config.stub!(:spec_dir).and_return(File.join(@template_dir, "spec"))
|
40
|
+
end
|
41
|
+
|
42
|
+
it "if sources.yaml not found" do
|
43
|
+
File.stub!(:exist?).and_return(false)
|
44
|
+
@config.src_files.should == []
|
45
|
+
@config.stylesheets.should == []
|
46
|
+
@config.spec_files.should == ['javascripts/ExampleSpec.js', 'javascripts/SpecHelper.js']
|
47
|
+
@config.mappings.should == {
|
48
|
+
'/__root__' => @config.project_root,
|
49
|
+
'/__spec__' => @config.spec_dir
|
50
|
+
}
|
51
|
+
end
|
52
|
+
|
53
|
+
it "if jasmine.yml is empty" do
|
54
|
+
@config.stub!(:simple_config_file).and_return(File.join(@template_dir, 'spec/javascripts/support/jasmine.yml'))
|
55
|
+
YAML.stub!(:load).and_return(false)
|
56
|
+
@config.src_files.should == []
|
57
|
+
@config.stylesheets.should == []
|
58
|
+
@config.spec_files.should == ['javascripts/ExampleSpec.js', 'javascripts/SpecHelper.js']
|
59
|
+
@config.mappings.should == {
|
60
|
+
'/__root__' => @config.project_root,
|
61
|
+
'/__spec__' => @config.spec_dir
|
62
|
+
}
|
63
|
+
end
|
64
|
+
|
65
|
+
it "using default jasmine.yml" do
|
66
|
+
@config.stub!(:simple_config_file).and_return(File.join(@template_dir, 'spec/javascripts/support/jasmine.yml'))
|
67
|
+
@config.src_files.should == []
|
68
|
+
@config.spec_files.should == ['javascripts/ExampleSpec.js', 'javascripts/SpecHelper.js']
|
69
|
+
@config.mappings.should == {
|
70
|
+
'/__root__' => @config.project_root,
|
71
|
+
'/__spec__' => @config.spec_dir
|
72
|
+
}
|
73
|
+
end
|
74
|
+
|
75
|
+
it "simple_config stylesheets" do
|
76
|
+
@config.stub!(:simple_config_file).and_return(File.join(@template_dir, 'spec/javascripts/support/jasmine.yml'))
|
77
|
+
YAML.stub!(:load).and_return({'stylesheets' => ['foo.css', 'bar.css']})
|
78
|
+
Dir.stub!(:glob).and_return do |glob_string|
|
61
79
|
glob_string
|
62
|
-
else
|
63
|
-
original_glob.call(glob_string)
|
64
80
|
end
|
81
|
+
@config.stylesheets.should == ['foo.css', 'bar.css']
|
82
|
+
end
|
83
|
+
|
84
|
+
it "using rails jasmine.yml" do
|
85
|
+
original_glob = Dir.method(:glob)
|
86
|
+
Dir.stub!(:glob).and_return do |glob_string|
|
87
|
+
if glob_string =~ /public/
|
88
|
+
glob_string
|
89
|
+
else
|
90
|
+
original_glob.call(glob_string)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
@config.stub!(:simple_config_file).and_return(File.join(@template_dir, 'spec/javascripts/support/jasmine-rails.yml'))
|
94
|
+
@config.spec_files.should == ['javascripts/ExampleSpec.js', 'javascripts/SpecHelper.js']
|
95
|
+
@config.src_files.should == ['javascripts/prototype.js',
|
96
|
+
'javascripts/effects.js',
|
97
|
+
'javascripts/controls.js',
|
98
|
+
'javascripts/dragdrop.js',
|
99
|
+
'javascripts/application.js']
|
100
|
+
@config.js_files.should == [
|
101
|
+
'/javascripts/prototype.js',
|
102
|
+
'/javascripts/effects.js',
|
103
|
+
'/javascripts/controls.js',
|
104
|
+
'/javascripts/dragdrop.js',
|
105
|
+
'/javascripts/application.js',
|
106
|
+
'/__spec__/javascripts/ExampleSpec.js',
|
107
|
+
'/__spec__/javascripts/SpecHelper.js',
|
108
|
+
]
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should provide a list of all spec files with full paths" do
|
112
|
+
@config.spec_files_full_paths.should == [
|
113
|
+
File.join(@template_dir, 'spec/javascripts/ExampleSpec.js'),
|
114
|
+
File.join(@template_dir, 'spec/javascripts/SpecHelper.js')
|
115
|
+
]
|
65
116
|
end
|
66
|
-
@config.stub!(:simple_config_file).and_return(File.join(@template_dir, 'spec/javascripts/support/jasmine-rails.yml'))
|
67
|
-
@config.spec_files.should == ['javascripts/ExampleSpec.js', 'javascripts/SpecHelper.js']
|
68
|
-
@config.src_files.should == ['javascripts/prototype.js',
|
69
|
-
'javascripts/effects.js',
|
70
|
-
'javascripts/controls.js',
|
71
|
-
'javascripts/dragdrop.js',
|
72
|
-
'javascripts/application.js']
|
73
|
-
@config.js_files.should == [
|
74
|
-
'/javascripts/prototype.js',
|
75
|
-
'/javascripts/effects.js',
|
76
|
-
'/javascripts/controls.js',
|
77
|
-
'/javascripts/dragdrop.js',
|
78
|
-
'/javascripts/application.js',
|
79
|
-
'/__spec__/javascripts/ExampleSpec.js',
|
80
|
-
'/__spec__/javascripts/SpecHelper.js',
|
81
|
-
]
|
82
|
-
end
|
83
117
|
|
84
|
-
it "should provide a list of all spec files with full paths" do
|
85
|
-
@config.spec_files_full_paths.should == [
|
86
|
-
File.join(@template_dir, 'spec/javascripts/ExampleSpec.js'),
|
87
|
-
File.join(@template_dir, 'spec/javascripts/SpecHelper.js')
|
88
|
-
]
|
89
118
|
end
|
90
119
|
|
91
120
|
end
|
92
121
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
122
|
+
describe "browsers" do
|
123
|
+
it "should use firefox by default" do
|
124
|
+
ENV.should_receive(:[], "JASMINE_BROWSER").and_return(nil)
|
125
|
+
config = Jasmine::Config.new
|
126
|
+
config.stub!(:start_servers)
|
127
|
+
Jasmine::SeleniumDriver.should_receive(:new).
|
128
|
+
with(anything(), anything(), "*firefox", anything()).
|
129
|
+
and_return(mock(Jasmine::SeleniumDriver, :connect => true))
|
130
|
+
config.start
|
131
|
+
end
|
99
132
|
|
100
|
-
|
101
|
-
|
102
|
-
|
133
|
+
it "should use ENV['JASMINE_BROWSER'] if set" do
|
134
|
+
ENV.should_receive(:[], "JASMINE_BROWSER").and_return("mosaic")
|
135
|
+
config = Jasmine::Config.new
|
136
|
+
config.stub!(:start_servers)
|
137
|
+
Jasmine::SeleniumDriver.should_receive(:new).
|
138
|
+
with(anything(), anything(), "*mosaic", anything()).
|
139
|
+
and_return(mock(Jasmine::SeleniumDriver, :connect => true))
|
140
|
+
config.start
|
141
|
+
end
|
103
142
|
end
|
104
143
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
144
|
+
describe "#start_selenium_server" do
|
145
|
+
it "should use an existing selenium server if SELENIUM_SERVER_PORT is set" do
|
146
|
+
config = Jasmine::Config.new
|
147
|
+
ENV.stub!(:[], "SELENIUM_SERVER_PORT").and_return(1234)
|
148
|
+
Jasmine.should_receive(:wait_for_listener).with(1234, "selenium server")
|
149
|
+
config.start_selenium_server
|
150
|
+
end
|
111
151
|
end
|
112
152
|
|
113
153
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jasmine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rajan Agaskar
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2010-
|
13
|
+
date: 2010-03-10 00:00:00 -08:00
|
14
14
|
default_executable: jasmine
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|