jim 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. data/HISTORY +28 -0
  2. data/README.rdoc +1 -1
  3. data/Rakefile +2 -1
  4. data/jim.gemspec +67 -9
  5. data/lib/jim/bundler.rb +14 -11
  6. data/lib/jim/cli.rb +51 -9
  7. data/lib/jim/index.rb +3 -7
  8. data/lib/jim/installer.rb +140 -22
  9. data/lib/jim/templates/commands +21 -6
  10. data/lib/jim/version_parser.rb +2 -3
  11. data/lib/jim.rb +19 -2
  12. data/test/fixtures/jimfile +3 -3
  13. data/test/fixtures/sammy-0.5.0/HISTORY.md +135 -0
  14. data/test/fixtures/sammy-0.5.0/LICENSE +22 -0
  15. data/test/fixtures/sammy-0.5.0/README.md +81 -0
  16. data/test/fixtures/sammy-0.5.0/Rakefile +174 -0
  17. data/test/fixtures/sammy-0.5.0/examples/backend/README.md +23 -0
  18. data/test/fixtures/sammy-0.5.0/examples/backend/Rakefile +15 -0
  19. data/test/fixtures/sammy-0.5.0/examples/backend/app.rb +17 -0
  20. data/test/fixtures/sammy-0.5.0/examples/backend/app.ru +3 -0
  21. data/test/fixtures/sammy-0.5.0/examples/backend/public/javascripts/app.js +106 -0
  22. data/test/fixtures/sammy-0.5.0/examples/backend/public/javascripts/jquery.cloudkit.js +840 -0
  23. data/test/fixtures/sammy-0.5.0/examples/backend/public/javascripts/jquery.js +19 -0
  24. data/test/fixtures/sammy-0.5.0/examples/backend/public/javascripts/sammy.js +1013 -0
  25. data/test/fixtures/sammy-0.5.0/examples/backend/public/templates/index.html.erb +11 -0
  26. data/test/fixtures/sammy-0.5.0/examples/backend/public/templates/task.html.erb +4 -0
  27. data/test/fixtures/sammy-0.5.0/examples/backend/public/templates/task_details.html.erb +4 -0
  28. data/test/fixtures/sammy-0.5.0/examples/backend/views/app.sass +63 -0
  29. data/test/fixtures/sammy-0.5.0/examples/backend/views/index.haml +18 -0
  30. data/test/fixtures/sammy-0.5.0/examples/form_handling/files/form.html +12 -0
  31. data/test/fixtures/sammy-0.5.0/examples/form_handling/index.html +65 -0
  32. data/test/fixtures/sammy-0.5.0/examples/hello_world/index.html +50 -0
  33. data/test/fixtures/sammy-0.5.0/examples/location_override/README.md +15 -0
  34. data/test/fixtures/sammy-0.5.0/examples/location_override/data.html +110 -0
  35. data/test/fixtures/sammy-0.5.0/examples/location_override/index.html +79 -0
  36. data/test/fixtures/sammy-0.5.0/examples/location_override/test.html +121 -0
  37. data/test/fixtures/sammy-0.5.0/lib/min/sammy-0.5.0.min.js +5 -0
  38. data/test/fixtures/sammy-0.5.0/lib/min/sammy-lastest.min.js +5 -0
  39. data/test/fixtures/sammy-0.5.0/lib/plugins/sammy.cache.js +117 -0
  40. data/test/fixtures/sammy-0.5.0/lib/plugins/sammy.haml.js +539 -0
  41. data/test/fixtures/sammy-0.5.0/lib/plugins/sammy.json.js +362 -0
  42. data/test/fixtures/sammy-0.5.0/lib/plugins/sammy.mustache.js +415 -0
  43. data/test/fixtures/sammy-0.5.0/lib/plugins/sammy.nested_params.js +118 -0
  44. data/test/fixtures/sammy-0.5.0/lib/plugins/sammy.storage.js +515 -0
  45. data/test/fixtures/sammy-0.5.0/lib/plugins/sammy.template.js +117 -0
  46. data/test/fixtures/sammy-0.5.0/lib/sammy.js +1367 -0
  47. data/test/fixtures/sammy-0.5.0/test/fixtures/partial +1 -0
  48. data/test/fixtures/sammy-0.5.0/test/fixtures/partial.html +1 -0
  49. data/test/fixtures/sammy-0.5.0/test/fixtures/partial.noengine +1 -0
  50. data/test/fixtures/sammy-0.5.0/test/fixtures/partial.template +1 -0
  51. data/test/fixtures/sammy-0.5.0/test/index.html +84 -0
  52. data/test/fixtures/sammy-0.5.0/test/test_sammy_application.js +953 -0
  53. data/test/fixtures/sammy-0.5.0/test/test_sammy_event_context.js +252 -0
  54. data/test/fixtures/sammy-0.5.0/test/test_sammy_location_proxy.js +91 -0
  55. data/test/fixtures/sammy-0.5.0/test/test_sammy_plugins.js +296 -0
  56. data/test/fixtures/sammy-0.5.0/test/test_sammy_storage.js +175 -0
  57. data/test/fixtures/sammy-0.5.0/test/test_server +27 -0
  58. data/test/fixtures/sammy-0.5.0/vendor/jquery-1.4.1.js +6078 -0
  59. data/test/fixtures/sammy-0.5.0/vendor/jquery-1.4.1.min.js +152 -0
  60. data/test/fixtures/sammy-0.5.0/vendor/jsdoc/doc.haml +58 -0
  61. data/test/fixtures/sammy-0.5.0/vendor/jsdoc/jsdoc.rb +143 -0
  62. data/test/fixtures/sammy-0.5.0/vendor/jslitmus.js +670 -0
  63. data/test/fixtures/sammy-0.5.0/vendor/qunit/qunit.css +119 -0
  64. data/test/fixtures/sammy-0.5.0/vendor/qunit/qunit.js +1043 -0
  65. data/test/fixtures/sammy-0.5.0/vendor/qunit-spec.js +127 -0
  66. data/test/helper.rb +23 -3
  67. data/test/test_jim_bundler.rb +9 -8
  68. data/test/test_jim_cli.rb +21 -12
  69. data/test/test_jim_installer.rb +152 -35
  70. data/test/test_jim_version_parser.rb +4 -0
  71. metadata +117 -27
  72. data/.document +0 -5
