From b78ac1b49a47320e55dad6345cac31dee673f04f Mon Sep 17 00:00:00 2001 From: Piotr Murach Date: Sat, 20 Jan 2018 20:57:28 +0100 Subject: [PATCH] Add profanity rule specs --- spec/unit/rules/profanity_spec.rb | 37 +++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 spec/unit/rules/profanity_spec.rb diff --git a/spec/unit/rules/profanity_spec.rb b/spec/unit/rules/profanity_spec.rb new file mode 100644 index 0000000..69b8c27 --- /dev/null +++ b/spec/unit/rules/profanity_spec.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +RSpec.describe Queen::Rules::Profanity do + it "defines a name" do + profanity = Queen::Rules::Profanity.new + expect(profanity.name).to eq('Profanity') + end + + it "checks for word profanities reprimands" do + profanity = Queen::Rules::Profanity.new + + profanity.check('ass') + + expect(profanity.reprimands).not_to be_empty + end + + it "checks for non-stem words" do + profanity = Queen::Rules::Profanity.new + + profanity.check('Fucking') + reprimand = profanity.reprimands.first + + expect(reprimand.message).to eq("\e[33mFucking\e[0m might be viewed as profane. Consider removing this word.") + end + + it "checks a text for profanities" do + profanity = Queen::Rules::Profanity.new + text = "Kicked friend in the ass\nHis rear end hurt like hell." + + profanity.check(text) + + expect(profanity.reprimands.map(&:line)).to eq([0, 1]) + expect(profanity.reprimands.map(&:column)).to eq([21, 23]) + expect(profanity.reprimands[0].message).to include('ass') + expect(profanity.reprimands[1].message).to include('hell') + end +end