jim 0.2.3 → 0.3.0.pre

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.
Files changed (66) hide show
  1. data/Gemfile +2 -1
  2. data/Gemfile.lock +2 -0
  3. data/HISTORY +13 -0
  4. data/README.md +148 -0
  5. data/Rakefile +6 -3
  6. data/bin/jim +1 -2
  7. data/default +0 -0
  8. data/jim.gemspec +142 -105
  9. data/lib/jim.rb +1 -1
  10. data/lib/jim/bundler.rb +168 -73
  11. data/lib/jim/cli.rb +200 -151
  12. data/lib/jim/index.rb +20 -9
  13. data/lib/jim/installer.rb +46 -46
  14. data/lib/jim/rack.rb +57 -20
  15. data/lib/jim/templates/jimfile +11 -5
  16. data/lib/jim/version_parser.rb +3 -3
  17. data/test/fixtures/infoincomments.js +1 -1
  18. data/test/fixtures/jimfile +14 -7
  19. data/test/fixtures/jquery-1.4.1.js +3 -6057
  20. data/test/fixtures/jquery.color.js +1 -1
  21. data/test/fixtures/localfile.js +1 -1
  22. data/test/fixtures/mustache.js/package.json +1 -1
  23. data/test/fixtures/noversion.js +1 -1
  24. data/test/fixtures/old_jimfile +7 -0
  25. data/test/fixtures/sammy-0.5.0/examples/backend/app.rb +4 -4
  26. data/test/fixtures/sammy-0.5.0/examples/backend/public/javascripts/app.js +18 -18
  27. data/test/fixtures/sammy-0.5.0/examples/backend/public/javascripts/jquery.cloudkit.js +1 -1
  28. data/test/fixtures/sammy-0.5.0/examples/backend/public/javascripts/jquery.js +1 -1
  29. data/test/fixtures/sammy-0.5.0/examples/backend/public/javascripts/sammy.js +161 -161
  30. data/test/fixtures/sammy-0.5.0/examples/backend/public/templates/task.html.erb +1 -1
  31. data/test/fixtures/sammy-0.5.0/examples/backend/public/templates/task_details.html.erb +1 -1
  32. data/test/fixtures/sammy-0.5.0/examples/backend/views/app.sass +6 -6
  33. data/test/fixtures/sammy-0.5.0/examples/backend/views/index.haml +5 -5
  34. data/test/fixtures/sammy-0.5.0/examples/form_handling/index.html +16 -16
  35. data/test/fixtures/sammy-0.5.0/examples/hello_world/index.html +13 -13
  36. data/test/fixtures/sammy-0.5.0/examples/location_override/data.html +28 -28
  37. data/test/fixtures/sammy-0.5.0/examples/location_override/index.html +18 -18
  38. data/test/fixtures/sammy-0.5.0/examples/location_override/test.html +36 -36
  39. data/test/fixtures/sammy-0.5.0/lib/min/sammy-0.5.0.min.js +1 -1
  40. data/test/fixtures/sammy-0.5.0/lib/min/sammy-lastest.min.js +1 -1
  41. data/test/fixtures/sammy-0.5.0/lib/plugins/sammy.cache.js +13 -13
  42. data/test/fixtures/sammy-0.5.0/lib/plugins/sammy.haml.js +2 -2
  43. data/test/fixtures/sammy-0.5.0/lib/plugins/sammy.json.js +15 -15
  44. data/test/fixtures/sammy-0.5.0/lib/plugins/sammy.mustache.js +46 -46
  45. data/test/fixtures/sammy-0.5.0/lib/plugins/sammy.nested_params.js +29 -29
  46. data/test/fixtures/sammy-0.5.0/lib/plugins/sammy.storage.js +54 -54
  47. data/test/fixtures/sammy-0.5.0/lib/plugins/sammy.template.js +17 -17
  48. data/test/fixtures/sammy-0.5.0/lib/sammy.js +220 -220
  49. data/test/fixtures/sammy-0.5.0/test/fixtures/partial.html +1 -1
  50. data/test/fixtures/sammy-0.5.0/test/index.html +26 -26
  51. data/test/fixtures/sammy-0.5.0/test/test_sammy_application.js +60 -60
  52. data/test/fixtures/sammy-0.5.0/test/test_sammy_event_context.js +21 -21
  53. data/test/fixtures/sammy-0.5.0/test/test_sammy_location_proxy.js +3 -3
  54. data/test/fixtures/sammy-0.5.0/test/test_sammy_plugins.js +17 -17
  55. data/test/fixtures/sammy-0.5.0/test/test_sammy_storage.js +4 -4
  56. data/test/helper.rb +15 -0
  57. data/test/test_jim_bundler.rb +114 -74
  58. data/test/test_jim_cli.rb +34 -18
  59. data/test/test_jim_index.rb +19 -19
  60. data/test/test_jim_installer.rb +13 -13
  61. data/test/test_jim_rack.rb +41 -0
  62. data/test/test_jim_version_parser.rb +4 -4
  63. metadata +204 -41
  64. data/.gitignore +0 -24
  65. data/README.rdoc +0 -105
  66. data/lib/jim/templates/commands +0 -58
