warbler 1.3.0.beta1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. data/History.txt +9 -0
  2. data/LICENSE.txt +1 -1
  3. data/Manifest.txt +22 -0
  4. data/README.txt +6 -3
  5. data/Rakefile +2 -2
  6. data/bin/warble +1 -1
  7. data/ext/JarMain.java +3 -2
  8. data/ext/WarMain.java +3 -2
  9. data/ext/WarblerJar.java +2 -1
  10. data/ext/WarblerJarService.java +2 -1
  11. data/lib/warbler.rb +1 -1
  12. data/lib/warbler/application.rb +17 -1
  13. data/lib/warbler/config.rb +12 -3
  14. data/lib/warbler/gems.rb +1 -1
  15. data/lib/warbler/jar.rb +17 -12
  16. data/lib/warbler/task.rb +6 -15
  17. data/lib/warbler/templates/bundler.erb +3 -0
  18. data/lib/warbler/templates/jar.erb +5 -0
  19. data/lib/warbler/templates/rack.erb +1 -1
  20. data/lib/warbler/templates/war.erb +1 -0
  21. data/lib/warbler/traits.rb +5 -3
  22. data/lib/warbler/traits/bundler.rb +52 -14
  23. data/lib/warbler/traits/gemspec.rb +6 -11
  24. data/lib/warbler/traits/jar.rb +4 -1
  25. data/lib/warbler/traits/merb.rb +2 -1
  26. data/lib/warbler/traits/nogemspec.rb +2 -1
  27. data/lib/warbler/traits/rack.rb +3 -1
  28. data/lib/warbler/traits/rails.rb +13 -8
  29. data/lib/warbler/traits/war.rb +12 -6
  30. data/lib/warbler/version.rb +2 -2
  31. data/lib/warbler/war.rb +7 -0
  32. data/lib/warbler_jar.jar +0 -0
  33. data/spec/drb_helper.rb +41 -0
  34. data/spec/sample_bundler/Gemfile.lock +10 -0
  35. data/spec/sample_bundler/config.ru +0 -0
  36. data/spec/sample_bundler/vendor/bundle/jruby/1.8/cache/rake-0.8.7.gem +0 -0
  37. data/spec/sample_bundler/vendor/bundle/jruby/1.8/gems/rake-0.8.7/lib/rake.rb +2506 -0
  38. data/spec/sample_bundler/vendor/bundle/jruby/1.8/specifications/rake-0.8.7.gemspec +31 -0
  39. data/spec/sample_bundler/vendor/bundle/ruby/1.8/cache/rake-0.8.7.gem +0 -0
  40. data/spec/sample_bundler/vendor/bundle/ruby/1.8/gems/rake-0.8.7/lib/rake.rb +2506 -0
  41. data/spec/sample_bundler/vendor/bundle/ruby/1.8/specifications/rake-0.8.7.gemspec +30 -0
  42. data/spec/sample_bundler/vendor/bundle/ruby/1.9.1/cache/rake-0.8.7.gem +0 -0
  43. data/spec/sample_bundler/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb +2506 -0
  44. data/spec/sample_bundler/vendor/bundle/ruby/1.9.1/specifications/rake-0.8.7.gemspec +30 -0
  45. data/spec/sample_jar/sample_jar.gemspec +0 -1
  46. data/spec/sample_war/config/environments/production.rb +3 -0
  47. data/spec/spec_helper.rb +32 -5
  48. data/spec/warbler/application_spec.rb +11 -2
  49. data/spec/warbler/bundler_spec.rb +136 -0
  50. data/spec/warbler/config_spec.rb +2 -2
  51. data/spec/warbler/gems_spec.rb +2 -2
  52. data/spec/warbler/jar_spec.rb +63 -108
  53. data/spec/warbler/task_spec.rb +29 -20
  54. data/spec/warbler/traits_spec.rb +3 -2
  55. data/spec/warbler/war_spec.rb +3 -2
  56. data/warble.rb +3 -0
  57. data/web.xml.erb +2 -2
  58. metadata +179 -177
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{rake}
5
+ s.version = "0.8.7"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Jim Weirich"]
9
+ s.date = %q{2009-05-14}
10
+ s.description = %q{Rake is a Make-like program implemented in Ruby. Tasks and dependencies are specified in standard Ruby syntax.}
11
+ s.email = %q{jim@weirichhouse.org}
12
+ s.executables = ["rake"]
13
+ s.extra_rdoc_files = ["README", "MIT-LICENSE", "TODO", "CHANGES", "doc/command_line_usage.rdoc", "doc/glossary.rdoc", "doc/proto_rake.rdoc", "doc/rakefile.rdoc", "doc/rational.rdoc", "doc/release_notes/rake-0.4.14.rdoc", "doc/release_notes/rake-0.4.15.rdoc", "doc/release_notes/rake-0.5.0.rdoc", "doc/release_notes/rake-0.5.3.rdoc", "doc/release_notes/rake-0.5.4.rdoc", "doc/release_notes/rake-0.6.0.rdoc", "doc/release_notes/rake-0.7.0.rdoc", "doc/release_notes/rake-0.7.1.rdoc", "doc/release_notes/rake-0.7.2.rdoc", "doc/release_notes/rake-0.7.3.rdoc", "doc/release_notes/rake-0.8.0.rdoc", "doc/release_notes/rake-0.8.2.rdoc", "doc/release_notes/rake-0.8.3.rdoc", "doc/release_notes/rake-0.8.4.rdoc", "doc/release_notes/rake-0.8.5.rdoc", "doc/release_notes/rake-0.8.6.rdoc", "doc/release_notes/rake-0.8.7.rdoc"]
14
+ s.files = ["bin/rake", "README", "MIT-LICENSE", "TODO", "CHANGES", "doc/command_line_usage.rdoc", "doc/glossary.rdoc", "doc/proto_rake.rdoc", "doc/rakefile.rdoc", "doc/rational.rdoc", "doc/release_notes/rake-0.4.14.rdoc", "doc/release_notes/rake-0.4.15.rdoc", "doc/release_notes/rake-0.5.0.rdoc", "doc/release_notes/rake-0.5.3.rdoc", "doc/release_notes/rake-0.5.4.rdoc", "doc/release_notes/rake-0.6.0.rdoc", "doc/release_notes/rake-0.7.0.rdoc", "doc/release_notes/rake-0.7.1.rdoc", "doc/release_notes/rake-0.7.2.rdoc", "doc/release_notes/rake-0.7.3.rdoc", "doc/release_notes/rake-0.8.0.rdoc", "doc/release_notes/rake-0.8.2.rdoc", "doc/release_notes/rake-0.8.3.rdoc", "doc/release_notes/rake-0.8.4.rdoc", "doc/release_notes/rake-0.8.5.rdoc", "doc/release_notes/rake-0.8.6.rdoc", "doc/release_notes/rake-0.8.7.rdoc"]
15
+ s.homepage = %q{http://rake.rubyforge.org}
16
+ s.rdoc_options = ["--line-numbers", "--main", "README", "--title", "Rake -- Ruby Make"]
17
+ s.require_paths = ["lib"]
18
+ s.rubyforge_project = %q{rake}
19
+ s.rubygems_version = %q{1.7.2}
20
+ s.summary = %q{Ruby based make-like utility.}
21
+
22
+ if s.respond_to? :specification_version then
23
+ s.specification_version = 2
24
+
25
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
26
+ else
27
+ end
28
+ else
29
+ end
30
+ end
@@ -7,7 +7,6 @@ Gem::Specification.new do |s|
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Nick Sieger"]
9
9
  s.date = %q{2010-11-03}
10
- s.default_executable = %q{sample_jar}
11
10
  s.description = %q{Sample jar application for Warbler specs.}
12
11
  s.email = ["nick@nicksieger.com"]
13
12
  s.executables = ["sample_jar"]
@@ -20,3 +20,6 @@ config.action_view.cache_template_loading = true
20
20
 
21
21
  # Disable delivery errors, bad email addresses will be ignored
22
22
  # config.action_mailer.raise_delivery_errors = false
23
+
24
+ # Uncomment to activate MT-safe Rails
25
+ # config.threadsafe!
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2010 Engine Yard, Inc.
2
+ # Copyright (c) 2010-2011 Engine Yard, Inc.
3
3
  # Copyright (c) 2007-2009 Sun Microsystems, Inc.
4
4
  # This source code is available under the MIT license.
5
5
  # See the file LICENSE.txt for details.
@@ -36,12 +36,13 @@ end
36
36
  module Spec::Example::ExampleGroupMethods
37
37
  def run_in_directory(dir)
38
38
  before :each do
39
- @pwd = Dir.getwd
39
+ (@pwd ||= []) << Dir.getwd
40
+ Dir.chdir(@pwd.first) # let directory always be relative to project root
40
41
  Dir.chdir(dir)
41
42
  end
42
43
 
43
44
  after :each do
44
- Dir.chdir(@pwd)
45
+ Dir.chdir(@pwd.pop)
45
46
  end
46
47
  end
47
48
 
@@ -56,7 +57,7 @@ module Spec::Example::ExampleGroupMethods
56
57
  def use_fresh_environment
57
58
  before(:each) do
58
59
  @env_save = {}
59
- (ENV.keys.grep(/BUNDLE/) + ["RUBYOPT", "GEM_PATH"]).each {|k| @env_save[k] = ENV[k]; ENV[k] = nil}
60
+ (ENV.keys.grep(/BUNDLE/) + ["RUBYOPT"]).each {|k| @env_save[k] = ENV[k]; ENV.delete(k)}
60
61
  end
61
62
 
62
63
  after(:each) do
@@ -68,7 +69,33 @@ module Spec::Example::ExampleGroupMethods
68
69
  after(:each) do
69
70
  rm_rf FileList["log", ".bundle", "tmp/war"]
70
71
  rm_f FileList["*.war", "*.foobar", "**/config.ru", "*web.xml*", "config/web.xml*", "config/warble.rb",
71
- "file.txt", 'manifest', 'Gemfile*', 'MANIFEST.MF*', 'init.rb*', '**/*.class']
72
+ "file.txt", 'manifest', '*Gemfile*', 'MANIFEST.MF*', 'init.rb*', '**/*.class']
73
+ end
74
+ end
75
+
76
+ def run_out_of_process_with_drb
77
+ before :all do
78
+ require 'drb'
79
+ DRb.start_service
80
+ @orig_dir = Dir.pwd
81
+ end
82
+
83
+ let(:drbclient) do
84
+ drb
85
+ DRbObject.new(nil, 'druby://127.0.0.1:7890').tap do |drbclient|
86
+ loop { (drbclient.alive? && break) rescue nil }
87
+ end
88
+ end
89
+
90
+ let(:drb) do
91
+ Thread.new do
92
+ ruby "-I#{Warbler::WARBLER_HOME}/lib", File.join(@orig_dir, 'spec/drb_helper.rb')
93
+ end
94
+ end
95
+
96
+ after :each do
97
+ drbclient.stop
98
+ drb.join
72
99
  end
