Skip to content
Browse files

Extract error message for an unrecognized setting in the configuratio…

…n controller.
  • Loading branch information...
1 parent 40ae745 commit 30c1926e29a319230a6932db27ab7582bf0cbe3e Marcel Molina committed
Showing with 17 additions and 1 deletion.
  1. +2 −1 lib/twurl/configuration_controller.rb
  2. +15 −0 test/configuration_controller_test.rb
View
3 lib/twurl/configuration_controller.rb
@@ -1,5 +1,6 @@
module Twurl
class ConfigurationController < AbstractCommandController
+ UNRECOGNIZED_SETTING_MESSAGE = "Unknown configuration setting: '%s'"
def dispatch
case options.subcommands.first
when 'default'
@@ -14,7 +15,7 @@ def dispatch
OAuthClient.rcfile.save
end
else
- CLI.puts "Unknown configuration setting: '#{options.subcommands.first}'"
+ CLI.puts(UNRECOGNIZED_SETTING_MESSAGE % options.subcommands.first)
end
end
end
View
15 test/configuration_controller_test.rb
@@ -1,5 +1,20 @@
require File.dirname(__FILE__) + '/test_helper'
+class Twurl::ConfigurationController::DispatchTest < Test::Unit::TestCase
+ def test_error_message_is_displayed_if_setting_is_unrecognized
+ options = Twurl::CLI::Options.test_exemplar
+ client = Twurl::OAuthClient.test_exemplar
+
+ options.subcommands = ['unrecognized', 'value']
+
+ mock(Twurl::CLI).puts(Twurl::ConfigurationController::UNRECOGNIZED_SETTING_MESSAGE % 'unrecognized').times(1)
+ mock(Twurl::OAuthClient.rcfile).save.times(0)
+
+ controller = Twurl::ConfigurationController.new(client, options)
+ controller.dispatch
+ end
+end
+
class Twurl::ConfigurationController::DispatchDefaultSettingTest < Test::Unit::TestCase
def test_setting_default_profile_just_by_username
options = Twurl::CLI::Options.test_exemplar

0 comments on commit 30c1926

Please sign in to comment.
Something went wrong with that request. Please try again.