shenandoah 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/ChangeLog.markdown CHANGED
@@ -1,3 +1,12 @@
1
+ 0.1.1
2
+ =====
3
+
4
+ * Correct bug in Shenandoah::Tasks which made plain-Rakefile use not work
5
+ * Add task descriptions for all the tasks -- visible with rake -T
6
+ * Automatically absolutize locator paths for plain-Rakefile use
7
+ * Allow specs to be constrained using rake task arguments instead of an env var
8
+ * Allow spec generator to be invoked from any project (not just rails projects) via `rake shen:generate[spec_name]`
9
+
1
10
  0.1.0
2
11
  =====
3
12
 
data/README.markdown CHANGED
@@ -78,7 +78,7 @@ To run the specs from the command line:
78
78
 
79
79
  To run an individual spec file called "application_spec.js":
80
80
 
81
- $ rake shen:spec SHEN_SPEC=application
81
+ $ rake shen:spec[application]
82
82
 
83
83
  To start the server:
84
84
 
@@ -103,7 +103,7 @@ To run all the specs from the command_line:
103
103
 
104
104
  To run an individual spec file called "application_spec.js":
105
105
 
106
- $ rake shen:spec SHEN_SPEC=application
106
+ $ rake shen:spec[application]
107
107
 
108
108
  To start the server:
109
109
 
data/Rakefile CHANGED
@@ -22,6 +22,7 @@ begin
22
22
  # Have to use rspec 1.2.4 for buildr compat
23
23
  gem.add_development_dependency('rspec', '= 1.2.4')
24
24
  gem.add_development_dependency('rack-test', '>= 0.3.0')
25
+ gem.add_development_dependency('hpricot', '>= 0.8.1')
25
26
  gem.add_development_dependency('rspec_hpricot_matchers', '>= 1.0.0')
26
27
  gem.add_development_dependency('braid', '>= 0.5.0')
27
28
 
@@ -31,6 +32,13 @@ begin
31
32
  gem.add_development_dependency('net-sftp', '= 2.0.2')
32
33
  gem.add_development_dependency('highline', '= 1.5.0')
33
34
  gem.add_development_dependency('hoe', '= 1.12.2')
35
+ gem.add_development_dependency('rubyzip', '= 0.9.1')
36
+ gem.add_development_dependency('builder', '= 2.1.2')
37
+ gem.add_development_dependency('rubyforge', '= 1.0.3')
38
+ gem.add_development_dependency('rjb', '= 1.1.6')
39
+ gem.add_development_dependency('Antwrap', '= 0.7.0')
40
+ gem.add_development_dependency('xml-simple', '= 1.0.12')
41
+ gem.add_development_dependency('archive-tar-minitar', '= 0.5.2')
34
42
  end
35
43
 
36
44
  Jeweler::RubyforgeTasks.new
@@ -41,6 +49,7 @@ end
41
49
  require 'spec/rake/spectask'
42
50
  Spec::Rake::SpecTask.new(:spec) do |spec|
43
51
  spec.libs << 'lib' << 'spec'
52
+ spec.verbose = true
44
53
  spec.spec_files = FileList['spec/**/*_spec.rb']
45
54
  end
46
55
 
@@ -54,18 +63,27 @@ end
54
63
 
55
64
  task :default => :spec
56
65
 
57
- require 'rake/rdoctask'
58
- Rake::RDocTask.new do |rdoc|
66
+ def version
59
67
  if File.exist?('VERSION.yml')
60
68
  config = YAML.load(File.read('VERSION.yml'))
61
- version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
69
+ "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
62
70
  else
63
- version = ""
71
+ ""
64
72
  end
73
+ end
65
74
 
75
+ require 'rake/rdoctask'
76
+ Rake::RDocTask.new do |rdoc|
66
77
  rdoc.rdoc_dir = 'rdoc'
67
78
  rdoc.title = "shenandoah #{version}"
68
79
  rdoc.rdoc_files.include('README*')
69
80
  rdoc.rdoc_files.include('lib/**/*.rb')
70
81
  end
71
82
 
83
+ desc "Uninstall the current (development) version of the gem"
84
+ task :uninstall do |t|
85
+ system("sudo gem uninstall shenandoah -v #{version}")
86
+ end
87
+
88
+ task :build => [:gemspec]
89
+ task :install => [:uninstall]
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 1
4
- :patch: 0
4
+ :patch: 1
@@ -5,13 +5,15 @@ module Shenandoah
5
5
  attr_accessor :main_path, :spec_path, :tmp_path
