I'm attempting to perform a mutation-test on some ruby code using rspec. I am just learning ruby and I don't really know if I'm doing it right. Part of the code I'm trying to test is:
class Cipher
def initialize()
@a_offset = 65 #'A'.unpack('C').first
@z_offset = 90 #'Z'.unpack('C').first
end
def encode(key, plain_text)
key_offset = key.upcase.unpack('C').first
cipher_text = plain_text.upcase.split('').collect do |letter|
cipher_letter = (letter.unpack('C').first + key_offset - @a_offset)
if cipher_letter > @z_offset
cipher_letter -= ( @z_offset - @a_offset + 1 )
end
cipher_letter.chr
end
return cipher_text.join
end
So far my test suite looks like this:
require 'rspec'
require 'Cipher'
describe "#initialize" do
it "should have correct @a_offset" do
encoder = Cipher.new()
expect(encoder.instance_variable_get(:@a_offset)).to eq 65
end
it "should have correct @z_offset" do
encoder = Cipher.new()
expect(encoder.instance_variable_get(:@z_offset)).to eq 90
end
end
describe "#encode" do
it "It should correctly encode Caesar with key = A"do
encoder = Cipher.new()
expect(encoder.encode('R', 'CAESAR')).to eq ("TRVJRI")
end
end
When running rspec my 3 tests pass. However when I use mutation testing on this suite I only kill 3/343 which is not very good.