-
-
Save havenwood/6a1f8e1c7e6b2a1831ef76f6459030de to your computer and use it in GitHub Desktop.
#ruby IRC example of a spec for jason479's code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'etc' | |
module Needs | |
class << self | |
def root | |
raise('try with doas') unless Process.uid.zero? | |
end | |
def release(number) | |
raise('you need an OpenBSD system') unless openbsd? | |
raise("only OpenBSD #{number} is supported") unless version?(number) | |
end | |
private | |
def openbsd? | |
Etc.uname[:sysname] == 'OpenBSD' | |
end | |
def version?(version) | |
Etc.uname[:release] == version | |
end | |
end | |
end | |
require 'minitest/autorun' | |
describe Needs do | |
describe '#root' do | |
describe 'a non-zero process id' do | |
it 'raises an error' do | |
Process.stub :uid, 42 do | |
error = assert_raises { Needs.root } | |
assert_equal error.message, 'try with doas' | |
end | |
end | |
end | |
describe 'a process id of zero' do | |
it 'does nothing' do | |
Process.stub :uid, 0 do | |
assert_nil Needs.root | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment