-
Notifications
You must be signed in to change notification settings - Fork 0
/
calc_spec.rb
58 lines (51 loc) · 1.16 KB
/
calc_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
require 'rspec'
class Calc
attr_reader :accumulator
def initialize x
@accumulator = x
end
def increment
@accumulator += 1
end
def accumulator_zero?
accumulator == 0
end
end
describe Calc do
describe '#accumulator_zero?' do
it 'is zero' do
new_calc = Calc.new(0)
expect(new_calc.accumulator_zero?).to be_truthy
# alternative
expect(new_calc).to be_accumulator_zero
end
it 'is not zero' do
new_calc = Calc.new(10)
expect(new_calc.accumulator_zero?).to be_falsy
# alternative
expect(new_calc).to_not be_accumulator_zero
end
end
context 'increment accumulator' do
it 'brittle test' do
new_calc = Calc.new(10)
expect(new_calc.increment).to eq(11)
end
it 'non brittle test' do
new_calc = Calc.new(10)
expect do
new_calc.increment
end.to change { new_calc.accumulator }.by(1)
end
end
context 'setting accumulator' do
it 'to 10' do
new_calc = Calc.new(10)
expect(new_calc.accumulator).to eq(10)
end
it 'to 20' do
new_calc = Calc.new(20)
expect(new_calc.accumulator).to eq(20)
end
end
end