除外するフィルター

除外するフィルター
># Exclusion filters
exclusion filterを宣言し、そのフィルターをグループ全体またはexampleにタグ付けすることによって、実行からexampleを除外することができる。シンボルだけでメタデータを明示できる。

>You can exclude examples from a run by declaring an exclusion filter and then tagging examples, or entire groups, with that filter. You can also specify metadata using only symbols.

exampleを除外する
>### Exclude an example

```rb
RSpec.configure do |c|
  # declare an exclusion filter
  c.filter_run_excluding :broken => true
end

RSpec.describe "something" do
  it "does one thing" do
  end

  # tag example for exclusion by adding metadata　
  it "does another thing", :broken => true do # この例が除外される
  end
end
```
```
Run options: exclude {:broken=>true}

something
  does one thing

Finished in 0.03501 seconds (files took 2.16 seconds to load)
1 example, 0 failures
```
グループを除外する
>### Exclude a group

```rb
RSpec.configure do |c|
  c.filter_run_excluding :broken => true
end

RSpec.describe "group 1", :broken => true do # このグループが除外される
  it "group 1 example 1" do
  end

  it "group 1 example 2" do
  end
end

RSpec.describe "group 2" do
  it "group 2 example 1" do
  end
end
```
```
Run options: exclude {:broken=>true}

group 2
  group 2 example 1

Finished in 0.03073 seconds (files took 2.1 seconds to load)
1 example, 0 failures
```
複数のグループを除外する
>### Exclude multiple groups
```rb
RSpec.configure do |c|
  c.filter_run_excluding :broken => true
end

RSpec.describe "group 1", :broken => true do　# どちらのグループも除外される
  before(:context) do
    raise "you should not see me"
  end

  it "group 1 example 1" do
  end

  it "group 1 example 2" do
  end
end

RSpec.describe "group 2", :broken => true do
  before(:example) do
    raise "you should not see me"
  end

  it "group 2 example 1" do
  end
end
```
```
Run options: exclude {:broken=>true}

All examples were filtered out

Finished in 0.00644 seconds (files took 2.24 seconds to load)
0 examples, 0 failures
```
除外されたexampleグループ内のbefore,afterフックは実行されない
>### before/after(:context) hooks in excluded example group are not run
```rb
RSpec.configure do |c|
  c.filter_run_excluding :broken => true
end

RSpec.describe "group 1" do
  before(:context) { puts "before context in included group" }
  after(:context)  { puts "after context in included group"  }

  it "group 1 example" do
  end
end

RSpec.describe "group 2", :broken => true do
  before(:context) { puts "before context in excluded group" }
  after(:context)  { puts "after context in excluded group"  }

  context "context 1" do
    it "group 2 context 1 example 1" do
    end
  end
end
```
```
Run options: exclude {:broken=>true}

group 1
before context in included group
  group 1 example
after context in included group

Finished in 0.03408 seconds (files took 2.36 seconds to load)
1 example, 0 failures
```
>### Use symbols as metadata
```rb
RSpec.configure do |c|
  c.filter_run_excluding :broken
end

RSpec.describe "something" do
  it "does one thing" do
  end

  # tag example for exclusion by adding metadata
  it "does another thing", :broken do # シンボルだけで除外可能
  end
end
```
```
Run options: exclude {:broken=>true}

something
  does one thing

Finished in 0.04131 seconds (files took 1.24 seconds to load)
1 example, 0 failures
```