rsutphin-shenandoah 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. data/.braids +8 -0
  2. data/.document +5 -0
  3. data/.gitignore +6 -0
  4. data/ChangeLog.markdown +13 -0
  5. data/LICENSE +20 -0
  6. data/LICENSE-Blue-Ridge +20 -0
  7. data/LICENSE-Screw.Unit +22 -0
  8. data/LICENSE-Smoke +22 -0
  9. data/README.markdown +280 -0
  10. data/Rakefile +71 -0
  11. data/VERSION.yml +4 -0
  12. data/lib/shenandoah/buildr.rb +9 -0
  13. data/lib/shenandoah/buildr/locator.rb +17 -0
  14. data/lib/shenandoah/buildr/shenandoah_tasks.rb +18 -0
  15. data/lib/shenandoah/buildr/test_framework.rb +28 -0
  16. data/lib/shenandoah/css/screw.css +90 -0
  17. data/lib/shenandoah/javascript/browser/runner.js +34 -0
  18. data/lib/shenandoah/javascript/common/jquery-1.3.2.js +4376 -0
  19. data/lib/shenandoah/javascript/common/jquery.fn.js +29 -0
  20. data/lib/shenandoah/javascript/common/jquery.print.js +109 -0
  21. data/lib/shenandoah/javascript/common/screw.behaviors.js +129 -0
  22. data/lib/shenandoah/javascript/common/screw.builder.js +104 -0
  23. data/lib/shenandoah/javascript/common/screw.events.js +45 -0
  24. data/lib/shenandoah/javascript/common/screw.matchers.js +254 -0
  25. data/lib/shenandoah/javascript/common/screw.mocking.js +22 -0
  26. data/lib/shenandoah/javascript/common/smoke.core.js +6 -0
  27. data/lib/shenandoah/javascript/common/smoke.mock.js +130 -0
  28. data/lib/shenandoah/javascript/common/smoke.stub.js +29 -0
  29. data/lib/shenandoah/javascript/console/consoleReportForRake.js +32 -0
  30. data/lib/shenandoah/javascript/console/env.rhino.js +8841 -0
  31. data/lib/shenandoah/javascript/console/js.jar +0 -0
  32. data/lib/shenandoah/javascript/console/runner.js +43 -0
  33. data/lib/shenandoah/javascript/console/shell.js.erb +23 -0
  34. data/lib/shenandoah/locator.rb +17 -0
  35. data/lib/shenandoah/rails/locator.rb +27 -0
  36. data/lib/shenandoah/rails/tasks.rb +16 -0
  37. data/lib/shenandoah/runner.rb +69 -0
  38. data/lib/shenandoah/server.rb +88 -0
  39. data/lib/shenandoah/server/views/index.haml +12 -0
  40. data/lib/shenandoah/tasks.rb +62 -0
  41. data/rails_generators/shen_spec/shen_spec_generator.rb +27 -0
  42. data/rails_generators/shen_spec/templates/fixture.html.erb +13 -0
  43. data/rails_generators/shen_spec/templates/javascript_spec.js.erb +8 -0
  44. data/rails_generators/shenandoah/shenandoah_generator.rb +21 -0
  45. data/rails_generators/shenandoah/templates/application.html +16 -0
  46. data/rails_generators/shenandoah/templates/application_spec.js +14 -0
  47. data/rails_generators/shenandoah/templates/shenandoah.rake +2 -0
  48. data/rails_generators/shenandoah/templates/spec_helper.js +1 -0
  49. data/shenandoah.gemspec +155 -0
  50. data/spec/rails_generators/shen_spec_generator_spec.rb +81 -0
  51. data/spec/rails_generators/shenandoah_generator_spec.rb +80 -0
  52. data/spec/rails_generators/spec_helper.rb +21 -0
  53. data/spec/shenandoah/buildr/locator_spec.rb +33 -0
  54. data/spec/shenandoah/buildr/shenandoah_tasks_spec.rb +27 -0
  55. data/spec/shenandoah/buildr/spec_helper.rb +2 -0
  56. data/spec/shenandoah/buildr/test_framework_spec.rb +77 -0
  57. data/spec/shenandoah/locator_spec.rb +74 -0
  58. data/spec/shenandoah/rails/locator_spec.rb +57 -0
  59. data/spec/shenandoah/rails/tasks_spec.rb +32 -0
  60. data/spec/shenandoah/runner_spec.rb +110 -0
  61. data/spec/shenandoah/server_spec.rb +216 -0
  62. data/spec/shenandoah/tasks_spec.rb +85 -0
  63. data/spec/spec_helper.rb +61 -0
  64. metadata +262 -0
@@ -0,0 +1,43 @@
1
+ if(arguments.length == 0) {
2
+ print("Usage: test_runner.js /path/to/shenandoah /path/to/mainfiles /path/to/specfiles file_spec.js");
3
+ quit(1);
4
+ }
5
+
6
+ var SHENANDOAH = arguments[0]
7
+ var MAIN_PATH = arguments[1]
8
+ var SPEC_PATH = arguments[2]
9
+ var SPEC_FILE = arguments[3]
10
+
11
+ function require_main(file) {
12
+ require_absolute(MAIN_PATH + '/' + file)
13
+ }
14
+
15
+ function require_spec(file) {
16
+ require_absolute(SPEC_PATH + '/' + file)
17
+ }
18
+
19
+ function require_absolute(file) {
20
+ load(file)
21
+ }
22
+
23
+ var fixture = SPEC_FILE.replace(/^(.*?)_spec\.js$/, "$1.html");
24
+ print("Running " + SPEC_FILE + " with fixture '" + fixture + "'");
25
+
26
+ load(SHENANDOAH + "/lib/shenandoah/javascript/console/env.rhino.js");
27
+ window.location = fixture;
28
+
29
+ load(SHENANDOAH + "/lib/shenandoah/javascript/common/jquery-1.3.2.js");
30
+ load(SHENANDOAH + "/lib/shenandoah/javascript/common/jquery.fn.js");
31
+ load(SHENANDOAH + "/lib/shenandoah/javascript/common/jquery.print.js");
32
+ load(SHENANDOAH + "/lib/shenandoah/javascript/common/screw.builder.js");
33
+ load(SHENANDOAH + "/lib/shenandoah/javascript/common/screw.matchers.js");
34
+ load(SHENANDOAH + "/lib/shenandoah/javascript/common/screw.events.js");
35
+ load(SHENANDOAH + "/lib/shenandoah/javascript/common/screw.behaviors.js");
36
+ load(SHENANDOAH + "/lib/shenandoah/javascript/common/smoke.core.js");
37
+ load(SHENANDOAH + "/lib/shenandoah/javascript/common/smoke.mock.js");
38
+ load(SHENANDOAH + "/lib/shenandoah/javascript/common/smoke.stub.js");
39
+ load(SHENANDOAH + "/lib/shenandoah/javascript/common/screw.mocking.js");
40
+ load(SHENANDOAH + "/lib/shenandoah/javascript/console/consoleReportForRake.js");
41
+
42
+ load(SPEC_PATH + '/' + SPEC_FILE);
43
+ jQuery(window).trigger("load");
@@ -0,0 +1,23 @@
1
+ (function(){
2
+ var _old_quit = this.quit;
3
+ this.__defineGetter__("exit", function(){ _old_quit() });
4
+ this.__defineGetter__("quit", function(){ _old_quit() });
5
+
6
+ print("=================================================");
7
+ print(" Rhino JavaScript Shell");
8
+ print(" To exit type 'exit', 'quit', or 'quit()'.");
9
+ print("=================================================");
10
+
11
+ load("<%= shenandoah_root %>/lib/shenandoah/javascript/console/env.rhino.js");
12
+ print(" - loaded env.js");
13
+
14
+ window.location = "<%= shell_html_path %>";
15
+ print(" - sample DOM loaded");
16
+
17
+ load("<%= shenandoah_root %>/lib/shenandoah/javascript/common/jquery-1.3.2.js");
18
+ print (" jQuery-1.3.2 loaded");
19
+ // load(PLUGIN_PREFIX + "lib/jquery-1.2.6.js");
20
+ // print(" - jQuery-1.2.6 loaded");
21
+
22
+ print("=================================================");
23
+ })();
@@ -0,0 +1,17 @@
1
+ require 'rake'
2
+
3
+ module Shenandoah
4
+ class DefaultLocator
5
+ attr_accessor :main_path, :spec_path, :tmp_path
6
+
7
+ def initialize(options = {})
8
+ @main_path = options[:main_path] || "lib"
9
+ @spec_path = options[:spec_path] || "spec"
10
+ @tmp_path = options[:tmp_path] || ENV['TMPDIR'] || "tmp"
11
+ end
12
+
13
+ def spec_files
14
+ FileList["#{spec_path}/**/*_spec.js"]
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,27 @@
1
+ require 'shenandoah/locator'
2
+
3
+ module Shenandoah
4
+ module Rails
5
+ class Locator < Shenandoah::DefaultLocator
6
+ def initialize(options={})
7
+ super(
8
+ :main_path => File.join(RAILS_ROOT, options[:main_path] || "public/javascripts"),
9
+ :spec_path => File.join(RAILS_ROOT, options[:spec_path] || select_spec_subpath),
10
+ :tmp_path => File.join(RAILS_ROOT, "tmp/shenandoah")
11
+ )
12
+ end
13
+
14
+ private
15
+
16
+ def select_spec_subpath
17
+ %w(spec examples).each do |candidate|
18
+ if File.directory?(File.join(RAILS_ROOT, candidate))
19
+ return "#{candidate}/javascript"
20
+ end
21
+ end
22
+
23
+ "test/javascript" # default
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,16 @@
1
+ # This class is just sugar for initing Shenandoah::Tasks with a rails locator
2
+
3
+ require 'shenandoah/tasks'
4
+ require 'shenandoah/rails/locator'
5
+
6
+ module Shenandoah
7
+ module Rails
8
+ class Tasks < Shenandoah::Tasks
9
+ protected
10
+
11
+ def default_locator_type
12
+ Locator
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,69 @@
1
+ require 'fileutils'
2
+ require 'erb'
3
+
4
+ module Shenandoah
5
+ class Runner
6
+ def initialize(locator, options = {})
7
+ @locator = locator
8
+ @quiet = options[:quiet]
9
+ end
10
+
11
+ # Runs the specified specs. Returns an array of the specs that passed.
12
+ def run_console(specs)
13
+ FileUtils.cd @locator.spec_path do
14
+ runner_cmd = rhino_command(shen_path_to('lib/shenandoah/javascript/console/runner.js'))
15
+ args = [
16
+ shen_path_to,
17
+ @locator.main_path,
18
+ @locator.spec_path
19
+ ]
20
+
21
+ return specs.select { |spec|
22
+ system("#{runner_cmd} '#{args.join("' '")}' '#{spec.sub(%r{^#{@locator.spec_path}/}, '')}' #{@quiet ? '> /dev/null' : ''}")
23
+ }
24
+ end
25
+ end
26
+
27
+ def run_shell
28
+ create_shell_html
29
+ create_shell_js
30
+
31
+ rlwrap = `which rlwrap`.chomp
32
+ cmd = "#{rlwrap} #{rhino_command('-f', shell_js_path, '-f', '-')}"
33
+ $stderr.puts "Starting shell with #{cmd}"
34
+ system(cmd)
35
+ end
36
+
37
+ private
38
+
39
+ def shen_path_to(file=nil)
40
+ File.expand_path(File.dirname(__FILE__) + "/../../#{file}")
41
+ end
42
+ alias :shenandoah_root :shen_path_to
43
+
44
+ def rhino_command(*args)
45
+ "java -jar '#{shen_path_to 'lib/shenandoah/javascript/console/js.jar'}' -w -debug '#{args.join("' '")}'"
46
+ end
47
+
48
+ def shell_html_path
49
+ "#{@locator.tmp_path}/shell.html"
50
+ end
51
+
52
+ def shell_js_path
53
+ "#{@locator.tmp_path}/shell.js"
54
+ end
55
+
56
+ def create_shell_html
57
+ FileUtils.mkdir_p File.dirname(shell_html_path)
58
+ File.open(shell_html_path, 'w') do |f|
59
+ f.write "<html><body></body></html>"
60
+ end
61
+ end
62
+
63
+ def create_shell_js
64
+ js = ERB.new(File.read(shen_path_to('lib/shenandoah/javascript/console/shell.js.erb'))).result(binding)
65
+ FileUtils.mkdir_p File.dirname(shell_js_path)
66
+ File.open(shell_js_path, 'w') { |f| f.write js }
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,88 @@
1
+ require 'sinatra'
2
+ require 'haml'
3
+
4
+ module Shenandoah
5
+ # The server which enables in-browser execution of Screw.Unit specs in
6
+ # Shenandoah.
7
+ #
8
+ # It exposes a list of all the specs at the root of the server,
9
+ # organized by subdirectory, with links to individual test fixtures.
10
+ # The contents of the +main_path+ and +spec_path+ in the configured locator
11
+ # are exposed under <tt>/main</tt> and <tt>/spec</tt> respectively.
12
+ class Server < Sinatra::Base
13
+ set :root, File.dirname(__FILE__) + "/server"
14
+ set :port, 4410
15
+ enable :logging
16
+
17
+ get '/' do
18
+ section_map = options.locator.spec_files.
19
+ collect { |t| t.sub(%r{^#{options.locator.spec_path}/?}, '') }.
20
+ collect { |t| [File.dirname(t), File.basename(t).sub(/_spec.js$/, '.html')] }.
21
+ inject({}) { |h, (dir, file)| h[dir] ||= []; h[dir] << file; h }
22
+ @sections = section_map.collect { |dir, files| [dir, files.sort] }.sort
23
+
24
+ haml :index
25
+ end
26
+
27
+ get '/main/*' do
28
+ map_file(options.locator.main_path, params[:splat].first, "Main")
29
+ end
30
+
31
+ get '/spec/*' do
32
+ map_file(options.locator.spec_path, params[:splat].first, "Spec")
33
+ end
34
+
35
+ get '/screw.css' do
36
+ screw_css = File.join(options.locator.spec_path, 'screw.css')
37
+ unless File.exist?(screw_css)
38
+ screw_css = File.join(File.dirname(__FILE__), 'css/screw.css')
39
+ end
40
+ send_file screw_css
41
+ end
42
+
43
+ get '/shenandoah/browser-runner.js' do
44
+ content_type 'text/javascript'
45
+
46
+ last_modified runner_files.collect { |filename|
47
+ File.stat("#{File.dirname(__FILE__)}/#{filename}").mtime
48
+ }.max
49
+
50
+ runner_files.collect { |filename|
51
+ [
52
+ "\n//////\n////// #{filename}\n//////\n",
53
+ File.read("#{File.dirname(__FILE__)}/#{filename}")
54
+ ]
55
+ }.flatten
56
+ end
57
+
58
+ protected
59
+
60
+ def map_file(path, name, desc) # :nodoc:
61
+ file = File.join(path, name)
62
+ if File.exist?(file)
63
+ headers['Cache-Control'] = 'no-cache'
64
+ send_file file
65
+ else
66
+ halt 404, "#{desc} file not found: #{file}"
67
+ end
68
+ end
69
+
70
+ def runner_files # :nodoc:
71
+ # Can't just use Dir[] because order is important
72
+ [
73
+ "javascript/common/jquery-1.3.2.js",
74
+ "javascript/common/jquery.fn.js",
75
+ "javascript/common/jquery.print.js",
76
+ "javascript/common/screw.builder.js",
77
+ "javascript/common/screw.matchers.js",
78
+ "javascript/common/screw.events.js",
79
+ "javascript/common/screw.behaviors.js",
80
+ "javascript/common/smoke.core.js",
81
+ "javascript/common/smoke.mock.js",
82
+ "javascript/common/smoke.stub.js",
83
+ "javascript/common/screw.mocking.js",
84
+ "javascript/browser/runner.js"
85
+ ]
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,12 @@
1
+ %html
2
+ %head
3
+ %link{ :rel => "stylesheet", :href => "/screw.css", :type => "text/css", :charset => "utf-8" }
4
+ %body
5
+ - if options.respond_to?(:project_name) && options.project_name
6
+ %h1= "Specs for #{options.project_name}"
7
+ - @sections.each do |section, tests|
8
+ %h2= section == '.' ? '[root]' : section
9
+ %ul
10
+ - tests.each do |test|
11
+ %li
12
+ %a{ :href => ["spec", section, test].reject { |s| s == '.' }.join('/') }= test.sub(/.html$/, '')
@@ -0,0 +1,62 @@
1
+ require 'rake'
2
+ require 'shenandoah/runner'
3
+ require 'shenandoah/server'
4
+
5
+ module Shenandoah
6
+ class Tasks
7
+ attr_accessor :locator, :options, :runner
8
+
9
+ def initialize(options = {})
10
+ @options = options
11
+ @locator =
12
+ if options[:locator]
13
+ options[:locator]
14
+ else
15
+ default_locator_type.new(options)
16
+ end
17
+ @runner = Shenandoah::Runner.new(@locator)
18
+ create_serve_task
19
+ create_shell_task
20
+ create_run_task
21
+ end
22
+
23
+ def run_specs
24
+ files = @locator.spec_files
25
+ if ENV['SHEN_SPEC']
26
+ files = files.select { |f| f =~ /#{ENV['SHEN_SPEC']}/ }
27
+ end
28
+ successes = @runner.run_console(files)
29
+ if (successes.size != files.size)
30
+ raise "Shenandoah specs failed!"
31
+ end
32
+ end
33
+
34
+ protected
35
+
36
+ def default_locator_type
37
+ DefaultLocator
38
+ end
39
+
40
+ def create_serve_task
41
+ task('shen:serve') do |t|
42
+ Shenandoah::Server.set :locator, @locator
43
+ if @options[:project_name]
44
+ Shenandoah::Server.set :project_name, @options[:project_name]
45
+ end
46
+ Shenandoah::Server.run!
47
+ end
48
+ end
49
+
50
+ def create_shell_task
51
+ task('shen:shell') do |t|
52
+ @runner.run_shell
53
+ end
54
+ end
55
+
56
+ def create_run_task
57
+ task('shen:spec') do |t|
58
+ run_specs
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,27 @@
1
+ require 'rails_generator'
2
+ require 'shenandoah/rails/locator'
3
+
4
+ module Shenandoah
5
+ module Generators
6
+ class ShenSpecGenerator < ::Rails::Generator::NamedBase
7
+ def manifest
8
+ spec_path = Shenandoah::Rails::Locator.new.spec_path.sub %r{^#{RAILS_ROOT}/}, ''
9
+ record do |m|
10
+ m.directory "#{spec_path}/#{File.dirname(file_path)}"
11
+ m.template 'javascript_spec.js.erb', "#{spec_path}/#{file_path}_spec.js"
12
+ m.template 'fixture.html.erb', "#{spec_path}/#{file_path}.html"
13
+ end
14
+ end
15
+
16
+ def file_path
17
+ super.sub /_spec$/, ''
18
+ end
19
+
20
+ def javascript_class_name
21
+ klass, *mods_rev = class_name.sub(/Spec$/, '').split('::').reverse
22
+ mod_spec = mods_rev.reverse.collect { |m| m.downcase }.join('.')
23
+ [mod_spec, klass].reject { |p| p == "" }.join '.'
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
2
+ <html xmlns="http://www.w3.org/1999/xhtml">
3
+
4
+ <head>
5
+ <title><%= file_name %>.js | JavaScript Testing Results</title>
6
+ <link rel="stylesheet" href="/screw.css" type="text/css" charset="utf-8" />
7
+ <script type="text/javascript" src="/shenandoah/browser-runner.js"></script>
8
+ </head>
9
+
10
+ <body>
11
+ <!-- Put any HTML fixture elements here. -->
12
+ </body>
13
+ </html>
@@ -0,0 +1,8 @@
1
+ require_spec('spec_helper.js');
2
+ require_main('<%= file_path %>.js');
3
+
4
+ describe('<%= javascript_class_name %>', function () {
5
+ it("needs tests", function () {
6
+ expect("you").to(include, "some tests");
7
+ });
8
+ });
@@ -0,0 +1,21 @@
1
+ require 'rails_generator'
2
+ require 'shenandoah/rails/locator'
3
+
4
+ module Shenandoah
5
+ module Generators
6
+ class ShenandoahGenerator < ::Rails::Generator::Base
7
+ def manifest
8
+ spec_path = Shenandoah::Rails::Locator.new.spec_path.sub %r{^#{RAILS_ROOT}/}, ''
9
+ record do |m|
10
+ m.directory "lib/tasks"
11
+ m.file "shenandoah.rake", "lib/tasks/shenandoah.rake"
12
+
13
+ m.directory spec_path
14
+ m.file "spec_helper.js", "#{spec_path}/spec_helper.js"
15
+ m.file "application_spec.js", "#{spec_path}/application_spec.js"
16
+ m.file "application.html", "#{spec_path}/application.html"
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end