This repository has been archived by the owner on Oct 27, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add example of formatter that filters based on options passed to
describe() and it() methods.
- Loading branch information
1 parent
5950c7b
commit 07067fa
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
$:.unshift File.join(File.dirname(__FILE__), "/../../lib") | ||
require 'spec/runner/formatter/nested_text_formatter' | ||
|
||
class FilteredFormatter < Spec::Runner::Formatter::NestedTextFormatter | ||
def add_example_group(example_group) | ||
if example_group.options[:show] == false | ||
@showing = false | ||
else | ||
@showing = true | ||
puts example_group.description | ||
end | ||
end | ||
|
||
def example_passed(example) | ||
puts " " << example.description if @showing unless example.options[:show] == false | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# This demonstrates how you can write custom formatters to handle arbitrary | ||
# options passed to the +describe+ and +it+ methods. To see it in action, stand | ||
# in the project root and say: | ||
# | ||
# bin/spec -r examples/passing/filtered_formatter.rb examples/passing/filtered_formatter_example.rb -f FilteredFormatter | ||
# | ||
# You should only see the examples and groups below that are not explicitly | ||
# marked :show => false | ||
# | ||
# group 1 | ||
# example 1 a | ||
# group 3 | ||
# example 3 | ||
|
||
|
||
describe "group 1", :show => true do | ||
it "example 1 a", :show => true do | ||
end | ||
it "example 1 b", :show => false do | ||
end | ||
end | ||
|
||
describe "group 2", :show => false do | ||
it "example 2" do | ||
end | ||
end | ||
|
||
describe "group 3" do | ||
it "example 3" do | ||
end | ||
end |