Skip to content

Commit 18fecc9

Browse files
committed
Fixing tests
1 parent 96fd008 commit 18fecc9

2 files changed

Lines changed: 10 additions & 12 deletions

File tree

ext/libxml/ruby_xml_reader.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -122,34 +122,31 @@ VALUE rxml_reader_document(VALUE klass, VALUE doc)
122122
*/
123123
static VALUE rxml_reader_file(int argc, VALUE *argv, VALUE klass)
124124
{
125-
xmlTextReaderPtr xreader;
126125
VALUE path;
127126
VALUE options;
128127

129-
const char *xencoding = NULL;
130-
int xoptions = 0;
131-
132128
rb_scan_args(argc, argv, "11", &path, &options);
133129
Check_Type(path, T_STRING);
134130

131+
const char* xencoding = NULL;
132+
int xoptions = 0;
133+
135134
if (!NIL_P(options))
136135
{
137-
VALUE encoding = Qnil;
138-
VALUE parserOptions = Qnil;
139-
140136
Check_Type(options, T_HASH);
141137

142-
encoding = rb_hash_aref(options, BASE_URI_SYMBOL);
138+
VALUE encoding = rb_hash_aref(options, BASE_URI_SYMBOL);
143139
xencoding = NIL_P(encoding) ? NULL : xmlGetCharEncodingName(NUM2INT(encoding));
144140

145-
parserOptions = rb_hash_aref(options, OPTIONS_SYMBOL);
141+
VALUE parserOptions = rb_hash_aref(options, OPTIONS_SYMBOL);
146142
xoptions = NIL_P(parserOptions) ? 0 : NUM2INT(parserOptions);
147143
}
148144

149-
xreader = xmlReaderForFile(StringValueCStr(path), xencoding, xoptions);
145+
xmlTextReaderPtr xreader = xmlReaderForFile(StringValueCStr(path), xencoding, xoptions);
150146

147+
// Unfortunately libxml2 does not set xmlLastError and just returns a null reader
151148
if (xreader == NULL)
152-
rxml_raise(xmlGetLastError());
149+
rb_syserr_fail(ENOENT, StringValueCStr(path));
153150

154151
return rxml_reader_wrap(xreader);
155152
}

test/test_reader.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,10 @@ def test_file
6060
end
6161

6262
def test_invalid_file
63-
assert_raises(LibXML::XML::Error) do
63+
error = assert_raises(Errno::ENOENT) do
6464
LibXML::XML::Reader.file('/does/not/exist')
6565
end
66+
assert_equal("No such file or directory - /does/not/exist", error.message)
6667
end
6768

6869
def test_string

0 commit comments

Comments
 (0)