Skip to content

Commit 7709862

Browse files
committed
Refactoring - specs
1 parent b177e55 commit 7709862

File tree

2 files changed

+82
-21
lines changed

2 files changed

+82
-21
lines changed

ext/string.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ def marked_fixme?
66
def mark_fixme!
77
return self if marked_fixme?
88

9-
self.replace("#{self} g FIXME")
9+
self.append!(" g FIXME")
1010
end
1111

1212
def append!(value)
13-
return self if self == ""
13+
return self if empty?
1414

15-
self.replace("#{self}#{value}")
15+
self << value
1616
end
1717
end

spec/ext_spec.rb

Lines changed: 79 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,90 @@
11
require_relative 'spec_helper'
22

3+
describe Object do
4+
describe "#marked_fixme?" do
5+
subject { Object.new.marked_fixme? }
6+
it { should be_false }
7+
end
8+
9+
describe "#append!" do
10+
before { @object = Object.new.append!("somestring") }
11+
subject { @object }
12+
it { should eq @object }
13+
end
14+
15+
describe "#mark_fixme!" do
16+
before { @object = Object.new.mark_fixme! }
17+
subject { @object }
18+
it { should eq @object }
19+
end
20+
end
21+
322
describe Array do
4-
it "extracts options" do
5-
a = [1, 2, 3, 4, { option: true, option2: false }]
6-
a.extract_options!.should eql({ option: true, option2: false })
7-
a.should eql([1,2,3,4])
23+
describe "#extract_options!" do
24+
subject { [1, 2, 3, 4, options].extract_options! }
25+
26+
context "when contains options" do
27+
let(:options) { { option: true, option2: false } }
28+
it { should eq options }
29+
end
30+
31+
context "when contains no options" do
32+
let(:options) { nil }
33+
it { should be_empty }
34+
end
35+
end
36+
37+
describe "#append!" do
38+
subject { ["hello", "world"].append!("appended_string") }
39+
it { should eq ["helloappended_string", "worldappended_string"] }
40+
end
41+
42+
describe "#mark_fixme!" do
43+
subject { ["Hello", 1, 2, 3, "String"].mark_fixme! }
44+
it { should eq ["Hello g FIXME", 1, 2, 3, "String g FIXME"] }
45+
end
46+
end
47+
48+
describe String do
49+
describe "#marked_fixme?" do
50+
subject { "Hello#{suffix}".marked_fixme? }
51+
52+
context "when marked fixme" do
53+
let(:suffix) { "g FIXME" }
54+
it { should be_true }
55+
end
856

9-
a.extract_options!.should eql({})
10-
a.should eql([1,2,3,4])
57+
context "when not marked fixme" do
58+
let(:suffix) { "" }
59+
it { should be_false }
60+
end
1161
end
1262

13-
it "appends" do
14-
a = ["hello", "world"]
63+
describe "#mark_fixme!" do
64+
subject { "Hello #{suffix}".mark_fixme! }
65+
66+
context "already marked fixme" do
67+
let(:suffix) { "g FIXME" }
68+
it { should eq "Hello g FIXME" }
69+
end
70+
71+
context "not marked yet" do
72+
let(:suffix) { "" }
73+
it { should eq "Hello g FIXME" }
74+
end
75+
end
1576

16-
a.append!("appended_string")
77+
describe "#append!" do
78+
subject { "#{string}".append!("hello") }
79+
context "empty" do
80+
let(:string) { "" }
81+
it { should be_empty }
82+
end
1783

18-
a.should eql(["helloappended_string", "worldappended_string"])
84+
context "any other string" do
85+
let(:string) { "helloworld" }
86+
it { should eq "helloworldhello" }
87+
end
1988
end
2089
end
2190

@@ -152,12 +221,4 @@
152221

153222
hash2.deep_delete_unused!(hash1).should eql(hash1)
154223
end
155-
156-
describe String do
157-
it "marks fixme" do
158-
"Hello".mark_fixme!.should eql("Hello g FIXME")
159-
160-
"Hello g FIXME".mark_fixme!.should eql("Hello g FIXME")
161-
end
162-
end
163224
end

0 commit comments

Comments
 (0)