How to ignore or skip a test method using RSpec?

三世轮回 提交于 2019-12-03 01:12:04

You can use pending() or change it to xit or wrap assert in pending block for wait implementation:

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

Another way to skip tests:

# 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

source: rspec 3.4 documentation

Here is an alternate solution to ignore (skip) the above test method (say, Test01) from sample script.

describe 'Automation System' do

  # some code here

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

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

There are a number of alternatives for this. Mainly marking it as pending or skipped and there is a subtle difference between them. From the docs

An example can either be marked as skipped, in which is it not executed, or pending in which it is executed but failure will not cause a failure of the entire suite.

Refer the docs here:

Pending and skip are nice but I've always used this for larger describe/context blocks that I needed to ignore/skip.

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

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

There are two ways to skip a specific block of code from being running while testing.

Example : Using xit in place of it.

  it "redirects to the index page on success" do
    visit "/events"
  end

Change the above block of code to below.

xit "redirects to the index page on success" do #Adding x before it will skip this test.
    visit "/event"
end

Second way: By calling pending inside the block. Example:

 it "should redirects to the index page on success" do 
  pending                             #this will be skipped
    visit "/events" 
end
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!