73
100
  end
74
101
  end
@@ -1,11 +1,11 @@
1
1
  #--
2
- # Copyright (c) 2010 Engine Yard, Inc.
2
+ # Copyright (c) 2010-2011 Engine Yard, Inc.
3
3
  # Copyright (c) 2007-2009 Sun Microsystems, Inc.
4
4
  # This source code is available under the MIT license.
5
5
  # See the file LICENSE.txt for details.
6
6
  #++
7
7
 
8
- require File.dirname(__FILE__) + '/../spec_helper'
8
+ require File.expand_path('../../spec_helper', __FILE__)
9
9
 
10
10
  describe Warbler::Application do
11
11
  run_in_directory "spec/sample_war"
@@ -84,3 +84,12 @@ describe Warbler::Application do
84
84
  Warbler::Application.new.load_project_rakefile
85
85
  end
86
86
  end
87
+
88
+ describe Warbler::Application do
89
+ it "should report Warbler version with --version" do
90
+ ruby = File.join Config::CONFIG['bindir'], 'ruby'
91
+ output = `#{ruby} -rubygems -Ilib -S bin/warble --version`.chomp
92
+ output.should =~ /warbler/i
93
+ output.should =~ /#{Warbler::VERSION}/
94
+ end
95
+ end
@@ -0,0 +1,136 @@
1
+ #--
2
+ # Copyright (c) 2010-2011 Engine Yard, Inc.
3
+ # Copyright (c) 2007-2009 Sun Microsystems, Inc.
4
+ # This source code is available under the MIT license.
5
+ # See the file LICENSE.txt for details.
6
+ #++
7
+
8
+ require File.expand_path('../../spec_helper', __FILE__)
9
+
10
+ describe Warbler::Jar, "with Bundler" do
11
+ use_fresh_rake_application
12
+ use_fresh_environment
13
+ run_out_of_process_with_drb
14
+
15
+ def file_list(regex)
16
+ jar.files.keys.select {|f| f =~ regex }
17
+ end
18
+
19
+ def use_config(&block)
20
+ @extra_config = block
21
+ end
22
+
23
+ let(:config) { drbclient.config(@extra_config) }
24
+ let(:jar) { drbclient.jar }
25
+
26
+ context "in a war project" do
27
+ run_in_directory "spec/sample_war"
28
+ cleanup_temp_files
29
+
30
+ before :each do
31
+ File.open("Gemfile", "w") {|f| f << "gem 'rspec'"}
32
+ end
33
+
34
+ it "detects a Bundler trait" do
35
+ config.traits.should include(Warbler::Traits::Bundler)
36
+ end
37
+
38
+ it "detects a Gemfile and process only its gems" do
39
+ use_config do |config|
40
+ config.gems << "rake"
41
+ end
42
+ jar.apply(config)
43
+ file_list(%r{WEB-INF/Gemfile}).should_not be_empty
44
+ file_list(%r{WEB-INF/gems/specifications/rspec}).should_not be_empty
45
+ file_list(%r{WEB-INF/gems/specifications/rake}).should be_empty
46
+ end
47
+
48
+ it "copies Gemfiles into the war" do
49
+ File.open("Gemfile.lock", "w") {|f| f << "GEM"}
50
+ jar.apply(config)
51
+ file_list(%r{WEB-INF/Gemfile}).should_not be_empty
52
+ file_list(%r{WEB-INF/Gemfile.lock}).should_not be_empty
53
+ end
54
+
55
+ it "allows overriding of the gem path when using Bundler" do
56
+ use_config do |config|
57
+ config.gem_path = '/WEB-INF/jewels'
58
+ end
59
+ jar.apply(config)
60
+ file_list(%r{WEB-INF/jewels/specifications/rspec}).should_not be_empty
61
+ end
62
+
63
+ it "works with :git entries in Gemfiles" do
64
+ File.open("Gemfile", "w") {|f| f << "gem 'warbler', :git => '#{Warbler::WARBLER_HOME}'\n"}
65
+ silence { ruby "-S", "bundle", "install", "--local" }
66
+ jar.apply(config)
67
+ file_list(%r{WEB-INF/gems/bundler/gems/warbler[^/]*/lib/warbler/version\.rb}).should_not be_empty
68
+ file_list(%r{WEB-INF/gems/bundler/gems/warbler[^/]*/warbler.gemspec}).should_not be_empty
69
+ end
70
+
71
+ it "does not work with :path entries in Gemfiles" do
72
+ File.open("Gemfile", "w") {|f| f << "gem 'warbler', :path => '#{Warbler::WARBLER_HOME}'\n"}
73
+ silence do
74
+ ruby "-S", "bundle", "install", "--local"
75
+ jar.apply(config)
76
+ end
77
+ file_list(%r{warbler}).should be_empty
78
+ end
79
+
80
+ it "does not bundle dependencies in the test group by default" do
81
+ File.open("Gemfile", "w") {|f| f << "gem 'rake'\ngroup :test do\ngem 'rspec'\nend\n"}
82
+ jar.apply(config)
83
+ file_list(%r{WEB-INF/gems/gems/rake[^/]*/}).should_not be_empty
84
+ file_list(%r{WEB-INF/gems/gems/rspec[^/]*/}).should be_empty
85
+ file_list(%r{WEB-INF/gems/specifications/rake}).should_not be_empty
86
+ file_list(%r{WEB-INF/gems/specifications/rspec}).should be_empty
87
+ end
88
+
89
+ it "adds BUNDLE_WITHOUT to init.rb" do
90
+ jar.add_init_file(config)
91
+ contents = jar.contents('META-INF/init.rb')
92
+ contents.should =~ /ENV\['BUNDLE_WITHOUT'\]/
93
+ contents.should =~ /'development:test'/
94
+ end
95
+
96
+ it "uses ENV['BUNDLE_GEMFILE'] if set" do
97
+ mv "Gemfile", "Special-Gemfile"
98
+ ENV['BUNDLE_GEMFILE'] = "Special-Gemfile"
99
+ config.traits.should include(Warbler::Traits::Bundler)
100
+ end
101
+ end
102
+
103
+ context "in a jar project" do
104
+ run_in_directory "spec/sample_jar"
105
+ cleanup_temp_files
106
+
107
+ it "works with :git entries in Gemfiles" do
108
+ File.open("Gemfile", "w") {|f| f << "gem 'warbler', :git => '#{Warbler::WARBLER_HOME}'\n"}
109
+ silence { ruby "-S", "bundle", "install", "--local" }
110
+ jar.apply(config)
111
+ file_list(%r{^bundler/gems/warbler[^/]*/lib/warbler/version\.rb}).should_not be_empty
112
+ file_list(%r{^bundler/gems/warbler[^/]*/warbler.gemspec}).should_not be_empty
113
+ end
114
+ end
115
+
116
+ context "when frozen" do
117
+ run_in_directory "spec/sample_bundler"
118
+
119
+ it "includes the bundler gem" do
120
+ jar.apply(config)
121
+ config.gems.detect{|k,v| k.name == 'bundler'}.should_not be_nil
122
+ file_list(/bundler-/).should_not be_empty
123
+ end
124
+
125
+ it "does not include the bundler cache directory" do
126
+ jar.apply(config)
127
+ file_list(%r{vendor/bundle}).should be_empty
128
+ end
129
+
130
+ it "includes ENV['BUNDLE_FROZEN'] in init.rb" do
131
+ jar.apply(config)
132
+ contents = jar.contents('META-INF/init.rb')
133
+ contents.split("\n").grep(/ENV\['BUNDLE_FROZEN'\] = '1'/).should_not be_empty
134
+ end
135
+ end
136
+ end
@@ -1,11 +1,11 @@
1
1
  #--
