学习如何测试很难!我只是想让 MiniTest 运行,伙计,这是一场斗争。我看过 Ryan 的 RailsCasts 并阅读了我能找到的关于这个主题的所有文档。
我只是在做(或试图做)助手、模型和请求的测试。现在,我的模型和辅助测试只是失败了。
但是,我编写了真正的身份验证集成测试,它们甚至都没有运行!!!看这个:
➜ 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!
嗯,这真是太棒了,它在那些应该做的事情上失败了。现在为什么不运行“test/requests”目录中的东西!
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
我可以在文件中间键入“Joe Blow”,我什至没有收到语法错误。该文件不被拾取的任何理由都是零。看到名称“登录集成”了吗?好吧,它像这样绑定在我的 minitest_helper.rb 中:
class IntegrationTest < MiniTest::Spec
include Rails.application.routes.url_helpers
include Capybara::DSL
register_spec_type(/integration$/i, self)
end
如果这是我们正在使用的地方,那么将这些东西包含在 Rails 4 代码库中肯定看起来有点早。谁能告诉我我做错了什么?