Skip to content

Commit

Permalink
+ Include class name in spec name. (thomasmarshall)
Browse files Browse the repository at this point in the history
Not a normal scenario, since normally it is `describe` all the way
down, but if you happen to have your specs embedded in a class, this
will add the top level class name to your spec name.

eg:

```ruby
class Foo < Minitest::Spec
  it "a"
  describe "b" do
    it "c"
  end
end
```

[git-p4: depot-paths = "//src/minitest/dev/": change = 14348]
  • Loading branch information
zenspider committed Nov 21, 2024
1 parent b3cab87 commit 3d54995
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/minitest/spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def describe desc, *additional_desc, &block # :doc:
stack = Minitest::Spec.describe_stack
is_spec_class = Class === self && kind_of?(Minitest::Spec::DSL)
name = [stack.last, desc, *additional_desc]
name.prepend self if stack.empty? && is_spec_class
sclas =
stack.last \
|| (is_spec_class && self) \
Expand Down
17 changes: 17 additions & 0 deletions test/minitest/test_minitest_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,23 @@ def test_name2
assert_equal "ExampleB::random_method", spec_b.name
end

def test_name_inside_class
spec_a = nil
spec_b = nil
inside_class_example = Class.new Minitest::Spec
Object.const_set :InsideClassExample, inside_class_example
inside_class_example.class_eval do
spec_a = describe "a" do
spec_b = describe "b" do; end
end
end

assert_equal "InsideClassExample::a", spec_a.name
assert_equal "InsideClassExample::a::b", spec_b.name
ensure
Object.send :remove_const, :InsideClassExample
end

def test_structure
x, y, z, * = util_structure

Expand Down

0 comments on commit 3d54995

Please sign in to comment.