6
6
 
7
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"
8
+ @main_path = File.expand_path(options[:main_path] || "lib")
9
+ @spec_path = File.expand_path(options[:spec_path] || "spec")
10
+ @tmp_path = File.expand_path(options[:tmp_path] || ENV['TMPDIR'] || "tmp")
11
11
  end
12
12
 
13
13
  def spec_files
14
14
  FileList["#{spec_path}/**/*_spec.js"]
15
15
  end
16
+
17
+ private
16
18
  end
17
19
  end
@@ -28,7 +28,7 @@ module Shenandoah
28
28
  create_shell_html
29
29
  create_shell_js
30
30
 
31
- rlwrap = `which rlwrap`.chomp
31
+ rlwrap = `which rlwrap`.chomp.sub(/^no.*/, '') # some versions of which report errors on stdout
32
32
  cmd = "#{rlwrap} #{rhino_command('-f', shell_js_path, '-f', '-')}"
33
33
  $stderr.puts "Starting shell with #{cmd}"
34
34
  system(cmd)
@@ -1,6 +1,9 @@
1
1
  require 'rake'
2
+ require 'shenandoah/locator'
2
3
  require 'shenandoah/runner'
3
4
  require 'shenandoah/server'
5
+ require 'rails_generator'
6
+ require 'rails_generator/scripts/generate'
4
7
 
5
8
  module Shenandoah
6
9
  class Tasks
@@ -18,26 +21,58 @@ module Shenandoah
18
21
  create_serve_task
19
22
  create_shell_task
20
23
  create_run_task
24
+ create_gen_task
21
25
  end
22
26
 
23
- def run_specs
27
+ def run_specs(pattern=nil)
24
28
  files = @locator.spec_files
25
29
  if ENV['SHEN_SPEC']