@@ -0,0 +1,127 @@
1
+ (function($) {
2
+
3
+ QUnit.Spec = function(name) {
4
+ this.before = false;
5
+ this.after = false;
6
+ QUnit.module(name);
7
+ };
8
+
9
+
10
+ // RSpec style describe
11
+ // takes an arbitrary number of arguments that are contactenated as strings
12
+ // the last argument is the configuration object
13
+ // which can have before: after: callbacks
14
+ function describe() {
15
+ var args = $.makeArray(arguments),
16
+ // configuration function
17
+ config = (args.length > 0 && args[args.length - 1]['before']) ? args.pop() : {},
18
+ spec = new QUnit.Spec(args.join(' '));
19
+ spec['before'] = config['before'] || config['setup'];
20
+ spec['after'] = config['after'] || config['teardown'];
21
+ return spec;
22
+ }
23
+
24
+
25
+ $.extend(QUnit.Spec.prototype, {
26
+
27
+ // RSpec style test definition
28
+ it: function(name, callback, nowait) {
29
+ var spec = this;
30
+ var spec_context = {};
31
+ QUnit.test(name, function() {
32
+ if (spec.before) spec.before.apply(spec_context);
33
+ callback.apply(spec_context, [this]);
34
+ if (spec.after) spec.after.apply(spec_context);
35
+ });
36
+ return spec;
37
+ },
38
+
39
+ // Shoulda style test definition
40
+ should: function(name, callback, nowait) {
41
+ name = 'should ' + name;
42
+ return this.it.apply(this, [name, callback, nowait]);
43
+ },
44
+
45
+ pending: function(name, callback, nowait) {
46
+ name = '<span style="color: #EB8531;" class="pending">DEFERRED: ' + name + '</span>';
47
+ QUnit.test(name, function () { QUnit.ok(true) }, nowait);
48
+ return this;
49
+ },
50
+
51
+ should_eventually: function(name, callback, nowait) {
52
+ return this.pending(name, callback, nowait);
53
+ }
54
+
55
+ });
56
+
57
+
58
+ $.extend(QUnit, {
59
+ // aliases for describe
60
+ describe: describe,
61
+ context: describe,
62
+
63
+ // asserts that the method is defined (like respond_to?)
64
+ defined: function(object, method) {
65
+ return QUnit.ok(QUnit.is('Function', object[method]), method + ' is not defined on ' + object);
66
+ },
67
+
68
+ // asserts that the object is of a certain type
69
+ isType: function(object, type) {
70
+ return ok(QUnit.is(type, object), "expected " + object + " to be a " + type);
71
+ },
72
+
73
+ // assert a string matches a regex
74
+ matches: function(matcher, string, message) {
75
+ return QUnit.ok(!!matcher.test(string), "expected: " + string + "match(" + matcher.toString() + ")");
76
+ },
77
+
78
+ // assert that a matching error is raised
79
+ // expected can be a regex, a string, or an object
80
+ raised: function(expected_error, callback) {
81
+ var error = '';
82
+ try {
83
+ callback.apply(this);
84
+ } catch(e) {
85
+ error = e;
86
+ }
87
+ message = "expected error: " + expected_error.toString() + ", actual error:" + error.toString();
88
+ if (expected_error.constructor == RegExp) {
89
+ return QUnit.matches(expected_error, error.toString(), message);
90
+ } else if (expected_error.constructor == String) {
91
+ return QUnit.equals(expected_error, error.toString(), message);
92
+ } else {
93
+ return QUnit.equals(expected_error, error, message);
94
+ }
95
+ },
96
+
97
+ notRaised: function(callback) {
98
+ var error = '';
99
+ try {
100
+ callback.apply(this);
101
+ } catch(e) {
102
+ error = e;
103
+ }
104
+ message = "expected: no errors, actual error: " + error.toString();
105
+ QUnit.equals('', error, message);
106
+ },
107
+
108
+ soon: function(callback, context, secs, many_expects) {
109
+ if (typeof context == 'undefined') context = this;
110
+ if (typeof secs == 'undefined') secs = 1;
111
+ if (typeof many_expects == 'undefined') many_expects = 1;
112
+ QUnit.expect(many_expects);
113
+ QUnit.stop();
114
+ setTimeout(function() {
115
+ callback.apply(context);
116
+ QUnit.start();
117
+ }, secs * 500);
118
+ },
119
+
120
+ flunk: function() {
121
+ QUnit.ok(false, 'FLUNK');
122
+ }
123
+
124
+ });
125
+
126
+
127
+ })(jQuery);
data/test/helper.rb CHANGED
@@ -9,8 +9,17 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
9
9
  $LOAD_PATH.unshift(File.dirname(__FILE__))
