Skip to content

Commit

Permalink
gemified
Browse files Browse the repository at this point in the history
  • Loading branch information
nakajima committed Sep 9, 2008
1 parent f80defc commit 7725840
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 11 deletions.
11 changes: 11 additions & 0 deletions .gemified
@@ -0,0 +1,11 @@
---
:homepage: http://github.com/nakajima/screw-driver
:author: Pat Nakajima
:dependencies:
- sinatra
- hpricot
:version: 0.0.1
:name: screw-driver
:summary: Run your Screw.Unit specs from the command line.
:email: patnakajima@gmail.com
:has_rdoc: false
37 changes: 37 additions & 0 deletions .manifest
@@ -0,0 +1,37 @@
README
Rakefile
bin/screwdriver
lib/browser.rb
lib/browsers/firefox.rb
lib/browsers/safari.rb
lib/ext/string.rb
lib/helpers.rb
lib/rails.rb
lib/suite.rb
js/jquery.ajax_queue.js
js/screw.driver.js
spec/browser_spec.rb
spec/fixtures/bar.js
spec/fixtures/bar_spec.js
spec/fixtures/foo.js
spec/fixtures/foo_spec.js
spec/fixtures/jquery.ajax_queue.js
spec/fixtures/public/javascripts/application.js
spec/fixtures/public/javascripts/lib.js
spec/fixtures/screw-unit/jquery-1.2.6.js
spec/fixtures/screw-unit/jquery.fn.js
spec/fixtures/screw-unit/jquery.print.js
spec/fixtures/screw-unit/screw.assets.js
spec/fixtures/screw-unit/screw.behaviors.js
spec/fixtures/screw-unit/screw.builder.js
spec/fixtures/screw-unit/screw.css
spec/fixtures/screw-unit/screw.events.js
spec/fixtures/screw-unit/screw.matchers.js
spec/fixtures/screw-unit/screw.server.js
spec/fixtures/screw.driver.js
spec/fixtures/spec_helper.js
spec/fixtures/src/great.js
spec/fixtures/suite.html
spec/rails_spec.rb
spec/spec_helper.rb
spec/suite_spec.rb
59 changes: 59 additions & 0 deletions js/jquery.ajax_queue.js
@@ -0,0 +1,59 @@
// AjaxQueue - by Pat Nakajima
(function($) {
var startNextRequest = function() {
if ($.ajaxQueue.currentRequest) { return; }
if (request = $.ajaxQueue.queue.shift()) {
$.ajaxQueue.currentRequest = request;
request.perform();
}
}

var Request = function(url, type, options) {
this.opts = options || { };
this.opts.url = url;
this.opts.type = type;
var oldComplete = this.opts.complete || function() { }
this.opts.complete = function(response) {
oldComplete(response);
$.ajaxQueue.currentRequest = null;
startNextRequest();
};
}

Request.prototype.perform = function() {
$.ajax(this.opts);
}

var addRequest = function(url, type, options) {
var request = new Request(url, type, options);
$.ajaxQueue.queue.push(request);
startNextRequest();
}

$.ajaxQueue = {
queue: [],

currentRequest: null,

reset: function() {
$.ajaxQueue.queue = [];
$.ajaxQueue.currentRequest = null;
},

post: function(url, options) {
addRequest(url, 'POST', options);
},

get: function(url, options) {
addRequest(url, 'GET', options);
},

put: function(url, options) {
addRequest(url, 'PUT', options);
},

"delete": function(url, options) {
addRequest(url, 'DELETE', options);
}
}
})(jQuery)
32 changes: 32 additions & 0 deletions js/screw.driver.js
@@ -0,0 +1,32 @@
(function($) {
$(Screw).bind('before', function() {
$.ajaxQueue.post('/before');
});

$(Screw).bind('after', function() {
$.ajaxQueue.post('/after');
$.ajaxQueue.post('/exit');
});

$(Screw).bind('loaded', function() {
$('.it').bind('passed', function(e) {
$.ajaxQueue.post('/passed');
});

$('.it').bind('failed', function(e, reason) {
var specName = $(this).find('h2').text();

// ERROR
if (reason.fileName || reason.lineNumber || reason.line) {
return $.ajaxQueue.post('/errored', {
data: { name: specName, reason: reason }
});
}

// FAILURE
$.ajaxQueue.post('/failed', {
data: { name: specName, reason: reason }
});
});
});
})(jQuery);
34 changes: 28 additions & 6 deletions lib/suite.rb
Expand Up @@ -48,7 +48,7 @@ def link_urls
end

def to_s
doc.to_s
doc.to_html
end

def browser
Expand All @@ -73,10 +73,14 @@ def generate_js_urls
def generate_css_urls
link_urls.each { |url| generate(url, "text/css") }
end

def generate_framework_urls
['/jquery.ajax_queue.js', 'screw.driver.js'].each { |url| generate(url, 'text/javascript') }
end

def generate(url, content_type, prefix=working_directory)
prefix = load_paths.detect { |path| File.exists?(File.join(Dir.pwd, path, url)) } || '.'
path = File.join(Dir.pwd, prefix, url)
prefix = load_paths.detect { |path| File.exists?(File.join(path, url)) } || '.'
path = File.join(prefix, url)
@context.send(:get, url) do
headers 'Content-Type' => content_type
File.read(path)
Expand Down Expand Up @@ -125,13 +129,31 @@ def parse_args(args)
@rails = options.rails
@server = options.server
@path = File.join(Dir.pwd, args.shift)
@load_paths = [File.dirname(@path)]
@load_paths += options.paths if options.paths
setup_load_paths(options.paths)
end
end

def setup_load_paths(paths=[])
@load_paths = paths.map { |path| File.join(Dir.pwd, path) }
@load_paths << File.join(File.dirname(__FILE__), '..', 'js')
@load_paths << File.dirname(@path)
end

def doc
Hpricot(File.open(@path))
@doc ||= begin
@doc = Hpricot(File.open(@path))
@doc.search('script').each do |script|
case script['src']
when "/screw-unit/screw.behaviors.js" then append_script(script, :before, 'jquery.ajax_queue.js')
when "/screw-unit/screw.events.js" then append_script(script, :after, 'screw.driver.js')
end
end
@doc
end
end

def append_script(script, pos, name)
script.send(pos, %(<script src="/#{name}"> </script>))
end
end
end
Expand Down
2 changes: 0 additions & 2 deletions spec/fixtures/suite.html
Expand Up @@ -7,10 +7,8 @@
<script src="/screw-unit/jquery.print.js"></script>
<script src="/screw-unit/screw.builder.js"></script>
<script src="/screw-unit/screw.matchers.js"></script>
<script src="/screw.driver.js"></script>
<script src="/screw-unit/screw.events.js"></script>
<script src="/screw-unit/screw.behaviors.js"></script>
<script src="/jquery.ajax_queue.js"></script>

<script src="/spec_helper.js"></script>

Expand Down
6 changes: 3 additions & 3 deletions spec/suite_spec.rb
Expand Up @@ -30,7 +30,7 @@
end

it "should find external script_urls" do
@suite.should have(15).script_urls
@suite.should have(13).script_urls
end

it "should find external link_urls" do
Expand Down Expand Up @@ -62,12 +62,12 @@

describe "load paths" do
it "should have 1 load_path by default" do
@suite.should have(1).load_paths
@suite.should have(2).load_paths
end

it "should append load paths" do
suite = create_suite '--load-paths', 'src'
suite.should have(2).load_paths
suite.should have(3).load_paths
end

it "should serve files from added load paths directory" do
Expand Down

0 comments on commit 7725840

Please sign in to comment.