From 0bba284e9447a4a6aa95990b65db5ae4d44ce989 Mon Sep 17 00:00:00 2001 From: Nihad Abbasov Date: Fri, 16 May 2014 22:56:29 +0500 Subject: [PATCH] add specs for CLI --- spec/gitlab/cli_spec.rb | 68 +++++++++++++++++++++++++++++++++++++++++ spec/spec_helper.rb | 11 +++++++ 2 files changed, 79 insertions(+) create mode 100644 spec/gitlab/cli_spec.rb diff --git a/spec/gitlab/cli_spec.rb b/spec/gitlab/cli_spec.rb new file mode 100644 index 000000000..426e3d8b9 --- /dev/null +++ b/spec/gitlab/cli_spec.rb @@ -0,0 +1,68 @@ +require 'spec_helper' + +describe Gitlab::CLI do + describe ".run" do + context "when command is version" do + it "should show gem version" do + output = capture_output { Gitlab::CLI.run('-v') } + expect(output).to eq("Gitlab Ruby Gem #{Gitlab::VERSION}\n") + end + end + + context "when command is help" do + it "should show available actions" do + output = capture_output { Gitlab::CLI.run('help') } + expect(output).to include('Available commands:') + end + end + + context "when command is user" do + before do + stub_get("/user", "user") + @output = capture_output { Gitlab::CLI.run('user') } + end + + it "should show executed command" do + expect(@output).to include('Gitlab.user') + end + + it "should show user data" do + expect(@output).to include('name') + expect(@output).to include('John Smith') + end + end + end + + describe ".start" do + context "when command with excluded fields" do + before do + stub_get("/user", "user") + args = ['user', '--except=id,email,name'] + @output = capture_output { Gitlab::CLI.start(args) } + end + + it "should show user data with excluded fields" do + expect(@output).to_not include('John Smith') + expect(@output).to include('bio') + expect(@output).to include('created_at') + end + end + + context "when command with required fields" do + before do + stub_get("/user", "user") + args = ['user', '--only=id,email,name'] + @output = capture_output { Gitlab::CLI.start(args) } + end + + it "should show user data with required fields" do + expect(@output).to include('id') + expect(@output).to include('name') + expect(@output).to include('email') + expect(@output).to include('John Smith') + expect(@output).to_not include('bio') + expect(@output).to_not include('created_at') + end + end + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2cb11d5f0..28df28be2 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -2,6 +2,17 @@ require 'webmock/rspec' require File.expand_path('../../lib/gitlab', __FILE__) +require File.expand_path('../../lib/gitlab/cli', __FILE__) + +def capture_output + out = StringIO.new + $stdout = out + $stderr = out + yield + $stdout = STDOUT + $stderr = STDERR + out.string +end def load_fixture(name) File.new(File.dirname(__FILE__) + "/fixtures/#{name}.json")