Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 如何忽略或跳过使用RSpec的测试方法?_Ruby_Rspec_Selenium Webdriver_Rspec2 - Fatal编程技术网

Ruby 如何忽略或跳过使用RSpec的测试方法?

Ruby 如何忽略或跳过使用RSpec的测试方法?,ruby,rspec,selenium-webdriver,rspec2,Ruby,Rspec,Selenium Webdriver,Rspec2,请指导如何使用RSpec禁用以下测试方法之一。我正在使用SelenuimWebDriver+RSpec组合来运行测试 require 'rspec' require 'selenium-webdriver' describe 'Automation System' do before(:each) do ### end after(:each) do @driver.quit end it 'Test01' do #positive

请指导如何使用RSpec禁用以下测试方法之一。我正在使用SelenuimWebDriver+RSpec组合来运行测试

require 'rspec'
require 'selenium-webdriver'

describe 'Automation System' do

  before(:each) do    
    ###
  end

  after(:each) do
    @driver.quit
  end

  it 'Test01' do
      #positive test case
  end

  it 'Test02' do
      #negative test case
  end    
end
您可以使用
it
或将其更改为
xit
或将assert包装在挂起块中以等待实现:

describe 'Automation System' do

  # some code here

  it 'Test01' do
     pending("is implemented but waiting")
  end

  it 'Test02' do
     # or without message
     pending
  end

  pending do
    "string".reverse.should == "gnirts"
  end

  xit 'Test03' do
     true.should be(true)
  end    
end

下面是一个从示例脚本中忽略(跳过)上述测试方法(例如,
Test01
)的替代解决方案

describe 'Automation System' do

  # some code here

  it 'Test01' do
     skip "is skipped" do
     ###CODE###
     end
  end

  it 'Test02' do
     ###CODE###         
  end    
end

有两种方法可以在测试时跳过正在运行的特定代码块

示例:使用xit代替它

  it "redirects to the index page on success" do
    visit "/events"
  end
将上面的代码块更改为下面的代码块

xit "redirects to the index page on success" do #Adding x before it will skip this test.
    visit "/event"
end
第二种方法:在块内调用pending。 例如:

 it "should redirects to the index page on success" do 
  pending                             #this will be skipped
    visit "/events" 
end

这方面有很多选择。主要将其标记为
挂起
跳过
,两者之间存在细微差别。从文件中

可以将示例标记为跳过(未执行),或者标记为挂起(执行但失败不会导致整个套件失败)

请参阅此处的文档:


另一种跳过测试的方法:

# feature test
scenario 'having js driver enabled', skip: true do
  expect(page).to have_content 'a very slow test'
end

# controller spec
it 'renders a view very slow', skip: true do
  expect(response).to be_very_slow
end

来源:

挂起和跳过很好,但我总是将其用于需要忽略/跳过的更大的描述/上下文块

describe Foo do
  describe '#bar' do
    it 'should do something' do
      ...
    end

    it 'should do something else' do
      ...
    end
  end
end if false

我喜欢这个。从语义上讲,“跳过”、“退出”和“挂起”是不同的东西。这对于解决这个问题来说确实是一种误解。不,这不是最清晰的方法,但它确实有效。此外,您可以将
场景
更改为
xscenario
:)结果是
xcontext
&
xdescripe
也有效:)我发现相关,尽管它不是合适的复制目标。您可以在
周围使用
钩子并调用
示例。根据条件跳过