Skip to content

Commit

Permalink
[fastlane_core] add support to Ruby 3.3 (fastlane#21683)
Browse files Browse the repository at this point in the history
* Relax regular expression that captures compilation error to be compatible with ruby 3.3

* Relax regular expression that captures compilation error to be compatible with ruby 3.3

* Change the way we build the test and its expected results to accomodate for internal changes in ruby 3.3 evaluation of __FILE__ within the eval() call

* Update fastlane/spec/plugins_specs/plugin_generator_spec.rb

Co-authored-by: Roger Oba <rogerluan.oba@gmail.com>

---------

Co-authored-by: Roger Oba <rogerluan.oba@gmail.com>
  • Loading branch information
2 people authored and SubhrajyotiSen committed Jan 17, 2024
1 parent 2937b1f commit 3337c4f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions fastlane/spec/plugins_specs/plugin_generator_spec.rb
Expand Up @@ -111,7 +111,9 @@
end

it "creates a plugin.rb file for the plugin" do
plugin_rb_file = File.join(tmp_dir, gem_name, 'lib', 'fastlane', 'plugin', "#{plugin_name}.rb")
relative_path = File.join('lib', 'fastlane', 'plugin', "#{plugin_name}.rb")
plugin_rb_file = File.join(tmp_dir, gem_name, relative_path)

expect(File.exist?(plugin_rb_file)).to be(true)

plugin_rb_contents = File.read(plugin_rb_file)
Expand All @@ -122,7 +124,10 @@
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)

# rubocop:disable Security/Eval
eval(plugin_rb_contents)
# Starting with Ruby 3.3, we must pass the __FILE__ of the actual file location for the all_class method implementation to work.
# Also, we expand the relative_path within Dir.chdir, as Dir.chdir on macOS will make it so tmp paths will always be under /private,
# while expand_path called from outside of Dir.chdir will not be prefixed by /private
eval(plugin_rb_contents, binding, File.expand_path(relative_path), __LINE__)
# rubocop:enable Security/Eval

# If we evaluate the contents of the generated plugin.rb file,
Expand Down
Expand Up @@ -48,7 +48,7 @@ def initialize(config, path, block_for_missing, skip_printing_values = false)

print_resulting_config_values unless skip_printing_values # only on success
rescue SyntaxError => ex
line = ex.to_s.match(/\(eval\):(\d+)/)[1]
line = ex.to_s.match(/\(eval.*\):(\d+)/)[1]
UI.error("Error in your #{File.basename(path)} at line #{line}")
UI.content_error(content, line)
UI.user_error!("Syntax error in your configuration file '#{path}' on line #{line}: #{ex}")
Expand Down
2 changes: 1 addition & 1 deletion frameit/spec/strings_parser_spec.rb
Expand Up @@ -48,7 +48,7 @@
describe "failure parsing" do
it "logs a helpful message on a bad file" do
expect(Frameit::UI).to receive(:error).with(/.*translations.bad.strings line 2:/)
expect(Frameit::UI).to receive(:verbose).with(/undefined method .\[\]. for nil:NilClass/)
expect(Frameit::UI).to receive(:verbose).with(/undefined method .\[\]. for nil/)
expect(Frameit::UI).to receive(:error).with(/Empty parsing result for .*translations.bad.strings/)

translations = Frameit::StringsParser.parse("./frameit/spec/fixtures/translations.bad.strings")
Expand Down

0 comments on commit 3337c4f

Please sign in to comment.