8
8
let ( :matcher_config ) { Mutant ::Matcher ::Config ::DEFAULT }
9
9
let ( :object_space ) { class_double ( ObjectSpace ) }
10
10
let ( :object_space_modules ) { [ ] }
11
+ let ( :parser ) { instance_double ( Mutant ::Parser ) }
11
12
12
13
let ( :world ) do
13
14
instance_double (
43
44
)
44
45
end
45
46
47
+ shared_examples 'expected warning' do
48
+ let ( :warns ) { [ ] }
49
+
50
+ before do
51
+ allow ( config . reporter ) . to receive ( :warn , &warns . method ( :<< ) )
52
+ end
53
+
54
+ it 'warns with expected warning' do
55
+ expect { apply } . to change ( warns , :to_a ) . from ( [ ] ) . to ( [ expected_warning ] )
56
+ end
57
+ end
58
+
46
59
shared_examples_for 'bootstrap call' do
47
60
it 'returns expected env' do
48
61
expect ( apply ) . to eql ( expected_env )
49
62
end
50
- end
51
63
52
- def expect_warning
53
- expect ( config . reporter ) . to receive ( :warn )
54
- . with ( expected_warning )
55
- . and_return ( config . reporter )
64
+ it 'performs IO in expected sequence' do
65
+ apply
66
+
67
+ expect ( object_space )
68
+ . to have_received ( :each_object )
69
+ . with ( Module )
70
+ . ordered
71
+
72
+ expect ( integration_class )
73
+ . to have_received ( :new )
74
+ . with ( config )
75
+ . ordered
76
+
77
+ expect ( integration )
78
+ . to have_received ( :setup )
79
+ . ordered
80
+ end
56
81
end
57
82
58
83
before do
59
- expect ( integration_class ) . to receive ( :new )
60
- . with ( config )
61
- . and_return ( integration )
62
-
63
- expect ( integration ) . to receive_messages ( setup : integration )
84
+ allow ( integration_class ) . to receive_messages ( new : integration )
85
+ allow ( integration ) . to receive_messages ( setup : integration )
64
86
65
- expect ( object_space ) . to receive ( :each_object )
66
- . with ( Module )
67
- . and_return ( object_space_modules . each )
87
+ allow ( object_space ) . to receive_messages (
88
+ each_object : object_space_modules . each
89
+ )
68
90
end
69
91
70
92
describe '#warn' do
71
- let ( :object ) { described_class . new ( world , config ) }
72
- let ( :expected_warning ) { instance_double ( String ) }
93
+ subject { described_class . new ( world , config ) }
73
94
74
- subject { object . warn ( expected_warning ) }
95
+ def apply
96
+ subject . warn ( expected_warning )
97
+ end
75
98
76
- before { expect_warning }
99
+ let ( :expected_warning ) { instance_double ( String ) }
77
100
78
- it_behaves_like 'a command method'
101
+ include_examples 'expected warning'
102
+
103
+ it 'returns self' do
104
+ expect ( apply ) . to be ( subject )
105
+ end
79
106
end
80
107
81
108
describe '.call' do
@@ -87,27 +114,27 @@ def apply
87
114
let ( :object_space_modules ) { [ invalid_class ] }
88
115
89
116
let ( :expected_warning ) do
90
- "Class #name from: #{ invalid_class } raised an error: " \
117
+ "Object #name from: #{ invalid_class } raised an error: " \
91
118
"RuntimeError. #{ Mutant ::Env ::SEMANTICS_MESSAGE } "
92
119
end
93
120
121
+ # Not really a class, but does not leak a "wrong" class
122
+ # into later specs.
94
123
let ( :invalid_class ) do
95
- Class . new do
96
- def self . name
124
+ Object . new . tap do | object |
125
+ def object . name
97
126
fail
98
127
end
99
128
end
100
129
end
101
130
102
- after do
103
- # Fix Class#name so other specs do not see this one
104
- class << invalid_class
105
- undef :name
106
- def name ; end
107
- end
108
- end
131
+ include_examples 'expected warning'
132
+ include_examples 'bootstrap call'
133
+ end
109
134
110
- before { expect_warning }
135
+ context 'when Module#name calls return nil' do
136
+ let ( :anonymous_class ) { Class . new }
137
+ let ( :object_space_modules ) { [ anonymous_class ] }
111
138
112
139
include_examples 'bootstrap call'
113
140
end
@@ -164,8 +191,7 @@ def name; end
164
191
end
165
192
end
166
193
167
- before { expect_warning }
168
-
194
+ include_examples 'expected warning'
169
195
include_examples 'bootstrap call'
170
196
end
171
197
0 commit comments