2
- # Copyright (c) 2010 Engine Yard, Inc.
2
+ # Copyright (c) 2010-2011 Engine Yard, Inc.
3
3
  # Copyright (c) 2007-2009 Sun Microsystems, Inc.
4
4
  # This source code is available under the MIT license.
5
5
  # See the file LICENSE.txt for details.
6
6
  #++
7
7
 
8
- require File.dirname(__FILE__) + '/../spec_helper'
8
+ require File.expand_path('../../spec_helper', __FILE__)
9
9
 
10
10
  describe Warbler::Config do
11
11
  before :each do
@@ -1,11 +1,11 @@
1
1
  #--
2
- # Copyright (c) 2010 Engine Yard, Inc.
2
+ # Copyright (c) 2010-2011 Engine Yard, Inc.
3
3
  # Copyright (c) 2007-2009 Sun Microsystems, Inc.
4
4
  # This source code is available under the MIT license.
5
5
  # See the file LICENSE.txt for details.
6
6
  #++
7
7
 
8
- require File.dirname(__FILE__) + '/../spec_helper'
8
+ require File.expand_path('../../spec_helper', __FILE__)
9
9
 
10
10
  describe Warbler::Gems do
11
11
  it "should accept a hash for initialization" do
@@ -1,10 +1,11 @@
1
1
  #--
