running all unit-tests does not work (FactoryGirl,Shoulda,TestUnit) Follow
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_rails (1.2.0)
shoulda (2.11.3)
Any idea on how to avoid this? Am I missing a configuration issue? Thanks.
Please sign in to leave a comment.
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.
'test-unit' gem provides 'testrb' script for launching tests.
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?
Also you can launch all tests in project using rake tasks.
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.
In case anyone else finds this and is having the same problem... the following hack seems to solve the problem:
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.
: 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