小编Chi*_*thi的帖子

基于条件的 Rspec 测试

我有一个布尔变量condition。我有一些 rspec 测试用例来检查输入字段的存在。

if(condition == true)
   execute the following test cases. 
   it "some test case"
   end
   it "some test case 2"
   end

if(condition == false)
   execute the following test cases. 
   it "some test case 3"
   end
   it "some test case 4"
   end
Run Code Online (Sandbox Code Playgroud)

但是所有的测试用例都被执行了。我尝试使用context.

context "When condition is true"
  let(:condition) { TRUE }
  it "some test case"
  end
  it "some test case 2"
  end
context "When condition is false"
  let(:condition) { FALSE}
  it "some test case 3" …
Run Code Online (Sandbox Code Playgroud)

ruby unit-testing rspec

4
推荐指数
1
解决办法
3421
查看次数

标签 统计

rspec ×1

ruby ×1

unit-testing ×1