Learning how to test is HARD! I’m just trying to get MiniTest running and man, it is a STRUGGLE. I have watched Ryan’s RailsCasts and read all of the documentation I could find on the subject.
I am only doing (or attempting to do) testing for helpers, models, and requests. Right now, my model and helper tests are just stubbed out to flunk.
However, I have real authentication integration tests written, and they aren’t even being RUN!!! Look at this:
➜ myapp git:(master) rake
==============================================================================
SUITE test/factories,test/helpers,test,test/models,test/requests (SEED 41025)
==============================================================================
User
0001 must be a real test 0:00:00.005 FAIL
0:00:00.005 ERROR
==============================================================================
SUITE test/factories,test/helpers,test,test/models,test/requests (SEED 12794)
==============================================================================
SessionsHelper
0001 must be a real test 0:00:00.006 FAIL
0:00:00.006 ERROR
Errors running models, helpers!
Well that is just super, it failed on those like it was supposed to. Now why isn’t it running the stuff from the “test/requests” directory!
require 'minitest_helper'
describe "Login Integration" do
it "authenticates a user with a password" do
login_user
assert page.has_content?('Logged in')
end
it "fails to authenticate a user with a mismatched password" do
user = FactoryGirl.create(:user)
visit login_path
fill_in "Email", :with => user.email
fill_in "Password", :with => "bad password"
click_button "Log In"
assert page.has_content?('Invalid email or password')
end
it "logs out a user" do
login_user
click_link "Log Out"
assert page.has_content?('Logged out')
end
end
I can type “Joe Blow” in the middle of the file, and I’m not even getting a syntax error. There is zero reason whatsoever for this file not to get picked up. See the name, “Login Integration”? Well, it’s bound in my minitest_helper.rb like so:
class IntegrationTest < MiniTest::Spec
include Rails.application.routes.url_helpers
include Capybara::DSL
register_spec_type(/integration$/i, self)
end
It sure looks just a tad bit early to be including this stuff in the Rails 4 codebase if this is where we’re at with it. Can anyone tell me what I’m doing wrong?
I am lucky I figured this out. Testing stops after 2 failed tests. I have found no documentation on this whatsoever.
So if you stub out your tests, just do it like this:
That will cause it to “SKIP” the test, and continue on.
Do NOT do it like this:
Because if you do, the testing will mysteriously stop, and there won’t be anything to tell you why.
I like to have my model and helper tests stubbed out. Then I build my integration tests, and supplement with any unit tests I need along the way. I can still do that with MiniTest, it just stops after 2 errors. I haven’t read the code, perhaps there is some way to configure that threshold.