Sha256: 4e6c113776ec85ab82133a70800e1956be528ac8049601fdc740d894031c24dc

Contents?: true

Size: 1006 Bytes

Versions: 3

Compression:

Stored size: 1006 Bytes

Contents

require 'spec_helper'

class AfterInitializeWidget < Erector::Widget

  after_initialize do
    @foo ||= ''
    @foo += 'bar'
  end

  def content
    html do
      head do
        title "Welcome page"
      end
      body do
        p @foo
      end
    end
  end
end

class AfterInitializeWidgetTwo < AfterInitializeWidget
end

class AfterInitializeWidgetThree < AfterInitializeWidget
  after_initialize do
    @foo += 'baz'
  end
end

describe Erector::AfterInitialize do

  it 'should call the block' do
    AfterInitializeWidget.new.to_html.should == %Q{<html><head><title>Welcome page</title></head><body><p>bar</p></body></html>}
  end

  it 'should call the block only once' do
    AfterInitializeWidgetTwo.new.to_html.should == %Q{<html><head><title>Welcome page</title></head><body><p>bar</p></body></html>}
  end

  it 'should call each block' do
    AfterInitializeWidgetThree.new.to_html.should == %Q{<html><head><title>Welcome page</title></head><body><p>barbaz</p></body></html>}
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
erector-rails4-0.2.0 spec/erector/after_initialize_spec.rb
erector-rails4-0.1.3 spec/erector/after_initialize_spec.rb
erector-rails4-0.1.2 spec/erector/after_initialize_spec.rb