Skip to content

Commit d01bf69

Browse files
trinistrandrykonchin
authored andcommitted
Impove tests for error messages in Array#pack, String#unpack
1 parent 8bb046b commit d01bf69

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

core/array/pack/shared/basic.rb

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,15 @@
3333
end
3434

3535
ruby_version_is ""..."3.3" do
36-
# https://bugs.ruby-lang.org/issues/19150
37-
# NOTE: it's just a plan of the Ruby core team
3836
it "warns that a directive is unknown" do
3937
# additional directive ('a') is required for the X directive
40-
-> { [@obj, @obj].pack("a R" + pack_format) }.should complain(/unknown pack directive 'R'/)
41-
-> { [@obj, @obj].pack("a 0" + pack_format) }.should complain(/unknown pack directive '0'/)
42-
-> { [@obj, @obj].pack("a :" + pack_format) }.should complain(/unknown pack directive ':'/)
38+
-> { [@obj, @obj].pack("a R" + pack_format) }.should complain(/unknown pack directive 'R' in 'a R#{pack_format}'/)
39+
-> { [@obj, @obj].pack("a 0" + pack_format) }.should complain(/unknown pack directive '0' in 'a 0#{pack_format}'/)
40+
-> { [@obj, @obj].pack("a :" + pack_format) }.should complain(/unknown pack directive ':' in 'a :#{pack_format}'/)
4341
end
4442
end
4543

4644
ruby_version_is "3.3" do
47-
# https://bugs.ruby-lang.org/issues/19150
48-
# NOTE: Added this case just to not forget about the decision in the ticket
4945
it "raise ArgumentError when a directive is unknown" do
5046
# additional directive ('a') is required for the X directive
5147
-> { [@obj, @obj].pack("a R" + pack_format) }.should raise_error(ArgumentError, /unknown pack directive 'R'/)

core/string/unpack/shared/basic.rb

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,19 @@
99
"abc".unpack(d).should be_an_instance_of(Array)
1010
end
1111

12+
ruby_version_is ""..."3.3" do
13+
it "warns about using an unknown directive" do
14+
-> { "abcdefgh".unpack("a R" + unpack_format) }.should complain(/unknown unpack directive 'R' in 'a R#{unpack_format}'/)
15+
-> { "abcdefgh".unpack("a 0" + unpack_format) }.should complain(/unknown unpack directive '0' in 'a 0#{unpack_format}'/)
16+
-> { "abcdefgh".unpack("a :" + unpack_format) }.should complain(/unknown unpack directive ':' in 'a :#{unpack_format}'/)
17+
end
18+
end
19+
1220
ruby_version_is "3.3" do
13-
# https://bugs.ruby-lang.org/issues/19150
14-
it 'raise ArgumentError when a directive is unknown' do
15-
-> { "abcdefgh".unpack("a R" + unpack_format) }.should raise_error(ArgumentError, /unknown unpack directive 'R'/)
16-
-> { "abcdefgh".unpack("a 0" + unpack_format) }.should raise_error(ArgumentError, /unknown unpack directive '0'/)
17-
-> { "abcdefgh".unpack("a :" + unpack_format) }.should raise_error(ArgumentError, /unknown unpack directive ':'/)
21+
it "raises ArgumentError when a directive is unknown" do
22+
-> { "abcdefgh".unpack("a R" + unpack_format) }.should raise_error(ArgumentError, "unknown unpack directive 'R' in 'a R#{unpack_format}'")
23+
-> { "abcdefgh".unpack("a 0" + unpack_format) }.should raise_error(ArgumentError, "unknown unpack directive '0' in 'a 0#{unpack_format}'")
24+
-> { "abcdefgh".unpack("a :" + unpack_format) }.should raise_error(ArgumentError, "unknown unpack directive ':' in 'a :#{unpack_format}'")
1825
end
1926
end
2027
end

0 commit comments

Comments
 (0)