Forum: Ruby on Rails functional test NoMethodError

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Peter Cutting (Guest)
on 2006-12-22 14:09
(Received via mailing list)
I am trying to setup some tests for the first time but I have run into
an error
which I cannot solve

I have a function (set_due), defined in the main class (todo) , that
takes an
instance of the main class as a parameter, and updates an attribute
(due) of the
instance's DB record. Not very OO but works OK

I want to test that set_due correctly calculates a new due date. in the
functional test script I have added:-

def test_set_due
	@todo = => 4,:day=>1,:week=>2,:month=>nil)
	# might need to save here
	# need to assert something here

which gives the following error when running:-

test_set_due(TodosControllerTest):NoMethodError: undefined method
`set_due' for

The test cannot seem to find the set_due method? I have syntax checked
controller (ruby -c) and made the set_due method public but neither
helps. stuck

Chris T (Guest)
on 2006-12-22 14:47
(Received via mailing list)
Peter Cutting wrote:
> which gives the following error when running:-
> Peter
> >
Couple of pointers here. Think you're probably wanting to do a unit test
rather than a functional one. Unit tests are for testing you business
logic (which is what you seem to be wanting to do); functional tests for
simulating the calling of actions in your controller.

Also set_due isn't a function but a method, which acts upon the object
in which it is defined (I'm sure someone else could put this better --
I'm still a relative OO newbie). By calling it without a receiver, it is
implicitly called upon whatever self is, in your case the
TodosControllerTest class. In the above example you will need to do

Hope this helps (a bit)
This topic is locked and can not be replied to.