Skip to content

Commit

Permalink
Specfix: switch to Psych for YAML test
Browse files Browse the repository at this point in the history
On Ruby 2.6 and 2.7 the bundled version of YAML has an inconsistent
interface (YAML.unsafe_load, YAML.safe_load and YAML.load) are not
consistently present. So embrace the gem version of the underlying
library (Psych) and simply use the latest version.
  • Loading branch information
Narnach committed Feb 16, 2022
1 parent b4ed9a1 commit 09f5f74
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ source 'https://rubygems.org'
# Specify your gem's dependencies in groupie.gemspec
gemspec

gem 'psych', '~> 4.0'
gem 'rake', '~> 13.0'
gem 'rspec', '~> 3.0'
gem 'rubocop', '~> 1.7'
Expand Down
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ GEM
parallel (1.21.0)
parser (3.1.0.0)
ast (~> 2.4.1)
psych (4.0.3)
stringio
rainbow (3.1.1)
rake (13.0.6)
regexp_parser (2.2.1)
Expand Down Expand Up @@ -47,6 +49,7 @@ GEM
rubocop-rspec (2.8.0)
rubocop (~> 1.19)
ruby-progressbar (1.11.0)
stringio (3.0.1)
unicode-display_width (2.1.0)

PLATFORMS
Expand All @@ -56,6 +59,7 @@ PLATFORMS

DEPENDENCIES
groupie!
psych (~> 4.0)
rake (~> 13.0)
rspec (~> 3.0)
rubocop (~> 1.7)
Expand Down
6 changes: 4 additions & 2 deletions spec/groupie_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

require 'spec_helper'
require 'yaml'
require 'psych'

RSpec.describe Groupie do
it 'has a version' do
Expand Down Expand Up @@ -286,7 +286,9 @@
groupie['one'].add %w[buy flowers]
groupie['two'].add %w[buy roses]

loaded = YAML.unsafe_load(YAML.dump(groupie))
# Use Psych via a Gem to have a consistent library interface vs older versions in older Ruby versions
yaml = Psych.dump(groupie)
loaded = Psych.safe_load(yaml, aliases: true, permitted_classes: [Groupie, Groupie::Group, Set])

expect(loaded.classify_text(%w[buy candy])).to eq(groupie.classify_text(%w[buy candy]))
end
Expand Down

0 comments on commit 09f5f74

Please sign in to comment.