[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [websites/inqlude] /: Gracefully fail if Qt is not found
From:       Cornelius Schumacher <schumacher () kde ! org>
Date:       2016-10-15 22:49:43
Message-ID: E1bvXlv-0003rJ-KQ () code ! kde ! org
[Download RAW message or body]

Git commit 60d523b9a7726560f2a1fb1fb0919b726434ff95 by Cornelius Schumacher.
Committed on 15/10/2016 at 10:24.
Pushed by cschumac into branch 'master'.

Gracefully fail if Qt is not found

M  +13   -4    lib/cli_controller.rb
A  +2    -0    spec/stubs/qmake/qmake
M  +28   -5    spec/unit/cli_controller_spec.rb
M  +4    -0    spec/unit/spec_helper.rb

http://commits.kde.org/websites/inqlude/60d523b9a7726560f2a1fb1fb0919b726434ff95

diff --git a/lib/cli_controller.rb b/lib/cli_controller.rb
index 86c8a92..9a8b599 100644
--- a/lib/cli_controller.rb
+++ b/lib/cli_controller.rb
@@ -2,14 +2,23 @@ class CliController
   def self.print_versions(distro)
     puts "Inqlude: #{Inqlude::VERSION}"
 
-    qmake_out = `qmake -v`
-    qmake_out =~ /Qt version (.*) in/
-    puts "Qt: #{$1}"
+    if find_executable("qmake")
+      qmake_out = `qmake -v`
+      qmake_out =~ /Qt version (.*) in/
+      puts "Qt: #{$1}"
+    else
+      puts "Qt: not found"
+    end
 
     if distro
       puts "OS: #{distro.name} #{distro.version}"
     else
       puts "OS: unknown"
     end
-  end 
+  end
+
+  def self.find_executable(executable)
+    `which #{executable}`
+    $?.success?
+  end
 end
diff --git a/spec/stubs/qmake/qmake b/spec/stubs/qmake/qmake
new file mode 100755
index 0000000..665b48e
--- /dev/null
+++ b/spec/stubs/qmake/qmake
@@ -0,0 +1,2 @@
+echo QMake version 2.01a
+echo Using Qt version 4.8.6 in /usr/lib64hello
diff --git a/spec/unit/cli_controller_spec.rb b/spec/unit/cli_controller_spec.rb
index 94a882e..bb9a42a 100644
--- a/spec/unit/cli_controller_spec.rb
+++ b/spec/unit/cli_controller_spec.rb
@@ -14,15 +14,38 @@ describe CliController do
   let(:distro) {DistroUnknown.new}
 
   describe ".print_versions" do
-    it "prints versions" do
-      expected_output = <<EOT
+    context "with qmake installed" do
+      before do
+        ENV["PATH"] = stubs_path("qmake") + ":" + ENV["PATH"]
+      end
+
+      it "prints versions" do
+        expected_output = <<EOT
 Inqlude: #{Inqlude::VERSION}
 Qt: 4.8.6
 OS: <unknown distro> <unknown version>
 EOT
-      expect {
-        CliController.print_versions(distro)
-      }.to output(expected_output).to_stdout
+        expect {
+          CliController.print_versions(distro)
+        }.to output(expected_output).to_stdout
+      end
+    end
+
+    context "without qmake installed" do
+      before do
+        allow(CliController).to receive(:find_executable).with("qmake").and_return(false)
+      end
+
+      it "prints versions" do
+        expected_output = <<EOT
+Inqlude: #{Inqlude::VERSION}
+Qt: not found
+OS: <unknown distro> <unknown version>
+EOT
+        expect {
+          CliController.print_versions(distro)
+        }.to output(expected_output).to_stdout
+      end
     end
   end
 end
diff --git a/spec/unit/spec_helper.rb b/spec/unit/spec_helper.rb
index 918aae0..453b5ca 100644
--- a/spec/unit/spec_helper.rb
+++ b/spec/unit/spec_helper.rb
@@ -12,6 +12,10 @@ def test_data_path file_name
   File.expand_path(File.join('../../data/', file_name), __FILE__)
 end
 
+def stubs_path(context)
+  File.expand_path(File.join('../../stubs/', context), __FILE__)
+end
+
 def create_manifest name, release_date, version
   m = ManifestRelease.new
   m.name = name

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic