Forum: Ruby on Rails functional test NoMethodError

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
73756d80869c09ef04abe93025d7a117?d=identicon&s=25 Peter Cutting (Guest)
on 2006-12-22 13: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 = 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
58c6efb8466b9f85155fe6aa9fc37fce?d=identicon&s=25 Chris T (Guest)
on 2006-12-22 13: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
@todo.set_due(some_params).

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