0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Rspecのskip

0
Posted at

examplesを用いたskipの使用

Using skip with examples

Rspecはexampleがスキップしかつ実行しないことを指摘する色々な方法を提示する

RSpec offers a number of ways to indicate that an example should be skipped and not executed.

実施しない(doを入れないことで実行することなく保留される)

No implementation provided

Given a file named “examplewithoutblock_spec.rb” with:

RSpec.describe "an example" do
  it "is a skipped example"
end
Pending: Not yet implemented
1 example, 0 failures, 0 passed, 1 pending

When I run rspec example_without_block_spec.rb

Then the exit status should be 0

And the output should contain “1 example, 0 failures, 1 pending”

And the output should contain “Not yet implemented”

And the output should contain “examplewithoutblock_spec.rb:2”.

skipを使ってスキップする

Skipping using skip

Given a file named “skipped_spec.rb” with:

RSpec.describe "an example" do
  skip "is skipped" do
  end
end
Pending: No reason given
1 example, 0 failures, 0 passed, 1 pending

When I run rspec skipped_spec.rb

Then the exit status should be 0

And the output should contain “1 example, 0 failures, 1 pending”

And the output should contain:

Pending: (Failures listed here are expected and do not affect your suite's status)

  1) an example is skipped
     # No reason given
     # ./skipped_spec.rb:2

exampleの中でskipを使ってスキップする

Skipping using skip inside an example

Given a file named “skipped_spec.rb” with:

RSpec.describe "an example" do
  it "is skipped" do
    skip
  end
end
Pending: No reason given
1 example, 0 failures, 0 passed, 1 pending

When I run rspec skipped_spec.rb

Then the exit status should be 0

And the output should contain “1 example, 0 failures, 1 pending”

And the output should contain:

Pending: (Failures listed here are expected and do not affect your suite's status)

  1) an example is skipped
     # No reason given
     # ./skipped_spec.rb:2

一時的にspecify``itexampleの先頭にxにつけることによってスキップする

Temporarily skipping by prefixing it, specify, or example with an x

Given a file named “temporarilyskippedspec.rb” with:

RSpec.describe "an example" do
  xit "is skipped using xit" do
  end

  xspecify "is skipped using xspecify" do
  end

  xexample "is skipped using xexample" do
  end
end

When I run rspec temporarily_skipped_spec.rb

Then the exit status should be 0

And the output should contain “3 examples, 0 failures, 3 pending”

And the output should contain:

Pending: (Failures listed here are expected and do not affect your suite's status)

  1) an example is skipped using xit
     # Temporarily skipped with xit
     # ./temporarily_skipped_spec.rb:2

  2) an example is skipped using xspecify
     # Temporarily skipped with xspecify
     # ./temporarily_skipped_spec.rb:5

  3) an example is skipped using xexample
     # Temporarily skipped with xexample
     # ./temporarily_skipped_spec.rb:8

メタデータによってスキップする

Skipping using metadata

Given a file named “skipped_spec.rb” with:

RSpec.describe "an example" do
  example "is skipped", :skip => true do
  end
end

When I run rspec skipped_spec.rb

Then the exit status should be 0

And the output should contain “1 example, 0 failures, 1 pending”

And the output should contain:

Pending: (Failures listed here are expected and do not affect your suite's status)

  1) an example is skipped
     # No reason given
     # ./skipped_spec.rb:2

理由付きメタデータを使ってスキップする

Skipping using metadata with a reason

Given a file named “skippedwithreason_spec.rb” with:

RSpec.describe "an example" do
  example "is skipped", :skip => "waiting for planets to align" do
    raise "this line is never executed"
  end
end

When I run rspec skipped_with_reason_spec.rb

Then the exit status should be 0

And the output should contain “1 example, 0 failures, 1 pending”

And the output should contain:

Pending: (Failures listed here are expected and do not affect your suite's status)

  1) an example is skipped
     # waiting for planets to align
     # ./skipped_with_reason_spec.rb:2

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?