kind of working, yay

This commit is contained in:
John Bintz 2011-02-18 11:33:47 -05:00
commit da7741c3b8
6 changed files with 125 additions and 0 deletions

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
*.gem
.bundle
Gemfile.lock
pkg/*
.project

4
Gemfile Normal file
View File

@ -0,0 +1,4 @@
source "http://rubygems.org"
# Specify your gem's dependencies in jasmine-mozrepl.gemspec
gemspec

2
Rakefile Normal file
View File

@ -0,0 +1,2 @@
require 'bundler'
Bundler::GemHelper.install_tasks

23
jasmine-mozrepl.gemspec Normal file
View 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
View 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

View File

@ -0,0 +1,5 @@
module Jasmine
module MozRepl
VERSION = "0.0.1"
end
end