test/unit/assertions/assert_raises_tests.rb in assert-2.18.2 vs test/unit/assertions/assert_raises_tests.rb in assert-2.18.3

- old
+ new

@@ -4,90 +4,90 @@ module Assert::Assertions class AssertRaisesTests < Assert::Context include Assert::Test::TestHelpers desc "`assert_raises`" - setup do - d = @d = "assert raises fail desc" - @test = Factory.test do - assert_raises(StandardError, RuntimeError){ raise(StandardError) } # pass - assert_raises(StandardError, RuntimeError, d){ raise(Exception) } # fail - assert_raises(RuntimeError, d){ raise(StandardError) } # fail - assert_raises(RuntimeError, d){ true } # fail - assert_raises(d){ true } # fail + subject { test1 } + + let(:desc1) { "assert raises fail desc" } + let(:test1) { + desc = desc1 + Factory.test do + assert_raises(StandardError, RuntimeError) { raise(StandardError) } # pass + assert_raises(StandardError, RuntimeError, desc) { raise(Exception) } # fail + assert_raises(RuntimeError, desc) { raise(StandardError) } # fail + assert_raises(RuntimeError, desc) { true } # fail + assert_raises(desc) { true } # fail end - @test.run(&test_run_callback) - end - subject{ @test } + } should "produce results as expected" do - assert_equal 5, test_run_result_count - assert_equal 1, test_run_result_count(:pass) - assert_equal 4, test_run_result_count(:fail) - end + subject.run(&test_run_callback) - should "have a fail message with custom and generic explanations" do - exp = [ - "#{@d}\nStandardError or RuntimeError exception expected, not:", - "#{@d}\nRuntimeError exception expected, not:", - "#{@d}\nRuntimeError exception expected but nothing raised.", - "#{@d}\nAn exception expected but nothing raised." - ] + assert_that(test_run_result_count).equals(5) + assert_that(test_run_result_count(:pass)).equals(1) + assert_that(test_run_result_count(:fail)).equals(4) + + exp = + [ "#{desc1}\nStandardError or RuntimeError exception expected, not:", + "#{desc1}\nRuntimeError exception expected, not:", + "#{desc1}\nRuntimeError exception expected but nothing raised.", + "#{desc1}\nAn exception expected but nothing raised." + ] messages = test_run_results(:fail).map(&:message) - messages.each_with_index{ |msg, n| assert_match(/^#{exp[n]}/, msg) } + messages.each_with_index{ |msg, n| assert_that(msg).matches(/^#{exp[n]}/) } end should "return any raised exception instance" do error = nil error_msg = Factory.string - test = Factory.test do - error = assert_raises(RuntimeError){ raise(RuntimeError, error_msg) } - end + + test = + Factory.test do + error = assert_raises(RuntimeError) { raise(RuntimeError, error_msg) } + end test.run - assert_not_nil error - assert_kind_of RuntimeError, error - assert_equal error_msg, error.message + assert_that(error).is_not_nil + assert_that(error).is_kind_of(RuntimeError) + assert_that(error.message).equals(error_msg) - test = Factory.test do - error = assert_raises(RuntimeError){ } - end + test = Factory.test { error = assert_raises(RuntimeError) {} } test.run - assert_nil error + assert_that(error).is_nil end end class AssertNothingRaisedTests < Assert::Context include Assert::Test::TestHelpers desc "`assert_nothing_raised`" - setup do - d = @d = "assert nothing raised fail desc" - @test = Factory.test do - anr = :assert_nothing_raised - self.send(anr, StandardError, RuntimeError, d){ raise(StandardError) } # fail - self.send(anr, RuntimeError){ raise(StandardError) } # pass - self.send(anr, d){ raise(RuntimeError) } # fail - self.send(anr){ true } # pass + subject { test1 } + + let(:desc1) { "assert nothing raised fail desc" } + let(:test1) { + desc = desc1 + Factory.test do + assert_nothing_raised(StandardError, RuntimeError, desc) { raise(StandardError) } # fail + assert_nothing_raised(RuntimeError) { raise(StandardError) } # pass + assert_nothing_raised(desc) { raise(RuntimeError) } # fail + assert_nothing_raised { true } # pass end - @test.run(&test_run_callback) - end - subject{ @test } + } should "produce results as expected" do - assert_equal 4, test_run_result_count - assert_equal 2, test_run_result_count(:pass) - assert_equal 2, test_run_result_count(:fail) - end + subject.run(&test_run_callback) - should "have a fail message with custom and generic explanations" do - exp = [ - "#{@d}\nStandardError or RuntimeError exception not expected, but raised:", - "#{@d}\nAn exception not expected, but raised:" - ] + assert_that(test_run_result_count).equals(4) + assert_that(test_run_result_count(:pass)).equals(2) + assert_that(test_run_result_count(:fail)).equals(2) + + exp = + [ "#{desc1}\nStandardError or RuntimeError exception not expected, but raised:", + "#{desc1}\nAn exception not expected, but raised:" + ] messages = test_run_results(:fail).map(&:message) - messages.each_with_index{ |msg, n| assert_match(/^#{exp[n]}/, msg) } + messages.each_with_index{ |msg, n| assert_that(msg).matches(/^#{exp[n]}/) } end end end -