Skip to content

Commit

Permalink
Merge pull request #7 from sasamuku/fix_namespace
Browse files Browse the repository at this point in the history
fix namespace
  • Loading branch information
sasamuku authored Mar 19, 2024
2 parents d579d1d + 9ff703d commit 1ebbdda
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
10 changes: 9 additions & 1 deletion lib/rspec_tree/tree.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ class Tree
attr_reader :file, :type
attr_accessor :base_depth

PATTERN = /[A-Z][a-zA-Z]*::[A-Z][a-zA-Z]*/.freeze

def initialize(file, type)
@file = file
@file = const_to_string(file)
@type = type
@base_depth = 0
end
Expand Down Expand Up @@ -51,5 +53,11 @@ def dash
def tree(arg, name)
puts "├#{dash}#{name}: #{arg}"
end

def const_to_string(str)
str.gsub(PATTERN) do |match|
"'#{match}'"
end
end
end
end
7 changes: 5 additions & 2 deletions spec/data/sample.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
# This file is sample RSpec for test.

require "sample"
require "sample/example"
require_relative "sample/example"

RSpec.describe Sample::SampleClass do # rubocop:disable Metrics/BlockLength
include ExampleModule
include Example::SampleModule

RSpec.describe Sample do # rubocop:disable Metrics/BlockLength
let(:foo) { "foo" }

before do
Expand Down
4 changes: 2 additions & 2 deletions spec/rspec_tree_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

it "prints all" do
expect { subject }.to output(<<~OUTPUT).to_stdout
desc: Sample
desc: Sample::SampleClass
desc: First describe
├─────ctx: First context
├───────it: should do something
Expand All @@ -31,7 +31,7 @@

it "prints only describe and context" do
expect { subject }.to output(<<~OUTPUT).to_stdout
desc: Sample
desc: Sample::SampleClass
desc: First describe
├─────ctx: First context
├───────ctx: First nested context
Expand Down

0 comments on commit 1ebbdda

Please sign in to comment.