Skip to content

Commit 13d9709

Browse files
committed
test: adds spec to bring class methods over 90% coverage
Test in line 32 fails, not sure why
1 parent 6f536dd commit 13d9709

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
describe Injectable::ClassMethods do
2+
describe '#simple_class_attribute' do
3+
subject(:klass) do
4+
Class.new do
5+
include Injectable
6+
7+
def self.singleton_class?
8+
true
9+
end
10+
11+
class_eval do
12+
simple_class_attribute :flag
13+
end
14+
15+
def call
16+
'jarl'
17+
end
18+
end
19+
end
20+
21+
it 'defines instance reader delegating to singleton reader when singleton_class?' do
22+
klass.flag = 'on'
23+
expect(klass.flag).to eq('on')
24+
end
25+
26+
it 'passes the singleton class attribute value to the instances' do
27+
klass.flag = 'on'
28+
instance = klass.new
29+
expect(instance.flag).to eq('on')
30+
end
31+
32+
it 'allows to modify attribute value on the instance', skip: 'Failing, need to investigate' do
33+
instance = klass.new
34+
instance.instance_variable_set('@flag', 'local')
35+
expect(instance.flag).to eq('local')
36+
end
37+
38+
it 'does not pass instance values up to the singleton class value' do
39+
klass.flag = 'on'
40+
instance = klass.new
41+
instance.instance_variable_set('@flag', 'local')
42+
expect(klass.flag).to eq 'on'
43+
end
44+
end
45+
end

0 commit comments

Comments
 (0)