【问题标题】:Rspec and prevent tests from being run under some circumstancesRspec 并防止在某些情况下运行测试
【发布时间】:2014-03-19 07:30:53
【问题描述】:

我像这样使用 rspec:

描述 它'应该检查是否为 xx': 结束

如果满足某些条件,我如何防止运行 it 端主体中的某些测试?例如,如果函数 is_disabled 返回 true,则不应运行以下测试:

   it 'should check if the xx1':
   end

   it 'should check if the xx2':
   end

但以下应该:

   it 'should check if the xx3':
   end

   it 'should check if the xx4':
   end

你能做到吗:

context "if api calls enabled for MC, @app.is_disabled => 'USD' do
   it 'should check if the xx3':
   end

   it 'should check if the xx4':
   end  
end     

【问题讨论】:

    标签: ruby rspec


    【解决方案1】:

    是的,您可以使用 rspec implicit filters。示例:

    describe "if the app is enabled", :unless => @app.is_disabled do
       it 'should check if the xx3':
       end
    
       it 'should check if the xx4':
       end
    end
    
    describe "if the app is disabled", :if => @app.is_disabled do
       it 'should check if the xx1':
       end
    
       it 'should check if the xx2':
       end
    end
    

    【讨论】:

    • 你如何做检查:除非 => @app.name = "test"
    • describe "...", :unless => @app.name == "test" 做什么?
    猜你喜欢
    • 2022-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多