Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
where is wrong with contoller test?
OnRails Ruby
9/16/2007 12:52:00 AM
Hi, everybody!
I got a strange question when I did a controller test as below
On controller.rb:
def send_welcome_message(person)
some codes;
end
there 'person' is instance variables.
the controller_test.rb:
def test_send_welcome_message
post :send_welcome_message, :person=>{:id=>'2',
:name=>'somebody'}
assert_response :success
end
when I run this test, There always said,
1) Error:
test_send_welcome_message(TestControllerTest):
ArgumentError: wrong number of arguments (0 for 1)
I know there maybe params are set wrong,
but how can I fix it out? please help, Thanks!
--
Posted via
http://www.ruby-...
.
3 Answers
Phlip
9/16/2007 2:30:00 AM
0
OnRails Ruby wrote:
> I got a strange question when I did a controller test as below
The best place for Rails question is the Google Group called "Ruby on Rails:
Talk". And you had better get at least the book /Agile Web Development on
Rails/ before programming any more.
> On controller.rb:
>
> def send_welcome_message(person)
> some codes;
> end
> there 'person' is instance variables.
It is not; it's a method parameter.
However, actions don't (typically) take arguments. They always get data from
their web pages from the params hash, so you need to use
person = params[:person]
> ArgumentError: wrong number of arguments (0 for 1)
Right; the test rig did not pass person where you think it did, but the
action was expecting it there. Take it out of the action's arguments.
BTW congrats for testing; it will make all this stuff easier as you go!
--
Phlip
http://www.oreilly.com/catalog/9780...
"Test Driven Ajax (on Rails)"
assert_xpath, assert_javascript, & assert_ajax
Matthew Rudy Jacobs
9/17/2007 8:53:00 AM
0
OnRails Ruby wrote:
> Hi, everybody!
> I got a strange question when I did a controller test as below
> On controller.rb:
>
> def send_welcome_message(person)
> some codes;
> end
> there 'person' is instance variables.
Can I just check how you're using this method.
Is it a controller "action", as in, do you access it directly from a
url?
eg. /controller/send_welcome_message/1
Or is it just a convenience method?
If it is an action, then an action can only be called without an
argument
(it takes input from the http params, and inherits any instance
variables defined in before_filters)
you say "person" is an instance variable.
so it should look like this
def send_welcome_message
do the code involving @person
end
before_filter :get_person
def get_person
@person = Person.find(params[:id])
end
hopefully that'll fix your problem.
--
Posted via
http://www.ruby-...
.
OnRails Ruby
9/17/2007 6:22:00 PM
0
Thanks a lots, matthewrudy and Phlip
I had posted this question on groups google. and got the same answer.
I think that is a function like "def send_welcome_message(person)",
and that is a model method(action) like "def send_welcome_message",
so when I defined "def send_welcome_message(person)", I can call
it in I method(action), then you don't need to test this function.
This idea is right or not?
Thanks help!
--
Posted via
http://www.ruby-...
.
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
where is wrong with contoller test?
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password