# Test::Unit::TestCase not resolving correctly

**URL:** <https://www.ruby-forum.com/t/test-testcase-not-resolving-correctly/66869>\
**Category:** Ruby\
**Created:** [August 29, 2006, 10:50pm UTC](https://www.ruby-forum.com/t/test-testcase-not-resolving-correctly/66869 "2006-08-29T22:50:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [August 29, 2006, 10:50pm UTC](https://www.ruby-forum.com/t/test-testcase-not-resolving-correctly/66869/1 "2006-08-29T22:50:45Z")

</div>

I have test case that is failing.

===============================================================

1. Failure: testProj(TestProject) [---------\TestProject.rb:26]:  
\<“068906”\> expected but was \<“68906”\>.  
1 tests, 1 assertions, 1 failures, 0 errors  
===============================================================

In the assignment of the class variable value, the first assert\_equal  
test case appears to be comparing the expected value to the input of  
the class variable assignment…not the value returned by the  
assigment. The two asserts that follow the first yield the correct  
result, so I know the assignment of the class variable is correct. Any  
suggestions as to what I might be doing wrong in the first assert?

# =============================================================== Given the following in my test case:

class TestProject \< Test::Unit::TestCase  
def setup  
@prj=Project.new # new project  
end

def testProj  
assert\_equal(‘068906’,@prj.proj=‘68906’)  
assert\_equal(true,@prj.proj==‘068906’)  
assert\_equal(false,@prj.proj==‘68906’)  
end  
end

# =============================================================== And given the following function being called to assign the value of the class variable.

# Set the project number. # Project number gets tranlated to the

# format “nnnnnn”, and is zero filled. Note: while zero filling is

# the proper display of the project number, it does cause problems

# when trying to find folder names.

def proj=(num)  
if num.class == String  
raise ArgumentError,“Project number #{num} must be in the form  
\<#\>nnnnnn” if num !~/#\*(\d{1,6})/  
n = $1.to\_i  
elsif num.class == Fixnum  
n = num  
elsif num.class == Float  
n = num.to\_i  
else  
raise ArgumentError,“Project number #{num} is in an  
unrecognizable format”  
end  
@proj = sprintf("%06d",n)  
end

# =============================================================== The following test case does work 1 tests, 2 assertions, 0 failures, 0 errors

def testProj  
@prj.proj=‘68906’

# assert\_equal(“068906”,@prj.proj=‘68906’)

```
  assert_equal(true,@prj.proj=='068906')
  assert_equal(false,@prj.proj=='68906')

```

end

Your time, as always, is appreciated…  
dvn

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [August 29, 2006, 11:02pm UTC](https://www.ruby-forum.com/t/test-testcase-not-resolving-correctly/66869/2 "2006-08-29T23:02:48Z")

</div>

Hi –

On Wed, 30 Aug 2006, removed\_email\_address@domain.invalid wrote:

> In the assignment of the class variable value, the first assert\_equal

s/class variable/instance variable/

> test case appears to be comparing the expected value to the input of  
> the class variable assignment…not the value returned by the  
> assigment.

An assignment returns its right-hand side. This rule applies even to  
pseudo-assignment method calls:

class C  
attr\_reader :x  
def x=(y)  
@x = 100  
end  
end

c = C.new  
p c.x = 1 # prints 1, not 100  
p c.x # prints 100

The idea is to make the assignment-like method calls truly  
assignment-like.

David

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [August 29, 2006, 11:04pm UTC](https://www.ruby-forum.com/t/test-testcase-not-resolving-correctly/66869/3 "2006-08-29T23:04:49Z")

</div>

On Aug 29, 2006, at 4:50 PM, removed\_email\_address@domain.invalid wrote:

> # the class variable assignment…not the value returned by the def setup
> 
> ```
> raise ArgumentError,"Project number #{num} must be in the  
> end
> assert_equal(true,@prj.proj=='068906')
> assert_equal(false,@prj.proj=='68906')
> 
> ```
> 
> end
> 
> Your time, as always, is appreciated…  
> dvn

obj.meth = x always returns x, regardless of what the method would  
return in normal circumstances. You should test like this:

@prj.proj = ‘68906’

assert\_equal( ‘068906’, @prj.proj )

% cat assigns.rb  
class A  
def f=(x)  
false  
end  
end

a = A.new  
p a  
p( a.f = 22 )

% ruby assigns.rb  
#\<A:0x1e9328\>  
22