2
- # Copyright (c) 2010 Engine Yard, Inc.
2
+ # Copyright (c) 2010-2011 Engine Yard, Inc.
3
+ # Copyright (c) 2007-2009 Sun Microsystems, Inc.
3
4
  # This source code is available under the MIT license.
4
5
  # See the file LICENSE.txt for details.
5
6
  #++
6
7
 
7
- require File.dirname(__FILE__) + '/../spec_helper'
8
+ require File.expand_path('../../spec_helper', __FILE__)
8
9
 
9
10
  describe Warbler::Jar do
10
11
  use_fresh_rake_application
@@ -50,10 +51,16 @@ describe Warbler::Jar do
50
51
 
51
52
  it "requires 'rubygems' in init.rb" do
52
53
  jar.add_init_file(config)
53
- contents = jar.files['META-INF/init.rb'].read
54
+ contents = jar.contents('META-INF/init.rb')
54
55
  contents.split("\n").grep(/require 'rubygems'/).should_not be_empty
55
56
  end
56
57
 
58
+ it "adds ENV['GEM_HOME'] to init.rb" do
59
+ jar.add_init_file(config)
60
+ contents = jar.contents('META-INF/init.rb')
61
+ contents.should =~ /ENV\['GEM_HOME'\]/
62
+ end
63
+
57
64
  it "adds a main.rb" do
