Skip to content

Commit 98b5f68

Browse files
authored
Merge pull request #211 from sh19910711/patch/0040/unify-tdd
Enhancements for templates testing
2 parents f37806d + 8fb1ee4 commit 98b5f68

13 files changed

+228
-447
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ matrix:
2020
- rvm: ruby-head
2121
- rvm: rbx-2
2222
- rvm: jruby
23-
- env: TEST_SUITE=test:templates
23+
- env: TEST_SUITE=templates:test
2424
include:
25-
- env: TEST_SUITE=test:templates
25+
- env: TEST_SUITE=templates:test
2626
rvm: 2.2.5

lib/web_console/tasks/templates.rake

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
namespace :templates do
2+
desc 'Run tests for templates'
3+
task test: [ :daemonize, :npm, :rackup, :wait, :mocha, :kill, :exit ]
4+
task serve: [ :npm, :rackup ]
5+
6+
workdir = Pathname(EXPANDED_CWD).join('test/templates')
7+
pid = Pathname(Dir.tmpdir).join("web_console_test.pid")
8+
runner = URI.parse("http://#{ENV['IP'] || '127.0.0.1'}:#{ENV['PORT'] || 29292}/html/test_runner.html")
9+
rackup = "rackup --host #{runner.host} --port #{runner.port}"
10+
result = nil
11+
browser = 'phantomjs'
12+
13+
def need_to_wait?(uri)
14+
Net::HTTP.start(uri.host, uri.port) { |http| http.get(uri.path) }
15+
rescue Errno::ECONNREFUSED
16+
retry if yield
17+
end
18+
19+
task :daemonize do
20+
rackup += " -D --pid #{pid}"
21+
end
22+
23+
task :npm => [ :phantomjs ] do
24+
Dir.chdir(workdir) { system 'npm install --silent' }
25+
end
26+
27+
task :phantomjs do
28+
unless system("which #{browser} >/dev/null")
29+
browser = './node_modules/.bin/phantomjs'
30+
Dir.chdir(workdir) { system("test -f #{browser} || npm install --silent phantomjs-prebuilt") }
31+
end
32+
end
33+
34+
task :rackup do
35+
Dir.chdir(workdir) { system rackup }
36+
end
37+
38+
task :wait do
39+
cnt = 0
40+
need_to_wait?(runner) { sleep 1; cnt += 1; cnt < 5 }
41+
end
42+
43+
task :mocha do
44+
Dir.chdir(workdir) { result = system("#{browser} ./node_modules/mocha-phantomjs-core/mocha-phantomjs-core.js #{runner} dot") }
45+
end
46+
47+
task :kill do
48+
system "kill #{File.read pid}"
49+
end
50+
51+
task :exit do
52+
exit result
53+
end
54+
end

lib/web_console/tasks/test_templates.rake

Lines changed: 0 additions & 56 deletions
This file was deleted.

test/templates/config.ru

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ end
4343

4444
map "/mock/repl_sessions/result" do
4545
headers = { 'Content-Type' => 'application/json' }
46-
body = [ { output: '=> "fake-result"\n' }.to_json ]
46+
body = [ { output: '=> "fake-result"\n', context: [ :something, :somewhat, :somewhere ] }.to_json ]
4747
run lambda { |env| [ 200, headers, body ] }
4848
end
4949

test/templates/html/spec_runner.html.erb

Lines changed: 0 additions & 36 deletions
This file was deleted.

test/templates/html/test_runner.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<script src="/templates/console.js"></script>
2020

2121
<!-- find and load test cases -->
22-
<script src="/spec/spec_helper.js"></script>
22+
<script src="/test/test_helper.js"></script>
2323
<% Pathname.glob(TEST_ROOT.join "test/**/*_test.js") do |t| %>
2424
<script src="/<%= t.relative_path_from TEST_ROOT %>"></script>
2525
<% end %>

test/templates/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
"devDependencies": {
99
"chai": "^3.0.0",
1010
"mocha": "^2.2.5",
11-
"mocha-phantomjs": "^3.5.3"
11+
"mocha-phantomjs-core": "^1.3.1"
1212
}
1313
}

test/templates/spec/auto_complete_spec.js

Lines changed: 0 additions & 37 deletions
This file was deleted.

test/templates/spec/dom_helpers_spec.js

Lines changed: 0 additions & 105 deletions
This file was deleted.

0 commit comments

Comments
 (0)