Sha256: 439eb6b7110100367d9ec68ed6536613680126b71883c8e03418098dd62d579c

Contents?: true

Size: 1.92 KB

Versions: 5

Compression:

Stored size: 1.92 KB

Contents

require 'helper'

class TestConfig < Test::Unit::TestCase

  context "#respond_to?" do
    should "respond to methods and attributes" do
      Obscenity::Config.new do |config|
        [:blacklist, :whitelist, :replacement].each do |field|
          assert config.respond_to?(field)
        end
      end
    end
  end
  
  should "properly set the config parameters" do
    blacklist   = ['ass', 'shit', 'penis']
    whitelist   = ['penis']
    replacement = :stars
    
    config = Obscenity::Config.new do |config|
      config.blacklist   = blacklist
      config.whitelist   = whitelist
      config.replacement = replacement
    end
    
    assert_equal blacklist, config.blacklist
    assert_equal whitelist, config.whitelist
    assert_equal replacement, config.replacement
  end

  should "return default values if none is set" do
    config = Obscenity::Config.new
    assert_equal [], config.whitelist
    assert_equal :garbled, config.replacement
    assert_match /config\/blacklist.yml/, config.blacklist
  end

  should "return default values when default values are set" do
    config = Obscenity::Config.new do |config|
      config.blacklist   = :default
      config.replacement = :default
    end
    assert_equal [], config.whitelist
    assert_equal :default, config.replacement
    assert_match /config\/blacklist.yml/, config.blacklist
  end
  
  should "properly validate the config options" do
    [:blacklist, :whitelist].each do |field|
      exceptions = [
        [Obscenity::UnkownContent, {}], 
        [Obscenity::UnkownContent, ":unkown"], 
        [Obscenity::EmptyContentList, []], 
        [Obscenity::UnkownContentFile, "'path/to/file'"], 
        [Obscenity::UnkownContentFile, Pathname.new("'path/to/file'")]
      ].each do |klass, value|
        assert_raise(klass){
          Obscenity::Config.new do |config|
            config.instance_eval "config.#{field} = #{value}"
          end
        }
      end
    end
  end
  
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
obscenity2-0.0.2 test/test_config.rb
obscenity2-0.0.1 test/test_config.rb
obscenity-1.0.2 test/test_config.rb
obscenity-1.0.1 test/test_config.rb
obscenity-1.0.0 test/test_config.rb