I created a plugin for a OS Rails Project. The plugin makes the tests fails, in order开发者_StackOverflow to preserve the system consistency, i would like to override the app tests which fails once the behavior of my plugin is applied.
I have created patches to modify the methods of some existing classes through patches in Class and Instance methods, and I thought i could make the same with tests, but unfortunately i don't get access to the app tests in a plugin.
When i tried to access the TestClass, i get the following error:
cannot remove Object::DEFAULT_OPTIONS
...source/trunk/vendor/rails/activesupport/lib/active_support/dependencies.rb:603:in `remove_const'
...source/trunk/vendor/rails/activesupport/lib/active_support/dependencies.rb:603:in `remove_constant'
...source/trunk/vendor/rails/activesupport/lib/active_support/dependencies.rb:603:in `instance_eval'
...source/trunk/vendor/rails/activesupport/lib/active_support/dependencies.rb:603:in `remove_constant'
...source/trunk/vendor/rails/activesupport/lib/active_support/dependencies.rb:549:in `new_constants_in'
...source/trunk/vendor/rails/activesupport/lib/active_support/dependencies.rb:549:in `each'
...source/trunk/vendor/rails/activesupport/lib/active_support/dependencies.rb:549:in `new_constants_in'
...source/trunk/vendor/rails/activesupport/lib/active_support/dependencies.rb:156:in `require'
I read about Dependencies.load_paths, but i hadn't success on this way.
test_path = Rails.root.join('test', 'unit')
$LOAD_PATH << test_path
ActiveSupport::Dependencies.load_paths << test_path
require 'project_test'
Any idea whether it could be possibly on any way or not.
You may want to try load_once_paths
but I'm not sure it will solve your problem. It's quite hard to diagnose without looking at the actual code that is causing the issue.
That said though, you shouldn't have to modify application tests in your plugin. The tests for the application should be testing the behaviour that the developers of the application expect to see. If adding the plugin to the application causes the tests to fail then the behaviour of the application is no longer what is expected. In this case the developers of the application need to update the tests if the behaviour is as desired (or remove or change the plugin if the behaviour is not desired).
精彩评论