mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
Fix tests
This commit is contained in:
parent
5599b0a976
commit
93e81d7209
1 changed files with 21 additions and 18 deletions
|
@ -114,6 +114,9 @@ describe Pry::Code do
|
|||
end
|
||||
|
||||
describe 'filters and formatters' do
|
||||
def raw(str)
|
||||
Pry::Helpers::Text.strip_color(str)
|
||||
end
|
||||
before do
|
||||
@code = Pry::Code(Pry::Helpers::CommandHelpers.unindent <<-STR)
|
||||
class MyProgram
|
||||
|
@ -129,8 +132,8 @@ describe Pry::Code do
|
|||
should 'work with an inclusive range' do
|
||||
@code = @code.between(1..3)
|
||||
@code.length.should == 3
|
||||
@code.should =~ /\Aclass MyProgram/
|
||||
@code.should =~ /world!'\Z/
|
||||
raw(@code).should =~ /\Aclass MyProgram/
|
||||
raw(@code).should =~ /world!'\Z/
|
||||
end
|
||||
|
||||
should 'default to an inclusive range' do
|
||||
|
@ -141,22 +144,22 @@ describe Pry::Code do
|
|||
should 'work with an exclusive range' do
|
||||
@code = @code.between(2...4)
|
||||
@code.length.should == 2
|
||||
@code.should =~ /\A def self/
|
||||
@code.should =~ /world!'\Z/
|
||||
raw(@code).should =~ /\A def self/
|
||||
raw(@code).should =~ /world!'\Z/
|
||||
end
|
||||
|
||||
should 'use real line numbers for positive indices' do
|
||||
@code = @code.after(3, 3)
|
||||
@code = @code.between(4, 4)
|
||||
@code.length.should == 1
|
||||
@code.should =~ /\A end\Z/
|
||||
raw(@code).should =~ /\A end\Z/
|
||||
end
|
||||
end
|
||||
|
||||
describe '#before' do
|
||||
should 'work' do
|
||||
@code = @code.before(3, 1)
|
||||
@code.should =~ /\A def self\.main\Z/
|
||||
raw(@code).should =~ /\A def self\.main\Z/
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -164,15 +167,15 @@ describe Pry::Code do
|
|||
should 'work' do
|
||||
@code = @code.around(3, 1)
|
||||
@code.length.should == 3
|
||||
@code.should =~ /\A def self/
|
||||
@code.should =~ / end\Z/
|
||||
raw(@code).should =~ /\A def self/
|
||||
raw(@code).should =~ / end\Z/
|
||||
end
|
||||
end
|
||||
|
||||
describe '#after' do
|
||||
should 'work' do
|
||||
@code = @code.after(3, 1)
|
||||
@code.should =~ /\A end\Z/
|
||||
raw(@code).should =~ /\A end\Z/
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -201,26 +204,26 @@ describe Pry::Code do
|
|||
describe '#with_marker' do
|
||||
should 'show a marker in the right place' do
|
||||
@code = @code.with_marker(2)
|
||||
@code.should =~ /^ => def self/
|
||||
raw(@code).should =~ /^ => def self/
|
||||
end
|
||||
|
||||
should 'disable the marker when falsy' do
|
||||
@code = @code.with_marker(2)
|
||||
@code = @code.with_marker(false)
|
||||
@code.should =~ /^ def self/
|
||||
raw(@code).should =~ /^ def self/
|
||||
end
|
||||
end
|
||||
|
||||
describe '#with_indentation' do
|
||||
should 'indent the text' do
|
||||
@code = @code.with_indentation(2)
|
||||
@code.should =~ /^ def self/
|
||||
raw(@code).should =~ /^ def self/
|
||||
end
|
||||
|
||||
should 'disable the indentation when falsy' do
|
||||
@code = @code.with_indentation(2)
|
||||
@code = @code.with_indentation(false)
|
||||
@code.should =~ /^ def self/
|
||||
raw(@code).should =~ /^ def self/
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -229,23 +232,23 @@ describe Pry::Code do
|
|||
describe 'grep and with_line_numbers' do
|
||||
should 'work' do
|
||||
@code = @code.grep(/end/).with_line_numbers
|
||||
@code.should =~ /\A4: end/
|
||||
@code.should =~ /5: end\Z/
|
||||
raw(@code).should =~ /\A4: end/
|
||||
raw(@code).should =~ /5: end\Z/
|
||||
end
|
||||
end
|
||||
|
||||
describe 'grep and before and with_line_numbers' do
|
||||
should 'work' do
|
||||
@code = @code.grep(/e/).before(5, 5).with_line_numbers
|
||||
@code.should =~ /\A2: def self.main\n3:/
|
||||
@code.should =~ /4: end\Z/
|
||||
raw(@code).should =~ /\A2: def self.main\n3:/
|
||||
raw(@code).should =~ /4: end\Z/
|
||||
end
|
||||
end
|
||||
|
||||
describe 'before and after' do
|
||||
should 'work' do
|
||||
@code = @code.before(4, 2).after(2)
|
||||
@code.should == " puts 'Hello, world!'"
|
||||
raw(@code).should == " puts 'Hello, world!'\n"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue