Skip to content

Commit

Permalink
Measuring the coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
gotoyuzo committed Jun 8, 2015
1 parent e3b63e3 commit e4c5e5a
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 9 deletions.
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ source 'https://rubygems.org'
# Specify your gem's dependencies in otp.gemspec
gemspec

group :development, :test do
group :test do
gem "test-unit"
gem "simplecov"
end
8 changes: 8 additions & 0 deletions test/helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require "simplecov"
SimpleCov.start do
add_filter "/test/"
end

require "test/unit"
require "otp"

25 changes: 25 additions & 0 deletions test/test_base.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require_relative "helper"

class TestBase < Test::Unit::TestCase
def test_base
otp = OTP::Base.new
otp.new_secret(20)
assert_equal(32, otp.secret.length)
otp.new_secret(40)
assert_equal(64, otp.secret.length)
end

def test_methods_expected_to_be_override
base = OTP::Base.new
totp = OTP::TOTP.new

[
[:moving_factor, ],
[:type_specific_uri_params, ],
[:extract_type_specific_uri_params, {}],
].each do |m, *args|
assert_raise(NotImplementedError){ base.send(m, *args) }
assert_nothing_raised{ totp.send(m, *args) }
end
end
end
3 changes: 1 addition & 2 deletions test/test_base32.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require "test/unit"
require "otp/base32"
require_relative "helper"

class TestBase32 < Test::Unit::TestCase
def assert_encode(encoded, plain, padding: true)
Expand Down
3 changes: 1 addition & 2 deletions test/test_hotp.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require "test/unit"
require "otp"
require_relative "helper"

class TestHTOP < Test::Unit::TestCase
def assert_hotp(hotp, count, pass)
Expand Down
3 changes: 1 addition & 2 deletions test/test_totp.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require "test/unit"
require "otp"
require_relative "helper"

class TestTOTP < Test::Unit::TestCase
def assert_totp(totp, time, pass)
Expand Down
8 changes: 6 additions & 2 deletions test/test_uri.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require "test/unit"
require "otp"
require_relative "helper"

class TestURI < Test::Unit::TestCase
def test_totp
Expand Down Expand Up @@ -46,4 +45,9 @@ def test_hotp
assert_equal("My Company", otp.issuer)
assert_equal(otp.password, hotp.password)
end

def test_parse_invalid
assert_raise(RuntimeError){ OTP::URI.parse("http://www.netlab.jp") }
assert_raise(RuntimeError){ OTP::URI.parse("otpauth://foo") }
end
end

0 comments on commit e4c5e5a

Please sign in to comment.