spec/sprockets-plugin_spec.rb in sprockets-plugin-0.1.2 vs spec/sprockets-plugin_spec.rb in sprockets-plugin-0.2.0
- old
+ new
@@ -3,44 +3,48 @@
describe Sprockets::Plugin do
after :each do
Sprockets::Plugin.send :class_variable_set, :@@plugins, nil
end
- it "adds paths from plugins to newly created environments" do
- dir_1 = @sandbox.directory "plugin_1/assets"
- dir_2 = @sandbox.directory "plugin_2/assets"
- dir_3 = @sandbox.directory "plugin_3/assets"
-
- plugin_1 = Class.new Sprockets::Plugin
- plugin_1.append_path dir_1
- plugin_2 = Class.new Sprockets::Plugin
- plugin_2.append_path dir_2
- plugin_3 = Class.new Sprockets::Plugin
- plugin_3.append_path dir_3
-
- env = Sprockets::Environment.new
- env.paths.should == [dir_1, dir_2, dir_3].map(&:to_s)
- end
+ describe "#append_plugin_paths" do
+ it "adds paths from plugins to environments" do
+ dir_1 = @sandbox.directory "plugin_1/assets"
+ dir_2 = @sandbox.directory "plugin_2/assets"
+ dir_3 = @sandbox.directory "plugin_3/assets"
+
+ plugin_1 = Class.new Sprockets::Plugin
+ plugin_1.append_path dir_1
+ plugin_2 = Class.new Sprockets::Plugin
+ plugin_2.append_path dir_2
+ plugin_3 = Class.new Sprockets::Plugin
+ plugin_3.append_path dir_3
+
+ env = Sprockets::Environment.new
+ env.append_plugin_paths
+ env.paths.should == [dir_1, dir_2, dir_3].map(&:to_s)
+ end
- it "adds a #append_plugin_paths method for adding paths from plugins" do
- dir_1 = @sandbox.directory "plugin_1/assets"
- dir_2 = @sandbox.directory "plugin_2/assets"
- dir_3 = @sandbox.directory "plugin_3/assets"
-
- plugin_1 = Class.new Sprockets::Plugin
- plugin_1.append_path dir_1
-
- env = Sprockets::Environment.new
- env.paths.should == [dir_1].map(&:to_s)
-
- plugin_2 = Class.new Sprockets::Plugin
- plugin_2.append_path dir_2
- plugin_3 = Class.new Sprockets::Plugin
- plugin_3.append_path dir_3
-
- env.append_plugin_paths
- env.paths.should == [dir_1, dir_2, dir_3].map(&:to_s)
+ it "does not add duplicate paths" do
+ dir_1 = @sandbox.directory "plugin_1/assets"
+ dir_2 = @sandbox.directory "plugin_2/assets"
+ dir_3 = @sandbox.directory "plugin_3/assets"
+
+ plugin_1 = Class.new Sprockets::Plugin
+ plugin_1.append_path dir_1
+
+ env = Sprockets::Environment.new
+ env.append_plugin_paths
+ env.paths.should == [dir_1].map(&:to_s)
+
+ plugin_2 = Class.new Sprockets::Plugin
+ plugin_2.append_path dir_2
+ plugin_3 = Class.new Sprockets::Plugin
+ plugin_3.append_path dir_3
+
+ env.append_plugin_paths
+ env.paths.should == [dir_1, dir_2, dir_3].map(&:to_s)
+ end
end
describe ".append_path" do
it "adds paths" do
dir_1 = @sandbox.directory "plugin/assets/images"
@@ -90,58 +94,19 @@
plugin.append_path dir_1, dir_2 ,dir_3
plugin.paths.should == [dir_1, dir_2, dir_3].map(&:to_s)
end
end
- describe ".prepend_path" do
- it "adds paths" do
- dir_1 = @sandbox.directory "plugin/assets/images"
- dir_2 = @sandbox.directory "plugin/assets/javascripts"
- dir_3 = @sandbox.directory "plugin/assets/stylesheets"
+ describe ".append_paths_in" do
+ it "adds paths within the given path" do
+ assets_dir = @sandbox.directory "plugin/assets"
+ dir_1 = assets_dir.directory "images"
+ dir_2 = assets_dir.directory "javascripts"
+ dir_3 = assets_dir.directory "stylesheets"
plugin = Class.new Sprockets::Plugin
- plugin.prepend_path dir_1
- plugin.prepend_path dir_2
- plugin.prepend_path dir_3
- plugin.paths.should == [dir_3, dir_2, dir_1].map(&:to_s)
- end
-
- it "adds the paths relative to the plugin root" do
- dir_1 = @sandbox.directory "plugin/assets/images"
- dir_2 = @sandbox.directory "plugin/assets/javascripts"
- dir_3 = @sandbox.directory "plugin/assets/stylesheets"
-
- plugin = Class.new Sprockets::Plugin
- plugin.root @sandbox.join "plugin"
- plugin.prepend_path "assets/images"
- plugin.prepend_path "assets/javascripts"
- plugin.prepend_path "assets/stylesheets"
- plugin.paths.should == [dir_3, dir_2, dir_1].map(&:to_s)
- end
-
- it "only adds existing paths" do
- dir_1 = @sandbox.directory "plugin/assets/images"
- dir_2 = @sandbox.directory "plugin/assets/javascripts"
- dir_3 = @sandbox.join "plugin/assets/stylesheets"
-
- plugin = Class.new Sprockets::Plugin
- plugin.prepend_path dir_1
- plugin.prepend_path dir_2
- plugin.prepend_path dir_3
- plugin.paths.should == [dir_2, dir_1].map(&:to_s)
- end
- end
-
- describe ".prepends_paths" do
- it "adds multiple paths at once" do
- dir_1 = @sandbox.directory "plugin/assets/images"
- dir_2 = @sandbox.directory "plugin/assets/javascripts"
- dir_3 = @sandbox.directory "plugin/assets/stylesheets"
-
- plugin = Class.new Sprockets::Plugin
- plugin.append_path dir_1
- plugin.prepend_paths dir_2 ,dir_3
- plugin.paths.should == [dir_2, dir_3, dir_1].map(&:to_s)
+ plugin.append_paths_in assets_dir
+ plugin.paths.should == [dir_1, dir_2, dir_3].map(&:to_s)
end
end
describe ".root" do
it "converts the given path to a Pathname object" do