-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change show_source tests into integration tests (#793)
* Remove trailing spaces * Migrate show_source tests to integration tests Because show_source tests often need to define class and/or methods, they can easily leak state to other tests. Changing them to integration tests will ensure that they are run in a clean environment. * Fix NoMethodError caused by SourceFinder#method_target
- Loading branch information
Showing
3 changed files
with
265 additions
and
228 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,263 @@ | ||
# frozen_string_literal: false | ||
require 'irb' | ||
|
||
require_relative "../helper" | ||
|
||
module TestIRB | ||
class ShowSourceTest < IntegrationTestCase | ||
def setup | ||
super | ||
|
||
write_rc <<~'RUBY' | ||
IRB.conf[:USE_PAGER] = false | ||
RUBY | ||
end | ||
|
||
def test_show_source | ||
write_ruby <<~'RUBY' | ||
binding.irb | ||
RUBY | ||
|
||
out = run_ruby_file do | ||
type "show_source IRB.conf" | ||
type "exit" | ||
end | ||
|
||
assert_match(%r[/irb\/init\.rb], out) | ||
end | ||
|
||
def test_show_source_alias | ||
write_ruby <<~'RUBY' | ||
binding.irb | ||
RUBY | ||
|
||
out = run_ruby_file do | ||
type "$ IRB.conf" | ||
type "exit" | ||
end | ||
|
||
assert_match(%r[/irb\/init\.rb], out) | ||
end | ||
|
||
def test_show_source_string | ||
write_ruby <<~'RUBY' | ||
binding.irb | ||
RUBY | ||
|
||
out = run_ruby_file do | ||
type "show_source 'IRB.conf'" | ||
type "exit" | ||
end | ||
|
||
assert_match(%r[/irb\/init\.rb], out) | ||
end | ||
|
||
def test_show_source_method_s | ||
write_ruby <<~RUBY | ||
class Baz | ||
def foo | ||
end | ||
end | ||
class Bar < Baz | ||
def foo | ||
super | ||
end | ||
end | ||
binding.irb | ||
RUBY | ||
|
||
out = run_ruby_file do | ||
type "show_source Bar#foo -s" | ||
type "exit" | ||
end | ||
|
||
assert_match(%r[#{@ruby_file.to_path}:2\s+def foo\r\n end\r\n], out) | ||
end | ||
|
||
def test_show_source_method_s_with_incorrect_signature | ||
write_ruby <<~RUBY | ||
class Baz | ||
def foo | ||
end | ||
end | ||
class Bar < Baz | ||
def foo | ||
super | ||
end | ||
end | ||
binding.irb | ||
RUBY | ||
|
||
out = run_ruby_file do | ||
type "show_source Bar#fooo -s" | ||
type "exit" | ||
end | ||
|
||
assert_match(%r[Error: Couldn't locate a super definition for Bar#fooo], out) | ||
end | ||
|
||
def test_show_source_private_method | ||
write_ruby <<~RUBY | ||
class Bar | ||
private def foo | ||
end | ||
end | ||
binding.irb | ||
RUBY | ||
|
||
out = run_ruby_file do | ||
type "show_source Bar#foo" | ||
type "exit" | ||
end | ||
|
||
assert_match(%r[#{@ruby_file.to_path}:2\s+private def foo\r\n end\r\n], out) | ||
end | ||
|
||
def test_show_source_private_singleton_method | ||
write_ruby <<~RUBY | ||
class Bar | ||
private def foo | ||
end | ||
end | ||
binding.irb | ||
RUBY | ||
|
||
out = run_ruby_file do | ||
type "bar = Bar.new" | ||
type "show_source bar.foo" | ||
type "exit" | ||
end | ||
|
||
assert_match(%r[#{@ruby_file.to_path}:2\s+private def foo\r\n end\r\n], out) | ||
end | ||
|
||
def test_show_source_method_multiple_s | ||
write_ruby <<~RUBY | ||
class Baz | ||
def foo | ||
end | ||
end | ||
class Bar < Baz | ||
def foo | ||
super | ||
end | ||
end | ||
class Bob < Bar | ||
def foo | ||
super | ||
end | ||
end | ||
binding.irb | ||
RUBY | ||
|
||
out = run_ruby_file do | ||
type "show_source Bob#foo -ss" | ||
type "exit" | ||
end | ||
|
||
assert_match(%r[#{@ruby_file.to_path}:2\s+def foo\r\n end\r\n], out) | ||
end | ||
|
||
def test_show_source_method_no_instance_method | ||
write_ruby <<~RUBY | ||
class Baz | ||
end | ||
class Bar < Baz | ||
def foo | ||
super | ||
end | ||
end | ||
binding.irb | ||
RUBY | ||
|
||
out = run_ruby_file do | ||
type "show_source Bar#foo -s" | ||
type "exit" | ||
end | ||
|
||
assert_match(%r[Error: Couldn't locate a super definition for Bar#foo], out) | ||
end | ||
|
||
def test_show_source_method_exceeds_super_chain | ||
write_ruby <<~RUBY | ||
class Baz | ||
def foo | ||
end | ||
end | ||
class Bar < Baz | ||
def foo | ||
super | ||
end | ||
end | ||
binding.irb | ||
RUBY | ||
|
||
out = run_ruby_file do | ||
type "show_source Bar#foo -ss" | ||
type "exit" | ||
end | ||
|
||
assert_match(%r[Error: Couldn't locate a super definition for Bar#foo], out) | ||
end | ||
|
||
def test_show_source_method_accidental_characters | ||
write_ruby <<~'RUBY' | ||
class Baz | ||
def foo | ||
end | ||
end | ||
class Bar < Baz | ||
def foo | ||
super | ||
end | ||
end | ||
binding.irb | ||
RUBY | ||
|
||
out = run_ruby_file do | ||
type "show_source Bar#foo -sddddd" | ||
type "exit" | ||
end | ||
|
||
assert_match(%r[#{@ruby_file.to_path}:2\s+def foo\r\n end], out) | ||
end | ||
|
||
def test_show_source_receiver_super | ||
write_ruby <<~RUBY | ||
class Baz | ||
def foo | ||
end | ||
end | ||
class Bar < Baz | ||
def foo | ||
super | ||
end | ||
end | ||
binding.irb | ||
RUBY | ||
|
||
out = run_ruby_file do | ||
type "bar = Bar.new" | ||
type "show_source bar.foo -s" | ||
type "exit" | ||
end | ||
|
||
assert_match(%r[#{@ruby_file.to_path}:2\s+def foo\r\n end], out) | ||
end | ||
end | ||
end |
Oops, something went wrong.