spec/writer_spec.rb in SgfParser-2.0.0 vs spec/writer_spec.rb in SgfParser-3.0.0
- old
+ new
@@ -1,14 +1,14 @@
-require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
+require 'spec_helper'
-describe "SGF::Writer" do
+RSpec.describe SGF::Writer do
+ let(:parser) { SGF::Parser.new }
+
TEMP_FILE = 'spec/data/temp.sgf'
- after :each do
- FileUtils.rm_f TEMP_FILE
- end
+ after { FileUtils.rm_f TEMP_FILE }
it "should save a simple tree properly" do
sgf = File.read('spec/data/simple.sgf')
parse_save_load_and_compare_to_saved sgf
end
@@ -30,21 +30,21 @@
parse_save_load_and_compare_to_saved sgf
end
it "should indent a simple SGF nicely" do
sgf = save_to_temp_file_and_read '(;FF[4])'
- sgf.should == "\n(\n ;FF[4]\n)"
+ expect(sgf).to eq "\n(\n ;FF[4]\n)"
end
it "should indent a one-node SGF with two properties" do
sgf = save_to_temp_file_and_read '(;FF[4]PW[Cho Chikun])'
- sgf.should == "\n(\n ;FF[4]\n PW[Cho Chikun]\n)"
+ expect(sgf).to eq "\n(\n ;FF[4]\n PW[Cho Chikun]\n)"
end
it "should indent two nodes on same column" do
sgf = save_to_temp_file_and_read '(;FF[4];PB[qq])'
- sgf.should == "\n(\n ;FF[4]\n ;PB[qq]\n)"
+ expect(sgf).to eq "\n(\n ;FF[4]\n ;PB[qq]\n)"
end
it "should indent branches further" do
string = '(;FF[4](;PB[qq])(;PB[qa]))'
sgf = save_to_temp_file_and_read string
@@ -56,11 +56,11 @@
)
(
;PB[qa]
)
)}
- sgf.should == expected
+ expect(sgf).to eq expected
end
it "should indent two gametrees" do
string = '(;FF[4];PB[qq])(;FF[4];PB[dd])'
sgf = save_to_temp_file_and_read string
@@ -71,27 +71,28 @@
)
(
;FF[4]
;PB[dd]
)}
- sgf.should == expected
+ expect(sgf).to eq expected
end
private
def parse_save_load_and_compare_to_saved string
- parser =SGF::Parser.new
- tree = parser.parse string
- tree.save TEMP_FILE
- tree2 = get_tree_from TEMP_FILE
- tree2.should == tree
+ collection = parse_and_save string
+ collection2 = get_collection_from TEMP_FILE
+ expect(collection2).to eq collection
end
+ def save_to_temp_file_and_read string
+ parse_and_save string
+ File.read TEMP_FILE
+ end
- def save_to_temp_file_and_read sgf_string
- tree = SGF::Parser.new.parse sgf_string
- tree.save TEMP_FILE
- sgf = File.read TEMP_FILE
- sgf
+ def parse_and_save string
+ collection = parser.parse string
+ collection.save TEMP_FILE
+ collection
end
-end
\ No newline at end of file
+end