@@ -1,6 +1,6 @@
1
1
  (function($) {
2
2
  with(QUnit) {
3
-
3
+
4
4
  var test_app = new Sammy.Application(function() {
5
5
  this.silence_404 = true;
6
6
  this.element_selector = '#main';
@@ -25,7 +25,7 @@
25
25
  .should('set params', function() {
26
26
  deepEqual(this.context.params, new Sammy.Object({test: 'hooray'}));
27
27
  });
28
-
28
+
29
29
 
30
30
  context('Sammy', 'EventContext', 'redirect', {
31
31
  before: function() {
@@ -62,7 +62,7 @@
62
62
  context.notFound();
63
63
  });
64
64
  });
65
-
65
+
66
66
  context('Sammy', 'EventContext', 'partial', {
67
67
  before: function() {
68
68
  this.app = test_app;
@@ -78,8 +78,8 @@
78
78
  })
79
79
  .should('not run through template() if Sammy.Template is not present', function() {
80
80
  var contents = '';
81
- this.context.partial('fixtures/partial.template', {name: 'TEMPLATE!', class_name: 'test_template'}, function(data) {
82
- contents = data;
81
+ this.context.partial('fixtures/partial.template', {name: 'TEMPLATE!', class_name: 'test_template'}, function(data) {
82
+ contents = data;
83
83
  });
84
84
  soon(function () {
85
85
  equal(contents, '<div class="<%= class_name %>"><%= name %></div>');
@@ -90,8 +90,8 @@
90
90
  var app = new Sammy.Application(function() { this.element_selector = '#main'; });
91
91
  app.use(Sammy.Template);
92
92
  this.context = new app.context_prototype(app);
93
- this.context.partial('fixtures/partial.template', {name: 'TEMPLATE!', class_name: 'test_template'}, function(data) {
94
- contents = data;
93
+ this.context.partial('fixtures/partial.template', {name: 'TEMPLATE!', class_name: 'test_template'}, function(data) {
94
+ contents = data;
95
95
  });
96
96
  soon(function () {
97
97
  equal(contents, '<div class="test_template">TEMPLATE!</div>');
@@ -102,7 +102,7 @@
102
102
  app = new Sammy.Application(function() { this.element_selector = '#main'; }),
103
103
  data = [{name: 'one', class_name: 'it-1'}, {name: 'two', class_name: 'it-2'}],
104
104
  expected = '<div class="it-1">one</div><div class="it-2">two</div>';
105
-
105
+
106
106
  app.use(Sammy.Template);
107
107
  this.context = new app.context_prototype(app);
108
108
  this.context.partial('fixtures/partial.template', data);
@@ -121,13 +121,13 @@
121
121
  app.use(Sammy.Cache);
122
122
  app.clearCache();
123
123
  this.context = new app.context_prototype(app);
124
- this.context.partial('fixtures/partial.html', function(data) {
125
- contents = data;
124
+ this.context.partial('fixtures/partial.html', function(data) {
125
+ contents = data;
126
126
  });
127
127
  soon(function () {
128
128
  equal(contents, '<div class="test_partial">PARTIAL</div>');
129
129
  equal(app.cache('partial:fixtures/partial.html'), '<div class="test_partial">PARTIAL</div>');
130
- this.context.partial('fixtures/partial.html', function(data) {
130
+ this.context.partial('fixtures/partial.html', function(data) {
131
131
  contents = data;
132
132
  });
133
133
  equal(contents, '<div class="test_partial">PARTIAL</div>');
@@ -141,7 +141,7 @@
141
141
  app.clearCache();
142
142
  app.cache_partials = false;
143
143
  this.context = new app.context_prototype(app);
144
- this.context.partial('fixtures/partial.html', function(data) {
144
+ this.context.partial('fixtures/partial.html', function(data) {
145
145
  contents = data;
146
146
  });
147
147
  soon(function () {
@@ -166,7 +166,7 @@
166
166
  changed = true;
167
167
  });
168
168
  test_app.run();
169
- this.context.partial('fixtures/partial.html', function(data) {
169
+ this.context.partial('fixtures/partial.html', function(data) {
170
170
  changed = false;
171
171
  });
172
172
  soon(function() {
@@ -176,10 +176,10 @@
176
176
  })
177
177
  .should('use default engine if provided and template doesnt match an engine', function() {
178
178
  var contents = '';
179
- var app = new Sammy.Application(function() {
180
- this.element_selector = '#main';
179
+ var app = new Sammy.Application(function() {
180
+ this.element_selector = '#main';
181
181
  this.template_engine = 'template';
182
-
182
+
183
183
  this.helper('template', function(template, data) {
184
184
  return "!!!" + template.toString() + "!!!";
185
185
  });
@@ -192,8 +192,8 @@
192
192
  })
193
193
  .should('use default engine as a method if template doesnt match an engine', function() {
194
194
  var contents = '';
195
- var app = new Sammy.Application(function() {
196
- this.element_selector = '#main';
195
+ var app = new Sammy.Application(function() {
196
+ this.element_selector = '#main';
197
197
  this.template_engine = function(template, data) {
198
198
  return "!!!" + template.toString() + "!!!";
199
199
  };
@@ -204,7 +204,7 @@
204
204
  equal(app.$element().text(), '!!!NOENGINE!!!');
205
205
  });
206
206
  });
207
-
207
+
208
208
  context('Sammy', 'EventContext', 'trigger', {
209
209
  before: function() {
210
210
  this.context = test_context;
@@ -247,6 +247,6 @@
247
247
  deepEqual(passed_data, test_data);
248
248
  });
249
249
  });
250
-
250
+
251
251
  };
252
- })(jQuery);
252
+ })(jQuery);
@@ -1,6 +1,6 @@
1
1
  (function($) {
2
2
  with(QUnit) {
3
-
3
+
4
4
  context('Sammy', 'HashLocationProxy', {
5
5
  before: function() {
6
6
  this.app = new Sammy.Application;
@@ -45,7 +45,7 @@
45
45
  }
46
46
  });
47
47
 
48
-
48
+
49
49
  context('Sammy', 'DataLocationProxy', {
50
50
  before: function() {
51
51
  this.app = new Sammy.Application(function() {
@@ -88,4 +88,4 @@
88
88
  });
89
89
 
90
90
  }
91
- })(jQuery);
91
+ })(jQuery);
@@ -49,15 +49,15 @@
49
49
  this.app.store('cache').clear('mycache');
50
50
  ok(!this.app.cache('mycache'))
51
51
  });
52
-
53
-
52
+
53
+
54
54
  context('Sammy', 'Template', {
55
55
  before: function() {
56
56
  this.app = new Sammy.Application(function() {
57
57
  this.use(Sammy.Template);
58
58
  });
59
59
  this.context = new this.app.context_prototype(this.app, 'get', '#/', {});
60
-
60
+
61
61
  this.alias_app = new Sammy.Application(function() {
62
62
  this.use(Sammy.Template, 'tpl');
63
63
  });
@@ -85,8 +85,8 @@
85
85
  ok($.isFunction(this.alias_context.tpl));
86
86
  ok(this.alias_context.tpl.toString().match(/srender/));
87
87
  });
88
-
89
-
88
+
89
+
90
90
  context('Sammy.NestedParams', 'parsing', {
91
91
  before: function () {
92
92
  this.app = new Sammy.Application(function() {
@@ -105,7 +105,7 @@
105
105
  $('#nested_params_test_form').submit();
106
106
  soon(function() {
107
107
  ok(app.form_params);
108
- equal(app.form_params['author'], 'Thoreau');
108
+ equal(app.form_params['author'], 'Thoreau');
109
109
  app.unload();
110
110
  }, this, 1, 2);
111
111
  })
@@ -129,7 +129,7 @@
129
129
  equal(app.form_params['poll']['name'], 'Which beverage do you like best?');
130
130
  equal(app.form_params['poll']['priority'], '10');
131
131
  app.unload();
132
- }, this, 1, 3);
132
+ }, this, 1, 3);
133
133
  })
134
134
  .should('parse nested hashes', function() {
135
135
  var app = this.app;
@@ -164,7 +164,7 @@
164
164
  equal(app.form_params['woods']['trees'][0]['name'], 'Spruce');
165
165
  equal(app.form_params['woods']['trees'][1]['name'], 'Maple');
166
166
  app.unload();
167
- }, this, 1, 3);
167
+ }, this, 1, 3);
168
168
  })
169
169
  .should('parse arrays in nested hashes in nested arrays', function() {
170
170
  var app = this.app;
@@ -175,7 +175,7 @@
175
175
  equal(app.form_params['pages'][0]['words'][0], 'Woods');
176
176
  equal(app.form_params['pages'][1]['words'][0], 'Money');
177
177
  app.unload();
178
- }, this, 1, 3);
178
+ }, this, 1, 3);
179
179
  })
180
180
  .should('parse complex hashes in nested arrays in nested hashes', function() {
181
181
  var app = this.app;
@@ -200,7 +200,7 @@
200
200
  app.unload();
201
201
  }, this, 1, 2);
202
202
  });
203
-
203
+
204
204
  context('Sammy.NestedParams', 'bad fields', {
205
205
  before: function () {
206
206
  this.app = new Sammy.Application(function() {
@@ -214,8 +214,8 @@
214
214
  app._parseFormParams($('#bad_nested_params_form'));
215
215
  });
216
216
  });
217
-
218
-
217
+
218
+
219
219
  // Pretty much a copy of the Template tests
220
220
  context('Sammy', 'Mustache', {
221
221
  before: function() {
@@ -252,7 +252,7 @@
252
252
  ok($.isFunction(this.alias_context.ms));
253
253
  ok(this.alias_context.ms.toString().match(/Mustache/));
254
254
  });
255
-
255
+
256
256
  context('Sammy', 'JSON', {
257
257
  before: function() {
258
258
  this.app = new Sammy.Application(function() {
@@ -274,8 +274,8 @@
274
274
  .should('stringify JSON if object is an object', function() {
275
275
  equal(this.context.json({test: "123"}),"{\"test\":\"123\"}");
276
276
  });
277
-
278
-
277
+
278
+
279
279
  context('Sammy', 'Haml', {
280
280
  before: function() {
281
281
  this.app = new Sammy.Application(function() {
@@ -291,6 +291,6 @@
291
291
  var template = ".mytemplate= title";
292
292
  deepEqual(this.context.haml(template, {title: "HAML!!"}), "<div class=\"mytemplate\">HAML!!\n</div>");
293
293
  });
294
-
294
+
295
295
  };
296
- })(jQuery);
296
+ })(jQuery);
@@ -87,7 +87,7 @@
87
87
  equal(fired, 'bar');
88
88
  $('#main').unbind('set-test_store.foo');
89
89
  });
90
- })
90
+ })
91
91
  .should('fetch value or run callback', function() {
92
92
  ok(!this.store.get('foo'));
93
93
  this.store.fetch('foo', function() {
@@ -108,7 +108,7 @@
108
108
  });
109
109
  }
110
110
  });
111
-
111
+
112
112
  context('Sammy.Storage', {
113
113
  before: function() {
114
114
  this.app = new Sammy.Application(function() {
@@ -123,7 +123,7 @@
123
123
  .should('add the store method to event contexts', function() {
124
124
  ok($.isFunction(this.context.store));
125
125
  });
126
-
126
+
127
127
  context('Sammy.Storage', 'store', {
128
128
  before: function() {
129
129
  var store = null;
@@ -172,4 +172,4 @@
172
172
  ok(!this.store.get('foo'));
173
173
  });
174
174
  };
175
- })(jQuery);
175
+ })(jQuery);
data/test/helper.rb CHANGED
@@ -57,4 +57,19 @@ class Test::Unit::TestCase
57
57
  assert !File.readable?(full_path), "Expected #{full_path} to not be a readable file"
58
58
  end
59
59
 
60
+ # stolen from the thor specs
61
+ def capture(stream)
62
+ begin
63
+ stream = stream.to_s
64
+ eval "$#{stream} = StringIO.new"
65
+ yield
66
+ result = eval("$#{stream}").string
67
+ ensure
68
+ eval("$#{stream} = #{stream.upcase}")
69
+ end
70
+
71
+ result
72
+ end
73
+ alias :silence :capture
74
+
60
75
  end
@@ -11,142 +11,182 @@ class TestJimBundler < Test::Unit::TestCase
11
11
  Jim::Installer.new(fixture_path('infoincomments.js'), File.join(root, 'tmp', 'lib')).install
12
12
  @bundler = Jim::Bundler.new(fixture('jimfile'), Jim::Index.new(@directories))
13
13
  end
14
-
14
+
15
15
  context "initialize" do
16
-
16
+
17
17
  should "load jimfile data if jimfile is a Pathname" do
18
18
  @bundler = Jim::Bundler.new(Pathname.new(fixture_path('jimfile')), Jim::Index.new(@directories))
19
19
  assert @bundler
20
20
  assert_equal fixture('jimfile'), @bundler.jimfile
21
21
  end
22
-
22
+
23
23
  should "load jimfile data as a string" do
24
24
  assert @bundler
25
25
  assert_equal fixture('jimfile'), @bundler.jimfile
26
26
  end
27
-
27
+
28
28
  should "parse options out of jimfile" do
29
- assert_equal 'test/tmp/public/javascripts/bundled.js', @bundler.options[:bundled_path]
30
- assert_equal 'test/tmp/public/javascripts/vendor', @bundler.options[:vendor_dir]
29
+ assert_equal 'test/tmp/', @bundler.bundle_dir.to_s
30
+ assert_equal 'test/tmp/public/javascripts/vendor', @bundler.options[:vendor_dir].to_s
31
31
  end
32
-
32
+
33
33
  should "set index and include vendor dir" do
34
34
  assert @bundler.index.is_a?(Jim::Index)
35
35
  assert_equal [@bundler.options[:vendor_dir]] + @directories, @bundler.index.directories
36
- end
37
- end
38
-
36
+ end
37
+
38
+ should "parse old jimfile" do
39
+ @bundler = Jim::Bundler.new(Pathname.new(fixture_path('old_jimfile')), Jim::Index.new(@directories))
40
+ assert @bundler
41
+ assert_equal fixture('old_jimfile'), @bundler.jimfile
42
+ assert_equal 'test/tmp/public/javascripts', @bundler.bundle_dir.to_s
43
+ assert_equal 'test/tmp/public/javascripts/vendor', @bundler.options[:vendor_dir].to_s
44
+ assert @bundler.bundles['default']
45
+ end
46
+ end
47
+
39
48
  context "resolve!" do
40
-
49
+
41
50
  should "find projects listed in the jimfile and set paths" do
42
51
  assert @bundler.paths.empty?
43
52
  @bundler.resolve!
44
- assert @bundler.paths
45
- assert_equal 3, @bundler.paths.length
46
- @bundler.paths.each do |path, name, version|
53
+ assert @bundler.paths.is_a?(Hash)
54
+ assert @bundler.paths['default']
55
+ assert_equal 3, @bundler.paths['default'].length
56
+ @bundler.paths['default'].each do |path, name, version|
47
57
  assert path.is_a?(Pathname)
48
58
  assert name.is_a?(String)
49
59
  end
50
60
  end
51
-
61
+
52
62
  should "set paths in same order as in jimfile" do
53
63
  @bundler.resolve!
54
- assert_equal Pathname.new(fixture_path('jquery-1.4.1.js')), @bundler.paths[0][0]
64
+ assert_equal Pathname.new(fixture_path('jquery-1.4.1.js')), @bundler.paths['default'][0][0]
55
65
  end
56
-
66
+
57
67
  should "raise error if file can not be found" do
58
68
  FileUtils.rm_rf(tmp_path) if File.directory?(tmp_path)
59
69
  assert_raise(Jim::Bundler::MissingFile) {
60
70
  @bundler.resolve!
61
71
  }
62
72
  end
63
-
73
+
64
74
  end
65
-
75
+
66
76
  context "vendor!" do
67
-
77
+
68
78
  should "copy files in jimfile to path specified" do
69
79
  vendor_dir = Pathname.new(tmp_path) + 'vendor'
70
80
  @bundler.vendor!(vendor_dir)
71
81
  assert_readable vendor_dir + 'myproject-1.2.2.js'
72
82
  assert !File.readable?(vendor_dir + 'localfile.js'), "shouldnt vendor local files"
73
83
  end
74
-
84
+
75
85
  end
76
-
86
+
77
87
  context "bundle!" do
78
-
88
+
79
89
  should "concatenate file into a string" do
80
- @bundler.options = {}
81
- bundle = @bundler.bundle!
90
+ @bundler.bundle_dir = nil
91
+ bundle = @bundler.bundle!("default")
82
92
  assert bundle.is_a?(String)
83
- assert_match(/jQuery/, bundle)
93
+ assert_match(/jQuery/, bundle, "Bundle should include jQuery")
84
94
  end
85
-
95
+
86
96
  should "raise error if file cant be found" do
87
97
  FileUtils.rm_rf(tmp_path) if File.directory?(tmp_path)
88
98
  assert_raise(Jim::Bundler::MissingFile) {
89
99
  @bundler.bundle!
90
100
  }
91
101
  end
92
-
102
+
93
103
  should "write to file specified in options" do
94
- bundle_path = @bundler.options[:bundled_path]
104
+ bundle_dir = @bundler.bundle_dir
105
+ assert @bundler.bundle!
106
+ assert bundle = File.read(bundle_dir + 'default.js')
107
+ assert_match(/jQuery/, bundle, "Bundle should include jQuery")
108
+ end
109
+
110
+ should "write all files if path is given" do
111
+ bundle_dir = @bundler.bundle_dir
95
112
  assert @bundler.bundle!
96
- assert bundle = File.read(bundle_path)
97
- assert_match(/jQuery/, bundle)
98
- end
99
-
100
- should "write to file if path is given" do
101
- bundle_path = File.join(tmp_path, 'app.js')
102
- assert @bundler.bundle!(bundle_path)
103
- assert bundle = File.read(bundle_path)
104
- assert_match(/jQuery/, bundle)
105
- end
106
-
107
- should "write to IO if IO is given" do
108
- bundle_path = File.join(tmp_path, 'app.js')
109
- assert @bundler.bundle!(File.open(bundle_path, 'w'))
110
- assert bundle = File.read(bundle_path)
111
- assert_match(/jQuery/, bundle)
112
- end
113
-
113
+ assert bundle = File.read(bundle_dir + 'default.js')
114
+ assert_match(/jQuery/, bundle, "Bundle should include jQuery")
115
+ assert bundle = File.read(bundle_dir + 'base.js')
116
+ assert_match(/jQuery/, bundle, "Bundle should include jQuery")
117
+ end
118
+
119
+ should "write specific bundle if given" do
120
+ bundle_dir = @bundler.bundle_dir
121
+ assert @bundler.bundle!("base")
122
+ assert bundle = File.read(bundle_dir + 'base.js')
123
+ assert_match(/jQuery/, bundle, "Bundle should include jQuery")
124
+ end
125
+
126
+ should "raise error if no bundle path or bundle name is specified" do
127
+ @bundler.bundle_dir = nil
128
+ assert_raise(Jim::Bundler::InvalidBundle) {
129
+ @bundler.bundle!
130
+ }
131
+ end
132
+
133
+ should "return array of paths" do
134
+ bundle_dir = @bundler.bundle_dir
135
+ assert paths = @bundler.bundle!
136
+ assert paths.is_a?(Array)
137
+ assert_contains paths, bundle_dir + 'base.js'
138
+ assert_contains paths, bundle_dir + 'default.js'
139
+ end
140
+
114
141
  end
115
-
142
+
116
143
  context "compress!" do
117
144
  setup do
118
- @bundler.stubs(:compress_js).returns(@bundler.bundle!(false))
145
+ @bundler.stubs(:compress_js).returns("jQuery")
119
146
  end
120
-
147
+
121
148
  should "run through google compressor" do
122
- @bundler.options = {}
123
- bundle = @bundler.compress!
149
+ @bundler.bundle_dir = nil
150
+ bundle = @bundler.compress!("default")
124
151
  assert bundle.is_a?(String)
125
- assert_match(/jQuery/, bundle)
152
+ assert_match(/jQuery/, bundle, "Bundle should include jQuery")
126
153
  end
127
-
128
- should "write to file specified in options" do
129
- bundle_path = @bundler.options[:compressed_path]
154
+
155
+ should "write to dir specified in options" do
156
+ bundle_path = @bundler.bundle_dir
130
157
  assert @bundler.compress!
131
- assert bundle = File.read(bundle_path)
132
- assert_match(/jQuery/, bundle)
133
- end
134
-
135
- should "write to file if path is given" do
136
- bundle_path = File.join(tmp_path, 'app.js')
137
- assert @bundler.compress!(bundle_path)
138
- assert bundle = File.read(bundle_path)
139
- assert_match(/jQuery/, bundle)
140
- end
141
-
142
- should "write to IO if IO is given" do
143
- bundle_path = File.join(tmp_path, 'app.js')
144
- assert @bundler.compress!(File.open(bundle_path, 'w'))
145
- assert bundle = File.read(bundle_path)
146
- assert_match(/jQuery/, bundle)
147
- end
148
-
158
+ assert bundle = File.read(bundle_path + 'default.min.js')
159
+ assert_match(/jQuery/, bundle, "Bundle should include jQuery")
160
+ assert bundle = File.read(bundle_path + 'base.min.js')
161
+ assert_match(/jQuery/, bundle, "Bundle should include jQuery")
162
+ end
163
+
164
+ should "write specific bundle if given" do
165
+ bundle_path = @bundler.bundle_dir
166
+ assert @bundler.compress!("base")
167
+ assert bundle = File.read(bundle_path + 'base.min.js')
168
+ assert_match(/jQuery/, bundle, "Bundle should include jQuery")
169
+ assert !File.readable?(bundle_path + 'default.min.js')
170
+ end
171
+
172
+ should "use compressed_suffix option" do
173
+ @bundler.options[:compressed_suffix] = '-min'
174
+ bundle_path = @bundler.bundle_dir
175
+ assert @bundler.compress!("base")
176
+ assert bundle = File.read(bundle_path + 'base-min.js')
177
+ assert_match(/jQuery/, bundle, "Bundle should include jQuery")
178
+ end
179
+ end
180
+
181
+ context "jimfile_to_json" do
182
+ should "convert back to JSON string" do
183
+ json = @bundler.jimfile_to_json
184
+ assert json
185
+ assert json.is_a?(String)
186
+ assert_match(/^\{/, json)
187
+ end
149
188
  end
189
+
150
190
  end
151
191
 
152
192
  end