Skip to content

Commit d33baa7

Browse files
committed
Fix global Proc leak, add CI, and minor cleanups
Remove Proc.send :include that leaked methods globally by inlining _test_pass/_test_fail to avoid send (which ignores refinements). Add GitHub Actions CI for ruby head, 4.0.2, 3.4, truffleruby, jruby. Fix typo (lamdba), use $stderr, HTTPS homepage, drop deprecated test_files.
1 parent a3e12be commit d33baa7

4 files changed

Lines changed: 33 additions & 13 deletions

File tree

.github/workflows/test.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
branches: [master]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
ruby: ['head', '4.0.2', '3.4', 'truffleruby', 'jruby']
16+
steps:
17+
- uses: actions/checkout@v4
18+
- uses: ruby/setup-ruby@v1
19+
with:
20+
ruby-version: ${{ matrix.ruby }}
21+
bundler-cache: true
22+
- run: bundle exec rake test

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Dependencies
2222
------------
2323

2424
- Ruby 2.1 or higher (tested on Ruby 3.4 and 4.0.2)
25-
- minitest/spec (part of MRI 1.9+ standard library)
25+
- minitest/spec
2626

2727
Example
2828
-------

lib/testrocket.rb

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,27 @@ module TestRocket
99
extend Module.new { attr_accessor :out }
1010

1111
refine Proc do
12-
# Include TestRocket methods WITHOUT implementation selected
13-
Proc.send :include, TestRocket
14-
1512
# If we're in a production environment, the tests shall do nothing.
1613
if ENV['RACK_ENV'] == 'production' ||
1714
(defined?(Rails) && Rails.env.production?) ||
1815
ENV['RAILS_ENV'] == 'production'
19-
def _test(a, b); end
16+
def _test_pass; end
17+
def _test_fail; end
2018
def _show(r); end
2119
def _pend; end
2220
def _desc; end
2321
else
24-
def _test(a, b); send((call rescue()) ? a : b) end
25-
def _show(r); (TestRocket.out || STDERR) << r + "\n"; r end
22+
def _test_pass; (call rescue()) ? _pass : _fail end
23+
def _test_fail; (call rescue()) ? _fail : _pass end
24+
def _show(r); (TestRocket.out || $stderr) << r + "\n"; r end
2625
def _pass; ' OK' end
2726
def _fail; " FAIL @ #{source_location * ':'}" end
2827
def _pend; "PENDING '#{call}' @ #{source_location * ':'}" end
2928
def _desc; " FIRE '#{call}'!" end
3029
end
3130

32-
def +@; _show _test :_pass, :_fail end
33-
def -@; _show _test :_fail, :_pass end
31+
def +@; _show _test_pass end
32+
def -@; _show _test_fail end
3433
def ~; _show _pend end
3534
def !; _show _desc end
3635
end

testrocket.gemspec

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@ Gem::Specification.new do |s|
77
s.platform = Gem::Platform::RUBY
88
s.authors = ['Peter Cooper', 'Christoph Grabo']
99
s.email = %w[git@peterc.org chris@dinarrr.com]
10-
s.homepage = 'http://github.com/peterc/testrocket'
11-
s.summary = %q{A super lightweight lamdba-based testing library for Ruby}
12-
s.description = %q{A super lightweight lamdba-based testing library for Ruby}
10+
s.homepage = 'https://github.com/peterc/testrocket'
11+
s.summary = %q{A super lightweight lambda-based testing library for Ruby}
12+
s.description = %q{A super lightweight lambda-based testing library for Ruby}
1313
s.license = 'MIT'
1414
s.required_ruby_version = '>= 2.1'
1515

1616
s.files = Dir.glob('{lib,test}/**/*') + %w[README.md LICENSE Gemfile testrocket.gemspec]
17-
s.test_files = Dir.glob('test/**/*')
1817
s.executables = Dir.glob('bin/*').map { |f| File.basename(f) }
1918
s.require_paths = ['lib']
2019

0 commit comments

Comments
 (0)