10
10
  require 'jim'
11
11
 
12
- Jim.logger = Logger.new('/dev/null')
13
- Jim::Installer.tmp_root = File.join(File.dirname(__FILE__), 'tmp', 'jimtmproot')
12
+ unless !!ENV['PRINT']
13
+ Jim.logger = Logger.new('/dev/null')
14
+ else
15
+ logger = Logger.new(STDOUT)
16
+ logger.level = Logger::DEBUG
17
+ logger.formatter = Proc.new {|s, t, n, msg| "\n* #{s}: #{msg}\n"}
18
+ Jim.logger = logger
19
+ end
20
+
21
+ JIM_TMP_ROOT = File.join(File.dirname(__FILE__), 'tmp', 'jimtmproot')
22
+ Jim::Installer.tmp_root = JIM_TMP_ROOT
14
23
 
15
24
  class Test::Unit::TestCase
16
25
 
@@ -23,7 +32,7 @@ class Test::Unit::TestCase
23
32
  end
24
33
 
25
34
  def tmp_path
26
- File.join(File.dirname(__FILE__), 'tmp')
35
+ Pathname.new(File.join(File.dirname(__FILE__), 'tmp')).expand_path
27
36
  end
28
37
 
29
38
  def assert_readable(*args)
@@ -31,9 +40,20 @@ class Test::Unit::TestCase
31
40
  assert File.readable?(full_path), "Expected #{full_path} to be a readable file"
32
41
  end
33
42
 
