Functional test NoMethodError


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



Peter Cutting wrote:

which gives the following error when running:-

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)