Unit Test newbie problem

Hi All,

I got a set of tests for a Ruby app. The first fails unexpectedly
("wrong number of args"). I added code to show that the app works as
I think it should. Any ideas?

The code is below:

I'm running:
Rails 2.3.5, Ruby 1.8.6, WinXP-Pro/SP3, Firefox 3.6.2, Firebug 1.5.3,
MySQL 5.0.37-community-nt, Mongrel, Apache HTTP Server 2.2.15

Thanks in advance,
Richard

# GenModCRUD.rb <<<<<<<<<<<<< The Program >>>>>>>>>>>>>>>

RichardOnRails wrote:

Hi All,

I got a set of tests for a Ruby app. The first fails unexpectedly
("wrong number of args"). I added code to show that the app works as
I think it should. Any ideas

You're getting that error on line 12. What's on line 12? (It's hard to
tell which blank and comment lines are really in your code.)

The code is below:

I'm running:
Rails 2.3.5, Ruby 1.8.6, WinXP-Pro/SP3, Firefox 3.6.2, Firebug 1.5.3,
MySQL 5.0.37-community-nt, Mongrel, Apache HTTP Server 2.2.15

There is no reason to give us the details of your browser when
discussing server-side code.

Thanks in advance,
Richard

Best,

Not relevant to the problem but this doesn't actually make methods
private (it's just the symbol literal 'private'). Remove the : for it
to actually do something (similarly for the public later on)

Fred

Hi Marnen and Frederick,

Thanks for looking into my problem.

Frederick: I removed the colons from the public and private macros
Marnen: The code and the output I got from running them is at
http://www.pastie.org/963644. It's got line numbers. As you
obviously can now see, line 12 is the second line in::

    assert_equal( "edit, index, new, show",
  crud_views_as_a_string(:string), "Surprise")

Thanks again,
Richard

Hi Marnen and Frederick,

Thanks for looking into my problem.

Frederick: I removed the colons from the public and private macros
Marnen: The code and the output I got from running them is athttp://www.pastie.org/963644. It's got line numbers. As you
obviously can now see, line 12 is the second line in::

assert\_equal\( &quot;edit, index, new, show&quot;,
    crud\_views\_as\_a\_string\(:string\), &quot;Surprise&quot;\)

Actually it says it's line 12 in TestGMC.rb which isn't one of the
files listed. What's in there ?

Fred

Minor correction:

View http://www.pastie.org/963750 instead of the "pastie" link I
provided earlier.

My minor error was that the first line of TestGMC.rb was a comment
with the wrong filename. That led me to post incorrect labels in the
"pastie".

I apologize for the sloppiness.

Best wishes,
Richard

OK guys,

All problems solved.
As you suspected, no doubt, all problems were my errors. But I lacked
faith in Unit Tests so I failed to diligently investigate how reported
errors may be caused by defects in my code.

But after posting the code for a second time, I started to notice
some strange code fragments. Ultimately I found three defects in my
app that caused the three unexpected things in the test output. As I
said, all defects have been ameliorated, resulting in a clean Unit
Test report.

Thank you both for continuing to help be gain strength, little by
little, in Ruby/Rails programming.

Best wishes,]
Richard

The problem is that the function crud_views_as_a_string is not defined
(GenModCRUD.rb:22:` def crud_views_as_a_string') to take an argument.
But in your test you are calling it with an argument :string
(TestGMC.rb:12: `crud_views_as_a_string(:string)'

I'm not sure what you're testing, but to simply remove the error, you
would want TestGMC.rb:12 line to read:

assert_equal( "edit, index, new, show", crud_views_as_a_string(),
"Surprise")

Thanks for your help. My faith the Unit Test *really* works is
strengthening :slight_smile:

RichardOnRails wrote:

Thanks for your help. My faith the Unit Test *really* works is
strengthening :slight_smile:

Excellent! When you get a chance, try RSpec, see how much nicer it is,
and watch yourself achieve enlightenment!

Best,

Will do!

Best wishes,
Richard