summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/options.rb58
1 files changed, 52 insertions, 6 deletions
diff --git a/spec/options.rb b/spec/options.rb
index b6ce9a4..25741db 100644
--- a/spec/options.rb
+++ b/spec/options.rb
@@ -9,25 +9,71 @@ describe AYK::Options do
before(:all) do
@opt = AYK::Options.new 'Spec tests'
end
- it "set option key1" do
+ 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 "get option key1 through method missing" do
+ 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 "get option key1 through []" do
+ it "should get option key1 through []" do
@opt[:key1].should eql 666
end
- it "get option nokey through method missing" do
+ it "should get option nokey through method missing" do
@opt.nokey.should eql nil
end
- it "get option nokey through []" do
+ it "should get option nokey through []" do
@opt[:nokey].should eql nil
end
- it "nice init" do
+ 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