spec/swearjar_spec.rb in swearjar-1.0.0 vs spec/swearjar_spec.rb in swearjar-1.1.0

- old
+ new

@@ -1,48 +1,87 @@ +# encoding: UTF-8 require 'spec_helper' describe Swearjar do - it "should detect dirty words" do - Swearjar.default.profane?('fuck you jim henson').should be_true + expect(Swearjar.default.profane?('jackass chan')).to be_truthy end it "should detect dirty words regardless of case" do - Swearjar.default.profane?('FuCk you jim henson').should be_true + expect(Swearjar.default.profane?('JACKASS CHAN')).to be_truthy end it "should not detect non-dirty words" do - Swearjar.default.profane?('i love you jim henson').should be_false + expect(Swearjar.default.profane?('I love Jackie Chan movies')).to be_falsey end it "should give us a scorecard" do - Swearjar.default.scorecard('fuck you jim henson').should == {'sexual'=>1} + expect(Swearjar.default.scorecard('honky jim henson')).to eq({'discriminatory'=>1}) end it "should detect multiword" do - Swearjar.default.scorecard('jim henson has a hard on').should == {'sexual'=>1} + expect(Swearjar.default.scorecard('jim henson has a hard on')).to eq({'sexual'=>1}) end it "should detect multiword plurals" do - Swearjar.default.scorecard('jim henson has a hard ons').should == {'sexual'=>1} + expect(Swearjar.default.scorecard('jim henson has a hard ons')).to eq({'sexual'=>1}) end it "should detect simple dirty plurals" do - Swearjar.default.profane?('jim henson had two dicks').should be_true - Swearjar.default.profane?('jim henson has two asses').should be_true + expect(Swearjar.default.profane?('jim henson had two dicks')).to be_truthy + expect(Swearjar.default.profane?('jim henson has two asses')).to be_truthy end it "should censor a string" do - Swearjar.default.censor('jim henson has a massive hard on he is gonna use to fuck everybody').should == 'jim henson has a massive **** ** he is gonna use to **** everybody' + expect(Swearjar.default.censor('jim henson has a massive hard on he is gonna use to fuck everybody')).to eq('jim henson has a massive **** ** he is gonna use to **** everybody') end it "should not do much when given a non-string" do - Swearjar.default.profane?(nil).should be_false + expect(Swearjar.default.profane?(nil)).to be_falsey end + it "doesn't mark an empty string as profane" do + expect(Swearjar.default.profane?("")).to be_falsey + end + it "should allow you to load a new yaml file" do - sj = Swearjar.new - sj.load_file(File.expand_path('../data/swear.yml', __FILE__)) - sj.censor("Python is the best language!").should == "****** is the best language!" + sj = Swearjar.new(File.expand_path('../data/swear.yml', __FILE__)) + expect(sj.censor("Python is the best language!")).to eq("****** is the best language!") end -end \ No newline at end of file + it "detects multiple entries" do + expect(Swearjar.default.scorecard("cunts cunts cunts")).to eq({"insult" => 3, "sexual" => 3}) + expect(Swearjar.default.scorecard("damn damnit dammit")).to eq({"inappropriate" => 3, "blasphemy" => 3}) + end + + it "detects plurals of words ending in 'e'" do + expect(Swearjar.default.profane?("asspirates")).to be_truthy + end + + it "detects profane emojis" do + expect(Swearjar.default.profane?("🖕")).to be_truthy + end + + it "detects profane emojis with skin tone" do + expect(Swearjar.default.profane?("🖕🏾")).to be_truthy + end + + it "censors profane emojis" do + expect(Swearjar.default.censor("Fuck you🖕 🖕🖕")).to eq("**** you* **") + end + + it "censors with regular expression matching" do + expect(Swearjar.default.censor("foonIgg3rbar foo nigger")).to eq("************ foo ******") + end + + it "censors with a mix of normal and regular expression matches" do + expect(Swearjar.default.censor("fagfaggot faggotfag")).to eq("********* *********") + end + + it "detects scorecard with regular expression matching" do + expect(Swearjar.default.scorecard("foonIgg3rbar foo nigger")).to eq({"discriminatory" => 2}) + end + + xit "doesn't substitute simple words when they occur later as substrings" do + expect(Swearjar.default.censor("anus janus")).to eq("**** janus") + end +end