Permalink
Browse files

I'll miss rspec, it was a respectable framework up until 2.0. Let's d…

…ocument everything with Cukes! #FAIL
  • Loading branch information...
1 parent d7507e3 commit ae839c4733a8ae1c07c5064cea519208abaf3398 Mark Percival committed Mar 31, 2011
Showing with 46 additions and 38 deletions.
  1. +2 −1 Gemfile
  2. +5 −10 Gemfile.lock
  3. +8 −0 Rakefile
  4. +2 −2 spec/aes_spec.rb
  5. +3 −3 spec/digest_spec.rb
  6. +1 −1 spec/hmac_spec.rb
  7. +23 −18 spec/rsa_spec.rb
  8. +2 −3 spec/spec_helper.rb
View
@@ -1,3 +1,4 @@
source "http://rubygems.org"
gemspec
-gem 'rspec'
+gem 'minitest'
+gem 'mini_shoulda'
View
@@ -6,19 +6,14 @@ PATH
GEM
remote: http://rubygems.org/
specs:
- diff-lcs (1.1.2)
- rspec (2.5.0)
- rspec-core (~> 2.5.0)
- rspec-expectations (~> 2.5.0)
- rspec-mocks (~> 2.5.0)
- rspec-core (2.5.1)
- rspec-expectations (2.5.0)
- diff-lcs (~> 1.1.2)
- rspec-mocks (2.5.0)
+ mini_shoulda (0.2.0)
+ minitest (~> 2.0.2)
+ minitest (2.0.2)
PLATFORMS
ruby
DEPENDENCIES
gibberish!
- rspec
+ mini_shoulda
+ minitest
View
@@ -0,0 +1,8 @@
+require 'rake/testtask'
+Rake::TestTask.new do |t|
+ t.libs << "spec"
+ t.test_files = FileList['spec/*_spec.rb']
+ t.verbose = true
+end
+$: << '.'
+require 'spec/spec_helper'
View
@@ -10,14 +10,14 @@
secret_text = "Made with Gibberish"
encrypted = @cipher.e(secret_text)
from_openssl = `echo "#{encrypted}" | openssl enc -d -aes-256-cbc -a -k password`
- from_openssl.should eql(secret_text)
+ from_openssl.must_equal(secret_text)
end
it "should decrypt base64 encoded data from the OpenSSL CLI" do
secret_text = "Made with Gibberish"
from_openssl = `echo #{secret_text} | openssl enc -aes-256-cbc -a -k password`
decrypted_text = @cipher.d(from_openssl).chomp
- decrypted_text.should eql(secret_text)
+ decrypted_text.must_equal(secret_text)
end
end
View
@@ -3,15 +3,15 @@
describe "A variety of digest methods" do
it "should work with MD5" do
- Gibberish::MD5("password").should eql("5f4dcc3b5aa765d61d8327deb882cf99")
+ Gibberish::MD5("password").must_equal("5f4dcc3b5aa765d61d8327deb882cf99")
end
it "should work with SHA1" do
- Gibberish::SHA1("password").should eql("5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8")
+ Gibberish::SHA1("password").must_equal("5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8")
end
it "should work with SHA256" do
- Gibberish::SHA256("password").should eql("5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8")
+ Gibberish::SHA256("password").must_equal("5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8")
end
end
View
@@ -3,7 +3,7 @@
describe "HMAC" do
it "should hopefully work" do
- Gibberish::HMAC("password", "data").should eql("08d13c72bed7ace5efadc09df109a78a5d713097")
+ Gibberish::HMAC("password", "data").must_equal("08d13c72bed7ace5efadc09df109a78a5d713097")
end
end
View
@@ -3,19 +3,19 @@
describe "RSA key generation" do
it "should generate a key" do
keypair = Gibberish::RSA.generate_keypair
- keypair.should be_instance_of(Gibberish::RSA::KeyPair)
+ keypair.must_be_instance_of(Gibberish::RSA::KeyPair)
end
it "should generate a key with custom bits" do
keypair = Gibberish::RSA.generate_keypair(1024)
- keypair.should be_instance_of(Gibberish::RSA::KeyPair)
+ keypair.must_be_instance_of(Gibberish::RSA::KeyPair)
end
it "should answer to public and private key methods" do
keypair = Gibberish::RSA.generate_keypair(1024)
- keypair.should be_instance_of(Gibberish::RSA::KeyPair)
- keypair.public_key.should_not be_nil
- keypair.private_key.should_not be_nil
+ keypair.must_be_instance_of(Gibberish::RSA::KeyPair)
+ keypair.public_key.wont_be_nil
+ keypair.private_key.wont_be_nil
end
end
@@ -30,40 +30,45 @@
it "should encrypt/decrypt with a keypair" do
encrypted = @cipher.encrypt("Some data")
decrypted = @cipher.decrypt(encrypted)
- encrypted.should match(/^[a-zA-Z0-9\+\/\n=]+$/) # Be base64
- decrypted.should eql("Some data")
+ encrypted.must_match(/^[a-zA-Z0-9\+\/\n=]+$/) # Be base64
+ decrypted.must_equal("Some data")
end
it "should work without private key" do
enc = @pub_cipher.encrypt("Some data")
- enc.should match(/^[a-zA-Z0-9\+\/\n=]+$/) # Be base64
+ enc.must_match(/^[a-zA-Z0-9\+\/\n=]+$/) # Be base64
end
end
describe "OpenSSL interop" do
- before :all do
- @private_key = File.read('spec/openssl/private.pem')
- @public_key = File.read('spec/openssl/public.pem')
- keypair = Gibberish::RSA.generate_keypair(1024)
- keypair.passphrase = "p4ssw0rd"
- tmp_file = "/tmp/gibberish-spec-#{Time.now.to_i}#{rand(100)}"
+ before do
+ @ossl_private_key = File.read('spec/openssl/private.pem')
+ @ossl_public_key = File.read('spec/openssl/public.pem')
+ @keypair = Gibberish::RSA.generate_keypair(1024)
+ @keypair.passphrase = "p4ssw0rd"
+ tmp_file = "/tmp/gibberish-spec"
@pub_key_file = "#{tmp_file}-pub.pem"
@priv_key_file = "#{tmp_file}-priv.pem"
- File.open(@pub_key_file, 'w') {|f| f.write(keypair.private_key) }
- File.open(@priv_key_file, 'w') {|f| f.write(keypair.public_key) }
+ File.open(@pub_key_file, 'w') {|f| f.write(@keypair.public_key) }
+ File.open(@priv_key_file, 'w') {|f| f.write(@keypair.private_key) }
end
it "should decode with an OpenSSL generated private key" do
# openssl genrsa -des3 -out private.pem 2048
# openssl rsa -in private.pem -out public.pem -outform PEM -pubout
# openssl rsautl -encrypt -inkey public.pem -pubin -in plaintext.txt -out plaintext.crypted
- cipher = Gibberish::RSA.new(@private_key, 'p4ssw0rd')
- cipher.decrypt(File.read('spec/openssl/plaintext.crypted'), :binary => true).should eql(File.read('spec/openssl/plaintext.txt'))
+ cipher = Gibberish::RSA.new(@ossl_private_key, 'p4ssw0rd')
+ cipher.decrypt(File.read('spec/openssl/plaintext.crypted'), :binary => true).must_equal(File.read('spec/openssl/plaintext.txt'))
end
it "should encode an OpenSSL compatible format" do
+ # openssl rsautl -decrypt -inkey /tmp/gibberish-spec-priv.pem -in /tmp/gibberish-spec-test.crypted
+ cipher = Gibberish::RSA.new(@keypair.public_key)
+ tmp_crypt_file = '/tmp/gibberish-spec-test.crypted'
+ File.open(tmp_crypt_file, 'w') {|f| f.write(cipher.encrypt("secret text", :binary => true))}
+ # `openssl rsautl -decrypt -inkey /tmp/gibberish-spec-priv.pem -in /tmp/gibberish-spec-test.crypted`
end
end
View
@@ -1,8 +1,7 @@
require 'rubygems'
require 'bundler/setup'
+gem 'minitest' # ensures you're using the gem, and not the built in MT
+require 'minitest/autorun'
require 'gibberish'
-RSpec.configure do |config|
- # some (optional) config here
-end

0 comments on commit ae839c4

Please sign in to comment.