summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorLee Jarvis <ljjarvis@gmail.com>2014-11-19 13:00:35 +0000
committerLee Jarvis <ljjarvis@gmail.com>2014-11-19 13:00:35 +0000
commite3901588e3e767ffd6a08e32b535d15c5032351a (patch)
treea12273434e679ee7e5d4917e515aa48ce069c8e3 /test
parentc811bc2e28b2326b924c69abe2e4729508f482b5 (diff)
downloadslop-e3901588e3e767ffd6a08e32b535d15c5032351a.tar.gz
Add custom "finish" method for options
Diffstat (limited to 'test')
-rw-r--r--test/result_test.rb17
1 files changed, 17 insertions, 0 deletions
diff --git a/test/result_test.rb b/test/result_test.rb
index 68fd83f..cfa66d2 100644
--- a/test/result_test.rb
+++ b/test/result_test.rb
@@ -1,5 +1,15 @@
require 'test_helper'
+module Slop
+ class ReverseEverythingOption < BoolOption
+ def finish(result)
+ result.used_options.grep(Slop::StringOption).each do |opt|
+ opt.value = opt.value.reverse
+ end
+ end
+ end
+end
+
describe Slop::Result do
before do
@options = Slop::Options.new
@@ -22,6 +32,13 @@ describe Slop::Result do
assert_equal "bar", @result[:foo]
end
+ it "handles custom finishing" do
+ @options.string "--foo"
+ @options.reverse_everything "-r"
+ @result.parser.reset.parse %w(-r --name lee --foo bar)
+ assert_equal %w(eel rab), @result.to_hash.values_at(:name, :foo)
+ end
+
describe "#[]" do
it "returns an options value" do
assert_equal "lee", @result["name"]