summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Giddins <segiddins@segiddins.me>2017-03-31 11:25:38 -0500
committerSamuel Giddins <segiddins@segiddins.me>2017-03-31 11:25:38 -0500
commit7adc5766c89ccc03e0e71d8ad6f5f2d05b605d8a (patch)
treee7c3c01b6b4b549e65196e2b9c07d8a668339f17
parentfa61ff501492b74cb11cff1fef82aa9038784511 (diff)
downloadbundler-7adc5766c89ccc03e0e71d8ad6f5f2d05b605d8a.tar.gz
[UI::Shell] Simplify level comparison logic
-rw-r--r--lib/bundler/ui/shell.rb15
-rw-r--r--spec/bundler/ui_spec.rb14
2 files changed, 23 insertions, 6 deletions
diff --git a/lib/bundler/ui/shell.rb b/lib/bundler/ui/shell.rb
index 697290f795..87a92471fb 100644
--- a/lib/bundler/ui/shell.rb
+++ b/lib/bundler/ui/shell.rb
@@ -40,16 +40,15 @@ module Bundler
end
def debug(msg, newline = nil)
- tell_me(msg, nil, newline) if level("debug")
+ tell_me(msg, nil, newline) if debug?
end
def debug?
- # needs to be false instead of nil to be newline param to other methods
- level("debug") ? true : false
+ level("debug")
end
def quiet?
- LEVELS.index(@level) <= LEVELS.index("warn")
+ level("quiet")
end
def ask(msg)
@@ -66,11 +65,15 @@ module Bundler
def level=(level)
raise ArgumentError unless LEVELS.include?(level.to_s)
- @level = level
+ @level = level.to_s
end
def level(name = nil)
- name ? LEVELS.index(name) <= LEVELS.index(@level) : @level
+ return @level unless name
+ unless index = LEVELS.index(name)
+ raise "#{name.inspect} is not a valid level"
+ end
+ index <= LEVELS.index(@level)
end
def trace(e, newline = nil, force = false)
diff --git a/spec/bundler/ui_spec.rb b/spec/bundler/ui_spec.rb
index 41c037527b..fc76eb1ee7 100644
--- a/spec/bundler/ui_spec.rb
+++ b/spec/bundler/ui_spec.rb
@@ -25,4 +25,18 @@ RSpec.describe Bundler::UI do
expect(methods.call(described_class)).to eq(methods.call(shell))
end
end
+
+ describe Bundler::UI::Shell do
+ let(:options) { {} }
+ subject { described_class.new(options) }
+ describe "debug?" do
+ it "returns a boolean" do
+ subject.level = :debug
+ expect(subject.debug?).to eq(true)
+
+ subject.level = :error
+ expect(subject.debug?).to eq(false)
+ end
+ end
+ end
end