Sha256: 2eeb574fd8549ec5af590584eb42352ebda003394b91c4b5e3801bcb75c5585a

Contents?: true

Size: 1.93 KB

Versions: 7

Compression:

Stored size: 1.93 KB

Contents

# File: placeholder_spec.rb

require_relative '../../spec_helper'

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

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
      expect { Placeholder.new('foobar') }.not_to raise_error
    end

    it 'should know the name of its variable' do
      expect(subject.name).to eq('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, {})
      expect(rendered_text).to be_empty

      # Case: locals Hash has a nil value associated to 'foobar'
      rendered_text = subject.render(Object.new, 'foobar' => nil)
      expect(rendered_text).to 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, {})
      expect(rendered_text).to 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')
      expect(rendered_text).to eq('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, {})
      expect(rendered_text).to eq('world')
    end
  end # context
end # describe
end # module
end # module

# End of file

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
macros4cuke-0.5.14 spec/macros4cuke/templating/placeholder_spec.rb
macros4cuke-0.5.13 spec/macros4cuke/templating/placeholder_spec.rb
macros4cuke-0.5.12 spec/macros4cuke/templating/placeholder_spec.rb
macros4cuke-0.5.11 spec/macros4cuke/templating/placeholder_spec.rb
macros4cuke-0.5.10 spec/macros4cuke/templating/placeholder_spec.rb
macros4cuke-0.5.09 spec/macros4cuke/templating/placeholder_spec.rb
macros4cuke-0.5.08 spec/macros4cuke/templating/placeholder_spec.rb