Sha256: 2422b537479f21312cdb31d08d29ea11510f8bb3d9f4d0f27089f726d617b082

Contents?: true

Size: 1.97 KB

Versions: 5

Compression:

Stored size: 1.97 KB

Contents

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

require_relative '../../spec_helper'

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

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
      ->() { 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 absent' 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  # Add singleton method foobar that returns nil
        nil
      end
      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 # Add singleton method foobar that returns 'world'
        'world'
      end
      rendered_text = subject.render(context, {})
      rendered_text.should == 'world'
    end

  end # context

end # describe

end # module

end # module

# End of file

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
macros4cuke-0.3.25 spec/macros4cuke/templating/placeholder_spec.rb
macros4cuke-0.3.24 spec/macros4cuke/templating/placeholder_spec.rb
macros4cuke-0.3.23 spec/macros4cuke/templating/placeholder_spec.rb
macros4cuke-0.3.22 spec/macros4cuke/templating/placeholder_spec.rb
macros4cuke-0.3.21 spec/macros4cuke/templating/placeholder_spec.rb