@@ -10,7 +10,9 @@ class ContextWithTracerIntegrationTest < IntegrationTestCase
10
10
def setup
11
11
super
12
12
13
- @envs . merge! ( "NO_COLOR" => "true" , "RUBY_DEBUG_HISTORY_FILE" => '' )
13
+ omit "Tracer gem is not available when running on TruffleRuby" if RUBY_ENGINE == "truffleruby"
14
+
15
+ @envs . merge! ( "NO_COLOR" => "true" )
14
16
end
15
17
16
18
def example_ruby_file
@@ -29,54 +31,30 @@ def bar(obj)
29
31
RUBY
30
32
end
31
33
32
- def test_use_tracer_is_disabled_by_default
34
+ def test_use_tracer_enabled_when_gem_is_unavailable
33
35
write_rc <<~RUBY
34
- IRB.conf[:USE_TRACER] = false
36
+ # Simulate the absence of the tracer gem
37
+ ::Kernel.send(:alias_method, :irb_original_require, :require)
38
+
39
+ ::Kernel.define_method(:require) do |name|
40
+ raise LoadError, "cannot load such file -- tracer (test)" if name.match?("tracer")
41
+ ::Kernel.send(:irb_original_require, name)
42
+ end
43
+
44
+ IRB.conf[:USE_TRACER] = true
35
45
RUBY
36
46
37
47
write_ruby example_ruby_file
38
48
39
49
output = run_ruby_file do
40
50
type "bar(Foo)"
41
- type "exit! "
51
+ type "exit"
42
52
end
43
53
44
- assert_nil IRB . conf [ :USER_TRACER ]
45
- assert_not_include ( output , "#depth:" )
46
- assert_not_include ( output , "Foo.foo" )
47
- end
48
-
49
- def test_use_tracer_enabled_when_gem_is_unavailable
50
- begin
51
- gem 'tracer'
52
- omit "Skipping because 'tracer' gem is available."
53
- rescue Gem ::LoadError
54
- write_rc <<~RUBY
55
- IRB.conf[:USE_TRACER] = true
56
- RUBY
57
-
58
- write_ruby example_ruby_file
59
-
60
- output = run_ruby_file do
61
- type "bar(Foo)"
62
- type "exit!"
63
- end
64
-
65
- assert_include ( output , "Tracer extension of IRB is enabled but tracer gem wasn't found." )
66
- end
54
+ assert_include ( output , "Tracer extension of IRB is enabled but tracer gem wasn't found." )
67
55
end
68
56
69
57
def test_use_tracer_enabled_when_gem_is_available
70
- if Gem ::Version . new ( RUBY_VERSION ) < Gem ::Version . new ( '3.1.0' )
71
- omit "Ruby version before 3.1.0 does not support Tracer integration. Skipping this test."
72
- end
73
-
74
- begin
75
- gem 'tracer'
76
- rescue Gem ::LoadError
77
- omit "Skipping because 'tracer' gem is not available. Enable with WITH_TRACER=true."
78
- end
79
-
80
58
write_rc <<~RUBY
81
59
IRB.conf[:USE_TRACER] = true
82
60
RUBY
@@ -85,13 +63,29 @@ def test_use_tracer_enabled_when_gem_is_available
85
63
86
64
output = run_ruby_file do
87
65
type "bar(Foo)"
88
- type "exit! "
66
+ type "exit"
89
67
end
90
68
91
69
assert_include ( output , "Object#bar at" )
92
70
assert_include ( output , "Foo.foo at" )
93
71
assert_include ( output , "Foo.foo #=> 100" )
94
72
assert_include ( output , "Object#bar #=> 100" )
73
+
74
+ # Test that the tracer output does not include IRB's own files
75
+ assert_not_include ( output , "irb/workspace.rb" )
76
+ end
77
+
78
+ def test_use_tracer_is_disabled_by_default
79
+ write_ruby example_ruby_file
80
+
81
+ output = run_ruby_file do
82
+ type "bar(Foo)"
83
+ type "exit"
84
+ end
85
+
86
+ assert_not_include ( output , "#depth:" )
87
+ assert_not_include ( output , "Foo.foo" )
95
88
end
89
+
96
90
end
97
91
end
0 commit comments