使用 Capybara 和 Rspec,如何为特定测试禁用 config:all

With Capybara and Rspec, how to disable config :all for a specific test

我没有那么少的测试,所以为了节省时间,我使用以下配置跳过了登录过程:

config.before :all, type: :feature do
    stub_login
    visit "/auth=admin:123456&origin=http://#{Capybara.current_session.server.host}:#{Capybara.current_session.server.port}"
end

但现在我必须测试登录屏幕,我陷入困境:任何尝试进入登录屏幕(访问或注销)都会导致登录页面作为存根 return 登录状态的相关数据

我想知道如何取消这个特定的配置?有没有办法标记它以便特定测试(或规范)可以忽略它?

想法和提示?谢谢

最终我拆分了 "config.before :all":

config.before :all, type: :logged do
    stub_login
end

config.before :all, type: :feature do
    visit '.......'
end

测试来自:

describe 'some tests with login', type: [:feature, :logged] do
.....

至:

describe 'login screen tests', type: :feature do
.....

另一个更好的解决方案是:

config.before :all do |spec|

    not_logged = spec.class.metadata[:not_logged]
    if not_logged
        ......not logged script
    else
       ......logged script 
    end

和规范:

describe 'login view', type: :feature, :not_logged=> true do
    .....
end