Sha256: fc66a56570afaf9ad5c33acc7a8ad4a5d80e3aabf008e639ed86fe5c2496b6aa

Contents?: true

Size: 1.9 KB

Versions: 5

Compression:

Stored size: 1.9 KB

Contents

##
# spec/lib/skn_utils/configurable_spec.rb
#

class MyApp
  include SknUtils::Configurable.with( :app_id, :title, :cookie_name, enable_root: true) # No options hash defaults to true
  # - and accept defaults for #env=, #root=, and #logger=

  # notice: self.logger=, the self is required when assigning values
  self.logger = Object.new

  configure do
    app_id 'some app'
    title 'My Title'
    cookie_name 'Chocolate'
  end

  def null_value
    @app_id.dup
  end
end

module MyMod
  include SknUtils::Configurable.with(:app_id, :title, :cookie_name,  enable_root: false)

  def self.null_value
    @app_id.dup
  end
end

MyMod.configure do
  app_id 'some module'
  title 'Some Title'
  cookie_name 'Caramel'
end


describe SknUtils::Configurable, "Gem Configuration module." do

  let(:my_app) { MyApp.new }

  context "Top Level AppClass Extra Operational Features. " do

    it "MyApp.env.test? returns expected value. " do
      expect( MyApp.env.test? ).to be true
    end
    it "MyApp.root returns expected value. " do
      expect( MyApp.root.realdirpath.to_s ).to eq( Dir.pwd )
    end
    it "MyApp.logger returns expected value. " do
      expect( MyApp.logger ).to be_instance_of(Object) # eq('No Logger Assigned.')
    end
  end

  context "Module & Class Operational Features. " do

    it "my_app#config.title returns expected value. " do
      expect( MyApp.config.title ).to eq( "My Title" )
    end
    it "my_app#config.app_id returns expected value. " do
      expect( MyApp.config.app_id ).to eq( "some app" )
    end

    it "MyMod#config.app_id  returns expected value. " do
      expect( MyMod.config.app_id ).to eq( "some module" )
    end
    it "MyMod#config.cookie_name returns expected value. " do
      expect( MyMod.config.cookie_name ).to eq( 'Caramel' )
    end

    it "MyMod#logger raises NoMethodError as expected. " do
      expect{ MyMod.logger }.to raise_error(NoMethodError)
    end

  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
skn_utils-5.1.2 spec/lib/skn_utils/configurable_spec.rb
skn_utils-5.1.1 spec/lib/skn_utils/configurable_spec.rb
skn_utils-5.1.0 spec/lib/skn_utils/configurable_spec.rb
skn_utils-5.0.2 spec/lib/skn_utils/configurable_spec.rb
skn_utils-5.0.1 spec/lib/skn_utils/configurable_spec.rb