Skip to content

Commit

Permalink
Ex04 accessor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Danila Patsiora authored and Danila Patsiora committed Sep 2, 2019
1 parent 872c8d1 commit 87b7180
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions courses/ruby/ex04-myattr/my_attr_accessor_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
require 'openssl'
require 'base64'
require "minitest/autorun"
require "minitest/pride"
require_relative "my_attr_accessor"

class MyAttrAccessorTest < Minitest::Test
Module.prepend MyAcc
def test_single_my_attr_accessor
klass = Class.new do
my_attr_accessor(:acc, "./user_key.txt")
end
instance = klass.new
msg=instance.acc_set("d2hdmnHxYJcxsajeblGv92vPgtBo8nxQ+nvPzZwNlLf7HEYWRo79aTiFJkusT/mbcVkKv/MPwRc0zil7YwbaQB733KgVduq1OHCXtAoc8P2fRHprvYE3nsru5Iz+fYPo46afEqnd8kqjIg44cLjobS+Y9p+/iJAcFripStM86bk=", "B8lIigGs9fanDbEZfijgJG/42wxEzVpNQrK379lQdBolCEZsD2cTEW5cCY8pVnSEi2xO4Sj/tKW4nJvgxL/UkqmFI/jyBKfMexMTzFb8w7audRq99E0DlmJ9t6OQhkmIUN1aqeZOUMbOxd5WnxSNsBxUSf64v1ntErRSl3KfBD4=")
assert_equal "Hello World!", instance.acc
end

def test_wrong_signature_my_attr_accessor
klass = Class.new do
my_attr_accessor(:acc, "./user_key.txt")
end
instance = klass.new
msg = instance.acc_set("d2hdmnHxYJcxsajeblGv92vPgtBo8nxQ+nvPzZwNlLf7HEYWRo79aTiFJkusT/mbcVkKv/MPwRc0zil7YwbaQB733KgVduq1OHCXtAoc8P2fRHprvYE3nsru5Iz+fYPo46afEqnd8kqjIg44cLjobS+Y9p+/iJAcFripStM86bk=", "B2lIigGs9fanDbEZfijgJG/42wxEzVpNQrK379lQdBolCEZsD2cTEW5cCY8pVnSEi2xO4Sj/tKW4nJvgxL/UkqmFI/jyBKfMexMTzFb8w7audRq99E0DlmJ9t6OQhkmIUN1aqeZOUMbOxd5WnxSNsBxUSf64v1ntErRSl3KfBD4=")
assert_equal "Error", msg
end

def test_wrong_key_my_attr_accessor
klass = Class.new do
my_attr_accessor(:acc, "./user_key.txt")
end
instance = klass.new
msg = instance.acc_set("cHNfFM+Y6ap8e6ExiGuVbaeqVdJe9KwoQwAWqdmkGvyRA4SAP0BPuPrp7P2lSEjbN5WMzEYuERZ6fxgbA83rx+hOov8YdQ0TYk34mbTaC3KOdPIduSvRHc3196nyCa752Jvyc8VeNHdt5brq32jDqrMTaej8QnzGJx3p6NuP3nY=", "JyKEo41d+xCbsDqhdkW2Ex/kpVjnIy8x5RcSE55V0nOcoKFTRgTdEivE6A9X1U3HAi1usGFnv/6QiSPsBUxkxEafnPHVpX62BR1k293+81L8iaYUQsniz9MDoEHStwsFGnc+YktOQksKTmu9JR29BPTpk7lwkEeYQmT8L748sfg=")
assert_equal "Wrong Key", msg
end

def test_no_file_my_attr_accessor
klass = Class.new do
@@msg=my_attr_accessor(:acc, nil)
end
instance = klass.new
assert_equal "File not found", @@msg
end

end

0 comments on commit 87b7180

Please sign in to comment.