aboutsummaryrefslogtreecommitdiffstats
path: root/spec/mspec/lib/mspec/helpers/io.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/mspec/lib/mspec/helpers/io.rb')
-rw-r--r--spec/mspec/lib/mspec/helpers/io.rb82
1 files changed, 40 insertions, 42 deletions
diff --git a/spec/mspec/lib/mspec/helpers/io.rb b/spec/mspec/lib/mspec/helpers/io.rb
index 83d14441a7..57dc0d53a4 100644
--- a/spec/mspec/lib/mspec/helpers/io.rb
+++ b/spec/mspec/lib/mspec/helpers/io.rb
@@ -61,53 +61,51 @@ class IOStub
end
end
-class Object
- # Creates a "bare" file descriptor (i.e. one that is not associated
- # with any Ruby object). The file descriptor can safely be passed
- # to IO.new without creating a Ruby object alias to the fd.
- def new_fd(name, mode="w:utf-8")
- mode = options_or_mode(mode)
-
- if mode.kind_of? Hash
- if mode.key? :mode
- mode = mode[:mode]
- else
- raise ArgumentError, "new_fd options Hash must include :mode"
- end
+# Creates a "bare" file descriptor (i.e. one that is not associated
+# with any Ruby object). The file descriptor can safely be passed
+# to IO.new without creating a Ruby object alias to the fd.
+def new_fd(name, mode="w:utf-8")
+ mode = options_or_mode(mode)
+
+ if mode.kind_of? Hash
+ if mode.key? :mode
+ mode = mode[:mode]
+ else
+ raise ArgumentError, "new_fd options Hash must include :mode"
end
-
- IO.sysopen name, fmode(mode)
end
- # Creates an IO instance for a temporary file name. The file
- # must be deleted.
- def new_io(name, mode="w:utf-8")
- IO.new new_fd(name, options_or_mode(mode)), options_or_mode(mode)
- end
+ IO.sysopen name, fmode(mode)
+end
- # This helper simplifies passing file access modes regardless of
- # whether the :encoding feature is enabled. Only the access specifier
- # itself will be returned if :encoding is not enabled. Otherwise,
- # the full mode string will be returned (i.e. the helper is a no-op).
- def fmode(mode)
- if FeatureGuard.enabled? :encoding
- mode
- else
- mode.split(':').first
- end
- end
+# Creates an IO instance for a temporary file name. The file
+# must be deleted.
+def new_io(name, mode="w:utf-8")
+ IO.new new_fd(name, options_or_mode(mode)), options_or_mode(mode)
+end
- # This helper simplifies passing file access modes or options regardless of
- # whether the :encoding feature is enabled. Only the access specifier itself
- # will be returned if :encoding is not enabled. Otherwise, the full mode
- # string or option will be returned (i.e. the helper is a no-op).
- def options_or_mode(oom)
- return fmode(oom) if oom.kind_of? String
+# This helper simplifies passing file access modes regardless of
+# whether the :encoding feature is enabled. Only the access specifier
+# itself will be returned if :encoding is not enabled. Otherwise,
+# the full mode string will be returned (i.e. the helper is a no-op).
+def fmode(mode)
+ if FeatureGuard.enabled? :encoding
+ mode
+ else
+ mode.split(':').first
+ end
+end
- if FeatureGuard.enabled? :encoding
- oom
- else
- fmode(oom[:mode] || "r:utf-8")
- end
+# This helper simplifies passing file access modes or options regardless of
+# whether the :encoding feature is enabled. Only the access specifier itself
+# will be returned if :encoding is not enabled. Otherwise, the full mode
+# string or option will be returned (i.e. the helper is a no-op).
+def options_or_mode(oom)
+ return fmode(oom) if oom.kind_of? String
+
+ if FeatureGuard.enabled? :encoding
+ oom
+ else
+ fmode(oom[:mode] || "r:utf-8")
end
end