58
65
  jar.apply(config)
59
66
  file_list(%r{^META-INF/main.rb$}).should_not be_empty
@@ -91,23 +98,15 @@ describe Warbler::Jar do
91
98
  file_list(%r{^specifications/rubyzip.*\.gemspec}).should_not be_empty
92
99
  end
93
100
 
94
- it "sets files to be stored in the archive from the spec" do
95
- touch "extra.foobar"
96
- jar.apply(config)
97
- file_list(%r{^sample_jar/History\.txt$}).should_not be_empty
98
- file_list(%r{^sample_jar/lib/sample_jar\.rb$}).should_not be_empty
99
- file_list(%r{^sample_jar/extra\.foobar$}).should be_empty
100
- end
101
-
102
101
  it "sets load paths in init.rb" do
103
102
  jar.add_init_file(config)
104
- contents = jar.files['META-INF/init.rb'].read
103
+ contents = jar.contents('META-INF/init.rb')
105
104
  contents.split("\n").grep(/LOAD_PATH\.unshift.*sample_jar\/lib/).should_not be_empty
106
105
  end
107
106
 
108
107
  it "loads the default executable in main.rb" do
109
108
  jar.apply(config)
110
- contents = jar.files['META-INF/main.rb'].read
109
+ contents = jar.contents('META-INF/main.rb')
111
110
  contents.split("\n").grep(/load.*sample_jar\/bin\/sample_jar/).should_not be_empty
