# Unit testing: example p. 156 pickaxe2

**URL:** <https://www.ruby-forum.com/t/unit-testing-example-p-156-pickaxe2/115869>\
**Category:** Ruby\
**Created:** [September 29, 2007, 3:02pm UTC](https://www.ruby-forum.com/t/unit-testing-example-p-156-pickaxe2/115869 "2007-09-29T15:02:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![7stud](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/7/57b2e6/32.png) [@7stud](https://www.ruby-forum.com/u/7stud)\
**Post date:** [September 29, 2007, 3:02pm UTC](https://www.ruby-forum.com/t/unit-testing-example-p-156-pickaxe2/115869/1 "2007-09-29T15:02:15Z")

</div>

How do you make this example fail:

require “test/unit”

class TestsWhichFail \< Test::Unit::TestCase  
def test\_reading  
assert\_not\_nil(ARGF.read, “Read next line of input”)  
end  
end

I tried specifying an empty file on the command line, no file, a file  
with two words in it, and a file that doesn’t exist, but I can’t get it  
to fail. Yet, the output in the book shows:

1 tests, 1 assertions, 1 failures, 0 errors

---

<div class="post-metadata">

**Author:** ![7stud](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/7/57b2e6/32.png) [@7stud](https://www.ruby-forum.com/u/7stud)\
**Post date:** [October 1, 2007, 6:27am UTC](https://www.ruby-forum.com/t/unit-testing-example-p-156-pickaxe2/115869/2 "2007-10-01T06:27:31Z")

</div>

Anyone?

---

<div class="post-metadata">

**Author:** ![7stud](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/7/57b2e6/32.png) [@7stud](https://www.ruby-forum.com/u/7stud)\
**Post date:** [October 1, 2007, 11:40am UTC](https://www.ruby-forum.com/t/unit-testing-example-p-156-pickaxe2/115869/3 "2007-10-01T11:40:21Z")

</div>

7stud – wrote:

> How do you make this example fail:
> 
> require “test/unit”
> 
> class TestsWhichFail \< Test::Unit::TestCase  
> def test\_reading  
> assert\_not\_nil(ARGF.read, “Read next line of input”)  
> end  
> end

If I add this line:

ARGF.read #\<—\*\*\*  
assert\_not\_nil(ARGF.read, “Read next line of input”)

and I specify a data file name on the command line, then the test fails.  
Curiously, if I omit specifying a data file name on the command line,  
and I type ^D while the program is running, I can’t get the test to  
fail.
