Sha256: 773df2c5bc8cb56f95517e796efb5f2271b5c99ebbc7900413a32f1b7dbb39ee

Contents?: true

Size: 2 KB

Versions: 12

Compression:

Stored size: 2 KB

Contents

# encoding: utf-8 -- You should see a paragraph character: ยง
# File: section_spec.rb

require_relative '../../spec_helper'
require_relative '../../../lib/macros4cuke/templating/engine'	# Load the classes under test

module Macros4Cuke

module Templating # Open this namespace to get rid of module qualifier prefixes


describe Placeholder do
  # Default instantiation rule
  subject { Placeholder.new('foobar') }

  context "Creation and initialization:" do

    it "should be created with a variable name" do
      lambda { Placeholder.new('foobar') }.should_not raise_error
    end
    
    it "should know the name of its variable" do 
      subject.name.should == 'foobar'
    end    

  end # context 

  context "Provided services:" do 
    it "should render an empty string when no actual value is bound to the placeholder" do
      # Case: context has no value associated to 'foobar'
      rendered_text = subject.render(Object.new, {})
      rendered_text.should be_empty
      
      # Case: locals Hash has a nil value associated to 'foobar'
      rendered_text = subject.render(Object.new, {'foobar' => nil})
      rendered_text.should be_empty

      # Case: context object has a nil value associated to 'foobar'
      context = Object.new
      def context.foobar; nil; end  # Add singleton method foobar that returns nil
      rendered_text = subject.render(context, {})
      rendered_text.should be_empty        
    end
    
    it "should render the actual value bound to the placeholder" do
      # Case: locals Hash has a value associated to 'foobar'
      rendered_text = subject.render(Object.new, {'foobar' => 'hello'})
      rendered_text.should == 'hello'

      # Case: context object has a value associated to 'foobar'
      context = Object.new
      def context.foobar; 'world'; end  # Add singleton method foobar that returns 'world'
      rendered_text = subject.render(context, {})
      rendered_text.should == 'world'       
    end
  
  end # context

end # describe

end # module

end # module

# End of file

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
macros4cuke-0.3.14 spec/macros4cuke/templating/placeholder_spec.rb
macros4cuke-0.3.13 spec/macros4cuke/templating/placeholder_spec.rb
macros4cuke-0.3.12 spec/macros4cuke/templating/placeholder_spec.rb
macros4cuke-0.3.11 spec/macros4cuke/templating/placeholder_spec.rb
macros4cuke-0.3.10 spec/macros4cuke/templating/placeholder_spec.rb
macros4cuke-0.3.09 spec/macros4cuke/templating/placeholder_spec.rb
macros4cuke-0.3.08 spec/macros4cuke/templating/placeholder_spec.rb
macros4cuke-0.3.07 spec/macros4cuke/templating/placeholder_spec.rb
macros4cuke-0.3.06 spec/macros4cuke/templating/placeholder_spec.rb
macros4cuke-0.3.03 spec/macros4cuke/templating/placeholder_spec.rb
macros4cuke-0.3.02 spec/macros4cuke/templating/placeholder_spec.rb
macros4cuke-0.3.01 spec/macros4cuke/templating/placeholder_spec.rb