112
111
  end
113
112
 
@@ -116,21 +115,7 @@ describe Warbler::Jar do
116
115
  jar.compile(config)
117
116
  jar.apply(config)
118
117
  file_list(%r{^sample_jar/lib/sample_jar\.class$}).should_not be_empty
119
- jar.files['sample_jar/lib/sample_jar.rb'].read.should =~ /require __FILE__\.sub/
120
- end
121
-
122
- context "and a missing file" do
123
- before :each do
124
- mv "Rakefile", "Rakefile.tmp"
125
- end
126
-
127
- after :each do
128
- mv "Rakefile.tmp", "Rakefile"
129
- end
130
-
131
- it "should warn about the missing file but still continue" do
132
- capture { jar.apply(config) }.should =~ /Rakefile/
133
- end
118
+ jar.contents('sample_jar/lib/sample_jar.rb').should =~ /require __FILE__\.sub/
134
119
  end
135
120
  end
136
121
 
@@ -154,7 +139,7 @@ describe Warbler::Jar do
154
139
 
155
140
  it "loads the first bin/executable in main.rb" do
156
141
  silence { jar.apply(config) }
157
- contents = jar.files['META-INF/main.rb'].read
142
+ contents = jar.contents('META-INF/main.rb')
158
143
  contents.split("\n").grep(/load.*sample_jar\/bin\/sample_jar/).should_not be_empty
159
144
  end
160
145
  end
@@ -192,13 +177,13 @@ describe Warbler::Jar do
192
177
 
193
178
  it "sets load paths in init.rb" do
194
179
  jar.add_init_file(config)
195
- contents = jar.files['META-INF/init.rb'].read
180
+ contents = jar.contents('META-INF/init.rb')
196
181
  contents.split("\n").grep(/LOAD_PATH\.unshift.*sample_jar\/lib/).should_not be_empty
197
182
  end
198
183
 
199
184
  it "loads the first bin/executable in main.rb" do
200
185
  jar.apply(config)
201
- contents = jar.files['META-INF/main.rb'].read
186
+ contents = jar.contents('META-INF/main.rb')
202
187
  contents.split("\n").grep(/load.*sample_jar\/bin\/sample_jar/).should_not be_empty
203
188
  end
204
189
  end
@@ -231,6 +216,13 @@ describe Warbler::Jar do
231
216
  file_list(%r{WEB-INF/gems/specifications/rake.*\.gemspec}).should_not be_empty
232
217
  end
233
218
 
219
+ it "adds ENV['GEM_HOME'] to init.rb" do
220
+ jar.add_init_file(config)
221
+ contents = jar.contents('META-INF/init.rb')
222
+ contents.should =~ /ENV\['GEM_HOME'\]/
223
+ contents.should =~ /WEB-INF\/gems/
224
+ end
225
+
234
226
  it "does not include log files by default" do
235
227
  jar.apply(config)
236
228
  file_list(%r{WEB-INF/log}).should_not be_empty
@@ -368,6 +360,14 @@ describe Warbler::Jar do
368
360
  file_list(%r{lib/tasks/utils.rake}).should be_empty
369
361
  end
370
362
 
363
+ it "can exclude public files from the .war" do
364
+ use_config do |config|
365
+ config.excludes += FileList['public/robots.txt']
366
+ end
367
+ jar.apply(config)
368
+ file_list(%r{robots.txt}).should be_empty
369
+ end
370
+
371
371
  it "reads configuration from #{Warbler::Config::FILE}" do
