From d814fe2542e5884978a67c2ddf4c42d35096c510 Mon Sep 17 00:00:00 2001 From: sasamuku Date: Sun, 17 Mar 2024 12:26:43 +0900 Subject: [PATCH 1/2] add ctx type --- lib/rspec_tree/tree.rb | 4 ++-- spec/rspec_tree_spec.rb | 51 +++++++++++++++++++++++++++++------------ 2 files changed, 38 insertions(+), 17 deletions(-) diff --git a/lib/rspec_tree/tree.rb b/lib/rspec_tree/tree.rb index 652d5fb..459b228 100644 --- a/lib/rspec_tree/tree.rb +++ b/lib/rspec_tree/tree.rb @@ -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 diff --git a/spec/rspec_tree_spec.rb b/spec/rspec_tree_spec.rb index 4ca4fc2..895a101 100644 --- a/spec/rspec_tree_spec.rb +++ b/spec/rspec_tree_spec.rb @@ -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 From b2f16205a6fefc9ae101a445a3808b9019f6dbea Mon Sep 17 00:00:00 2001 From: sasamuku Date: Sun, 17 Mar 2024 12:28:44 +0900 Subject: [PATCH 2/2] fix readme --- README.md | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 0033522..0fe2d86 100644 --- a/README.md +++ b/README.md @@ -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 ``` ```