43
+ def assert_file_contents(match, *args)
44
+ full_path = File.join(*args)
45
+ file_contents = File.read(full_path)
46
+ assert_match(match, file_contents, "Expected file at #{full_path} with content #{file_contents} to match #{match.inspect}")
47
+ end
48
+
34
49
  def assert_dir(*args)
35
50
  full_path = File.join(*args)
36
51
  assert File.directory?(full_path), "Expected #{full_path} to be a directory"
37
52
  end
38
53
 
54
+ def assert_not_readable(*args)
55
+ full_path = File.join(*args)
56
+ assert !File.readable?(full_path), "Expected #{full_path} to not be a readable file"
57
+ end
58
+
39
59
  end
@@ -26,13 +26,13 @@ class TestJimBundler < Test::Unit::TestCase
26
26
  end
27
27
 
28
28
  should "parse options out of jimfile" do
29
- assert_equal 'tmp/public/javascripts/bundled.js', @bundler.options[:bundled_path]
30
- assert_equal 'tmp/public/javascripts/vendor', @bundler.options[:vendor_dir]
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]
31
31
  end
32
32
 
33
- should "set index" do
33
+ should "set index and include vendor dir" do
34
34
  assert @bundler.index.is_a?(Jim::Index)
35
- assert_equal @directories, @bundler.index.directories
35
+ assert_equal [@bundler.options[:vendor_dir]] + @directories, @bundler.index.directories
36
36
  end
37
37
  end
38
38
 
@@ -43,14 +43,15 @@ class TestJimBundler < Test::Unit::TestCase
43
43
  @bundler.resolve!
44
44
  assert @bundler.paths
45
45
  assert_equal 2, @bundler.paths.length
46
- @bundler.paths.each do |path|
46
+ @bundler.paths.each do |path, name, version|
47
47
  assert path.is_a?(Pathname)
48
+ assert name.is_a?(String)
48
49
  end
49
50
  end
50
51
 
51
52
  should "set paths in same order as in jimfile" do
52
53
  @bundler.resolve!
53
- assert_equal Pathname.new(fixture_path('jquery-1.4.1.js')), @bundler.paths.first
54
+ assert_equal Pathname.new(fixture_path('jquery-1.4.1.js')), @bundler.paths[0][0]
54
55
  end
55
56
 
56
57
  should "raise error if file can not be found" do
@@ -67,8 +68,8 @@ class TestJimBundler < Test::Unit::TestCase
67
68
  should "copy files in jemfile to path specified" do
68
69
  vendor_dir = Pathname.new(tmp_path) + 'vendor'
69
70
  @bundler.vendor!(vendor_dir)
70
- assert_readable vendor_dir + 'jquery.js'
71
- assert_readable vendor_dir + 'myproject.js'
71
+ assert_readable vendor_dir + 'jquery-1.4.1.js'
72
+ assert_readable vendor_dir + 'myproject-1.2.2.js'
72
73
  end
73
74
 
74
75
  end
data/test/test_jim_cli.rb CHANGED
@@ -5,7 +5,7 @@ class TestJimCLI < Test::Unit::TestCase
5
5
  context "Jim::CLI" do
6
6
  setup do
7
7
  FileUtils.rm_rf(tmp_path) if File.directory?(tmp_path)
8
- other_tmp_path = File.join(File.dirname(__FILE__), '..', 'tmp')
8
+ other_tmp_path = File.join(File.dirname(__FILE__), '..', '..' 'tmp')
9
9
  FileUtils.rm_rf(other_tmp_path) if File.directory?(other_tmp_path)
10
10
  Jim::Installer.new(fixture_path('infoincomments.js'), tmp_path).install
11
11
  Jim::Installer.new(fixture_path('jquery-1.4.1.js'), tmp_path).install
@@ -18,15 +18,26 @@ class TestJimCLI < Test::Unit::TestCase
18
18
  end
19
19
  end
20
20
 