372
372
  mkdir_p "config"
373
373
  File.open(Warbler::Config::FILE, "w") do |dest|
@@ -394,6 +394,7 @@ describe Warbler::Jar do
394
394
 
395
395
  it "allows specification of dependency by Gem::Dependency" do
396
396
  spec = mock "gem spec"
397
+ spec.stub!(:name).and_return "hpricot"
397
398
  spec.stub!(:full_name).and_return "hpricot-0.6.157"
398
399
  spec.stub!(:full_gem_path).and_return "hpricot-0.6.157"
399
400
  spec.stub!(:loaded_from).and_return "hpricot.gemspec"
@@ -406,7 +407,7 @@ describe Warbler::Jar do
406
407
  use_config do |config|
407
408
  config.gems = [Gem::Dependency.new("hpricot", "> 0.6")]
408
409
  end
409
- jar.apply(config)
410
+ silence { jar.apply(config) }
410
411
  end
411
412
 
412
413
  it "copies loose java classes to WEB-INF/classes" do
@@ -493,17 +494,30 @@ describe Warbler::Jar do
493
494
  config.gems.keys.should include(Gem::Dependency.new("hpricot", Gem::Requirement.new("=0.6")))
494
495
  end
495
496
 
496
- it "sets the jruby max runtimes to 1 when MT Rails is detected" do
497
- task :environment do
498
- config = mock "config"
499
- @rails.stub!(:configuration).and_return(config)
500
- config.stub!(:threadsafe!)
501
- config.should_receive(:allow_concurrency).and_return true
502
- config.should_receive(:preload_frameworks).and_return true
497
+ context "with threadsafe! enabled" do
498
+ before :each do
499
+ cp "config/environments/production.rb", "config/environments/production.rb.orig"
500
+ File.open("config/environments/production.rb", "a") {|f| f.puts "", "config.threadsafe!" }
503
501
  end
504
502
 
505
- config.webxml.booter.should == :rails
506
- config.webxml.jruby.max.runtimes.should == 1
503
+ after :each do
504
+ mv "config/environments/production.rb.orig", "config/environments/production.rb"
505
+ end
506
+
507
+ it "sets the jruby min and max runtimes to 1" do
508
+ config.webxml.booter.should == :rails
509
+ config.webxml.jruby.min.runtimes.should == 1
510
+ config.webxml.jruby.max.runtimes.should == 1
511
+ end
512
+
513
+ it "doesn't override already configured runtime numbers" do
514
+ use_config do |config|
515
+ config.webxml.jruby.min.runtimes = 2
516
+ config.webxml.jruby.max.runtimes = 2
517
+ end
518
+ config.webxml.jruby.min.runtimes.should == 2
519
+ config.webxml.jruby.max.runtimes.should == 2
520
+ end
507
521
  end
508
522
 
509
523
  it "adds RAILS_ENV to init.rb" do
@@ -511,7 +525,7 @@ describe Warbler::Jar do
511
525
  config.webxml.booter = :rails
512
526
  end
513
527
  jar.add_init_file(config)
514
- contents = jar.files['META-INF/init.rb'].read
528
+ contents = jar.contents('META-INF/init.rb')
515
529
  contents.should =~ /ENV\['RAILS_ENV'\]/
516
530
  contents.should =~ /'production'/
517
531
  end
@@ -537,12 +551,12 @@ describe Warbler::Jar do
537
551
  merb.const_set("BootLoader", boot_loader)
538
552
  merb.const_set("VERSION", "1.0")
539
553
  dependencies = Class.new do
540
- @@dependencies = []
554
+ @dependencies = []
541
555
  def self.dependencies
542
- @@dependencies
556
+ @dependencies
543
557
  end
544
558
  def self.dependencies=(deps)
545
- @@dependencies = deps
559
+ @dependencies = deps
546
560
  end
547
561
  end
548
562
  boot_loader.const_set("Dependencies", dependencies)
@@ -599,71 +613,12 @@ describe Warbler::Jar do
599
613
 
600
614
  it "adds RACK_ENV to init.rb" do
601
615
  jar.add_init_file(config)
602
- contents = jar.files['META-INF/init.rb'].read
616
+ contents = jar.contents('META-INF/init.rb')
603
617
  contents.should =~ /ENV\['RACK_ENV'\]/
604
618
  contents.should =~ /'production'/
605
619
  end
606
620
  end
