Skip to content

Commit 7ce4e15

Browse files
authored
fix(ruby): Use string_content capture for Ruby test name extraction (#229)
Given this Ruby file: ```ruby require "test_helper" class CategoryTest < ActiveSupport::TestCase context "validations" do should validate_presence_of(:name) should validate_length_of(:name).is_at_most(255) should validate_uniqueness_of(:name) should validate_presence_of(:slug) should validate_length_of(:slug).is_at_most(255) should validate_uniqueness_of(:slug) end end ``` Attempting to run test called `"validations"` results in the following output: ``` # Running: ...... Finished in 0.196336s, 30.5599 runs/s, 30.5599 assertions/s. 6 runs, 6 assertions, 0 failures, 0 errors, 0 skips ⏵ Task `test test/models/category_test.rb -n ""validations""` finished successfully ⏵ Command: /opt/homebrew/bin/fish -i -c 'bin/rails' ``` With this fix: ``` # Running: ...... Finished in 0.212972s, 28.1727 runs/s, 28.1727 assertions/s. 6 runs, 6 assertions, 0 failures, 0 errors, 0 skips ⏵ Task `test test/models/category_test.rb -n "validations"` finished successfully ⏵ Command: /opt/homebrew/bin/fish -i -c 'bin/rails' ``` No changes but capturing the test name as a string without quotes gives more control over tests that, for example, use regular expressions in their names. Closes #222
1 parent 07b1c95 commit 7ce4e15

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

languages/ruby/runnables.scm

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,14 @@
3838
; Examples
3939
((call
4040
method: (identifier) @run
41-
(#any-of? @run "describe" "context" "it" "its" "specify" "example" "feature" "scenario" "fdescribe" "fcontext" "fit" "fexample" "focus" "it_behaves_like" "it_should_behave_like" "include_context" "include_examples")
41+
(#any-of? @run
42+
"describe" "context" "it" "its" "specify" "example" "feature" "scenario" "fdescribe" "fcontext"
43+
"fit" "fexample" "focus" "it_behaves_like" "it_should_behave_like" "include_context"
44+
"include_examples")
4245
arguments: (argument_list
4346
.
44-
(_) @name @RUBY_TEST_NAME)) @_ruby-test
47+
(_
48+
(string_content) @name @RUBY_TEST_NAME))) @_ruby-test
4549
(#set! tag ruby-test))
4650

4751
; Examples (one-liner syntax)

0 commit comments

Comments
 (0)