Skip to content

Commit

Permalink
Merge pull request #697 from alyssais/commit_sig_key_error
Browse files Browse the repository at this point in the history
Use Hash#fetch instead of Hash#[] for more understandable error messages
  • Loading branch information
Vicent Martí authored May 8, 2017
2 parents 57b46eb + bf087b0 commit 4d8ae7f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ext/rugged/rugged_signature.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ git_signature *rugged_signature_get(VALUE rb_sig, git_repository *repo)

Check_Type(rb_sig, T_HASH);

rb_name = rb_hash_aref(rb_sig, CSTR2SYM("name"));
rb_email = rb_hash_aref(rb_sig, CSTR2SYM("email"));
rb_name = rb_hash_fetch(rb_sig, CSTR2SYM("name"));
rb_email = rb_hash_fetch(rb_sig, CSTR2SYM("email"));
rb_time = rb_hash_aref(rb_sig, CSTR2SYM("time"));
rb_time_offset = rb_hash_aref(rb_sig, CSTR2SYM("time_offset"));

Expand Down
12 changes: 12 additions & 0 deletions test/commit_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,18 @@ def test_write_empty_email_fails
end
end

def test_write_signature_raises_key_error_for_missing_keys
person = {:name => 'Jake', :time => Time.now} # no :email
assert_raises KeyError do
Rugged::Commit.create(@repo,
:message => "This is the commit message\n\nThis commit is created from Rugged",
:committer => person,
:author => person,
:parents => [@repo.head.target],
:tree => "c4dc1555e4d4fa0e0c9c3fc46734c7c35b3ce90b")
end
end

def test_create_commit_to_s
person = {:name => 'Scott', :email => '[email protected]', :time => Time.now }

Expand Down

0 comments on commit 4d8ae7f

Please sign in to comment.