1
0
Fork 0
mirror of https://github.com/awesome-print/awesome_print synced 2023-03-27 23:22:34 -04:00

Added split expects for testing ruby 2.7 or earlier

This commit is contained in:
Bryan Hanks, PMP 2021-01-24 19:06:19 -06:00
parent 4b5fae1d18
commit 6e6b0d3085
3 changed files with 41 additions and 15 deletions

View file

@ -26,7 +26,6 @@ gemfile:
jobs:
allow_failures:
- rvm: 2.7
- rvm: ruby-head
include:
- rvm: 2.6

View file

@ -68,16 +68,20 @@ RSpec.describe 'Single method' do
def world; end
end
method = Hello.instance_method(:world)
if RUBY_VERSION >= '2.7'
expect(method.ai(plain: true)).to eq('Hello#world () /Users/bryanhanks/projects/3rd_party/awesome_print/spec/methods_spec (unbound)#world()')
else
expect(method.ai(plain: true)).to eq('Hello (unbound)#world()')
end
end
it 'color: should handle an unbound method' do
class Hello
def world(a, b); end
end
method = Hello.instance_method(:world)
if RUBY_VERSION < '1.9.2'
expect(method.ai).to eq("\e[1;33mHello (unbound)\e[0m#\e[0;35mworld\e[0m\e[0;37m(arg1, arg2)\e[0m")
if RUBY_VERSION >= '2.7'
expect(method.ai).to eq("\e[1;33mHello#world (a, b) (unbound)\e[0m#\e[0;35mworld\e[0m\e[0;37m(a, b)\e[0m")
else
expect(method.ai).to eq("\e[1;33mHello (unbound)\e[0m#\e[0;35mworld\e[0m\e[0;37m(a, b)\e[0m")
end
@ -92,19 +96,31 @@ RSpec.describe 'Object methods' do
describe 'object.methods' do
it 'index: should handle object.methods' do
out = nil.methods.ai(plain: true).split("\n").grep(/is_a\?/).first
if RUBY_VERSION >= '2.7'
expect(out).to match(/^\s+\[\s*\d+\]\s+is_a\?\(arg1\)\s+NilClass \(Kernel\)$/)
else
expect(out).to match(/^\s+\[\s*\d+\]\s+is_a\?\(arg1\)\s+NilClass \(Kernel\)$/)
end
end
it 'no index: should handle object.methods' do
out = nil.methods.ai(plain: true, index: false).split("\n").grep(/is_a\?/).first
if RUBY_VERSION >= '2.7'
expect(out).to match(/^\s+is_a\?\(arg1\)\s+NilClass \(Kernel\)$/)
else
expect(out).to match(/^\s+is_a\?\(arg1\)\s+NilClass \(Kernel\)$/)
end
end
end
describe 'object.public_methods' do
it 'index: should handle object.public_methods' do
out = nil.public_methods.ai(plain: true).split("\n").grep(/is_a\?/).first
if RUBY_VERSION >= '2.7'
expect(out).to match(/^\s+\[\s*\d+\]\s+is_a\?\(arg1\)\s+NilClass \(Kernel\)$/)
else
expect(out).to match(/^\s+\[\s*\d+\]\s+is_a\?\(arg1\)\s+NilClass \(Kernel\)$/)
end
end
it 'no index: should handle object.public_methods' do
@ -132,8 +148,12 @@ RSpec.describe 'Object methods' do
def m1; end
def m2; end
end
if RUBY_VERSION < '1.9.2'
expect(Hello.new.protected_methods.ai(plain: true)).to eq("[\n [0] m1() Hello#m1 ()\n [1] m2() Hello#m2 ()\n]")
else
expect(Hello.new.protected_methods.ai(plain: true)).to eq("[\n [0] m1() Hello\n [1] m2() Hello\n]")
end
end
it 'no index: should handle object.protected_methods' do
class Hello
@ -398,8 +418,12 @@ RSpec.describe 'Methods arrays' do
out = Hello.methods.grep(/^m1$/).ai(plain: true)
expect(out).to eq("[\n [0] m1() Hello\n]")
out = Hello.methods.grep(/^m\d$/).ai(plain: true)
if RUBY_VERSION >= '2.7'
expect(out).to eq("[\n [0] m1() Hello.m1 ()\n [1] m2() Hello.m2 ()\n [2] m3() Hello.m3 ()\n]")
else
expect(out).to eq("[\n [0] m1() Hello\n [1] m2() Hello\n [2] m3() Hello\n]")
end
end
it 'obj1.methods.grep(pattern, &block) should pass the matching string within the block' do
class Hello
@ -421,8 +445,12 @@ RSpec.describe 'Methods arrays' do
end
out = Hello.methods.grep(/^m(\d)$/) { %w(none one)[$1.to_i] }.ai(plain: true)
if RUBY_VERSION >= '2.7'
expect(out).to eq("[\n [0] none() Hello.none ()\n [1] one() Hello.none ()\n]")
else
expect(out).to eq("[\n [0] none() Hello\n [1] one() Hello\n]")
end
end
# See https://github.com/awesome-print/awesome_print/issues/30 for details.
it 'grepping methods and converting them to_sym should work as expected' do

View file

@ -18,8 +18,8 @@
# require 'simplecov'
# SimpleCov.start
$LOAD_PATH.unshift(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
## $LOAD_PATH.unshift(File.dirname(__FILE__))
## $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
Dir[File.dirname(__FILE__) + '/support/**/*.rb'].each do |file|
require file
@ -44,8 +44,7 @@ RSpec.configure do |config|
# TODO: Make specs not order dependent
# config.order = :random
Kernel.srand config.seed
config.filter_run focus: true
config.run_all_when_everything_filtered = true
config.filter_run_when_matching focus: true
config.expect_with :rspec do |expectations|
expectations.syntax = :expect
end
@ -54,7 +53,7 @@ RSpec.configure do |config|
mocks.verify_partial_doubles = true
end
config.default_formatter = 'doc' if config.files_to_run.one?
#TODO - what is this? config.default_formatter = 'doc' if config.files_to_run.one?
# Run before all examples. Using suite or all will not work as stubs are
# killed after each example ends.