Skip to content

Commit

Permalink
Bit moar specs, refs #7
Browse files Browse the repository at this point in the history
  • Loading branch information
Sija committed Aug 16, 2016
1 parent 76e0515 commit 14d2479
Showing 1 changed file with 50 additions and 4 deletions.
54 changes: 50 additions & 4 deletions spec/gphoto2_spec.cr
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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

0 comments on commit 14d2479

Please sign in to comment.