kind of working, yay
This commit is contained in:
commit
da7741c3b8
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
*.gem
|
||||
.bundle
|
||||
Gemfile.lock
|
||||
pkg/*
|
||||
.project
|
4
Gemfile
Normal file
4
Gemfile
Normal file
@ -0,0 +1,4 @@
|
||||
source "http://rubygems.org"
|
||||
|
||||
# Specify your gem's dependencies in jasmine-mozrepl.gemspec
|
||||
gemspec
|
23
jasmine-mozrepl.gemspec
Normal file
23
jasmine-mozrepl.gemspec
Normal file
@ -0,0 +1,23 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
$:.push File.expand_path("../lib", __FILE__)
|
||||
require "jasmine-mozrepl/version"
|
||||
|
||||
Gem::Specification.new do |s|
|
||||
s.name = "jasmine-mozrepl"
|
||||
s.version = Jasmine::MozRepl::VERSION
|
||||
s.platform = Gem::Platform::RUBY
|
||||
s.authors = ["John Bintz"]
|
||||
s.email = ["john@coswellproductions.com"]
|
||||
s.homepage = ""
|
||||
s.summary = %q{Watch a Jasmine test suite in Firefox}
|
||||
s.description = %q{Using MozRepl, watch and get success/failure information from a Jasmine test suite}
|
||||
|
||||
s.rubyforge_project = "jasmine-mozrepl"
|
||||
|
||||
s.files = `git ls-files`.split("\n")
|
||||
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
||||
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
||||
s.require_paths = ["lib"]
|
||||
|
||||
s.add_dependency 'rainbow'
|
||||
end
|
86
lib/jasmine-mozrepl.rb
Normal file
86
lib/jasmine-mozrepl.rb
Normal file
@ -0,0 +1,86 @@
|
||||
require 'net/telnet'
|
||||
require 'rainbow'
|
||||
|
||||
module Jasmine
|
||||
module MozRepl
|
||||
def repl_reload(options = {})
|
||||
options = {
|
||||
:host => '127.0.0.1',
|
||||
:port => 4242,
|
||||
:jasmine_matcher => 'localhost:8888',
|
||||
:echo_to_console => false
|
||||
}.merge(options)
|
||||
|
||||
repl = Net::Telnet.new('Host' => options[:host], 'Port' => options[:port])
|
||||
repl.print(<<-ENDREPL)
|
||||
var targetWindow = null;
|
||||
for (var i = 0; i < window.length; ++i) {
|
||||
if (window[i].location.href.match(/#{options[:jasmine_matcher]}/)) {
|
||||
targetWindow = window[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
var result = null;
|
||||
var descriptionNode = null;
|
||||
|
||||
function hasFinishedAt() {
|
||||
var as = targetWindow.document.getElementsByTagName('span');
|
||||
for (var i = 0; i < as.length; ++i) {
|
||||
|
||||
if (as[i].innerHTML.match(/Finished at/)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function getDescription() {
|
||||
var descriptionNode = null;
|
||||
|
||||
var as = targetWindow.document.getElementsByTagName('a');
|
||||
for (var i = 0; i < as.length; ++i) {
|
||||
if (as[i].className.match(/description/)) {
|
||||
descriptionNode = as[i].innerHTML;
|
||||
break;
|
||||
}
|
||||
}
|
||||
repl.print(descriptionNode);
|
||||
}
|
||||
|
||||
function domReady() {
|
||||
var count = 10;
|
||||
|
||||
var countdown;
|
||||
countdown = function() {
|
||||
if (hasFinishedAt()) {
|
||||
getDescription();
|
||||
} else {
|
||||
if (count > 0) {
|
||||
repl.print(count);
|
||||
setTimeout(countdown, 1000);
|
||||
count--;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
countdown();
|
||||
}
|
||||
|
||||
if (targetWindow) {
|
||||
targetWindow.location = targetWindow.location;
|
||||
setTimeout(domReady, 1000);
|
||||
}
|
||||
ENDREPL
|
||||
message = nil
|
||||
|
||||
matcher = %r{\d+ specs?, (\d+) .+ in .+s}
|
||||
repl.waitfor(matcher) { |output| message = output[matcher] }
|
||||
repl.close
|
||||
|
||||
puts message.foreground(($1 == "0") ? :green : :red) if options[:echo_to_console]
|
||||
|
||||
message
|
||||
end
|
||||
end
|
||||
end
|
5
lib/jasmine-mozrepl/version.rb
Normal file
5
lib/jasmine-mozrepl/version.rb
Normal file
@ -0,0 +1,5 @@
|
||||
module Jasmine
|
||||
module MozRepl
|
||||
VERSION = "0.0.1"
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user