2012-05-15 29 views
0

学习如何测试很难!我只是试图让MiniTest跑步和男人,这是一个挫败。我观看了Ryan的RailsCasts并阅读了关于这个主题的所有文档。MiniTest行为奇怪,跳过集成测试文件夹

我只对(或试图做)测试帮助者,模型和请求。现在,我的模型和帮助程序测试只是被剔除而已。

但是,我有真正的身份验证集成测试书面,他们甚至没有运行!看看这个:

➜ 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! 

那么这只是超级,它没有像它应该的那些。现在为什么不运行“测试/请求”目录中的东西!

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 

它看起来确实只是一个稍微有点早应包括这个东西在钢轨4代码库,如果这就是我们在用它。谁能告诉我我做错了什么?

回答

1

我很幸运,我明白了这一点。 2次失败测试后停止测试。我没有发现任何文件。

所以,如果你踩灭你的测试,只是做这样的:

describe User do 

    it "needs a real test" 

end 

这将导致其“跳过”的考验,并继续。

不去做这样的:

describe User do 

    it "must have a real test" do 

    flunk "needs a real test" 

    end 

end 

因为如果你这样做,测试会神秘地停止,不会有什么告诉你为什么。

我喜欢将我的模型和帮助程序测试删除。然后我构建集成测试,并补充我需要的任何单元测试。我仍然可以用MiniTest做到这一点,它只是在2次错误后停止。我没有阅读代码,也许有一些方法来配置该阈值。