607
621
 
608
- context "with Bundler" do
609
- before :each do
610
- File.open("Gemfile", "w") {|f| f << "gem 'rspec'"}
611
- end
612
-
613
- it "detects a Bundler trait" do
614
- config.traits.should include(Warbler::Traits::Bundler)
615
- end
616
-
617
- it "detects a Bundler Gemfile and process only its gems" do
618
- use_config do |config|
619
- config.gems << "rake"
620
- end
621
- jar.apply(config)
622
- file_list(%r{WEB-INF/Gemfile}).should_not be_empty
623
- file_list(%r{WEB-INF/gems/specifications/rspec}).should_not be_empty
624
- file_list(%r{WEB-INF/gems/specifications/rake}).should be_empty
625
- end
626
-
627
- it "copies Bundler gemfiles into the war" do
628
- File.open("Gemfile.lock", "w") {|f| f << "GEM"}
629
- jar.apply(config)
630
- file_list(%r{WEB-INF/Gemfile}).should_not be_empty
631
- file_list(%r{WEB-INF/Gemfile.lock}).should_not be_empty
632
- end
633
-
634
- it "allows overriding of the gem path when using Bundler" do
635
- use_config do |config|
636
- config.gem_path = '/WEB-INF/jewels'
637
- end
638
- jar.apply(config)
639
- file_list(%r{WEB-INF/jewels/specifications/rspec}).should_not be_empty
640
- end
641
-
642
- it "works with :git entries in Bundler Gemfiles" do
643
- File.open("Gemfile", "w") {|f| f << "gem 'warbler', :git => '#{Warbler::WARBLER_HOME}'\n"}
644
- silence { ruby "-S", "bundle", "install", "--local" }
645
- jar.apply(config)
646
- file_list(%r{WEB-INF/gems/gems/warbler[^/]*/lib/warbler/version\.rb}).should_not be_empty
647
- file_list(%r{WEB-INF/gems/specifications/warbler}).should_not be_empty
648
- end
649
-
650
- it "does not bundle dependencies in the test group by default" do
651
- File.open("Gemfile", "w") {|f| f << "gem 'rake'\ngroup :test do\ngem 'rspec'\nend\n"}
652
- jar.apply(config)
653
- file_list(%r{WEB-INF/gems/gems/rake[^/]*/}).should_not be_empty
654
- file_list(%r{WEB-INF/gems/gems/rspec[^/]*/}).should be_empty
655
- file_list(%r{WEB-INF/gems/specifications/rake}).should_not be_empty
656
- file_list(%r{WEB-INF/gems/specifications/rspec}).should be_empty
657
- end
658
-
659
- it "adds BUNDLE_WITHOUT to init.rb" do
660
- jar.add_init_file(config)
661
- contents = jar.files['META-INF/init.rb'].read
662
- contents.should =~ /ENV\['BUNDLE_WITHOUT'\]/
663
- contents.should =~ /'development:test'/
664
- end
665
- end
666
-
667
622
  it "skips directories that don't exist in config.dirs and print a warning" do
668
623
  use_config do |config|
669
624
  config.dirs = %w(lib notexist)
@@ -718,7 +673,7 @@ describe Warbler::Jar do
718
673
  end
719
674
  jar.apply(config)
720
675
  file_list(%r{WEB-INF/myserver-web.xml}).should_not be_empty
721
- jar.files['WEB-INF/myserver-web.xml'].read.should =~ /web-app.*production/
676
+ jar.contents('WEB-INF/myserver-web.xml').should =~ /web-app.*production/
722
677
  end
723
678
 
724
679
  it "excludes test files in gems according to config.gem_excludes" do
@@ -747,7 +702,7 @@ describe Warbler::Jar do
747
702
  config.init_contents << "Rakefile"
748
703
  end
749
704
  jar.add_init_file(config)
750
- contents = jar.files['META-INF/init.rb'].read
705
+ contents = jar.contents('META-INF/init.rb')
751
706
  contents.should =~ /require 'rake'/
752
707
  end
753
708
 
@@ -756,7 +711,7 @@ describe Warbler::Jar do
756
711
  config.webxml.dummy = '<dummy/>'
757
712
  end
758
713
  jar.apply(config)
759
- jar.files['META-INF/init.rb'].read.should =~ /<dummy\/>/
714
+ jar.contents('META-INF/init.rb').should =~ /<dummy\/>/
760
715
  end
761
716
  end
762
717
  end