test/test_base.rb in obscenity-1.0.0 vs test/test_base.rb in obscenity-1.0.1
- old
+ new
@@ -23,11 +23,11 @@
should "respect the config options" do
assert_equal ['bad', 'word'], Obscenity::Base.blacklist
end
end
end
-
+
context "#whitelist" do
context "without custom config" do
setup { Obscenity::Base.whitelist = :default }
should "use the default content file when no config is found" do
assert Obscenity::Base.whitelist.is_a?(Array)
@@ -39,15 +39,15 @@
should "respect the config options" do
assert_equal ['safe', 'word'], Obscenity::Base.whitelist
end
end
end
-
+
context "#profane?" do
context "without whitelist" do
context "without custom config" do
- setup {
+ setup {
Obscenity::Base.blacklist = :default
Obscenity::Base.whitelist = :default
}
should "validate the profanity of a word based on the default list" do
assert Obscenity::Base.profane?('ass')
@@ -64,22 +64,22 @@
end
end
end
context "with whitelist" do
context "without custom blacklist config" do
- setup {
+ setup {
Obscenity::Base.blacklist = :default
Obscenity::Base.whitelist = ['biatch']
}
should "validate the profanity of a word based on the default list" do
assert Obscenity::Base.profane?('ass')
assert !Obscenity::Base.profane?('biatch')
assert !Obscenity::Base.profane?('hello')
end
end
context "with custom blacklist/whitelist config" do
- setup {
+ setup {
Obscenity::Base.blacklist = ['ass', 'word']
Obscenity::Base.whitelist = ['word']
}
should "validate the profanity of a word based on the custom list" do
assert Obscenity::Base.profane?('ass')
@@ -87,15 +87,15 @@
assert !Obscenity::Base.profane?('biatch')
end
end
end
end
-
+
context "#sanitize" do
context "without whitelist" do
context "without custom config" do
- setup {
+ setup {
Obscenity::Base.blacklist = :default
Obscenity::Base.whitelist = :default
}
should "sanitize and return a clean text based on the default list" do
assert_equal "Yo $@!#%, sup", Obscenity::Base.sanitize('Yo assclown, sup')
@@ -110,93 +110,97 @@
end
end
end
context "with whitelist" do
context "without custom blacklist config" do
- setup {
+ setup {
Obscenity::Base.blacklist = :default
Obscenity::Base.whitelist = ['biatch']
}
should "sanitize and return a clean text based on the default blacklist and custom whitelist" do
assert_equal "Yo $@!#%, sup", Obscenity::Base.sanitize('Yo assclown, sup')
assert_equal "Yo biatch, sup", Obscenity::Base.sanitize('Yo biatch, sup')
end
end
context "with custom blacklist/whitelist config" do
- setup {
+ setup {
Obscenity::Base.blacklist = ['clown', 'biatch']
Obscenity::Base.whitelist = ['biatch']
}
should "validate the profanity of a word based on the custom list" do
assert_equal "Yo $@!#%, sup", Obscenity::Base.sanitize('Yo clown, sup')
assert_equal "Yo biatch, sup", Obscenity::Base.sanitize('Yo biatch, sup')
end
end
end
end
-
+
context "#replacement" do
context "without whitelist" do
context "without custom config" do
- setup {
+ setup {
Obscenity::Base.blacklist = :default
Obscenity::Base.whitelist = :default
}
should "sanitize and return a clean text based on the default list" do
assert_equal "Yo ********, sup", Obscenity::Base.replacement(:stars).sanitize('Yo assclown, sup')
assert_equal "Yo $@!#%, sup", Obscenity::Base.replacement(:garbled).sanitize('Yo assclown, sup')
assert_equal "Yo *sscl*wn, sup", Obscenity::Base.replacement(:vowels).sanitize('Yo assclown, sup')
+ assert_equal "Oh, *h*t!", Obscenity::Base.replacement(:nonconsonants).sanitize('Oh, 5hit!')
assert_equal "Yo [censored], sup", Obscenity::Base.replacement('[censored]').sanitize('Yo assclown, sup')
assert_equal "Hello World", Obscenity::Base.replacement(:default).sanitize('Hello World')
end
end
context "with custom blacklist config" do
- setup { Obscenity::Base.blacklist = ['ass', 'word'] }
+ setup { Obscenity::Base.blacklist = ['ass', 'word', 'w0rd'] }
should "sanitize and return a clean text based on a custom list" do
assert_equal "Yo ****, sup", Obscenity::Base.replacement(:stars).sanitize('Yo word, sup')
assert_equal "Yo $@!#%, sup", Obscenity::Base.replacement(:garbled).sanitize('Yo word, sup')
assert_equal "Yo w*rd, sup", Obscenity::Base.replacement(:vowels).sanitize('Yo word, sup')
+ assert_equal "Yo w*rd, sup", Obscenity::Base.replacement(:nonconsonants).sanitize('Yo w0rd, sup')
assert_equal "Yo [censored], sup", Obscenity::Base.replacement('[censored]').sanitize('Yo word, sup')
assert_equal "Hello World", Obscenity::Base.replacement(:default).sanitize('Hello World')
end
end
end
context "with whitelist" do
context "without custom blacklist config" do
- setup {
+ setup {
Obscenity::Base.blacklist = :default
Obscenity::Base.whitelist = ['biatch']
}
should "sanitize and return a clean text based on the default blacklist and custom whitelist" do
assert_equal "Yo ********, sup", Obscenity::Base.replacement(:stars).sanitize('Yo assclown, sup')
assert_equal "Yo $@!#%, sup", Obscenity::Base.replacement(:garbled).sanitize('Yo assclown, sup')
assert_equal "Yo *sscl*wn, sup", Obscenity::Base.replacement(:vowels).sanitize('Yo assclown, sup')
+ assert_equal "What an *r**", Obscenity::Base.replacement(:nonconsonants).sanitize('What an ar5e')
assert_equal "Yo [censored], sup", Obscenity::Base.replacement('[censored]').sanitize('Yo assclown, sup')
assert_equal "Yo biatch, sup", Obscenity::Base.replacement(:default).sanitize('Yo biatch, sup')
end
end
context "with custom blacklist/whitelist config" do
- setup {
+ setup {
Obscenity::Base.blacklist = ['clown', 'biatch']
Obscenity::Base.whitelist = ['biatch']
}
should "validate the profanity of a word based on the custom list" do
assert_equal "Yo *****, sup", Obscenity::Base.replacement(:stars).sanitize('Yo clown, sup')
assert_equal "Yo $@!#%, sup", Obscenity::Base.replacement(:garbled).sanitize('Yo clown, sup')
assert_equal "Yo cl*wn, sup", Obscenity::Base.replacement(:vowels).sanitize('Yo clown, sup')
+ assert_equal "Yo cl*wn, sup", Obscenity::Base.replacement(:nonconsonants).sanitize('Yo clown, sup')
assert_equal "Yo [censored], sup", Obscenity::Base.replacement('[censored]').sanitize('Yo clown, sup')
assert_equal "Yo biatch, sup", Obscenity::Base.replacement(:default).sanitize('Yo biatch, sup')
assert_equal "Yo assclown, sup", Obscenity::Base.replacement(:default).sanitize('Yo assclown, sup')
end
end
end
end
-
+
context "#offensive" do
context "without whitelist" do
context "without custom config" do
- setup {
+ setup {
Obscenity::Base.blacklist = :default
Obscenity::Base.whitelist = :default
}
should "return an array with the offensive words based on the default list" do
assert_equal ['assclown'], Obscenity::Base.offensive('Yo assclown, sup')
@@ -211,43 +215,44 @@
end
end
end
context "with whitelist" do
context "without custom blacklist config" do
- setup {
+ setup {
Obscenity::Base.blacklist = :default
Obscenity::Base.whitelist = ['biatch']
}
should "return an array with the offensive words based on the default blacklist and custom whitelist" do
assert_equal ['assclown'], Obscenity::Base.offensive('Yo assclown, sup')
assert_equal [], Obscenity::Base.offensive('Yo biatch, sup')
end
end
context "with custom blacklist/whitelist config" do
- setup {
+ setup {
Obscenity::Base.blacklist = ['clown', 'biatch']
Obscenity::Base.whitelist = ['biatch']
}
should "return an array with the offensive words based on the custom list" do
assert_equal ['clown'], Obscenity::Base.offensive('Yo clown, sup')
assert_equal [], Obscenity::Base.offensive('Yo biatch, sup')
end
end
end
end
-
+
context "#replace" do
should "replace the given word by the given replacement method" do
[
- [:vowels, {original: "Yo biatch", clean: "Yo b**tch"}],
- [:stars, {original: "Yo biatch", clean: "Yo ******"}],
- [:garbled, {original: "Yo biatch", clean: "Yo $@!#%"}],
- [:default, {original: "Yo biatch", clean: "Yo $@!#%"}],
- ["[censored]", {original: "Yo biatch", clean: "Yo [censored]"}],
- [nil, {original: "Yo biatch", clean: "Yo $@!#%"}]
+ [:vowels, {original: "Oh 5hit", clean: "Oh 5h*t"}],
+ [:nonconsonants, {original: "Oh 5hit", clean: "Oh *h*t"}],
+ [:stars, {original: "Oh 5hit", clean: "Oh ****"}],
+ [:garbled, {original: "Oh 5hit", clean: "Oh $@!#%"}],
+ [:default, {original: "Oh 5hit", clean: "Oh $@!#%"}],
+ ["[censored]", {original: "Oh 5hit", clean: "Oh [censored]"}],
+ [nil, {original: "Oh 5hit", clean: "Oh $@!#%"}]
].each do |replacement_method, content|
- assert_equal content[:clean], Obscenity::Base.replacement(replacement_method).sanitize(content[:original])
+ assert_equal content[:clean], Obscenity::Base.replacement(replacement_method).sanitize(content[:original]), "(replacement should match for #{replacement_method})"
end
end
end
-
+
end