Undefined Method When Testing Rails Plugins With Shoulda
This is a quick post to help others who may have this problem in the future, or if I forget how I solved this problem (again).
The problem:
Running rake test in your Ruby on Rails plugin directory results in a method not found error (should_validate_presence_of in my case).
The solution:
- Run plugin tests from RAILS_ROOT to properly load environment, include shoulda rails initialization: PLUGIN=url_facade rake test:plugins
- Make sure that test_helper.rb includes the following: require ’shoulda’; require ’shoulda/rails’
The solution is pretty easy in the end, but this has tripped me up more than once!