spec/jsus/pool_spec.rb in jsus-0.3.6 vs spec/jsus/pool_spec.rb in jsus-0.4.0

- old
+ new

@@ -1,13 +1,13 @@ require 'spec_helper' describe Jsus::Pool do let(:input_dir) { "spec/data/ChainDependencies/app/javascripts" } let(:packages) { [ - Jsus::Package.new("#{input_dir}/Mash", :pool => subject), - Jsus::Package.new("#{input_dir}/Class", :pool => subject), - Jsus::Package.new("#{input_dir}/Hash", :pool => subject) + Jsus::Package.new("#{input_dir}/Mash"), + Jsus::Package.new("#{input_dir}/Class"), + Jsus::Package.new("#{input_dir}/Hash") ] } let(:sources) { packages.map {|p| p.source_files[0] } @@ -32,11 +32,11 @@ subject.packages.map {|p| p.name }.should include("Mash", "Hash", "Class") end it "should add all the source files to pool" do subject.should have_exactly(3).sources - subject.sources.map {|s| s.provides_names }.flatten.should include("Mash/Mash", "Hash/Hash", "Class/Class") + subject.sources.map {|s| s.provides.map {|tag| tag.to_s } }.flatten.should include("Mash/Mash", "Hash/Hash", "Class/Class") end it "should keep track of extensions" do pool = Jsus::Pool.new("spec/data/Extensions/app/javascripts") pool.send(:extensions_map).keys.should include(Jsus::Tag["Core/Class"]) @@ -54,13 +54,11 @@ end end describe "#lookup" do - before(:each) do - packages.each {|package| subject << package.source_files } - end + before(:each) { packages.each {|package| subject << package} } it "should find a source file providing given full name" do subject.lookup("Class/Class").should == sources[1] end @@ -69,17 +67,10 @@ end it "should allow tags" do subject.lookup(Jsus::Tag["Class/Class"]).should == sources[1] end - - it "should return replacements whenever possible" do - pkg = Jsus::Package.new("spec/data/ClassReplacement", :pool => subject) - subject << pkg.source_files - subject.lookup("Class/Class").should == pkg.source_files[0] - subject.lookup(Jsus::Tag["Class/Class"]).should == pkg.source_files[0] - end end describe "#lookup_direct_dependencies" do before(:each) do packages.each {|package| subject << package.source_files } @@ -102,12 +93,12 @@ before(:each) do packages.each {|package| subject << package.source_files } end it "should return a container with files and dependencies" do - subject.lookup_dependencies("Mash/Mash").should == [sources[1], sources[2]] - subject.lookup_dependencies(Jsus::Tag["Mash/Mash"]).should == [sources[1], sources[2]] + subject.lookup_dependencies("Mash/Mash").should =~ [sources[1], sources[2]] + subject.lookup_dependencies(Jsus::Tag["Mash/Mash"]).should =~ [sources[1], sources[2]] end it "should return empty array if pool doesn't contain given source" do subject.lookup_dependencies("Lol/Wtf").should == [] subject.lookup_dependencies(Jsus::Tag["Caught/Mosh"]).should == [] @@ -115,11 +106,11 @@ context "wildcard support" do let(:input_dir) { "spec/data/DependenciesWildcards/app/javascripts" } it "should support wildcards" do - subject.lookup_dependencies("Mash/Mash").should == [sources[1], sources[2]] + subject.lookup_dependencies("Mash/Mash").should =~ [sources[1], sources[2]] end end end @@ -134,17 +125,17 @@ describe "#lookup_extensions" do let(:input_dir) { "spec/data/Extensions/app/javascripts" } subject { Jsus::Pool.new(input_dir) } - it "should return empty array if there's not a single extension for given tag" do - subject.lookup_extensions("Core/WTF").should be_empty - subject.lookup_extensions(Jsus::Tag["Core/WTF"]).should be_empty + it "should return empty array if there's not a single extension for given file" do + source = Jsus::SourceFile.from_file("spec/data/test_source_one.js", :namespace => "Test") + subject.lookup_extensions(source).should be_empty end it "should return an array with extensions if there are extensions for given tag" do - subject.lookup_extensions("Core/Class").should have_exactly(1).item - subject.lookup_extensions(Jsus::Tag["Core/Class"]).should have_exactly(1).item + source = subject.lookup("Core/Class") + subject.lookup_extensions(source).should_not be_empty end end describe "#source_tree" do let(:input_dir) { "spec/data/Extensions/app/javascripts" }