Skip to content

Commit

Permalink
Simplify tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nunosilva800 committed Feb 5, 2024
1 parent da4e249 commit ff5cfb5
Showing 1 changed file with 54 additions and 41 deletions.
95 changes: 54 additions & 41 deletions test/irb/test_tracer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,79 +6,92 @@
require_relative "helper"

module TestIRB
class ContextWithTracerTest < TestCase
class ContextWithTracerIntegrationTest < IntegrationTestCase
def setup
IRB.init_config(nil)
IRB.conf[:VERBOSE] = false
super

@envs.merge!("NO_COLOR" => "true", "RUBY_DEBUG_HISTORY_FILE" => '')
end

def example_ruby_file
<<~'RUBY'
class Foo
def self.foo
100
end
end
def bar(obj)
obj.foo
end
binding.irb
RUBY
end

def test_use_tracer_is_disabled_by_default
IRB.conf[:USE_TRACER] = false
workspace = IRB::WorkSpace.new(Object.new)
irb = IRB::Irb.new(workspace, TestInputMethod.new)
# Context still needs this setter to be defined
assert irb.context.respond_to?(:use_tracer=)
write_rc <<~RUBY
IRB.conf[:USE_TRACER] = false
RUBY

write_ruby example_ruby_file

output = run_ruby_file do
type "bar(Foo)"
type "exit!"
end

assert_nil IRB.conf[:USER_TRACER]
assert_not_include(output, "#depth:")
assert_not_include(output, "Foo.foo")
end

def test_use_tracer_when_gem_is_unavailable
IRB.conf[:USE_TRACER] = true
def test_use_tracer_enabled_when_gem_is_unavailable
begin
gem 'tracer'
omit "Skipping test_use_tracer_when_gem_is_unavailable because 'tracer' gem is available."
omit "Skipping because 'tracer' gem is available."
rescue Gem::LoadError
workspace = IRB::WorkSpace.new(Object.new)
out, err = capture_output do
irb = IRB::Irb.new(workspace, TestInputMethod.new)
irb.eval_input
assert irb.context.respond_to?(:use_tracer=)
write_rc <<~RUBY
IRB.conf[:USE_TRACER] = true
RUBY

write_ruby example_ruby_file

output = run_ruby_file do
type "bar(Foo)"
type "exit!"
end
assert_equal "Tracer extension of IRB is enabled but tracer gem wasn't found.\n", err
assert_empty out

assert_include(output, "Tracer extension of IRB is enabled but tracer gem wasn't found.")
end
end
end

class ContextWithTracerIntegrationTest < IntegrationTestCase
def setup
super

def test_use_tracer_enabled_when_gem_is_available
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.1.0')
omit "Ruby version before 3.1.0 does not support Tracer integration. Skipping this test."
end

begin
gem 'tracer'
rescue Gem::LoadError
omit "Skipping ContextWithTracerIntegrationTest because 'tracer' gem is not available. Enable with WITH_TRACER=true."
omit "Skipping because 'tracer' gem is not available. Enable with WITH_TRACER=true."
end
end

def test_use_tracer_cmd_trace_call
write_rc <<~RUBY
IRB.conf[:USE_TRACER] = true
RUBY

write_ruby <<~'RUBY'
class Foo
def self.foo
100
end
end
def bar(obj)
obj.foo
end
binding.irb
RUBY
write_ruby example_ruby_file

output = run_ruby_file do
type "bar(Foo)"
type "exit!"
end

assert_include(output, "#depth:")
assert_include(output, "Foo.foo")
assert_include(output, "Object#bar at")
assert_include(output, "Foo.foo at")
assert_include(output, "Foo.foo #=> 100")
assert_include(output, "Object#bar #=> 100")
end
end
end

0 comments on commit ff5cfb5

Please sign in to comment.