Mahlon Smith avatar Mahlon Smith committed 52c37c7

Carry global configuration into instantiated template options. Minor
rspec update/cleanup.

Comments (0)

Files changed (8)

lib/inversion/template.rb

 
 		@source       = source
 		@node_tree    = [] # Parser expects this to always be an Array
-		@options      = opts
+		@options      = self.class.config.merge( opts )
 		@attributes   = {}
 		@source_file  = nil
 		@created_at   = Time.now

spec/inversion/parser_spec.rb

 		end
 
 		it "calls the #after_appending hook of container nodes when they're popped" do
-			container = mock( "container tag", :before_appending => false, :is_container? => true )
+			container = double( "container tag", :before_appending => false, :is_container? => true )
 			@state << container
 
 			container.should_receive( :after_appending ).with( @state )
 		end
 
 		it "calls the #before_appending callback on nodes that are appended to it" do
-			node = mock( "node", :is_container? => false, :after_appending => nil )
+			node = double( "node", :is_container? => false, :after_appending => nil )
 			node.should_receive( :before_appending ).with( @state )
 
 			@state << node
 		end
 
 		it "calls the #after_appending callback on nodes that are appended to it" do
-			node = mock( "node", :is_container? => false, :before_appending => nil )
+			node = double( "node", :is_container? => false, :before_appending => nil )
 			node.should_receive( :after_appending ).with( @state )
 
 			@state << node

spec/inversion/template/attrtag_spec.rb

 		context "with a methodchain" do
 
 			before( :each ) do
-				@attribute_object = mock( "template attribute" )
+				@attribute_object = double( "template attribute" )
 			end
 
 			it "renders a single method call with no arguments" do
 			end
 
 			it "renders multiple method calls with no arguments" do
-				additional_object = mock( 'additional template attribute' )
+				additional_object = double( 'additional template attribute' )
 				template = Inversion::Template.new( 'this is <?attr foo.bar.baz ?>' )
 				template.foo = @attribute_object
 				template.foo.should_receive( :bar ).and_return( additional_object )
 			end
 
 			it "renders multiple method calls with arguments" do
-				additional_object = mock( 'additional template attribute' )
+				additional_object = double( 'additional template attribute' )
 				template = Inversion::Template.new( 'this is <?attr foo.bar( 8 ).baz( :woo ) ?>' )
 				template.foo = @attribute_object
 				template.foo.should_receive( :bar ).with( 8 ).and_return( additional_object )
 
 			it "renders method calls with template attribute arguments" do
 				template = Inversion::Template.new( 'this is <?attr foo.bar( baz ) ?>' )
-				foo = mock( "foo attribute object" )
+				foo = double( "foo attribute object" )
 
 				template.foo = foo
 				template.baz = 18

spec/inversion/template/endtag_spec.rb

 
 	it "closes the parse state's currently-open container node before it's appended" do
 		container = double( "container node", :tagname => 'for', :location => nil )
-		parserstate = mock( "parser state" )
+		parserstate = double( "parser state" )
 
 		parserstate.should_receive( :pop ).and_return( container )
 

spec/inversion/template/escapetag_spec.rb

 	end
 
 	before( :each ) do
-		@attribute_object = mock( "template attribute" )
+		@attribute_object = double( "template attribute" )
 	end
 
 

spec/inversion/template/pptag_spec.rb

 	end
 
 	before( :each ) do
-		@attribute_object = mock( "template attribute" )
+		@attribute_object = double( "template attribute" )
 	end
 
 

spec/inversion/template/uriencodetag_spec.rb

 	end
 
 	before( :each ) do
-		@attribute_object = mock( "template attribute" )
+		@attribute_object = double( "template attribute" )
 	end
 
 

spec/inversion/template_spec.rb

 		end
 	end
 
+	it "carries its global configuration to per-template options" do
+		begin
+			orig_config = Inversion::Template.config
+			Inversion::Template.configure( :stat_delay => 300 )
+
+			template = Inversion::Template.new( 'hi!' )
+			expect( template.options[ :stat_delay ] ).to eq( 300 )
+
+			template = Inversion::Template.new( 'hi!', :stat_delay => 600 )
+			expect( template.options[ :stat_delay ] ).to eq( 600 )
+		ensure
+			Inversion::Template.config = orig_config
+		end
+	end
+
+
 	it "can make an human-readable string version of itself suitable for debugging" do
 		IO.should_receive( :read ).with( '/tmp/inspect.tmpl' ).and_return( '<?attr foo ?>' )
 		tmpl = Inversion::Template.load( '/tmp/inspect.tmpl' )
 		context "that hasn't changed since it was loaded" do
 
 			before( :each ) do
-				@template.source_file.stub!( :mtime ).and_return( @timestamp )
+				@template.source_file.stub( :mtime ).and_return( @timestamp )
 			end
 
 			it "knows that it hasn't changed" do
 				end
 
 				it "returns unchanged if the delay time has expired" do
-					@template.source_file.stub!( :mtime ).and_return( @timestamp - 30 )
+					@template.source_file.stub( :mtime ).and_return( @timestamp - 30 )
 					@template.instance_variable_set( :@last_checked, @timestamp - 30 )
 					@template.should_not be_changed()
 				end
 		context "that has changed since it was loaded" do
 
 			before( :each ) do
-				@template.source_file.stub!( :mtime ).and_return( @timestamp + 1 )
+				@template.source_file.stub( :mtime ).and_return( @timestamp + 1 )
 			end
 
 			it "knows that is has changed" do
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.