Skip to content

Commit

Permalink
Ruby 3.2 fix: remove File.exists? usage (#243)
Browse files Browse the repository at this point in the history
* CI: add Ruby 3.0, 3.1, and 3.2 to the test matrix

* CI: update actions to latest released versions

* CI: use ruby/setup-ruby action to install gems

This provides caching between builds, so should speed up the build.

* Resolve File.exists? deprecation

* Resolve Fixnum deprecation

* Resolve syntax error: invalid yield
  • Loading branch information
orien authored Feb 9, 2023
1 parent 55e5f2a commit 0946544
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 16 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ruby: [2.4, 2.5, 2.6, 2.7, jruby]
ruby: [2.4, 2.5, 2.6, 2.7, "3.0", 3.1, 3.2, jruby]
fail-fast: false
steps:
- uses: actions/checkout@v2.0.0
- uses: actions/checkout@v3
with:
fetch-depth: 1
- uses: ruby/setup-ruby@master
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
- run: bundle install --jobs 4 --retry 3
name: Install Ruby deps
bundler-cache: true
- run: bundle exec rake
2 changes: 1 addition & 1 deletion features/steps/automatic_feature_generation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class AutomaticFeatureGeneration < Spinach::FeatureSteps
Then 'I a feature should exist named "features/steps/cheezburger_can_i_has.rb"' do
in_current_dir do
@file = 'features/steps/cheezburger_can_i_has.rb'
File.exists?(@file).must_equal true
File.exist?(@file).must_equal true
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/spinach/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def feature_files

@args.each do |arg|
if arg.match(/\.feature/)
if File.exists? arg.gsub(/:\d*/, '')
if File.exist? arg.gsub(/:\d*/, '')
files_to_run << arg
else
fail! "#{arg} could not be found"
Expand Down
10 changes: 5 additions & 5 deletions test/spinach/cli_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -276,14 +276,14 @@
describe 'the feature really exists' do
it 'runs the feature' do
cli = Spinach::Cli.new(['features/some_feature.feature'])
File.stubs(:exists?).returns(true)
File.stubs(:exist?).returns(true)
cli.feature_files.must_equal ['features/some_feature.feature']
end
end

it 'it fails if the feature does not exist' do
cli = Spinach::Cli.new(['features/some_feature.feature'])
File.stubs(:exists?).returns(false)
File.stubs(:exist?).returns(false)
cli.expects(:fail!).with('features/some_feature.feature could not be found')

cli.feature_files
Expand All @@ -293,7 +293,7 @@
describe 'when a particular feature list is passed with line' do
it 'returns the feature with the line number' do
cli = Spinach::Cli.new(['features/some_feature.feature:10'])
File.stubs(:exists?).returns(true)
File.stubs(:exist?).returns(true)

cli.feature_files.must_equal ['features/some_feature.feature:10']
end
Expand All @@ -302,7 +302,7 @@
describe "when a particular feature list is passed with multiple lines" do
it "returns the feature with the line numbers" do
cli = Spinach::Cli.new(['features/some_feature.feature:10:20'])
File.stubs(:exists?).returns(true)
File.stubs(:exist?).returns(true)

cli.feature_files.must_equal ["features/some_feature.feature:10:20"]
end
Expand Down Expand Up @@ -337,7 +337,7 @@
Dir.expects(:glob).with('path/to/features/**/*.feature')
.returns(['several features'])

File.stubs(:exists?).returns(true)
File.stubs(:exist?).returns(true)

cli.feature_files.must_equal ['several features', 'some_feature.feature']
end
Expand Down
2 changes: 1 addition & 1 deletion test/spinach/dsl_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def before_each
end

@feature.new.step_location_for('I say goodbye').first.must_include '/dsl_test.rb'
@feature.new.step_location_for('I say goodbye').last.must_be_kind_of Fixnum
@feature.new.step_location_for('I say goodbye').last.must_be_kind_of Integer
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/spinach/generators/feature_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ module Spinach::Generators
in_current_dir do
subject.store
File.directory?("features/steps/").must_equal true
File.exists?("features/steps/cheezburger_can_i_has.rb").must_equal true
File.exist?("features/steps/cheezburger_can_i_has.rb").must_equal true
File.read("features/steps/cheezburger_can_i_has.rb").strip.must_equal(
subject.generate.strip
)
Expand Down
4 changes: 2 additions & 2 deletions test/spinach/reporter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ module Spinach

it "binds a callback around every scenario" do
@reporter.expects(:around_scenario_run)
Spinach.hooks.run_around_scenario(anything) do
yield
Spinach.hooks.run_around_scenario(anything) do |&block|
block.call
end
end

Expand Down

0 comments on commit 0946544

Please sign in to comment.