views:

151

answers:

3

So, I get this warning when I'm running my tests in ruby/RoR

.(eval):289: warning: don't put space before argument parentheses

I've checked every where (but obvoiusly not) and I can't find the origin of this error.

The above error just pops up inbetween the unit tests ...

Can someone clue me in onto how to find the location of this error?

A: 

It sounds to me that there is a rule which forbids a space between a function name and the parentheses enclosing the arguments of the function.

In many languages this would be considered a permissible stylistic variation.

Is the eval mentioned in the warning message, the 'function' being complained about?

Does the number 289 mean anything as a line number?

Could you search your source files for a parenthesis preceded by a space?

Incidentally, the message says warning. What happens if you ignore it?

pavium
Its just a warning. Nothing happens, but its kind of annoying. 289 is a line number in the eval'd code, exactly where its being eval'd or what is being eval'd is the difficult part. Its like 289 somewhere...
Daniel
A: 

If it's happening in between the unit tests it might be in a setup or teardown method. Try searching for eval or try reducing the code you are running until the error goes away. Then you'll know where to look (the code you just removed).

Ben Marini
+1  A: 

The file and line number are contained in the backtrace. However, in your case, the warning is inside a string being evaled at runtime. Which means there is no file. (Actually, the eval method does take optional arguments for the file name and line number that should be displayed in a backtrace, but in this case whoever wrote the code in question unfortunately forgot to pass those arguments.)

I fear that you have no other choice than to manually examine every single call to eval in your entire codebase, and that includes Rails, your testing framework, your entire application, your tests, your plugins, your helpers, the ruby standard library, ...

Of course, you should be aware that the problem might not be obvious as in

eval 'foo (bar, baz)'

It could also be something like

def foo(*args)
  puts args.join
end

bar = 'Hello'
baz = 'World'

foostr = 'foo'                        # in one file
barstr = 'bar'                        # in another file in a different directory
bazstr = 'baz'                        # in another file in a different directory
argstr = "(#{barstr}, #{bazstr})"     # in yet another file
$,     = ' '                          # in some third-party plugin
str    = [foostr, argstr].join        # in a fourth file
eval str                              # somewhere else entirely
eval str, binding, __FILE__, __LINE__ # this is how it *should* be done

Note the difference between the two warning messages: the first one reads exactly like the one you posted, but the second one has the filename instead of (eval) and the line number inside the file instead of the line number inside the eval string.

By the way: the line number 289 in the warning message is the line number inside the evald string! In other words: somewhere in your application there is a string being evald, which is at least 289 lines long! (Actually, it is more likely that this done not in your application but rather in Rails. The Rails router used to be a particularly bad offender, I don't know if this is still the case.)

Jörg W Mittag
*cries*This is a serious amount of code to look though!
Daniel