21
+ context "pack" do
22
+ should "run vendor, bundle, compress" do
23
+ Jim::Bundler.any_instance.stubs(:compress_js).returns("compressed.js")
24
+ run_cli("pack", "-j", fixture_path('Jimfile'), "--jimhome", tmp_path)
25
+ assert_readable tmp_path, 'public', 'javascripts', 'vendor', 'jquery-1.4.1.js'
26
+ assert_readable tmp_path, 'public', 'javascripts', 'vendor', 'myproject-1.2.2.js'
27
+ assert_readable tmp_path, 'public', 'javascripts', 'bundled.js'
28
+ assert_readable tmp_path, 'public', 'javascripts', 'compressed.js'
29
+ end
30
+ end
31
+
21
32
  context "bundle" do
22
33
  should "write bundled Jimfile to path" do
23
- run_cli("bundle", tmp_path + '/bundle.js', "-j", fixture_path('Jimfile'), "--jimhome", tmp_path)
24
- assert_readable tmp_path + '/bundle.js'
34
+ run_cli("bundle", tmp_path + 'bundle.js', "-j", fixture_path('Jimfile'), "--jimhome", tmp_path)
35
+ assert_readable tmp_path + 'bundle.js'
25
36
  end
26
37
 
27
38
  should "write to bundled_path if no path provided" do
28
39
  run_cli("bundle", "-j", fixture_path('Jimfile'), "--jimhome", tmp_path)
29
- assert_readable tmp_path, '..', '..', 'tmp', 'public', 'javascripts', 'bundled.js'
40
+ assert_readable tmp_path, 'public', 'javascripts', 'bundled.js'
30
41
  end
31
42
  end
32
43
 
@@ -36,23 +47,21 @@ class TestJimCLI < Test::Unit::TestCase
36
47
  end
37
48
 
38
49
  should "compress Jimfile to path" do
39
- run_cli("compress", tmp_path + '/compressed.js', "-j", fixture_path('Jimfile'), "--jimhome", tmp_path)
40
- assert_readable tmp_path + '/compressed.js'
50
+ run_cli("compress", tmp_path + 'compressed.js', "-j", fixture_path('Jimfile'), "--jimhome", tmp_path)
51
+ assert_readable tmp_path + 'compressed.js'
41
52
  end
42
53
 
43
54
  should "compress to compressed_path if no path provided" do
44
55
  run_cli("compress", "-j", fixture_path('Jimfile'), "--jimhome", tmp_path)
45
- assert_readable tmp_path, '..', '..', 'tmp', 'public', 'javascripts', 'compressed.js'
56
+ assert_readable tmp_path, 'public', 'javascripts', 'compressed.js'
46
57
  end
47
58
  end
48
59
 
49
60
  context "vendor" do
50
- should "vendor Jimfile to dir" do
51
-
52
- end
53
-
54
61
  should "vendor Jimfile to vendor dir" do
55
-
62
+ run_cli("vendor", "-j", fixture_path('Jimfile'), "--jimhome", tmp_path)
63
+ assert_readable tmp_path, 'public', 'javascripts', 'vendor', 'jquery-1.4.1.js'
64
+ assert_readable tmp_path, 'public', 'javascripts', 'vendor', 'myproject-1.2.2.js'
56
65
  end
57
66
  end
58
67
 
@@ -5,50 +5,51 @@ class TestJimInstaller < Test::Unit::TestCase
5
5
  context "Jim::Installer" do
6
6
  setup do
7
7
  # clear the tmp dir
8
- FileUtils.rm_rf(tmp_path) if File.directory?(tmp_path)
8
+ FileUtils.rm_rf(tmp_path) if File.exist?(tmp_path)
9
+ FileUtils.rm_rf(JIM_TMP_ROOT) if File.exist?(JIM_TMP_ROOT)
9
10
  end
10
-
11
+
11
12
  context "initializing" do
12
13
  setup do
13
14
  @installer = Jim::Installer.new('fetchpath', 'installpath', {:version => '1.1'})
14
15
  end
15
-
16
+
16
17
  should "set fetch path" do
17
18
  assert_equal Pathname.new('fetchpath'), @installer.fetch_path
18
19
  end
19
-
20
+
20
21
  should "set install path" do
21
22
  assert_equal Pathname.new('installpath'), @installer.install_path
22
23
  end
23
-
24
+
24
25
  should "set options" do
25
26
  assert_equal({:version => '1.1'}, @installer.options)
26
27
  end
27
-
28
+
28
29
  end
