From 14d2479306375846244c1f1d5beac300c49de6b9 Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Tue, 16 Aug 2016 04:09:38 +0200 Subject: [PATCH] Bit moar specs, refs #7 --- spec/gphoto2_spec.cr | 54 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 4 deletions(-) diff --git a/spec/gphoto2_spec.cr b/spec/gphoto2_spec.cr index 0e70edd..b5c6642 100644 --- a/spec/gphoto2_spec.cr +++ b/spec/gphoto2_spec.cr @@ -1,9 +1,23 @@ require "./spec_helper" +VERSION_PATTERN = /^\d+(\.\d+){1,3}(-\w+)?$/ + describe GPhoto2 do + describe "VERSION" do + it "should have proper format" do + GPhoto2::VERSION.should match VERSION_PATTERN + end + end + + describe ".library_version" do + it "should have proper format" do + GPhoto2.library_version.should match VERSION_PATTERN + end + end + describe ".result_as_string" do it "converts return code to proper string" do - codez = { + return_codes = { # libgphoto2 LibGPhoto2::GP_ERROR_IO => "I/O problem", LibGPhoto2::GP_ERROR_IO_LOCK => "Could not lock the device", @@ -12,21 +26,53 @@ describe GPhoto2 do LibGPhoto2::GP_ERROR_DIRECTORY_NOT_FOUND => "Directory not found", LibGPhoto2::GP_ERROR_CAMERA_BUSY => "I/O in progress", LibGPhoto2::GP_ERROR_NO_SPACE => "Not enough free space", + # random + -1 => "Unspecified error", + -777 => "Unknown error", + 777 => "Unknown error", } - codez.each do |code, string| - GPhoto2.result_as_string(code).should eq(string) + return_codes.each do |code, string| + GPhoto2.result_as_string(code).should eq string + end + end + end + + describe ".check?" do + context "the return code is GP_OK" do + it "returns true" do + GPhoto2.check?(LibGPhoto2::GP_OK).should be_true + end + end + context "the return code is not GP_OK" do + it "returns false" do + GPhoto2.check?(LibGPhoto2::GP_ERROR).should be_false + end + end + context "the return code is a value" do + it "returns true" do + GPhoto2.check?(10).should be_true end end end describe ".check!" do + context "the return code is GP_OK" do + it "should not raise" do + (GPhoto2.check!(LibGPhoto2::GP_OK) rescue :raised).should_not eq :raised + end + end context "the return code is not GP_OK" do it "raises GPhoto2::Error with a message and error code" do - code = -1 + code = LibGPhoto2::GP_ERROR message = "Unspecified error (#{code})" expect_raises(GPhoto2::Error, message) { GPhoto2.check!(code) } end end + context "the return code is a value" do + it "returns back the value" do + GPhoto2.check!(10).should eq 10 + end + end end end