30
+ trace "limiting shenandoah specs based on #{ENV['SHEN_SPEC'].inspect}"
26
31
  files = files.select { |f| f =~ /#{ENV['SHEN_SPEC']}/ }
27
32
  end
33
+ if pattern
34
+ trace "limiting shenandoah specs based on #{pattern.inspect}"
35
+ files = files.select { |f| f =~ /#{pattern}/ }
36
+ end
37
+ trace "running shenandoah specs\n - #{files.join("\n - ")}"
28
38
  successes = @runner.run_console(files)
29
39
  if (successes.size != files.size)
30
40
  raise "Shenandoah specs failed!"
31
41
  end
32
42
  end
33
43
 
44
+ def generate_spec(name)
45
+ raise "Please specify a spec name. E.g., shen:generate[foo]." unless name
46
+ ::Rails::Generator::Base::prepend_sources(
47
+ ::Rails::Generator::PathSource.new(
48
+ :shenandoah, File.join(File.dirname(__FILE__), '../../rails_generators'))
49
+ )
50
+ # These branches are functionally equivalent. They change the logging
51
+ # that rails_generator emits to omit the WD when the target is under
52
+ # the WD.
53
+ ENV['SHEN_SPEC_PATH'], dest =
54
+ if @locator.spec_path =~ /^#{FileUtils.pwd}\/?/
55
+ [@locator.spec_path.sub(/^#{FileUtils.pwd}\/?/, ''), FileUtils.pwd]
56
+ else
57
+ [@locator.spec_path, '']
58
+ end
59
+ ::Rails::Generator::Scripts::Generate.new.run(
60
+ ['shen_spec', '-t', name], :destination => dest,
61
+ :quiet => Rake.application.options.quiet)
62
+ end
63
+
34
64
  protected
35
65
 
66
+ def trace(msg)
67
+ $stderr.puts msg if Rake.application.options.trace
68
+ end
69
+
36
70
  def default_locator_type
37
71
  DefaultLocator
38
72
  end
39
73
 
40
74
  def create_serve_task
75
+ desc "Start the in-browser JavaScript spec runner on http://localhost:4410/"
41
76
  task('shen:serve') do |t|
42
77
  Shenandoah::Server.set :locator, @locator
43
78
  if @options[:project_name]
@@ -48,14 +83,23 @@ module Shenandoah
48
83
  end
49
84
 
50
85
  def create_shell_task
86
+ desc "Start the Shenandoah interactive JavaScript shell"
51
87
  task('shen:shell') do |t|
52
88
  @runner.run_shell
53
89
  end
54
90
  end
55
91
 
56
92
  def create_run_task
57
- task('shen:spec') do |t|
58
- run_specs
93
+ desc "Run the JavaScript specs"
94
+ task('shen:spec', :pattern) do |t, args|
95
+ run_specs args.pattern
96
+ end
97
+ end
98
+
99
+ def create_gen_task
100
+ desc "Generate a skeleton spec. Give the spec name as a task arg -- i.e. shen:generate[commands]."
101
+ task('shen:generate', :basename) do |t, args|
102
+ generate_spec args.basename
59
103
  end
60
104
  end
61
105
  end
@@ -5,7 +5,7 @@ module Shenandoah
5
5
  module Generators
6
6
  class ShenSpecGenerator < ::Rails::Generator::NamedBase
7
7
  def manifest
8
- spec_path = Shenandoah::Rails::Locator.new.spec_path.sub %r{^#{RAILS_ROOT}/}, ''
8
+ spec_path = ENV['SHEN_SPEC_PATH'] || Shenandoah::Rails::Locator.new.spec_path.sub(%r{^#{RAILS_ROOT}/}, '')
9
9
  record do |m|
10
10
  m.directory "#{spec_path}/#{File.dirname(file_path)}"
11
11
  m.template 'javascript_spec.js.erb', "#{spec_path}/#{file_path}_spec.js"
data/shenandoah.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{shenandoah}
5
- s.version = "0.1.0"
5
+ s.version = "0.1.1"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Rhett Sutphin"]
9
- s.date = %q{2009-06-16}
9
+ s.date = %q{2009-07-14}
10
10
  s.email = %q{rhett@detailedbalance.net}
11
11
  s.extra_rdoc_files = [
12
12
  "ChangeLog.markdown",
@@ -115,6 +115,7 @@ Gem::Specification.new do |s|
115
115
  s.add_runtime_dependency(%q<rails>, [">= 2.1.0"])
116
116
  s.add_development_dependency(%q<rspec>, ["= 1.2.4"])
117
117
  s.add_development_dependency(%q<rack-test>, [">= 0.3.0"])
118
+ s.add_development_dependency(%q<hpricot>, [">= 0.8.1"])
118
119
  s.add_development_dependency(%q<rspec_hpricot_matchers>, [">= 1.0.0"])
119
120
  s.add_development_dependency(%q<braid>, [">= 0.5.0"])
120
121
  s.add_development_dependency(%q<rake>, ["= 0.8.4"])
@@ -122,6 +123,13 @@ Gem::Specification.new do |s|
122
123
  s.add_development_dependency(%q<net-sftp>, ["= 2.0.2"])
123
124
  s.add_development_dependency(%q<highline>, ["= 1.5.0"])
124
125
  s.add_development_dependency(%q<hoe>, ["= 1.12.2"])
126
+ s.add_development_dependency(%q<rubyzip>, ["= 0.9.1"])
127
+ s.add_development_dependency(%q<builder>, ["= 2.1.2"])
128
+ s.add_development_dependency(%q<rubyforge>, ["= 1.0.3"])
129
+ s.add_development_dependency(%q<rjb>, ["= 1.1.6"])
130
+ s.add_development_dependency(%q<Antwrap>, ["= 0.7.0"])
131
+ s.add_development_dependency(%q<xml-simple>, ["= 1.0.12"])
132
+ s.add_development_dependency(%q<archive-tar-minitar>, ["= 0.5.2"])
125
133
  else
126
134
  s.add_dependency(%q<sinatra>, [">= 0.9.2"])
127
135
  s.add_dependency(%q<haml>, [">= 2.0.9"])
@@ -129,6 +137,7 @@ Gem::Specification.new do |s|
129
137
  s.add_dependency(%q<rails>, [">= 2.1.0"])
130
138
  s.add_dependency(%q<rspec>, ["= 1.2.4"])
131
139
  s.add_dependency(%q<rack-test>, [">= 0.3.0"])
140
+ s.add_dependency(%q<hpricot>, [">= 0.8.1"])
132
141
  s.add_dependency(%q<rspec_hpricot_matchers>, [">= 1.0.0"])
133
142
  s.add_dependency(%q<braid>, [">= 0.5.0"])
134
143
  s.add_dependency(%q<rake>, ["= 0.8.4"])
@@ -136,6 +145,13 @@ Gem::Specification.new do |s|
136
145
  s.add_dependency(%q<net-sftp>, ["= 2.0.2"])
137
146
  s.add_dependency(%q<highline>, ["= 1.5.0"])
138
147
  s.add_dependency(%q<hoe>, ["= 1.12.2"])
148
+ s.add_dependency(%q<rubyzip>, ["= 0.9.1"])
149
+ s.add_dependency(%q<builder>, ["= 2.1.2"])
150
+ s.add_dependency(%q<rubyforge>, ["= 1.0.3"])
151
+ s.add_dependency(%q<rjb>, ["= 1.1.6"])
152
+ s.add_dependency(%q<Antwrap>, ["= 0.7.0"])
153
+ s.add_dependency(%q<xml-simple>, ["= 1.0.12"])
154
+ s.add_dependency(%q<archive-tar-minitar>, ["= 0.5.2"])
139
155
  end
140
156
  else
141
157
  s.add_dependency(%q<sinatra>, [">= 0.9.2"])
@@ -144,6 +160,7 @@ Gem::Specification.new do |s|
144
160
  s.add_dependency(%q<rails>, [">= 2.1.0"])
145
161
  s.add_dependency(%q<rspec>, ["= 1.2.4"])
146
162
  s.add_dependency(%q<rack-test>, [">= 0.3.0"])
163
+ s.add_dependency(%q<hpricot>, [">= 0.8.1"])
147
164
  s.add_dependency(%q<rspec_hpricot_matchers>, [">= 1.0.0"])
148
165
  s.add_dependency(%q<braid>, [">= 0.5.0"])
149
166
  s.add_dependency(%q<rake>, ["= 0.8.4"])
@@ -151,5 +168,12 @@ Gem::Specification.new do |s|
151
168
  s.add_dependency(%q<net-sftp>, ["= 2.0.2"])
152
169
  s.add_dependency(%q<highline>, ["= 1.5.0"])
153
170
  s.add_dependency(%q<hoe>, ["= 1.12.2"])
171
+ s.add_dependency(%q<rubyzip>, ["= 0.9.1"])
172
+ s.add_dependency(%q<builder>, ["= 2.1.2"])
173
+ s.add_dependency(%q<rubyforge>, ["= 1.0.3"])
174
+ s.add_dependency(%q<rjb>, ["= 1.1.6"])
175
+ s.add_dependency(%q<Antwrap>, ["= 0.7.0"])
176
+ s.add_dependency(%q<xml-simple>, ["= 1.0.12"])
177
+ s.add_dependency(%q<archive-tar-minitar>, ["= 0.5.2"])
154
178
  end
155
179
  end
@@ -25,9 +25,9 @@ describe Shenandoah::Buildr::Locator do
25
25
 
26
26
  it "allows main to be overriden with test.using" do |variable|
27
27
  p = define('another', :base_dir => tmpdir) do
28
- test.using :main_path => "foo"
28
+ test.using :main_path => "/foo"
29
29
  end
30
30
 
31
- Shenandoah::Buildr::Locator.new(p).main_path.should == "foo"
31
+ Shenandoah::Buildr::Locator.new(p).main_path.should == "/foo"
32
32
  end
33
33
  end
@@ -11,12 +11,12 @@ describe Shenandoah::DefaultLocator do
11
11
  @loc = Shenandoah::DefaultLocator.new
12
12
  end
13
13
 
14
- it "has main_path = lib" do
15
- @loc.main_path.should == "lib"
14
+ it "has main_path = `pwd`/lib" do
15
+ @loc.main_path.should == File.join(FileUtils.pwd, "lib")
16
16
  end
17
17
 
18
- it "has spec_path = spec" do
19
- @loc.spec_path.should == "spec"
18
+ it "has spec_path = `pwd`/spec" do
19
+ @loc.spec_path.should == File.join(FileUtils.pwd, "spec")
20
20
  end
21
21
 
22
22
  it "uses the TMPDIR env var for tmp" do
@@ -25,21 +25,31 @@ describe Shenandoah::DefaultLocator do
25
25
  end
26
26
 
27
27
  it "has tmp_path = tmp" do
28
- @loc.tmp_path.should == "tmp"
28
+ @loc.tmp_path.should == File.join(FileUtils.pwd, "tmp")
29
29
  end
30
30
  end
31
31
 
32
32
  describe "initializing from options" do
33
33
  it "uses an explicit main path" do
34
- Shenandoah::DefaultLocator.new(:main_path => 'main').main_path.should == 'main'
34
+ Shenandoah::DefaultLocator.new(:main_path => '/main').main_path.should == '/main'
35
35
  end
36
36
 
37
37
  it "uses an explicit spec path" do
38
- Shenandoah::DefaultLocator.new(:spec_path => 'foo').spec_path.should == 'foo'
38
+ Shenandoah::DefaultLocator.new(:spec_path => '/foo').spec_path.should == '/foo'
39
39
  end
40
40
 
41
41
  it "uses an explicit tmp path" do
42
- Shenandoah::DefaultLocator.new(:tmp_path => 'foo').tmp_path.should == 'foo'
42
+ Shenandoah::DefaultLocator.new(:tmp_path => '/foo/tmp').tmp_path.should == '/foo/tmp'
43
+ end
44
+
45
+ describe "with relative paths" do
46
+ %w(main_path spec_path tmp_path).each do |kind|
47
+ k = kind.to_sym
48
+ it "absolutizes #{kind} against the working directory" do
49
+ Shenandoah::DefaultLocator.new(k => 'bar').send(k).should ==
50
+ File.join(FileUtils.pwd, 'bar')
51
+ end
52
+ end
43
53
  end
44
54
  end
45
55
 
@@ -26,7 +26,7 @@ describe Shenandoah::Rails::Tasks do
26
26
  end
27
27
 
28
28
  it "uses the explicitly provided locator over all others" do
29
- loc = Shenandoah::DefaultLocator.new(:main_path => 'foo')
30
- Shenandoah::Rails::Tasks.new(:locator => loc).locator.main_path.should == 'foo'
29
+ loc = Shenandoah::DefaultLocator.new(:main_path => '/foo')
30
+ Shenandoah::Rails::Tasks.new(:locator => loc).locator.main_path.should == '/foo'
31
31
  end
32
32
  end
@@ -68,25 +68,19 @@ describe Shenandoah::Runner do
68
68
 
69
69
  describe "#run_shell" do
70
70
  before do
71
- script_contents = ERB.new(<<-RUBY).result(binding)
72
- # This is a small script to invoke Runner#run_shell so that it's
73
- # input and output can be controlled for testing
74
- <% $LOAD_PATH.select { |p| p =~ /shenandoah/ }.each do |p| %>
75
- $LOAD_PATH.unshift(<%= p.inspect %>)
76
- <% end %>
71
+ tmpscript "spec_shell.rb", <<-RUBY
77
72
  require 'rubygems'
78
73
  require 'shenandoah/runner'
79
74
  require 'shenandoah/locator'
80
75
 
81
76
  loc = Shenandoah::DefaultLocator.new(
82
- :main_path => <%= @locator.main_path.inspect %>,
83
- :spec_path => <%= @locator.spec_path.inspect %>,
84
- :tmp_path => <%= @locator.tmp_path.inspect %>
77
+ :main_path => #{@locator.main_path.inspect},
78
+ :spec_path => #{@locator.spec_path.inspect},
79
+ :tmp_path => #{@locator.tmp_path.inspect}
85
80
  )
86
81
 
87
82
  Shenandoah::Runner.new(loc).run_shell
88
83
  RUBY
89
- tmpfile "spec_shell.rb", script_contents
90
84
  end
91
85
 
92
86
  def run_shell(jslines)
@@ -3,23 +3,24 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
3
3
  require 'shenandoah/tasks'
4
4
  require 'shenandoah/locator'
5
5
  require 'shenandoah/rails/locator'
6
+ require 'open3'
6
7
 
7
8
  describe Shenandoah::Tasks do
8
9
  describe "init" do
9
10
  include Shenandoah::Spec::Tmpfile
10
-
11
+
11
12
  it "uses a DefaultLocator by default" do
12
13
  Shenandoah::Tasks.new.locator.class.should == Shenandoah::DefaultLocator
13
14
  end
14
15
 
15
16
  it "configures the default locator with the provided options" do
16
- Shenandoah::Tasks.new(:main_path => 'foo').locator.main_path.should == 'foo'
17
+ Shenandoah::Tasks.new(:main_path => '/foo').locator.main_path.should == '/foo'
17
18
  end
18
-
19
+
19
20
  it "uses an explictly provided locator, ignoring other options" do
20
- loc = Shenandoah::DefaultLocator.new(:main_path => 'bar')
21
+ loc = Shenandoah::DefaultLocator.new(:main_path => '/bar')
21
22
  tasks = Shenandoah::Tasks.new(:locator => loc, :main_path => 'foo')
22
- tasks.locator.main_path.should == 'bar'
23
+ tasks.locator.main_path.should == '/bar'
23
24
  end
24
25
  end
25
26
 
@@ -36,13 +37,37 @@ describe Shenandoah::Tasks do
36
37
  Rake::Task::task_defined?('shen:serve').should be_true
37
38
  end
38
39
 
40
+ it "gives the shen:serve task a description" do
41
+ Rake::Task['shen:serve'].full_comment.should ==
42
+ "Start the in-browser JavaScript spec runner on http://localhost:4410/"
43
+ end
44
+
39
45
  it "adds a shen:shell task" do
40
46
  Rake::Task::task_defined?('shen:shell').should be_true
41
47
  end
42
48
 
49
+ it "gives the shen:shell task a description" do
50
+ Rake::Task['shen:shell'].full_comment.should ==
51
+ "Start the Shenandoah interactive JavaScript shell"
52
+ end
53
+
43
54
  it "adds a shen:spec task" do
44
55
  Rake::Task::task_defined?('shen:spec').should be_true
45
56
  end
57
+
58
+ it "gives the shen:spec task a description" do
59
+ Rake::Task['shen:spec'].full_comment.should ==
60
+ "Run the JavaScript specs"
61
+ end
62
+
63
+ it "adds a shen:generate task" do
64
+ Rake::Task::task_defined?('shen:generate').should be_true
65
+ end
66
+
67
+ it "gives the shen:generate task a description" do
68
+ Rake::Task['shen:generate'].full_comment.should ==
69
+ "Generate a skeleton spec. Give the spec name as a task arg -- i.e. shen:generate[commands]."
70
+ end
46
71
  end
47
72
 
48
73
  describe "running" do
@@ -75,6 +100,13 @@ describe Shenandoah::Tasks do
75
100
  @tasks.run_specs
76
101
  end
77
102
 
103
+ it "only runs the specs matching the pattern argument" do
104
+ @locator.should_receive(:spec_files).and_return(%w(ab bc cd))
105
+ @runner.should_receive(:run_console).with(%w(bc cd)).and_return(%w(bc cd))
106
+
107
+ @tasks.run_specs 'c'
108
+ end
109
+
78
110
  it "throws an exception on failure" do
79
111
  @locator.should_receive(:spec_files).and_return(%w(a b c))
80
112
  @runner.should_receive(:run_console).with(%w(a b c)).and_return(%w(a b))
@@ -82,4 +114,187 @@ describe Shenandoah::Tasks do
82
114
  lambda { @tasks.run_specs }.should raise_error(/Shenandoah specs failed!/)
83
115
  end
84
116
  end
117
+
118
+ describe "running for real" do
119
+ include Shenandoah::Spec::Tmpfile
120
+
121
+ before do
122
+ tmpscript "Rakefile", <<-RUBY
123
+ require 'shenandoah/tasks'
124
+ Shenandoah::Tasks.new
125
+ RUBY
126
+ end
127
+
128
+ def run_specs(task='shen:spec')
129
+ FileUtils.cd @tmpdir do
130
+ Open3.popen3("rake _#{SHEN_RAKE_VERSION}_ #{task}") do |stdin, stdout, stderr|
131
+ stdin.close
132
+ return stdout.read, stderr.read
133
+ end
134
+ end
135
+ end
136
+
137
+ def create_passing_spec(name='good')
138
+ tmpfile "spec/#{name}_spec.js", <<-JS
139
+ Screw.Unit(function () {
140
+ describe("good", function () {
141
+ it("passes", function () {
142
+ expect("good").to(equal, "good");
143
+ });
144
+ });
145
+ });
146
+ JS
147
+ tmpfile "spec/#{name}.html", <<-HTML
148
+ <html>
149
+ <head></head>
150
+ <body></body>
151
+ </html>
152
+ HTML
153
+ end
154
+
155
+ def create_failing_spec(name='bad')
156
+ tmpfile "spec/#{name}_spec.js", <<-JS
157
+ Screw.Unit(function () {
158
+ describe("bad", function () {
159
+ it("fails", function () {
160
+ expect("bad").to(equal, "good");
161
+ });
162
+ });
163
+ });
164
+ JS
165
+ tmpfile "spec/#{name}.html", <<-HTML
166
+ <html>
167
+ <head></head>
168
+ <body></body>
169
+ </html>
170
+ HTML
171
+ end
172
+
173
+ it "passes for a good spec" do
174
+ create_passing_spec
175
+
176
+ out, err = run_specs
177
+
178
+ err.should == ""
179
+ out.should =~ %r{1 test\(s\), 0 failure\(s\)}
180
+ end
181
+
182
+ it "reports all results together" do
183
+ pending
184
+ create_passing_spec('a')
185
+ create_passing_spec('b')
186
+ create_passing_spec('c')
187
+
188
+ out, err = run_specs
189
+
190
+ err.should == ""
191
+ out.should =~ %r{3 test\(s\), 0 failure\(s\)}
192
+ end
193
+
194
+ it "fails for a bad spec" do
195
+ create_failing_spec
196
+
197
+ out, err = run_specs
198
+
199
+ err.should =~ /Shenandoah specs failed/
200
+ out.should =~ %r{1 test\(s\), 1 failure\(s\)}
201
+ end
202
+
203
+ it "reports all failures" do
204
+ pending
205
+ create_failing_spec('a')
206
+ create_passing_spec('b')
207
+ create_failing_spec('c')
208
+
209
+ out, err = run_specs
210
+
211
+ err.should =~ /Shenandoah specs failed/
212
+ out.should =~ %r{3 test\(s\), 2 failure\(s\)}
213
+ end
214
+
215
+ it "only runs the specs matching the arg" do
216
+ create_passing_spec('foo')
217
+ create_passing_spec('bar')
218
+ create_passing_spec('baz')
219
+
220
+ out, err = run_specs('shen:spec[ba]')
221
+
222
+ err.should == ""
223
+ out.should_not =~ %r{Running foo_spec}
224
+ out.should =~ %r{Running bar_spec}
225
+ out.should =~ %r{Running baz_spec}
226
+ end
227
+ end
228
+
229
+ describe "generation" do
230
+ include Shenandoah::Spec::Tmpfile
231
+
232
+ before do
233
+ @quiet = Rake.application.options.quiet
234
+ Rake.application.options.quiet = true
235
+ end
236
+
237
+ after do
238
+ Rake.application.options.quiet = @quiet
239
+ end
240
+
241
+ describe "when spec path is under the working directory" do
242
+ before do
243
+ @specdir = tmpdir('specs')
244
+ @tasks = Shenandoah::Tasks.new(:spec_path => @specdir)
245
+ end
246
+
247
+ it "fails without a name" do
248
+ lambda { @tasks.generate_spec(nil) }.
249
+ should raise_error(/Please specify a spec name. E.g., shen:generate\[foo\]./)
250
+ end
251
+
252
+ it "generates the spec file" do
253
+ @tasks.generate_spec('arb')
254
+ File.exist?("#{@specdir}/arb_spec.js").should be_true
255
+ end
256
+
257
+ it "generates the HTML fixture" do
258
+ @tasks.generate_spec('zamm')
259
+ File.exist?("#{@specdir}/zamm.html").should be_true
260
+ end
261
+
262
+ describe "with nested paths" do
263
+ before do
264
+ @tasks.generate_spec("frob/zazz")
265
+ end
266
+
267
+ it "generates the spec file" do
268
+ File.exist?("#{@specdir}/frob/zazz_spec.js").should be_true
269
+ end
270
+
271
+ it "generates the HTML fixture" do
272
+ File.exist?("#{@specdir}/frob/zazz.html").should be_true
273
+ end
274
+ end
275
+ end
276
+
277
+ describe "when spec_path is not a child of working directory" do
278
+ before do
279
+ @original_wd = FileUtils.pwd
280
+ @specdir = tmpdir('specs')
281
+ @tasks = Shenandoah::Tasks.new(:spec_path => @specdir)
282
+ FileUtils.cd tmpdir('other')
283
+
284
+ @tasks.generate_spec("zip/zoom")
285
+ end
286
+
287
+ after do
288
+ FileUtils.cd @original_wd
289
+ end
290
+
291
+ it "generates the spec file" do
292
+ File.exist?("#{@specdir}/zip/zoom_spec.js").should be_true
293
+ end
294
+
295
+ it "generates the HTML fixture" do
296
+ File.exist?("#{@specdir}/zip/zoom.html").should be_true
297
+ end
298
+ end
299
+ end
85
300
  end
data/spec/spec_helper.rb CHANGED
@@ -1,8 +1,9 @@
1
1
  require 'spec'
2
2
  require 'rubygems'
3
-
4
- $LOAD_PATH.unshift(File.dirname(__FILE__))
5
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ # Rake needs to be locked to the version that buildr expects before
4
+ # anything else loads and gets the most recent installed version
5
+ SHEN_RAKE_VERSION = '0.8.4'
6
+ gem 'rake', "= #{SHEN_RAKE_VERSION}"
6
7
 
7
8
  Spec::Runner.configure do |config|
8
9
 
@@ -10,6 +11,13 @@ end
10
11
 
11
12
  module Shenandoah
12
13
  module Spec
14
+ def self.load_path_additions
15
+ [
16
+ File.dirname(__FILE__),
17
+ File.join(File.dirname(__FILE__), '..', 'lib')
18
+ ]
19
+ end
20
+
13
21
  module Tmpfile
14
22
  attr_writer :tmpdir
15
23
 
@@ -20,6 +28,13 @@ module Shenandoah
20
28
  n
21
29
  end
22
30
 
31
+ def tmpscript(name, contents)
32
+ tmpfile name,
33
+ Shenandoah::Spec.load_path_additions.
34
+ map { |a| "$LOAD_PATH.unshift(#{a.inspect})" }.
35
+ join("\n") + "\n" + contents
36
+ end
37
+
23
38
  def tmpdir(name=nil)
24
39
  n = @tmpdir
25
40
  if (name)
@@ -58,4 +73,6 @@ module Shenandoah
58
73
  end
59
74
  end
60
75
  end
61
- end
76
+ end
77
+
78
+ Shenandoah::Spec.load_path_additions.each { |p| $LOAD_PATH.unshift(p) }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shenandoah
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rhett Sutphin
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-16 00:00:00 -05:00
12
+ date: 2009-07-14 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -72,6 +72,16 @@ dependencies:
72
72
  - !ruby/object:Gem::Version
73
73
  version: 0.3.0
74
74
  version:
75
+ - !ruby/object:Gem::Dependency
76
+ name: hpricot
77
+ type: :development
78
+ version_requirement:
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: 0.8.1
84
+ version:
75
85
  - !ruby/object:Gem::Dependency
76
86
  name: rspec_hpricot_matchers
77
87
  type: :development
@@ -142,6 +152,76 @@ dependencies:
142
152
  - !ruby/object:Gem::Version
143
153
  version: 1.12.2
144
154
  version:
155
+ - !ruby/object:Gem::Dependency
156
+ name: rubyzip
157
+ type: :development
158
+ version_requirement:
159
+ version_requirements: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - "="
162
+ - !ruby/object:Gem::Version
163
+ version: 0.9.1
164
+ version:
165
+ - !ruby/object:Gem::Dependency
166
+ name: builder
167
+ type: :development
168
+ version_requirement:
169
+ version_requirements: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "="
172
+ - !ruby/object:Gem::Version
173
+ version: 2.1.2
174
+ version:
175
+ - !ruby/object:Gem::Dependency
176
+ name: rubyforge
177
+ type: :development
178
+ version_requirement:
179
+ version_requirements: !ruby/object:Gem::Requirement
180
+ requirements:
181
+ - - "="
182
+ - !ruby/object:Gem::Version
183
+ version: 1.0.3
184
+ version:
185
+ - !ruby/object:Gem::Dependency
186
+ name: rjb
187
+ type: :development
188
+ version_requirement:
189
+ version_requirements: !ruby/object:Gem::Requirement
190
+ requirements:
191
+ - - "="
192
+ - !ruby/object:Gem::Version
193
+ version: 1.1.6
194
+ version:
195
+ - !ruby/object:Gem::Dependency
196
+ name: Antwrap
197
+ type: :development
198
+ version_requirement:
199
+ version_requirements: !ruby/object:Gem::Requirement
200
+ requirements:
201
+ - - "="
202
+ - !ruby/object:Gem::Version
203
+ version: 0.7.0
204
+ version:
205
+ - !ruby/object:Gem::Dependency
206
+ name: xml-simple
207
+ type: :development
208
+ version_requirement:
209
+ version_requirements: !ruby/object:Gem::Requirement
210
+ requirements:
211
+ - - "="
212
+ - !ruby/object:Gem::Version
213
+ version: 1.0.12
214
+ version:
215
+ - !ruby/object:Gem::Dependency
216
+ name: archive-tar-minitar
217
+ type: :development
218
+ version_requirement:
219
+ version_requirements: !ruby/object:Gem::Requirement
220
+ requirements:
221
+ - - "="
222
+ - !ruby/object:Gem::Version
223
+ version: 0.5.2
224
+ version:
145
225
  description:
146
226
  email: rhett@detailedbalance.net
147
227
  executables: []