Skip to content

Commit 2c97cf4

Browse files
committed
Improve and fix &. operator specs
1 parent 25dc94e commit 2c97cf4

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

spec/ruby/language/safe_navigator_spec.rb

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,16 @@ def foo=(val)
6565

6666
it "allows assignment operators" do
6767
klass = Class.new do
68-
attr_accessor :m
68+
attr_reader :m
6969

7070
def initialize
7171
@m = 0
7272
end
73+
74+
def m=(v)
75+
@m = v
76+
42
77+
end
7378
end
7479

7580
obj = klass.new
@@ -83,20 +88,26 @@ def initialize
8388

8489
it "allows ||= operator" do
8590
klass = Class.new do
86-
attr_accessor :m
91+
attr_reader :m
8792

8893
def initialize
89-
@m = true
94+
@m = false
95+
end
96+
97+
def m=(v)
98+
@m = v
99+
42
90100
end
91101
end
92102

93103
obj = klass.new
94104

95-
(obj&.m &&= false).should == false
96-
obj.m.should == false
105+
(obj&.m ||= true).should == true
106+
obj.m.should == true
97107

98108
obj = nil
99-
(obj&.m &&= false).should == nil
109+
(obj&.m ||= true).should == nil
110+
obj.should == nil
100111
end
101112

102113
it "allows &&= operator" do
@@ -115,6 +126,7 @@ def initialize
115126

116127
obj = nil
117128
(obj&.m &&= false).should == nil
129+
obj.should == nil
118130
end
119131

120132
it "does not call the operator method lazily with an assignment operator" do

0 commit comments

Comments
 (0)