Skip to content

Commit 5efc31c

Browse files
committed
1 parent 93a1c0c commit 5efc31c

File tree

3 files changed

+5
-71
lines changed

3 files changed

+5
-71
lines changed

spec/mspec/lib/mspec/helpers/io.rb

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ def inspect
6565
# with any Ruby object). The file descriptor can safely be passed
6666
# to IO.new without creating a Ruby object alias to the fd.
6767
def new_fd(name, mode="w:utf-8")
68-
mode = options_or_mode(mode)
69-
7068
if mode.kind_of? Hash
7169
if mode.key? :mode
7270
mode = mode[:mode]
@@ -75,41 +73,15 @@ def new_fd(name, mode="w:utf-8")
7573
end
7674
end
7775

78-
IO.sysopen name, fmode(mode)
76+
IO.sysopen name, mode
7977
end
8078

8179
# Creates an IO instance for a temporary file name. The file
8280
# must be deleted.
8381
def new_io(name, mode="w:utf-8")
84-
IO.new new_fd(name, options_or_mode(mode)), options_or_mode(mode)
82+
IO.new new_fd(name, mode), mode
8583
end
8684

8785
def find_unused_fd
8886
Dir.entries("/dev/fd").map(&:to_i).max + 1
8987
end
90-
91-
# This helper simplifies passing file access modes regardless of
92-
# whether the :encoding feature is enabled. Only the access specifier
93-
# itself will be returned if :encoding is not enabled. Otherwise,
94-
# the full mode string will be returned (i.e. the helper is a no-op).
95-
def fmode(mode)
96-
if FeatureGuard.enabled? :encoding
97-
mode
98-
else
99-
mode.split(':').first
100-
end
101-
end
102-
103-
# This helper simplifies passing file access modes or options regardless of
104-
# whether the :encoding feature is enabled. Only the access specifier itself
105-
# will be returned if :encoding is not enabled. Otherwise, the full mode
106-
# string or option will be returned (i.e. the helper is a no-op).
107-
def options_or_mode(oom)
108-
return fmode(oom) if oom.kind_of? String
109-
110-
if FeatureGuard.enabled? :encoding
111-
oom
112-
else
113-
fmode(oom[:mode] || "r:utf-8")
114-
end
115-
end

spec/mspec/lib/mspec/utils/options.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ def randomize
384384
def repeat
385385
on("-R", "--repeat", "NUMBER",
386386
"Repeatedly run an example NUMBER times") do |o|
387-
MSpec.repeat = o.to_i
387+
MSpec.repeat = Integer(o)
388388
end
389389
end
390390

spec/mspec/spec/helpers/io_spec.rb

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
fd = new_fd @name
6565
fd.should be_kind_of(Integer)
6666

67-
@io = IO.new fd, fmode('w:utf-8')
67+
@io = IO.new fd, 'w:utf-8'
6868
@io.sync = true
6969
@io.print "io data"
7070

@@ -76,7 +76,7 @@
7676
fd = new_fd @name, { :mode => 'w:utf-8' }
7777
fd.should be_kind_of(Integer)
7878

79-
@io = IO.new fd, fmode('w:utf-8')
79+
@io = IO.new fd, 'w:utf-8'
8080
@io.sync = true
8181
@io.print "io data"
8282

@@ -134,41 +134,3 @@
134134
IO.read(@name).should == "io data"
135135
end
136136
end
137-
138-
describe Object, "#fmode" do
139-
it "returns the argument unmodified if :encoding feature is enabled" do
140-
FeatureGuard.should_receive(:enabled?).with(:encoding).and_return(true)
141-
fmode("rb:binary:utf-8").should == "rb:binary:utf-8"
142-
end
143-
144-
it "returns only the file access mode if :encoding feature is not enabled" do
145-
FeatureGuard.should_receive(:enabled?).with(:encoding).and_return(false)
146-
fmode("rb:binary:utf-8").should == "rb"
147-
end
148-
end
149-
150-
describe Object, "#options_or_mode" do
151-
describe "if passed a Hash" do
152-
it "returns a mode string if :encoding feature is not enabled" do
153-
FeatureGuard.should_receive(:enabled?).with(:encoding).twice.and_return(false)
154-
options_or_mode(:mode => "rb:binary").should == "rb"
155-
end
156-
157-
it "returns a Hash if :encoding feature is enabled" do
158-
FeatureGuard.should_receive(:enabled?).with(:encoding).and_return(true)
159-
options_or_mode(:mode => "rb:utf-8").should == { :mode => "rb:utf-8" }
160-
end
161-
end
162-
163-
describe "if passed a String" do
164-
it "returns only the file access mode if :encoding feature is not enabled" do
165-
FeatureGuard.should_receive(:enabled?).with(:encoding).and_return(false)
166-
options_or_mode("rb:binary:utf-8").should == "rb"
167-
end
168-
169-
it "returns the argument unmodified if :encoding feature is enabled" do
170-
FeatureGuard.should_receive(:enabled?).with(:encoding).and_return(true)
171-
options_or_mode("rb:binary:utf-8").should == "rb:binary:utf-8"
172-
end
173-
end
174-
end

0 commit comments

Comments
 (0)