From ad12d0d482c0514bca0770fde3d7b60918f8587d Mon Sep 17 00:00:00 2001 From: John Nunemaker Date: Thu, 13 Jul 2017 20:39:00 -0400 Subject: [PATCH] Make initialize without block return true for ok? It was returning false because the lack of a block would yield a local jump error which would then be rescued setting error and thus ok? to false. --- lib/github/result.rb | 2 +- test/github/result_test.rb | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/github/result.rb b/lib/github/result.rb index 96dfe74..041aa2c 100644 --- a/lib/github/result.rb +++ b/lib/github/result.rb @@ -15,7 +15,7 @@ module GitHub # def initialize begin - @value = yield + @value = yield if block_given? @error = nil rescue => e @error = e diff --git a/test/github/result_test.rb b/test/github/result_test.rb index 3f63ae4..ce93b90 100644 --- a/test/github/result_test.rb +++ b/test/github/result_test.rb @@ -83,4 +83,8 @@ class GitHub::ResultTest < Minitest::Test assert_equal e, GitHub::Result.new { raise e }.error end + + def test_initialize_without_block + assert_predicate GitHub::Result.new, :ok? + end end