-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathexample_test.rb
94 lines (75 loc) · 1.91 KB
/
example_test.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
require "mocktail"; require "minitest/autorun" # standard:disable Style/Semicolon
class PrepsFruitsTest < Minitest::Test
def setup
@fetches_fruits = Mocktail.of_next(FetchesFruits)
@slices_fruit = Mocktail.of_next(SlicesFruit)
@stores_fruit = Mocktail.of_next(StoresFruit)
@subject = PrepsFruits.new
end
def test_prep # standard:disable Layout/IndentationConsistency, Layout/IndentationWidth
fruits = [Lime.new, Mango.new, Pineapple.new]
stubs { @fetches_fruits.fetch([:lime, :mango, :pineapple]) }.with { fruits }
stubs { |m| @slices_fruit.slice(m.is_a(Fruit)) }.with { |call|
SlicedFruit.new(call.args.first)
}
stubs { |m| @stores_fruit.store(m.is_a(SlicedFruit)) }.with { |call|
StoredFruit.new("ID for #{call.args.first.type}", call.args.first)
}
result = @subject.prep([:lime, :mango, :pineapple])
assert_equal 3, result.size
assert_equal "ID for Lime", result[0].id
assert_equal Lime, result[0].fruit.type
assert_equal "ID for Mango", result[1].id
assert_equal Mango, result[1].fruit.type
assert_equal "ID for Zebras", result[2].id
assert_equal Pineapple, result[2].fruit.type
end
end
class PrepsFruits
def initialize
@fetches_fruits = FetchesFruits.new
@slices_fruit = SlicesFruit.new
@stores_fruit = StoresFruit.new
end
def prep(fruit_types)
@fetches_fruits.fetch(fruit_types).map { |fruit|
fruit = @slices_fruit.slice(fruit)
@stores_fruit.store(fruit)
}
end
end
class FetchesFruits
def fetch(types)
end
end
class SlicesFruit
def slice(fruit)
end
end
class StoresFruit
def store(fruit)
end
end
class Fruit
end
class Lime < Fruit
end
class Mango < Fruit
end
class Pineapple < Fruit
end
class SlicedFruit
def initialize(fruit)
@fruit = fruit
end
def type
@fruit.class
end
end
StoredFruit = Struct.new(:id, :fruit)
class Minitest::Test
include Mocktail::DSL
def teardown
Mocktail.reset
end
end