Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/flipper/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,12 @@ def pluralize(count, singular, plural)
"#{count} #{count == 1 ? singular : plural}"
end

def colorize(text, options)
IRB::Color.colorize(text, options)
def colorize(text, colors)
if defined?(Bundler)
Bundler.ui.add_color(text, *colors)
else
text
end
end

def indent(text, spaces)
Expand Down
29 changes: 27 additions & 2 deletions spec/flipper/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
describe "enable" do
describe "feature" do
it do
expect(subject).to have_attributes(status: 0, stdout: /feature.*enabled/)
expect(subject).to have_attributes(status: 0, stdout: /feature.*\e\[32m.*enabled/)
expect(Flipper).to be_enabled(:feature)
end
end

describe "-a User;1 feature" do
it do
expect(subject).to have_attributes(status: 0, stdout: /feature.*enabled.*User;1/m)
expect(subject).to have_attributes(status: 0, stdout: /feature.*\e\[33m.*enabled.*User;1/m)
expect(Flipper).to be_enabled(:feature, Flipper::Actor.new("User;1"))
end
end
Expand Down Expand Up @@ -142,6 +142,28 @@
end
end

context "bundler is not installed" do
let(:argv) { "list" }

around do |example|
original_bundler = Bundler
begin
Object.send(:remove_const, :Bundler)
example.run
ensure
Object.const_set(:Bundler, original_bundler)
end
end

it "should not raise an error" do
Flipper.enable(:enabled_feature)
Flipper.enable_group(:enabled_groups, :admins)
Flipper.add(:disabled_feature)

expect(subject).to have_attributes(status: 0, stdout: /enabled_feature.*enabled_groups.*disabled_feature/m)
end
end

def run(argv)
original_stdout = $stdout
original_stderr = $stderr
Expand All @@ -150,6 +172,9 @@ def run(argv)
$stderr = StringIO.new
status = 0

# Prentend this a TTY so we can test colorization
allow($stdout).to receive(:tty?).and_return(true)

begin
Flipper::CLI.run(argv)
rescue SystemExit => e
Expand Down