js-test-driver-rails 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/lib/js_test_driver/config.rb +7 -14
- data/lib/js_test_driver/runner.rb +9 -6
- data/lib/js_test_driver/version.rb +1 -1
- data/test/unit/config_test.rb +16 -8
- data/test/unit/runner_test.rb +12 -12
- metadata +2 -2
data/Gemfile.lock
CHANGED
@@ -100,6 +100,9 @@ module JsTestDriver
|
|
100
100
|
# but you still need to specify port for starting the server
|
101
101
|
define_config_variable(:server) { @server || "http://#{host}:#{port}" }
|
102
102
|
|
103
|
+
# the base path to which all of the paths in the config file are relative
|
104
|
+
define_config_variable(:base_path) { @base_path ||= '/' }
|
105
|
+
|
103
106
|
def included_files
|
104
107
|
@includes ||= []
|
105
108
|
end
|
@@ -119,7 +122,7 @@ module JsTestDriver
|
|
119
122
|
end
|
120
123
|
|
121
124
|
def to_s
|
122
|
-
hash = {'server' => server}
|
125
|
+
hash = {'server' => server, 'basepath' => base_path}
|
123
126
|
hash['load'] = loaded_files unless loaded_files.empty?
|
124
127
|
hash['exclude'] = map_paths(excluded_files) unless excluded_files.empty?
|
125
128
|
return hash.to_yaml
|
@@ -165,22 +168,12 @@ module JsTestDriver
|
|
165
168
|
map_paths(files)
|
166
169
|
end
|
167
170
|
|
168
|
-
def
|
169
|
-
|
170
|
-
config = File.expand_path(config_dir).split(File::SEPARATOR)
|
171
|
-
|
172
|
-
while source.first == config.first && !source.empty? && !config.empty?
|
173
|
-
source.shift
|
174
|
-
config.shift
|
175
|
-
end
|
176
|
-
|
177
|
-
parts = (['..'] * config.size) + source
|
178
|
-
|
179
|
-
return File.join(*parts)
|
171
|
+
def path_relative_to_base_path(path)
|
172
|
+
path.gsub(/^#{Regexp.escape(base_path)}/, '')
|
180
173
|
end
|
181
174
|
|
182
175
|
def map_paths(files)
|
183
|
-
files.map{|file|
|
176
|
+
files.map{|file| path_relative_to_base_path(file)}
|
184
177
|
end
|
185
178
|
|
186
179
|
def attributes=(values)
|
@@ -58,12 +58,15 @@ module JsTestDriver
|
|
58
58
|
# by default it will capture the browsers specified in the config,
|
59
59
|
# but you can pass an argument like 'opera,chrome,firefox' to capture opera, chrome and firefox
|
60
60
|
def capture_browsers(browsers = nil)
|
61
|
-
|
61
|
+
browsers ||= ''
|
62
|
+
browsers = browsers.split(',')
|
63
|
+
browsers = config.browsers if browsers.empty?
|
62
64
|
|
63
|
-
|
64
|
-
add_capture_browsers(command, browsers)
|
65
|
+
url = config.server + "/capture"
|
65
66
|
|
66
|
-
|
67
|
+
browsers.each do |browser|
|
68
|
+
spawn("#{browser} \'#{url}\'")
|
69
|
+
end
|
67
70
|
end
|
68
71
|
|
69
72
|
# runs the tests specified by the argument
|
@@ -171,11 +174,11 @@ module JsTestDriver
|
|
171
174
|
values.each do |attr, value|
|
172
175
|
self.send("#{attr}=", value)
|
173
176
|
end
|
174
|
-
end
|
177
|
+
end
|
175
178
|
|
176
179
|
class Command
|
177
180
|
def initialize(executable)
|
178
|
-
@command = "#{executable}"
|
181
|
+
@command = "#{executable}"
|
179
182
|
end
|
180
183
|
|
181
184
|
def option(name, value = nil)
|
data/test/unit/config_test.rb
CHANGED
@@ -4,7 +4,15 @@ module JsTestDriver
|
|
4
4
|
class ConfigTest < Test::Unit::TestCase
|
5
5
|
|
6
6
|
def default_result
|
7
|
-
{'server' => 'http://localhost:4224'}
|
7
|
+
{'server' => 'http://localhost:4224', 'basepath' => '/'}
|
8
|
+
end
|
9
|
+
|
10
|
+
def path(relative_file_name)
|
11
|
+
return File.expand_path(relative_file_name).gsub(/^\//, '')
|
12
|
+
end
|
13
|
+
|
14
|
+
def paths(arr)
|
15
|
+
arr.map{|s| path(s)}
|
8
16
|
end
|
9
17
|
|
10
18
|
def assert_config_includes(config, hash)
|
@@ -78,7 +86,7 @@ module JsTestDriver
|
|
78
86
|
config.includes('src/foo.js')
|
79
87
|
|
80
88
|
# then
|
81
|
-
assert_config_includes config, 'load' => ['src/foo.js']
|
89
|
+
assert_config_includes config, 'load' => paths(['src/foo.js'])
|
82
90
|
end
|
83
91
|
|
84
92
|
def test_config_with_includes_with_globbing
|
@@ -89,7 +97,7 @@ module JsTestDriver
|
|
89
97
|
config.includes('test/fixtures/foo/**/*.html')
|
90
98
|
|
91
99
|
# then
|
92
|
-
assert_config_includes config, 'load' => ['test/fixtures/foo/bar/a.html', 'test/fixtures/foo/a.html']
|
100
|
+
assert_config_includes config, 'load' => paths(['test/fixtures/foo/bar/a.html', 'test/fixtures/foo/a.html'])
|
93
101
|
end
|
94
102
|
|
95
103
|
def test_config_with_browsers
|
@@ -114,7 +122,7 @@ module JsTestDriver
|
|
114
122
|
end
|
115
123
|
|
116
124
|
# then
|
117
|
-
assert_config_includes config, 'load' => ['a', 'b', 'c']
|
125
|
+
assert_config_includes config, 'load' => paths(['a', 'b', 'c'])
|
118
126
|
end
|
119
127
|
|
120
128
|
def test_config_with_excludes
|
@@ -125,7 +133,7 @@ module JsTestDriver
|
|
125
133
|
config.excludes('test/fixtures/foo/**/*.html')
|
126
134
|
|
127
135
|
# then
|
128
|
-
assert_config_includes config, 'exclude' => ['test/fixtures/foo/bar/a.html', 'test/fixtures/foo/a.html']
|
136
|
+
assert_config_includes config, 'exclude' => paths(['test/fixtures/foo/bar/a.html', 'test/fixtures/foo/a.html'])
|
129
137
|
end
|
130
138
|
|
131
139
|
def test_config_with_excludes_with_globbing
|
@@ -136,7 +144,7 @@ module JsTestDriver
|
|
136
144
|
config.excludes('src/foo.js')
|
137
145
|
|
138
146
|
# then
|
139
|
-
assert_config_includes config, 'exclude' => ['src/foo.js']
|
147
|
+
assert_config_includes config, 'exclude' => paths(['src/foo.js'])
|
140
148
|
end
|
141
149
|
|
142
150
|
def test_empty_config_file
|
@@ -180,7 +188,7 @@ module JsTestDriver
|
|
180
188
|
config.includes "a/a", "/b/b", "../c"
|
181
189
|
|
182
190
|
# then
|
183
|
-
assert_config_includes config, 'load' => ["
|
191
|
+
assert_config_includes config, 'load' => paths(["a/a", '/b/b', "../c"])
|
184
192
|
end
|
185
193
|
|
186
194
|
def test_config_with_html_fixtures
|
@@ -192,7 +200,7 @@ module JsTestDriver
|
|
192
200
|
config.fixtures "fixture/directory", :name => "fixture_name", :namespace => "fixture_namespace"
|
193
201
|
|
194
202
|
# then
|
195
|
-
assert_config_includes config, 'load' => ["fixtures/fixture_namespace/fixture_name.js"]
|
203
|
+
assert_config_includes config, 'load' => paths(["configs/fixtures/fixture_namespace/fixture_name.js"])
|
196
204
|
end
|
197
205
|
|
198
206
|
def test_should_save_fixtures
|
data/test/unit/runner_test.rb
CHANGED
@@ -4,7 +4,7 @@ module JsTestDriver
|
|
4
4
|
class RunnerTest < Test::Unit::TestCase
|
5
5
|
|
6
6
|
def given_a_runner(opts = {})
|
7
|
-
return JsTestDriver::Runner.new(opts)
|
7
|
+
return JsTestDriver::Runner.new(opts)
|
8
8
|
end
|
9
9
|
|
10
10
|
def test_should_have_default_config_path
|
@@ -35,6 +35,10 @@ module JsTestDriver
|
|
35
35
|
JsTestDriver::Runner::Command.any_instance.expects(:system).with(cmd)
|
36
36
|
end
|
37
37
|
|
38
|
+
def expect_spawn(cmd)
|
39
|
+
JsTestDriver::Runner.any_instance.expects(:spawn).with(cmd)
|
40
|
+
end
|
41
|
+
|
38
42
|
def test_should_run_server_with_given_port_number
|
39
43
|
config = JsTestDriver::Config.new(:port => 6666)
|
40
44
|
runner = given_a_runner(:config => config)
|
@@ -60,18 +64,12 @@ module JsTestDriver
|
|
60
64
|
runner.run_tests('MyTestCase.some_test')
|
61
65
|
end
|
62
66
|
|
63
|
-
def test_should_raise_exception_if_no_browsers_defined_to_capture
|
64
|
-
runner = given_a_runner(:config => JsTestDriver::Config.new)
|
65
|
-
|
66
|
-
assert_raises(ArgumentError) do
|
67
|
-
runner.capture_browsers
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
67
|
def test_should_capture_default_browsers
|
72
68
|
runner = given_a_runner(:config => JsTestDriver::Config.new(:browsers => ['foo', 'bar', 'baz']))
|
73
69
|
|
74
|
-
|
70
|
+
['foo', 'bar', 'baz'].each do |browser|
|
71
|
+
expect_spawn("#{browser} 'http://localhost:4224/capture'")
|
72
|
+
end
|
75
73
|
|
76
74
|
runner.capture_browsers
|
77
75
|
end
|
@@ -79,7 +77,9 @@ module JsTestDriver
|
|
79
77
|
def test_should_capture_given_browsers
|
80
78
|
runner = given_a_runner(:config => JsTestDriver::Config.new(:browsers => ['foo', 'bar', 'baz']))
|
81
79
|
|
82
|
-
|
80
|
+
['aaa', 'bbb'].each do |browser|
|
81
|
+
expect_spawn("#{browser} 'http://localhost:4224/capture'")
|
82
|
+
end
|
83
83
|
|
84
84
|
runner.capture_browsers('aaa,bbb')
|
85
85
|
end
|
@@ -93,4 +93,4 @@ module JsTestDriver
|
|
93
93
|
end
|
94
94
|
|
95
95
|
end
|
96
|
-
end
|
96
|
+
end
|