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 = Todo.new(:when_id => 4,:day=>1,:week=>2,:month=>nil)
  # might need to save here
  set_due(@todo)
  # need to assert something here
end

which gives the following error when running:-

test_set_due(TodosControllerTest):NoMethodError: undefined method `set_due' for
#<TodosControllerTest:0x38d7460>

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

Peter

Peter Cutting wrote:

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 = Todo.new(:when_id => 4,:day=>1,:week=>2,:month=>nil)
    # might need to save here
    set_due(@todo)
    # need to assert something here
end

which gives the following error when running:-

test_set_due(TodosControllerTest):NoMethodError: undefined method `set_due' for
#<TodosControllerTest:0x38d7460>

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

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 @todo.set_due(some_params).

Hope this helps (a bit)