29
-
30
+
30
31
  context "fetch" do
31
32
  setup do
32
33
  @url = "http://jquery.com/download/jquery-1.4.1.js"
33
34
  FakeWeb.register_uri(:get, @url, :body => fixture('jquery-1.4.1.js'))
34
35
  end
35
-
36
+
36
37
  should "fetch remote file" do
37
38
  installer = Jim::Installer.new(@url, tmp_path)
38
39
  assert installer.fetch
39
40
  end
40
-
41
+
41
42
  should "fetch local file" do
42
43
  installer = Jim::Installer.new(fixture_path('jquery-1.4.1.js'), tmp_path)
43
44
  fetched_path = installer.fetch
44
45
  assert_dir fetched_path.dirname
45
46
  assert_equal 'jquery-1.4.1.js', fetched_path.basename.to_s
46
47
  end
47
-
48
+
48
49
  end
49
-
50
+
50
51
  context "determine_name_and_version" do
51
-
52
+
52
53
  should "determine from filename" do
53
54
  installer = Jim::Installer.new(fixture_path('jquery-1.4.1.js'), tmp_path)
54
55
  assert installer.fetch
@@ -56,7 +57,7 @@ class TestJimInstaller < Test::Unit::TestCase
56
57
  assert_equal '1.4.1', installer.version
57
58
  assert_equal 'jquery', installer.name
58
59
  end
59
-
60
+
60
61
  should "determine from package.json" do
61
62
  installer = Jim::Installer.new(fixture_path('mustache.js'), tmp_path)
62
63
  assert installer.fetch
@@ -64,7 +65,7 @@ class TestJimInstaller < Test::Unit::TestCase
64
65
  assert_equal "0.2.2", installer.version
65
66
  assert_equal "mustache", installer.name
66
67
  end
67
-
68
+
68
69
  should "determine from file comments" do
69
70
  installer = Jim::Installer.new(fixture_path('infoincomments.js'), tmp_path)
70
71
  assert installer.fetch
@@ -72,7 +73,7 @@ class TestJimInstaller < Test::Unit::TestCase
72
73
  assert_equal 'myproject', installer.name
73
74
  assert_equal '1.2.2', installer.version
74
75
  end
75
-
76
+
76
77
  should "determine from options" do
77
78
  installer = Jim::Installer.new(fixture_path('jquery-1.4.1.js'), tmp_path, :name => 'myproject', :version => '1.1.1')
78
79
  assert installer.fetch
@@ -80,7 +81,7 @@ class TestJimInstaller < Test::Unit::TestCase
80
81
  assert_equal 'myproject', installer.name
81
82
  assert_equal '1.1.1', installer.version
82
83
  end
83
-
84
+
84
85
  should "have default version if version can not be determined" do
85
86
  installer = Jim::Installer.new(fixture_path('noversion.js'), tmp_path)
86
87
  assert installer.fetch
@@ -88,32 +89,148 @@ class TestJimInstaller < Test::Unit::TestCase
88
89
  assert_equal 'noversion', installer.name
89
90
  assert_equal '0', installer.version
90
91
  end
91
-
92
+
92
93
  end
93
-
94
+
94
95
  context "install" do
