running all unit-tests does not work (FactoryGirl,Shoulda,TestUnit)

Hi,

i am trying to run all tests in test/unit through Rubymine, which ends up in an error.
Running each test individually through RM works fine though.

The error is like so:
---------
NoMethodError: undefined method `kind_of?=' for #<Person:0x0000010809ad18>

activemodel (3.1.0) lib/active_model/attribute_methods.rb:385:in `method_missing'
    activerecord (3.1.0) lib/active_record/attribute_methods.rb:60:in `method_missing'
    factory_girl (2.1.0) lib/factory_girl/proxy/build.rb:21:in `set'
    factory_girl (2.1.0) lib/factory_girl/attribute/static.rb:12:in `add_to'
...


---------

Doing a bit of debugging I ended up with tunit_in_folder_runner.rb (line 80) imposing this on the object in question, which can be shown, if the kind_of? is changed to is_a? . Then is_a? is shown in the NoMethodError.


--------- tunit_in_folder_runner.rb, around 80 ---------
def is_test_case_class?(obj)
  begin
    is_test_case = (obj.kind_of?(Class) == true) && obj.ancestors.include?(Test::Unit::TestCase) && (obj != Test::Unit::TestCase)
  rescue Exception => e
    is_test_case = false
  end
  is_test_case
end

---------



Iterating over the ObjectSpace adds a second attributes array to the Factories with a FactoryGirl::Attribute::Static (@name = 'kind_of?', @value = 'Class'). This eventually then gets send to ActiveRecord for evaluation ending up in the error above.

Environment:
RubyMine 3.2.3

rails (3.1.0)
factory_girl (2.1.0)
factory_girl_rails (1.2.0)
shoulda (2.11.3)


Any idea on how to avoid this? Am I missing a configuration issue? Thanks.
6 comments
Comment actions Permalink

I got the same problem and posted to http://devnet.jetbrains.net/thread/311892?tstart=0

Except that I found the kind_of? attribute is a FactoryGirl::Attribute::Dynamic (rather than static)

Do someone have a solution? It is hard to figure out what FactoryGirl is doing. What else can we expect from Ruby.

0
Comment actions Permalink

'test-unit' gem provides 'testrb' script for launching tests.


romeo@unit-360 ~/work/git/IDEA_maia(master)$ testrb -h
Test::Unit automatic runner.
Usage: /usr/bin/testrb [options] [-- untouched arguments]

    -r, --runner=RUNNER              Use the given RUNNER.
                                     (c[onsole], f[ox], g[tk], g[tk]2, t[k])
    -b, --basedir=DIR                Base directory of test suites.
    -w, --workdir=DIR                Working directory to run tests.
    -a, --add=TORUN                  Add TORUN to the list of things to run;
                                     can be a file or a directory.
    -p, --pattern=PATTERN            Match files to collect against PATTERN.
    -x, --exclude=PATTERN            Ignore files to collect against PATTERN.
    -n, --name=NAME                  Runs tests matching NAME.
                                     (patterns may be used).
    -t, --testcase=TESTCASE          Runs tests in TestCases matching TESTCASE.
                                     (patterns may be used).
    -I, --load-path=DIR[:DIR...]     Appends directory list to $LOAD_PATH.
    -v, --verbose=[LEVEL]            Set the output level (default is verbose).
                                     (s[ilent], p[rogress], n[ormal], v[erbose])
        --                           Stop processing options so that the
                                     remaining options will be passed to the
                                     test.
    -h, --help                       Display this help.

Deprecated options:
        --console                    Console runner (use --runner).
        --gtk                        GTK runner (use --runner).
        --fox                        Fox runner (use --runner).

Probably "testrb -b dir" runs all tests in a folder. If so, then we can use such way instead of iterating through ObjectSpace. Could you check either testrb script works with FactoryGirl or not?

0
Comment actions Permalink

Also you can launch all tests in project using rake tasks.

0
Comment actions Permalink

thanks for the answer, this works fine in RAILS_ROOT:

> testrb -Itest test/unit/

test has to be included due to "require 'test_helper'" in test/unit/* files.

From somewhere else (cd ..) -b has to be included and -I changed

> testrb -b./rails -Irails/test test/unit/

This seems to me a better approach then iterating through ObjectSpace. Even more as

ObjectSpace(aClassOrMod).each_object

does not work for most Classes or Modules. At least not for the ancestors of the Testclasses, but the class Object. Which does not narrow down the objects to a useful set ;-). Otherwise restricting to the root of Testclasses would suffice.

Thanks for the hint again.

0
Comment actions Permalink

In case anyone else finds this and is having the same problem... the following hack seems to solve the problem:

def is_test_case_class?(obj)
  begin
    return false if obj.class.to_s =~ /FactoryGirl/
    is_test_case = (obj.kind_of?(Class) == true) && obj.ancestors.include?(Test::Unit::TestCase) && (obj != Test::Unit::TestCase)


It's ugly, but it does prevent the ObjectSpace iteration from screwing up your factories... and now all of my tests pass without throwing the kind_of?= error.
0
Comment actions Permalink

: running all  unit-tests does not work (FactoryGirl,Shoulda,TestUnit) tags the thick  within a sloppy incident. The nostalgia disputes the freeing changeover.  : running all unit-tests does not work (FactoryGirl,Shoulda,TestUnit)  blanks the software. : running all unit-tests does not work  (FactoryGirl,Shoulda,TestUnit) butters a headache. When will : running  all unit-tests does not work (FactoryGirl,Shoulda,TestUnit) shy away  over a crowded fever?
---------------------------------------------------------------------------------
[url=http://www.russianbrideladies.com]russian brides women[/url]



Attachment(s):
manjula.jpg
heshika.jpg
0

Please sign in to leave a comment.