I'm uncertain if this is an issue, or simply a misunderstanding on my part.
I am trying to use ActionController::TestCase::Behaviour methods, such as get, post, etc.. This results in a NoMethodError:
NoMethodError: undefined method 'get' for #<FoosControllerTest:0x000001053a5718>
test/controllers/foos_controller_test.rb:65:in 'block in <class:FoosControllerTest>'
In minitest-rails/lib/minitest/rails/controller.rb, I uncommented require 'action_controller' and include ActionController::TestCase::Behaviours to load the module, but now I receive a different NoMethodError:
ruby-1.9.2-p290@foo/gems/actionpack-3.1.0/lib/action_controller/test_case.rb:12:in 'block in <module:TemplateAssertions>': undefined method 'setup' for MiniTest::Rails::Controller:Class (NoMethodError)
from ruby-1.9.2-p290@foo/gems/activesupport-3.1.0/lib/active_support/concern.rb:122:in 'class_eval'
I explicitly added a def setup ; ... ; end to my FooControllerTest class (because currently tests are in the MiniTest::Spec DSL using before do, but the errors persist.
def setup ; ... ; end
Thank you for minitest-rails.
(In the meantime, I've quickly switched to the mini_specunit shim. However, I'm confused about the different minitest rails gems.)
I've resolved the missing setup() method by requiring / including the ActiveSupport::Testing::SetupAndTeardown module.
class Controller < Spec
However, I'm still resolving the get, post, etc. methods, as now there's a nil ivar, @routes.
But I'll keep investigating and hopefully produce a pull request for this soon.
I believe these are the droids we're looking for:
But I'm not fluent enough with rails-core codebase to know right now what should we include and/or subclass :/
Will give these methods. So while I'm trying to resolve all this, I've done this in my test file:
class Controller < Spec
The ivars (@routes, @request, etc.) problem I mentioned above is a standard Rails3 problem, you must require 'rails/test_help'.
so, does including these make functional tests work in minitest-rails?
Not for me, no. As @phiggins commented on your issue, minitest-rails is quite new. I've just been commenting here while trying to understand how this all works and possibly contribute to "fix" it.
@tomash If you haven't seen it, there's also this project: https://github.com/metaskills/mini_specunit
I was able to get this to work by adding some code snippets from wojtekmach's minitest-rails-example application
Inside of minitest_helper.rb
# Add methods to be used by all specs here...
args.gsub(/\?/, '%s') % args[2..-1]
@routes = Rails.application.routes
I was then able to use the ActionController::TestCase::Behavior methods in a test
class PhraseCountersControllerTest < MiniTest::Rails::Controller
@controller = PhraseCountersController.new
describe "#new" do
it "must render new template" do
Not sure what the final resolution to the problem should be but maybe this will help.
Just FYI on this entire issue, MiniTest::Spec has landed in edge rails (4.0 pre). http://www.youtube.com/watch?v=1ieWRX0mPbI
Also looking for a proper solution to this. I went with something similar to what @carlosramireziii recommended. There were quite a few hiccups, but I finally got this working.
Note that the biggest hiccup was that requiring rails/test_help implicitly requires test/unit, which breaks if you're running minitest with Ruby 1.8. I came across the minitest_tu_shim gem which got these tests running in 1.8.
Is this still an issue in 0.0.7?
Improvements coming in 0.1.0.