Skip to content

Commit

Permalink
Merge pull request #5 from sasamuku/add_ctx_type
Browse files Browse the repository at this point in the history
add ctx type
  • Loading branch information
sasamuku authored Mar 17, 2024
2 parents c988c54 + b2f1620 commit 8c4e61d
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 24 deletions.
27 changes: 20 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,26 @@ If bundler is not being used to manage dependencies, install the gem by executin

```
$ rspec_tree all /path/to/your_spec.rb
desc: YourClass
├──ctx: when the version is 0.1.0
├────it: has a version number
├────it: does something useful
├──ctx: when the version is 0.1.1
├────it: has a version number
├────it: does something useful
desc: Sample
desc: First describe
├─────ctx: First context
├───────it: should do something
├───────ctx: First nested context
├─────────it: should do something
├───────it_behaves_like: shared example
desc: Second describe
├─────ctx: Second context
├───────it: should do something else
```

```
$ rspec_tree ctx /path/to/your_spec.rb
desc: Sample
desc: First describe
├─────ctx: First context
├───────ctx: First nested context
desc: Second describe
├─────ctx: Second context
```

```
Expand Down
4 changes: 2 additions & 2 deletions lib/rspec_tree/tree.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ def example(*args, &_block)
end

def it(*args, &_block)
tree(args.first, "it")
tree(args.first, "it") if type == :all
end

def it_behaves_like(*args, &_block)
tree(args.first, "it_behaves_like")
tree(args.first, "it_behaves_like") if type == :all
end

def dash
Expand Down
51 changes: 36 additions & 15 deletions spec/rspec_tree_spec.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,45 @@
# frozen_string_literal: true

# rubocop:disable Metrics/BlockLength
RSpec.describe RspecTree do
let(:rspec_file) { File.read("spec/data/sample.rb") }

describe ".all" do
subject { RspecTree::Tree.new(rspec_file, :all).print }
describe "#print" do
subject { RspecTree::Tree.new(rspec_file, type).print }

it "prints all (describe, context, it, etc.)" do
expect { subject }.to output(<<~OUTPUT).to_stdout
desc: Sample
desc: First describe
├─────ctx: First context
├───────it: should do something
├───────ctx: First nested context
├─────────it: should do something
├───────it_behaves_like: shared example
desc: Second describe
├─────ctx: Second context
├───────it: should do something else
OUTPUT
context "when called with :all" do
let(:type) { :all }

it "prints all" do
expect { subject }.to output(<<~OUTPUT).to_stdout
desc: Sample
desc: First describe
├─────ctx: First context
├───────it: should do something
├───────ctx: First nested context
├─────────it: should do something
├───────it_behaves_like: shared example
desc: Second describe
├─────ctx: Second context
├───────it: should do something else
OUTPUT
end
end

context "when called with :ctx" do
let(:type) { :ctx }

it "prints only describe and context" do
expect { subject }.to output(<<~OUTPUT).to_stdout
desc: Sample
desc: First describe
├─────ctx: First context
├───────ctx: First nested context
desc: Second describe
├─────ctx: Second context
OUTPUT
end
end
end
end
# rubocop:enable Metrics/BlockLength

0 comments on commit 8c4e61d

Please sign in to comment.