-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.test.rb
76 lines (64 loc) · 2.06 KB
/
options.test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# -*- encoding: utf-8 -*-
$:.unshift File.expand_path('../../..', __FILE__)
require 'haus/options'
require 'haus/test/helper/minitest'
require 'haus/test/helper/test_user'
$user ||= Haus::TestUser[$$]
class Haus::OptionsSpec < MiniTest::Spec
before do
@opt = Haus::Options.new
end
it 'must be a subclass of OptionParser' do
@opt.must_be_kind_of OptionParser
end
describe :initialize do
it 'must initialize @ostruct' do
ostruct = @opt.instance_variable_get :@ostruct
ostruct.must_be_kind_of OpenStruct
ostruct.path.must_be_kind_of String
ostruct.path.must_equal File.expand_path('../../../..', __FILE__)
ostruct.logger.must_be_kind_of Haus::Logger
end
it 'must set @ostruct.debug to true if ENV["DEBUG"]' do
capture_fork_io do
puts Haus::Options.new.debug == false
ENV['DEBUG'] = '1'
puts Haus::Options.new.debug == true
end.first.must_equal "true\ntrue\n"
end
it 'must accept one optional Hash argument like OpenStruct' do
o = Haus::Options.new :funcdef => :parity
o.funcdef.must_equal :parity
end
it 'must accept up to three arguments like OptionParser' do
o = Haus::Options.new 'Hello World', 42, '****'
o.banner.must_equal 'Hello World'
o.summary_width.must_equal 42
o.summary_indent.must_equal '****'
end
end
describe :path do
it 'must always return an absolute path' do
ostruct = @opt.instance_variable_get :@ostruct
ostruct.path.must_match %r{\A/}
@opt.path = '..'
ostruct.path.must_match %r{\A/}
end
end
describe :method_missing do
it 'must otherwise act like an OpenStruct object' do
@opt.force = true
@opt.force.must_equal true
@opt.horse = 'of course'
@opt.horse.must_equal 'of course'
@opt.norse = 'Viking'
@opt.norse.must_equal 'Viking'
end
end
describe :tap do
it 'must respond to #tap, which should behave like Ruby 1.9 Object#tap' do
@opt.must_respond_to :tap
@opt.tap { |o| o.must_equal @opt }.must_equal @opt
end
end
end