Sha256: d40cd32728a8abcc4a6ba23a69ff39e8ed38dc3047d2a7f6d4fc99812a6e3e94

Contents?: true

Size: 1.65 KB

Versions: 2

Compression:

Stored size: 1.65 KB

Contents

module RubyQuiz1
  describe Message do

    describe "#decrypt" do
      {
        "CLEPK HHNIY CFPWH FDFEH" => "YOURC IPHER ISWOR KINGX",
        "ABVAW LWZSY OORYK DUPVH" => "WELCO METOR UBYQU IZXXX"
      }.each do |k,v|
        context "with the encrypted message \"#{k}\"" do
          subject do
            described_class.new k
          end
          it "decrypts to \"#{v}\"" do
            expect(subject.decrypt).to eq v
          end
        end
      end
    end

    describe "#encrypt" do
      {
        "YOURC IPHER ISWOR KINGX" => "CLEPK HHNIY CFPWH FDFEH",
        "WELCO METOR UBYQU IZXXX" => "ABVAW LWZSY OORYK DUPVH",
        "WELCO METOR UBYQU IZ" => "ABVAW LWZSY OORYK DUPVH",
      }.each do |k,v|
        context "with the message #{k}" do
          subject do
            described_class.new k
          end
          it "encrypts to \"#{v}\"" do
            puts subject.send(:character_groups).collect(&:characters).join(" ")
            expect(subject.encrypt).to eq v
          end
        end
      end
    end

    describe "#character_groups", :private do
      {
        "HELLO WORLD" => "HELLO WORLD",
        "Hi There How Are You" => "HITHE REHOW AREYO UXXXX",
        "HI! IT IS VERY NICE to see you" => "HIITI SVERY NICET OSEEY OUXXX"
      }.each do |key, value|
        context "with a message #{key}" do
          subject { described_class.new key }
          let :character_groups do
            value.split(" ").collect { |v| CharacterGroup.new(v) }
          end
          it "builds the character groups #{value}" do
            expect(subject.character_groups).to eq character_groups
          end
        end
      end
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ruby_quiz_1-0.0.2 spec/lib/ruby_quiz_1/message_spec.rb
ruby_quiz_1-0.0.1 spec/lib/ruby_quiz_1/message_spec.rb