Sha256: dd0dd45b28b0b11e3a4abca86fd07415e87c0eb23a4adba7ebcfca6233253c6e
Contents?: true
Size: 1.48 KB
Versions: 11
Compression:
Stored size: 1.48 KB
Contents
require File.join(File.dirname(__FILE__), '../test_helper') # require 'hammer_cli/options/option_definition' describe HammerCLI::Options::OptionDefinition do class FakeFormatter < HammerCLI::Options::Normalizers::AbstractNormalizer def format(val) ">>>#{val}<<<" end end class TestOptionFormattersCmd < HammerCLI::AbstractCommand option "--test-format", "TEST_FORMAT", "Test option with a formatter", :format => FakeFormatter.new, :default => "A" option "--test-context", "CONTEXT", "Option saved into context", :context_target => :test_option end describe "formatters" do it "should use formatter to format a default value" do opt = TestOptionFormattersCmd.find_option("--test-format") opt_instance = opt.of(TestOptionFormattersCmd.new([])) opt_instance.read.must_equal '>>>A<<<' end it "should use formatter as a conversion block" do opt = TestOptionFormattersCmd.find_option("--test-format") opt_instance = opt.of(TestOptionFormattersCmd.new([])) # clamp api changed in 0.6.2 if opt_instance.respond_to? :write opt_instance.write('B') else opt_instance.take('B') end opt_instance.read.must_equal '>>>B<<<' end end describe "context" do it "should save option to context" do context = {} cmd = TestOptionFormattersCmd.new("", context) cmd.run(["--test-context=VALUE"]) context[:test_option].must_equal "VALUE" end end end
Version data entries
11 entries across 11 versions & 1 rubygems