From 02382433248cb0b9262a8561e292386e949f8d61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Thu, 4 Aug 2011 01:49:01 +0200 Subject: rename spec files --- spec/jcryption.rb | 36 -------------------- spec/jcryption_spec.rb | 36 ++++++++++++++++++++ spec/options.rb | 91 -------------------------------------------------- spec/options_spec.rb | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 127 insertions(+), 127 deletions(-) delete mode 100644 spec/jcryption.rb create mode 100644 spec/jcryption_spec.rb delete mode 100644 spec/options.rb create mode 100644 spec/options_spec.rb diff --git a/spec/jcryption.rb b/spec/jcryption.rb deleted file mode 100644 index a974ea1..0000000 --- a/spec/jcryption.rb +++ /dev/null @@ -1,36 +0,0 @@ -#! /usr/bin/env ruby -# -*- coding: UTF-8 -*- - -require 'ayk/jcryption' -# -describe JCryption do - # - describe 'Bignum' do - it '#to_bytes #from_bytes should work' do - 0x217962755220666f207463657073612074656577732061207369206d756e676942.should eql Bignum.from_bytes(0x217962755220666f207463657073612074656577732061207369206d756e676942.to_bytes) - end - it '#bits' do - K_BITS = 1024 - k = JCryption.gen_keypair( K_BITS ) - k.n.to_i.bits.should eql k.d.to_i.bits - k.d.to_i.bits.should eql k.d.to_i.bits - k.d.to_i.bits.should eql K_BITS - k.p.to_i.bits.should eql k.q.to_i.bits - k.q.to_i.bits.should eql k.q.to_i.bits - k.q.to_i.bits.should eql K_BITS/2 - end - end - # - describe 'JCryption' do - it 'should decrypt data' do - data = '50c412c556a9fab55b50bd0d989067b341f9cdbf12ccb65aeb69dbb360a8e0dbd2069d686873b659b1be7a4c78fe631d362dbf538a5298ecaff19f78cd859897a7317c71b51b90e0a8c03e10059b68826bfeb194a4339a0ecc4a571ba9066fcf3504ffe76e07468cbe03337d3cfebd4efe687f5da72bf694dada987cea884180 ac07cc8462ce0f3e23dafe5d19f47eb33024c91de48413a971bf3b88c159090a26933f694d868bad61517a817f57998ed57bcebcd46a4ed8661cec3e24a8cdf21595902c2fd566820382e2d4f2ee7f1f11fa87a760bcecdf46282147d2c3a1afed3797d22296abcc3b1289489e7c265b3b4223bf93cbf0bb5122c021501a4305' - d = 142955580847936812437193870755035814405124627347905842843339476660410062601811480700441889718210202009243007436072050916187661826876350920486486397010450730779696290631486871265879746303575786048408069636369193884693458677811152828648243101513361320608836252500169104146911809960770571514285315905292345077217 - n = 144356479900636891214255168759692179915080702955265792860263158994365175771327391113617049451662409039610467917872667615201472907166228721836687554904761268852157980063791071632316452235833332213934315100709197309374114347503598139080114451506623646859901230057693420846126487025125157251928362812236904436763 - h = JCryption::decrypt( data, d, n).split('&').inject({}) { |h_,vk| v,k = vk.split '='; h_[v]=k; h_ } - h['username'].should eql "my_username" - h['passwd'].should eql "my_password" - h['timestamp'].should eql "1252937955" - end - end -end -# diff --git a/spec/jcryption_spec.rb b/spec/jcryption_spec.rb new file mode 100644 index 0000000..a974ea1 --- /dev/null +++ b/spec/jcryption_spec.rb @@ -0,0 +1,36 @@ +#! /usr/bin/env ruby +# -*- coding: UTF-8 -*- + +require 'ayk/jcryption' +# +describe JCryption do + # + describe 'Bignum' do + it '#to_bytes #from_bytes should work' do + 0x217962755220666f207463657073612074656577732061207369206d756e676942.should eql Bignum.from_bytes(0x217962755220666f207463657073612074656577732061207369206d756e676942.to_bytes) + end + it '#bits' do + K_BITS = 1024 + k = JCryption.gen_keypair( K_BITS ) + k.n.to_i.bits.should eql k.d.to_i.bits + k.d.to_i.bits.should eql k.d.to_i.bits + k.d.to_i.bits.should eql K_BITS + k.p.to_i.bits.should eql k.q.to_i.bits + k.q.to_i.bits.should eql k.q.to_i.bits + k.q.to_i.bits.should eql K_BITS/2 + end + end + # + describe 'JCryption' do + it 'should decrypt data' do + data = '50c412c556a9fab55b50bd0d989067b341f9cdbf12ccb65aeb69dbb360a8e0dbd2069d686873b659b1be7a4c78fe631d362dbf538a5298ecaff19f78cd859897a7317c71b51b90e0a8c03e10059b68826bfeb194a4339a0ecc4a571ba9066fcf3504ffe76e07468cbe03337d3cfebd4efe687f5da72bf694dada987cea884180 ac07cc8462ce0f3e23dafe5d19f47eb33024c91de48413a971bf3b88c159090a26933f694d868bad61517a817f57998ed57bcebcd46a4ed8661cec3e24a8cdf21595902c2fd566820382e2d4f2ee7f1f11fa87a760bcecdf46282147d2c3a1afed3797d22296abcc3b1289489e7c265b3b4223bf93cbf0bb5122c021501a4305' + d = 142955580847936812437193870755035814405124627347905842843339476660410062601811480700441889718210202009243007436072050916187661826876350920486486397010450730779696290631486871265879746303575786048408069636369193884693458677811152828648243101513361320608836252500169104146911809960770571514285315905292345077217 + n = 144356479900636891214255168759692179915080702955265792860263158994365175771327391113617049451662409039610467917872667615201472907166228721836687554904761268852157980063791071632316452235833332213934315100709197309374114347503598139080114451506623646859901230057693420846126487025125157251928362812236904436763 + h = JCryption::decrypt( data, d, n).split('&').inject({}) { |h_,vk| v,k = vk.split '='; h_[v]=k; h_ } + h['username'].should eql "my_username" + h['passwd'].should eql "my_password" + h['timestamp'].should eql "1252937955" + end + end +end +# diff --git a/spec/options.rb b/spec/options.rb deleted file mode 100644 index 0fd84d5..0000000 --- a/spec/options.rb +++ /dev/null @@ -1,91 +0,0 @@ -#! /usr/bin/env ruby -# -*- coding: UTF-8 -*- - -require 'ayk/options' -# -describe AYK::Options do - # - describe 'simple usage' do - before(:all) do - @opt = AYK::Options.new 'Spec tests' - end - it "should set option key1" do - @opt.o("key 1 doc", :key1, 666) { puts 'trigger' } - end - it "should raise override existing key" do - lambda { @opt.o("key 1 doc", :key1, 666) { puts 'trigger' } }.should raise_error AYK::OptionsError - end - it "should set sub options" do - @opt.sub(:sub) do - o 'var 1', :var1, 69 - o 'var 2', :var2, 999 - end - @opt[:sub][:var1].should eql 69 - @opt[:sub][:var2].should eql 999 - end - it "should access subeys through [,]" do - @opt[:sub,:var1].should eql 69 - @opt[:sub,:var2].should eql 999 - end - it "should raise calling sub on existing option" do - lambda { @opt.sub :key1 }.should raise_error AYK::OptionsError - end - it "should raise unknown option when setting trigger" do - lambda { @opt.trigger :unknonwn }.should raise_error AYK::OptionsError - end - it "Options.get is private" do - lambda{ @opt.get(:key1) }.should raise_error NoMethodError - end - it "should set a trigger on assignment" do - @opt[:sub][:var1].should eql 69 - @opt[:sub].trigger :var1 do raise Exception.new "trigger" end - lambda{ @opt[:sub][:var1] = 96}.should raise_error Exception - @opt[:sub][:var1].should eql 69 - begin - @opt[:sub][:var1] = 96 - rescue Exception - $!.message.should eql "trigger" - end - @opt[:sub][:var1].should eql 69 - end - it "should get option key1 through method missing" do - @opt.key1.should eql 666 - end - it "should get option key1 through []" do - @opt[:key1].should eql 666 - end - it "should get option nokey through method missing" do - @opt.nokey.should eql nil - end - it "should get option nokey through []" do - @opt[:nokey].should eql nil - end - it "should return default valuei through method missing" do - @opt.default 'default value', 'none' - @opt.nokey.should eql 'none' - end - it "should return default value through []" do - @opt.default 'default value', 'none' - @opt[:nokey].should eql 'none' - end - it "should assign new value through []=" do - @opt[:sub][:var2].should eql 999 - @opt[:sub][:var2] = 666 - @opt[:sub][:var2].should eql 666 - end - it "should nice init" do - opts = AYK::Options.new('Spec nice') do |opt| - opt.dsl do - o 'var doc', :var, 666 - end - end - opts.var.should eql 666 - end - it "should be nicely included" do - class A__A; include AYK::Optioned end - A__A.options.name.should eql 'a__a' - end - end - # -end -# diff --git a/spec/options_spec.rb b/spec/options_spec.rb new file mode 100644 index 0000000..0fd84d5 --- /dev/null +++ b/spec/options_spec.rb @@ -0,0 +1,91 @@ +#! /usr/bin/env ruby +# -*- coding: UTF-8 -*- + +require 'ayk/options' +# +describe AYK::Options do + # + describe 'simple usage' do + before(:all) do + @opt = AYK::Options.new 'Spec tests' + end + it "should set option key1" do + @opt.o("key 1 doc", :key1, 666) { puts 'trigger' } + end + it "should raise override existing key" do + lambda { @opt.o("key 1 doc", :key1, 666) { puts 'trigger' } }.should raise_error AYK::OptionsError + end + it "should set sub options" do + @opt.sub(:sub) do + o 'var 1', :var1, 69 + o 'var 2', :var2, 999 + end + @opt[:sub][:var1].should eql 69 + @opt[:sub][:var2].should eql 999 + end + it "should access subeys through [,]" do + @opt[:sub,:var1].should eql 69 + @opt[:sub,:var2].should eql 999 + end + it "should raise calling sub on existing option" do + lambda { @opt.sub :key1 }.should raise_error AYK::OptionsError + end + it "should raise unknown option when setting trigger" do + lambda { @opt.trigger :unknonwn }.should raise_error AYK::OptionsError + end + it "Options.get is private" do + lambda{ @opt.get(:key1) }.should raise_error NoMethodError + end + it "should set a trigger on assignment" do + @opt[:sub][:var1].should eql 69 + @opt[:sub].trigger :var1 do raise Exception.new "trigger" end + lambda{ @opt[:sub][:var1] = 96}.should raise_error Exception + @opt[:sub][:var1].should eql 69 + begin + @opt[:sub][:var1] = 96 + rescue Exception + $!.message.should eql "trigger" + end + @opt[:sub][:var1].should eql 69 + end + it "should get option key1 through method missing" do + @opt.key1.should eql 666 + end + it "should get option key1 through []" do + @opt[:key1].should eql 666 + end + it "should get option nokey through method missing" do + @opt.nokey.should eql nil + end + it "should get option nokey through []" do + @opt[:nokey].should eql nil + end + it "should return default valuei through method missing" do + @opt.default 'default value', 'none' + @opt.nokey.should eql 'none' + end + it "should return default value through []" do + @opt.default 'default value', 'none' + @opt[:nokey].should eql 'none' + end + it "should assign new value through []=" do + @opt[:sub][:var2].should eql 999 + @opt[:sub][:var2] = 666 + @opt[:sub][:var2].should eql 666 + end + it "should nice init" do + opts = AYK::Options.new('Spec nice') do |opt| + opt.dsl do + o 'var doc', :var, 666 + end + end + opts.var.should eql 666 + end + it "should be nicely included" do + class A__A; include AYK::Optioned end + A__A.options.name.should eql 'a__a' + end + end + # +end +# -- cgit v1.1-2-g2b99