Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup of YAML specs #1108

Merged
merged 4 commits into from
Nov 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions library/yaml/dump_spec.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
require_relative '../../spec_helper'
require_relative 'fixtures/common'

# TODO: WTF is this using a global?
describe "YAML.dump" do
before :each do
@test_file = tmp("yaml_test_file")
end

after :each do
rm_r $test_file
rm_r @test_file
end

it "converts an object to YAML and write result to io when io provided" do
File.open($test_file, 'w' ) do |io|
File.open(@test_file, 'w' ) do |io|
YAML.dump( ['badger', 'elephant', 'tiger'], io )
end
YAML.load_file($test_file).should == ['badger', 'elephant', 'tiger']
YAML.load_file(@test_file).should == ['badger', 'elephant', 'tiger']
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: $test_file was used in one case only - it makes sense not to create and delete file for every other cases.


it "returns a string containing dumped YAML when no io provided" do
Expand Down
2 changes: 0 additions & 2 deletions library/yaml/fixtures/common.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
require 'yaml'

$test_file = tmp("yaml_test_file")
10 changes: 7 additions & 3 deletions library/yaml/load_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
require_relative 'fixtures/common'

describe "YAML.load_file" do
before :each do
@test_file = tmp("yaml_test_file")
end

after :each do
rm_r $test_file
rm_r @test_file
end

it "returns a hash" do
File.open($test_file,'w' ){|io| YAML.dump( {"bar"=>2, "car"=>1}, io ) }
YAML.load_file($test_file).should == {"bar"=>2, "car"=>1}
File.open(@test_file,'w' ){|io| YAML.dump( {"bar"=>2, "car"=>1}, io ) }
YAML.load_file(@test_file).should == {"bar"=>2, "car"=>1}
end
end
7 changes: 4 additions & 3 deletions library/yaml/shared/load.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@

describe :yaml_load_safe, shared: true do
it "returns a document from current io stream when io provided" do
File.open($test_file, 'w') do |io|
@test_file = tmp("yaml_test_file")
File.open(@test_file, 'w') do |io|
YAML.dump( ['badger', 'elephant', 'tiger'], io )
end
File.open($test_file) { |yf| YAML.send(@method, yf ) }.should == ['badger', 'elephant', 'tiger']
File.open(@test_file) { |yf| YAML.send(@method, yf ) }.should == ['badger', 'elephant', 'tiger']
ensure
rm_r $test_file
rm_r @test_file
end

it "loads strings" do
Expand Down