96
+
97
+ context "with a single file" do
98
+ setup do
99
+ @installer = Jim::Installer.new(fixture_path('jquery-1.4.1.js'), tmp_path)
100
+ assert @installer.install
101
+ @install_path = File.join(tmp_path, 'lib', 'jquery-1.4.1')
102
+ end
103
+
104
+ should "install a package.json" do
105
+ assert_readable @install_path, 'package.json'
106
+ assert_file_contents(/\"name\"\:\s*\"jquery\"/, @install_path, 'package.json')
107
+ end
108
+
109
+ should "move file into install path at name/version" do
110
+ assert_dir @install_path
111
+ assert_readable @install_path, 'jquery.js'
112
+ assert_equal fixture('jquery-1.4.1.js'), File.read(File.join(@install_path, 'jquery.js'))
113
+ end
114
+ end
95
115
 
96
- should "move file into install path at name/version" do
97
- installer = Jim::Installer.new(fixture_path('jquery-1.4.1.js'), tmp_path)
98
- assert installer.install
99
- install_path = File.join(tmp_path, 'lib', 'jquery-1.4.1')
100
- assert_dir install_path
101
- assert_readable install_path, 'jquery.js'
102
- assert_equal fixture('jquery-1.4.1.js'), File.read(File.join(install_path, 'jquery.js'))
116
+ context "with a file that seems to be installed already" do
117
+ should "raise error" do
118
+ @installer = Jim::Installer.new(fixture_path('jquery-1.4.1.js'), tmp_path)
119
+ assert @installer.install
120
+ @install_path = File.join(tmp_path, 'lib', 'jquery-1.4.1')
121
+ assert_readable @install_path, 'jquery.js'
122
+ @installer = Jim::Installer.new(fixture_path('jquery.color.js'), tmp_path, :name => 'jquery', :version => '1.4.1')
123
+ assert_raise(Jim::FileExists) {
124
+ @installer.install
125
+ }
126
+ end
103
127
  end
104
128
 
105
- should "install zips" do
106
- @url = "http://jquery.com/download/jquery.metadata-2.0.zip"
107
- FakeWeb.register_uri(:get, @url, :body => fixture('jquery.metadata-2.0.zip'))
108
- installer = Jim::Installer.new(@url, tmp_path)
109
- path = installer.install
110
- # puts Dir.glob(path + '**/**').inspect
111
- assert_dir path
112
- assert_dir path + 'jquery.metadata-2.0.zip'
113
- assert_readable path + 'jquery.metadata-2.0.zip' + 'jquery.metadata.2.0' +'jquery.metadata.js'
129
+ context "with a duplicate file" do
130
+ should "skip install but not raise error" do
131
+ @installer = Jim::Installer.new(fixture_path('jquery-1.4.1.js'), tmp_path)
132
+ assert @installer.install
133
+ @install_path = File.join(tmp_path, 'lib', 'jquery-1.4.1')
134
+ assert_readable @install_path, 'jquery.js'
135
+ @installer = Jim::Installer.new(fixture_path('jquery-1.4.1.js'), tmp_path)
136
+ assert @installer.install
137
+ assert_readable @install_path, 'jquery.js'
138
+ end
139
+ end
140
+
141
+ context "with a zip" do
142
+ setup do
143
+ @url = "http://jquery.com/download/jquery.metadata-2.0.zip"
144
+ FakeWeb.register_uri(:get, @url, :body => fixture('jquery.metadata-2.0.zip'))
145
+ @installer = Jim::Installer.new(@url, tmp_path)
146
+ @paths = @installer.install
147
+ @install_path = tmp_path + 'lib'
148
+ end
149
+
150
+ should "return an array of paths" do
151
+ assert @paths.is_a?(Array)
152
+ assert @paths.all? {|p| p.is_a?(Pathname) }
153
+ end
154
+
155
+ should "install each js file found separately" do
156
+ assert_dir tmp_path, 'lib', 'jquery.metadata-2.0'
157
+ assert_readable tmp_path, 'lib', 'jquery.metadata-2.0', 'jquery.metadata.js'
158
+ assert_readable tmp_path, 'lib', 'jquery.metadata.min-2.0', 'jquery.metadata.min.js'
159
+ assert_readable tmp_path, 'lib', 'jquery.metadata.pack-2.0', 'jquery.metadata.pack.js'
160
+ end
161
+
162
+ should "not install files found in ignored directories" do
163
+ assert_not_readable tmp_path, 'lib', 'test-2.0', 'test.js'
164
+ assert_not_readable tmp_path, 'lib', 'test-0', 'test.js'
165
+ end
166
+
167
+ should "install a package.json" do
168
+ json_path = @install_path + 'jquery.metadata-2.0' + 'package.json'
169
+ assert_readable json_path
170
+ assert_file_contents(/\"name\"\:\s*\"jquery\.metadata\"/, json_path)
171
+ end
172
+
173
+ end
174
+
175
+ context "with a dir" do
176
+ setup do
177
+ @installer = Jim::Installer.new(fixture_path('sammy-0.5.0'), tmp_path)
178
+ @paths = @installer.install
179
+ @install_path = tmp_path + 'lib'
180
+ end
181
+
182
+ should "return an array of paths" do
183
+ assert @paths.is_a?(Array)
184
+ assert @paths.all? {|p| p.is_a?(Pathname) }
185
+ end
186
+
187
+ should "install each js file found separately" do
188
+ assert_dir tmp_path, 'lib', 'sammy-0.5.0'
189
+ assert_readable tmp_path, 'lib', 'sammy-0.5.0', 'sammy.js'
190
+ assert_readable tmp_path, 'lib', 'sammy.template-0.5.0', 'sammy.template.js'
191
+ assert_readable tmp_path, 'lib', 'sammy.haml-0.5.0', 'sammy.haml.js'
192
+ end
193
+
194
+ should "not install files found in ignored directories" do
195
+ assert_not_readable tmp_path, 'lib', 'qunit-spec-0.5.0', 'qunit-spec.js'
196
+ assert_not_readable tmp_path, 'lib', 'qunit-spec-0', 'qunit-spec.js'
197
+ assert_not_readable tmp_path, 'lib', 'test_sammy_application-0.5.0', 'test_sammy_application.js'
198
+ assert_not_readable tmp_path, 'lib', 'test_sammy_application-0', 'test_sammy_application.js'
199
+ end
200
+
201
+ should "install a package.json" do
202
+ json_path = @install_path + 'sammy-0.5.0' + 'package.json'
203
+ assert_readable json_path
204
+ assert_file_contents(/\"name\"\:\s*\"sammy\"/, json_path)
205
+ end
114
206
  end
115
207
 
116
- end
208
+ context "with an existing package.json" do
209
+ setup do
210
+ @installer = Jim::Installer.new(fixture_path('mustache.js'), tmp_path)
211
+ @paths = @installer.install
212
+ @install_path = tmp_path + 'lib'
213
+ end
214
+
215
+ should "return an array of paths" do
216
+ assert @paths.is_a?(Array)
217
+ assert @paths.all? {|p| p.is_a?(Pathname) }
218
+ end
219
+
220
+ should "install each js file found separately" do
221
+ assert_dir tmp_path, 'lib', 'mustache-0.2.2'
222
+ assert_readable tmp_path, 'lib', 'mustache-0.2.2', 'mustache.js'
223
+ end
224
+
225
+ should "merge initial package.json values" do
226
+ json_path = @install_path + 'mustache-0.2.2' + 'package.json'
227
+ assert_readable json_path
228
+ assert_file_contents(/\"name\"\:\s*\"mustache\"/, json_path)
229
+ assert_file_contents(/\"author\"\:\s*\"Jan Lehnardt\"/, json_path)
230
+ end
231
+ end
117
232
 
233
+ end
234
+
118
235
  end
119
236
  end
@@ -23,10 +23,14 @@ class TestJimVersionParser < Test::Unit::TestCase
23
23
  ["sammy.plugin-1.0.1beta", ["sammy.plugin", "1.0.1beta"]],
24
24
  ["sammy.plugin.1.0.1.pre", ["sammy.plugin", "1.0.1.pre"]],
25
25
  ["sammy.plugin-1.0.1.beta", ["sammy.plugin", "1.0.1.beta"]],
26
+ ["sammy.plugin-1.0.1.min", ["sammy.plugin", "1.0.1.min"]],
26
27
  ["sammy 1.0.1", ["sammy", "1.0.1"]],
27
28
  ["sammy.plugin.1.0.1.js", ["sammy.plugin", "1.0.1"]],
28
29
  ["sammy.plugin.1.0.1.zip", ["sammy.plugin", "1.0.1"]],
29
30
  ["sammy.plugin.1.0.1", ["sammy.plugin", "1.0.1"]],
31
+ ["sammy.nested_params-0.5.0.js", ["sammy.nested_params", "0.5.0"]],
32
+ ["sammy.plugin-v0.5.0.js", ["sammy.plugin", "0.5.0"]],
33
+ ["sammy.plugin-a050.js", ["sammy.plugin-a050", "0"]],
30
34
  # ["sammy.plugin-a9asb02", ["sammy.plugin", "a9asb02"]],
31
35
  ["sammy-9asb02", ["sammy", "9asb02"]],
32
36
  ["noversion.js", ["noversion", "0"]]