transpec 1.6.1 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +0 -4
- data/.travis.yml +2 -1
- data/CHANGELOG.md +4 -0
- data/Guardfile +1 -1
- data/README.md +168 -18
- data/README.md.erb +154 -18
- data/lib/transpec/ast/node.rb +47 -0
- data/lib/transpec/cli.rb +1 -1
- data/lib/transpec/commit_message.rb +11 -1
- data/lib/transpec/configuration.rb +11 -10
- data/lib/transpec/converter.rb +36 -14
- data/lib/transpec/dynamic_analyzer/rewriter.rb +2 -2
- data/lib/transpec/option_parser.rb +11 -0
- data/lib/transpec/report.rb +16 -9
- data/lib/transpec/rspec_version.rb +9 -0
- data/lib/transpec/static_context_inspector.rb +4 -4
- data/lib/transpec/syntax/allow.rb +20 -0
- data/lib/transpec/syntax/example.rb +1 -1
- data/lib/transpec/syntax/expect.rb +5 -20
- data/lib/transpec/syntax/its.rb +2 -8
- data/lib/transpec/syntax/method_stub.rb +72 -37
- data/lib/transpec/syntax/mixin/allow_no_message.rb +8 -17
- data/lib/transpec/syntax/mixin/any_instance_block.rb +34 -0
- data/lib/transpec/syntax/mixin/expect_base.rb +70 -0
- data/lib/transpec/syntax/mixin/expectizable.rb +3 -0
- data/lib/transpec/syntax/mixin/have_matcher_owner.rb +5 -2
- data/lib/transpec/syntax/mixin/monkey_patch.rb +6 -0
- data/lib/transpec/syntax/mixin/{any_instance.rb → monkey_patch_any_instance.rb} +12 -8
- data/lib/transpec/syntax/mixin/send.rb +16 -3
- data/lib/transpec/syntax/mixin/should_base.rb +8 -2
- data/lib/transpec/syntax/oneliner_should.rb +2 -4
- data/lib/transpec/syntax/operator_matcher.rb +2 -2
- data/lib/transpec/syntax/raise_error.rb +2 -2
- data/lib/transpec/syntax/receive.rb +49 -0
- data/lib/transpec/syntax/rspec_configure.rb +8 -96
- data/lib/transpec/syntax/rspec_configure/expectations.rb +15 -0
- data/lib/transpec/syntax/rspec_configure/framework.rb +166 -0
- data/lib/transpec/syntax/rspec_configure/mocks.rb +19 -0
- data/lib/transpec/syntax/should.rb +1 -4
- data/lib/transpec/syntax/should_receive.rb +89 -43
- data/lib/transpec/util.rb +21 -7
- data/lib/transpec/version.rb +2 -2
- data/spec/transpec/ast/node_spec.rb +52 -0
- data/spec/transpec/commit_message_spec.rb +2 -2
- data/spec/transpec/configuration_spec.rb +14 -13
- data/spec/transpec/converter_spec.rb +151 -20
- data/spec/transpec/option_parser_spec.rb +10 -0
- data/spec/transpec/rspec_version_spec.rb +20 -6
- data/spec/transpec/static_context_inspector_spec.rb +2 -2
- data/spec/transpec/syntax/allow_spec.rb +140 -0
- data/spec/transpec/syntax/double_spec.rb +1 -1
- data/spec/transpec/syntax/expect_spec.rb +103 -10
- data/spec/transpec/syntax/have_spec.rb +4 -4
- data/spec/transpec/syntax/method_stub_spec.rb +41 -1
- data/spec/transpec/syntax/operator_matcher_spec.rb +6 -6
- data/spec/transpec/syntax/receive_spec.rb +270 -0
- data/spec/transpec/syntax/rspec_configure_spec.rb +241 -30
- data/spec/transpec/syntax/should_receive_spec.rb +93 -2
- data/spec/transpec/syntax/should_spec.rb +2 -2
- data/spec/transpec/util_spec.rb +2 -6
- data/transpec.gemspec +5 -3
- metadata +37 -14
@@ -2,17 +2,14 @@
|
|
2
2
|
|
3
3
|
require 'transpec/syntax'
|
4
4
|
require 'transpec/syntax/mixin/should_base'
|
5
|
-
require 'transpec/syntax/mixin/send'
|
6
5
|
require 'transpec/syntax/mixin/monkey_patch'
|
7
6
|
require 'transpec/syntax/mixin/expectizable'
|
8
|
-
require 'transpec/syntax/mixin/have_matcher_owner'
|
9
7
|
require 'transpec/util'
|
10
8
|
|
11
9
|
module Transpec
|
12
10
|
class Syntax
|
13
11
|
class Should < Syntax
|
14
|
-
include Mixin::ShouldBase, Mixin::
|
15
|
-
Mixin::HaveMatcherOwner, Util
|
12
|
+
include Mixin::ShouldBase, Mixin::MonkeyPatch, Mixin::Expectizable, Util
|
16
13
|
|
17
14
|
attr_reader :current_syntax_type
|
18
15
|
|
@@ -1,17 +1,16 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
3
|
require 'transpec/syntax'
|
4
|
-
require 'transpec/syntax/mixin/send'
|
5
|
-
require 'transpec/syntax/mixin/monkey_patch'
|
6
4
|
require 'transpec/syntax/mixin/expectizable'
|
5
|
+
require 'transpec/syntax/mixin/monkey_patch_any_instance'
|
7
6
|
require 'transpec/syntax/mixin/allow_no_message'
|
8
|
-
require 'transpec/syntax/mixin/
|
7
|
+
require 'transpec/syntax/mixin/any_instance_block'
|
9
8
|
|
10
9
|
module Transpec
|
11
10
|
class Syntax
|
12
11
|
class ShouldReceive < Syntax
|
13
|
-
include Mixin::
|
14
|
-
Mixin::
|
12
|
+
include Mixin::Expectizable, Mixin::MonkeyPatchAnyInstance, Mixin::AnyInstanceBlock,
|
13
|
+
Mixin::AllowNoMessage
|
15
14
|
|
16
15
|
alias_method :useless_expectation?, :allow_no_message?
|
17
16
|
|
@@ -51,7 +50,7 @@ module Transpec
|
|
51
50
|
end
|
52
51
|
|
53
52
|
convert_to_syntax!('expect', negative_form)
|
54
|
-
register_record(
|
53
|
+
register_record(ExpectRecord, negative_form)
|
55
54
|
end
|
56
55
|
|
57
56
|
def allowize_useless_expectation!(negative_form = 'not_to')
|
@@ -64,7 +63,7 @@ module Transpec
|
|
64
63
|
convert_to_syntax!('allow', negative_form)
|
65
64
|
remove_allowance_for_no_message!
|
66
65
|
|
67
|
-
register_record(
|
66
|
+
register_record(AllowRecord, negative_form)
|
68
67
|
end
|
69
68
|
|
70
69
|
def stubize_useless_expectation!
|
@@ -73,7 +72,11 @@ module Transpec
|
|
73
72
|
replace(selector_range, 'stub')
|
74
73
|
remove_allowance_for_no_message!
|
75
74
|
|
76
|
-
register_record(
|
75
|
+
register_record(StubRecord)
|
76
|
+
end
|
77
|
+
|
78
|
+
def add_receiver_arg_to_any_instance_implementation_block!
|
79
|
+
super && register_record(AnyInstanceBlockRecord)
|
77
80
|
end
|
78
81
|
|
79
82
|
private
|
@@ -125,8 +128,8 @@ module Transpec
|
|
125
128
|
# (args
|
126
129
|
# (arg :block_arg)) nil)
|
127
130
|
def block_node_taken_by_with_method_with_no_normal_args
|
128
|
-
|
129
|
-
next unless chained_node.
|
131
|
+
each_chained_method_node do |chained_node, child_node|
|
132
|
+
next unless chained_node.block_type?
|
130
133
|
return nil unless child_node.children[1] == :with
|
131
134
|
return nil if child_node.children[2]
|
132
135
|
return chained_node
|
@@ -144,57 +147,100 @@ module Transpec
|
|
144
147
|
# (args
|
145
148
|
# (arg :block_arg)) nil) :once)
|
146
149
|
def block_node_following_message_expectation_method
|
147
|
-
|
148
|
-
next unless chained_node.
|
149
|
-
return child_node if child_node.
|
150
|
+
each_chained_method_node do |chained_node, child_node|
|
151
|
+
next unless chained_node.send_type?
|
152
|
+
return child_node if child_node.block_type?
|
150
153
|
end
|
151
154
|
end
|
152
155
|
|
153
|
-
def register_record(
|
154
|
-
@report.records <<
|
155
|
-
original_syntax(conversion_type),
|
156
|
-
converted_syntax(conversion_type, negative_form_of_to)
|
157
|
-
)
|
156
|
+
def register_record(record_class, negative_form_of_to = nil)
|
157
|
+
@report.records << record_class.new(self, negative_form_of_to)
|
158
158
|
end
|
159
159
|
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
end
|
166
|
-
|
167
|
-
syntax << (positive? ? 'should_receive' : 'should_not_receive')
|
168
|
-
syntax << '(:message)'
|
160
|
+
class ExpectRecord < Record
|
161
|
+
def initialize(should_receive, negative_form_of_to)
|
162
|
+
@should_receive = should_receive
|
163
|
+
@negative_form_of_to = negative_form_of_to
|
164
|
+
end
|
169
165
|
|
170
|
-
|
171
|
-
syntax
|
172
|
-
|
166
|
+
def original_syntax
|
167
|
+
syntax = if @should_receive.any_instance?
|
168
|
+
'Klass.any_instance.'
|
169
|
+
else
|
170
|
+
'obj.'
|
171
|
+
end
|
172
|
+
syntax << "#{@should_receive.method_name}(:message)"
|
173
173
|
end
|
174
174
|
|
175
|
-
|
175
|
+
def converted_syntax
|
176
|
+
syntax = if @should_receive.any_instance?
|
177
|
+
'expect_any_instance_of(Klass).'
|
178
|
+
else
|
179
|
+
'expect(obj).'
|
180
|
+
end
|
181
|
+
syntax << (@should_receive.positive? ? 'to' : @negative_form_of_to)
|
182
|
+
syntax << ' receive(:message)'
|
183
|
+
end
|
176
184
|
end
|
177
185
|
|
178
|
-
|
179
|
-
|
186
|
+
class AllowRecord < Record
|
187
|
+
def initialize(should_receive, negative_form_of_to)
|
188
|
+
@should_receive = should_receive
|
189
|
+
@negative_form_of_to = negative_form_of_to
|
190
|
+
end
|
180
191
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
'expect_any_instance_of(Klass).'
|
192
|
+
def original_syntax
|
193
|
+
syntax = if @should_receive.any_instance?
|
194
|
+
'Klass.any_instance.'
|
185
195
|
else
|
186
|
-
'
|
196
|
+
'obj.'
|
187
197
|
end
|
188
|
-
|
189
|
-
|
198
|
+
syntax << "#{@should_receive.method_name}(:message)"
|
199
|
+
syntax << '.any_number_of_times' if @should_receive.any_number_of_times?
|
200
|
+
syntax << '.at_least(0)' if @should_receive.at_least_zero?
|
201
|
+
syntax
|
202
|
+
end
|
203
|
+
|
204
|
+
def converted_syntax
|
205
|
+
syntax = if @should_receive.any_instance?
|
190
206
|
'allow_any_instance_of(Klass).'
|
191
207
|
else
|
192
208
|
'allow(obj).'
|
193
209
|
end
|
194
|
-
|
210
|
+
syntax << (@should_receive.positive? ? 'to' : @negative_form_of_to)
|
211
|
+
syntax << ' receive(:message)'
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
class StubRecord < Record
|
216
|
+
def initialize(should_receive, *)
|
217
|
+
@should_receive = should_receive
|
218
|
+
end
|
219
|
+
|
220
|
+
def original_syntax
|
221
|
+
syntax = "obj.#{@should_receive.method_name}(:message)"
|
222
|
+
syntax << '.any_number_of_times' if @should_receive.any_number_of_times?
|
223
|
+
syntax << '.at_least(0)' if @should_receive.at_least_zero?
|
224
|
+
syntax
|
225
|
+
end
|
195
226
|
|
196
|
-
|
197
|
-
|
227
|
+
def converted_syntax
|
228
|
+
'obj.stub(:message)'
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
class AnyInstanceBlockRecord < Record
|
233
|
+
def initialize(should_receive, *)
|
234
|
+
@should_receive = should_receive
|
235
|
+
end
|
236
|
+
|
237
|
+
def original_syntax
|
238
|
+
"Klass.any_instance.#{@should_receive.method_name}(:message) { |arg| }"
|
239
|
+
end
|
240
|
+
|
241
|
+
def converted_syntax
|
242
|
+
"Klass.any_instance.#{@should_receive.method_name}(:message) { |instance, arg| }"
|
243
|
+
end
|
198
244
|
end
|
199
245
|
end
|
200
246
|
end
|
data/lib/transpec/util.rb
CHANGED
@@ -13,7 +13,7 @@ module Transpec
|
|
13
13
|
module_function
|
14
14
|
|
15
15
|
def proc_literal?(node)
|
16
|
-
return false unless node.
|
16
|
+
return false unless node.block_type?
|
17
17
|
|
18
18
|
send_node = node.children.first
|
19
19
|
receiver_node, method_name, *_ = *send_node
|
@@ -28,7 +28,7 @@ module Transpec
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def const_name(node)
|
31
|
-
return nil if node.nil? || node.
|
31
|
+
return nil if node.nil? || !node.const_type?
|
32
32
|
|
33
33
|
const_names = []
|
34
34
|
const_node = node
|
@@ -38,7 +38,7 @@ module Transpec
|
|
38
38
|
const_names << name
|
39
39
|
break unless namespace_node
|
40
40
|
break unless namespace_node.is_a?(Parser::AST::Node)
|
41
|
-
break if namespace_node.
|
41
|
+
break if namespace_node.cbase_type?
|
42
42
|
const_node = namespace_node
|
43
43
|
end
|
44
44
|
|
@@ -55,14 +55,17 @@ module Transpec
|
|
55
55
|
end
|
56
56
|
|
57
57
|
def in_explicit_parentheses?(node)
|
58
|
-
return false unless node.
|
58
|
+
return false unless node.begin_type?
|
59
59
|
source = node.loc.expression.source
|
60
60
|
source[0] == '(' && source[-1] == ')'
|
61
61
|
end
|
62
62
|
|
63
|
-
def
|
63
|
+
def block_node_taken_by_method(node)
|
64
64
|
parent_node = node.parent_node
|
65
|
-
|
65
|
+
return nil unless parent_node
|
66
|
+
return nil unless parent_node.block_type?
|
67
|
+
return nil unless parent_node.children.first.equal?(node)
|
68
|
+
parent_node
|
66
69
|
end
|
67
70
|
|
68
71
|
def indentation_of_line(arg)
|
@@ -71,12 +74,23 @@ module Transpec
|
|
71
74
|
when Parser::Source::Range then arg.source_line
|
72
75
|
when String then arg
|
73
76
|
else fail ArgumentError, "Invalid argument #{arg}"
|
74
|
-
|
77
|
+
end
|
75
78
|
|
76
79
|
/^(?<indentation>\s*)\S/ =~ line
|
77
80
|
indentation
|
78
81
|
end
|
79
82
|
|
83
|
+
def beginning_of_line_range(arg)
|
84
|
+
range = case arg
|
85
|
+
when AST::Node then arg.loc.expression
|
86
|
+
when Parser::Source::Range then arg
|
87
|
+
else fail ArgumentError, "Invalid argument #{arg}"
|
88
|
+
end
|
89
|
+
|
90
|
+
begin_pos = range.begin_pos - range.column
|
91
|
+
Parser::Source::Range.new(range.source_buffer, begin_pos, begin_pos)
|
92
|
+
end
|
93
|
+
|
80
94
|
def literal?(node)
|
81
95
|
case node.type
|
82
96
|
when *LITERAL_TYPES
|
data/lib/transpec/version.rb
CHANGED
@@ -266,6 +266,58 @@ module Transpec
|
|
266
266
|
end
|
267
267
|
end
|
268
268
|
end
|
269
|
+
|
270
|
+
describe '#send_type?' do
|
271
|
+
context 'when the node is send type' do
|
272
|
+
let(:source) do
|
273
|
+
<<-END
|
274
|
+
do_something
|
275
|
+
END
|
276
|
+
end
|
277
|
+
|
278
|
+
it 'returns true' do
|
279
|
+
ast.send_type?.should be_true
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
context 'when the node is not send type' do
|
284
|
+
let(:source) do
|
285
|
+
<<-END
|
286
|
+
foo = 1
|
287
|
+
END
|
288
|
+
end
|
289
|
+
|
290
|
+
it 'returns false' do
|
291
|
+
ast.send_type?.should be_false
|
292
|
+
end
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
296
|
+
describe '#defined_type?' do
|
297
|
+
context 'when the node is defined? type' do
|
298
|
+
let(:source) do
|
299
|
+
<<-END
|
300
|
+
defined?(Foo)
|
301
|
+
END
|
302
|
+
end
|
303
|
+
|
304
|
+
it 'returns true' do
|
305
|
+
ast.defined_type?.should be_true
|
306
|
+
end
|
307
|
+
end
|
308
|
+
|
309
|
+
context 'when the node is not defined? type' do
|
310
|
+
let(:source) do
|
311
|
+
<<-END
|
312
|
+
foo = 1
|
313
|
+
END
|
314
|
+
end
|
315
|
+
|
316
|
+
it 'returns false' do
|
317
|
+
ast.defined_type?.should be_false
|
318
|
+
end
|
319
|
+
end
|
320
|
+
end
|
269
321
|
end
|
270
322
|
end
|
271
323
|
end
|
@@ -11,7 +11,7 @@ module Transpec
|
|
11
11
|
subject(:commit_message) { CommitMessage.new(report, rspec_version, cli_args) }
|
12
12
|
let(:report) { Report.new }
|
13
13
|
let(:rspec_version) { RSpecVersion.new('2.99.0.beta1') }
|
14
|
-
let(:cli_args) { ['--force'] }
|
14
|
+
let(:cli_args) { ['--force', '--rspec-command', 'bundle exec rspec'] }
|
15
15
|
|
16
16
|
before do
|
17
17
|
report.records << Record.new('obj.stub(:message)', 'allow(obj).to receive(:message)')
|
@@ -47,7 +47,7 @@ module Transpec
|
|
47
47
|
body_lines[0].chomp
|
48
48
|
.should match(/^This conversion is done by Transpec \d+\.\d+\.\d+ with the following command:$/)
|
49
49
|
body_lines[1].chomp
|
50
|
-
.should == ' transpec --force'
|
50
|
+
.should == ' transpec --force --rspec-command "bundle exec rspec"'
|
51
51
|
end
|
52
52
|
|
53
53
|
it 'has blank line after the preface' do
|
@@ -9,19 +9,20 @@ module Transpec
|
|
9
9
|
|
10
10
|
context 'by default' do
|
11
11
|
[
|
12
|
-
[:convert_should?,
|
13
|
-
[:convert_oneliner?,
|
14
|
-
[:convert_should_receive?,
|
15
|
-
[:convert_stub?,
|
16
|
-
[:convert_have_items?,
|
17
|
-
[:convert_its?,
|
18
|
-
[:convert_deprecated_method?,
|
19
|
-
[:parenthesize_matcher_arg?,
|
20
|
-
[:
|
21
|
-
[:
|
22
|
-
[:
|
23
|
-
[:
|
24
|
-
[:
|
12
|
+
[:convert_should?, true],
|
13
|
+
[:convert_oneliner?, true],
|
14
|
+
[:convert_should_receive?, true],
|
15
|
+
[:convert_stub?, true],
|
16
|
+
[:convert_have_items?, true],
|
17
|
+
[:convert_its?, true],
|
18
|
+
[:convert_deprecated_method?, true],
|
19
|
+
[:parenthesize_matcher_arg?, true],
|
20
|
+
[:add_receiver_arg_to_any_instance_implementation_block?, true],
|
21
|
+
[:forced?, false],
|
22
|
+
[:skip_dynamic_analysis?, false],
|
23
|
+
[:negative_form_of_to, 'not_to'],
|
24
|
+
[:boolean_matcher_type, :conditional],
|
25
|
+
[:form_of_be_falsey, 'be_falsey']
|
25
26
|
].each do |attribute, value|
|
26
27
|
describe "##{attribute}" do
|
27
28
|
subject { configuration.send(attribute) }
|
@@ -362,7 +362,8 @@ module Transpec
|
|
362
362
|
end
|
363
363
|
|
364
364
|
describe '#process_expect' do
|
365
|
-
let(:expect_object) { double('expect_object').as_null_object }
|
365
|
+
let(:expect_object) { double('expect_object', receive_matcher: receive_object).as_null_object }
|
366
|
+
let(:receive_object) { double('receive_object') }
|
366
367
|
|
367
368
|
context 'when Configuration#convert_have_items? is true' do
|
368
369
|
before { configuration.convert_have_items = true }
|
@@ -394,6 +395,21 @@ module Transpec
|
|
394
395
|
converter.process_expect(expect_object)
|
395
396
|
end
|
396
397
|
end
|
398
|
+
|
399
|
+
it "invokes #process_any_instance_block with the expect's #receive matcher" do
|
400
|
+
converter.should_receive(:process_any_instance_block).with(receive_object)
|
401
|
+
converter.process_expect(expect_object)
|
402
|
+
end
|
403
|
+
end
|
404
|
+
|
405
|
+
describe '#process_allow' do
|
406
|
+
let(:allow_object) { double('allow_object', receive_matcher: receive_object).as_null_object }
|
407
|
+
let(:receive_object) { double('receive_object') }
|
408
|
+
|
409
|
+
it "invokes #process_any_instance_block with the allow's #receive matcher" do
|
410
|
+
converter.should_receive(:process_any_instance_block).with(receive_object)
|
411
|
+
converter.process_allow(allow_object)
|
412
|
+
end
|
397
413
|
end
|
398
414
|
|
399
415
|
describe '#process_should_receive' do
|
@@ -552,6 +568,11 @@ module Transpec
|
|
552
568
|
end
|
553
569
|
end
|
554
570
|
end
|
571
|
+
|
572
|
+
it 'invokes #process_any_instance_block with the should_receive' do
|
573
|
+
converter.should_receive(:process_any_instance_block).with(should_receive_object)
|
574
|
+
converter.process_allow(should_receive_object)
|
575
|
+
end
|
555
576
|
end
|
556
577
|
|
557
578
|
describe '#process_method_stub' do
|
@@ -638,6 +659,11 @@ module Transpec
|
|
638
659
|
include_examples 'does not invoke MethodStub#remove_allowance_for_no_message!'
|
639
660
|
end
|
640
661
|
end
|
662
|
+
|
663
|
+
it 'invokes #process_any_instance_block with the method stub' do
|
664
|
+
converter.should_receive(:process_any_instance_block).with(method_stub_object)
|
665
|
+
converter.process_allow(method_stub_object)
|
666
|
+
end
|
641
667
|
end
|
642
668
|
|
643
669
|
describe '#process_double' do
|
@@ -877,8 +903,8 @@ module Transpec
|
|
877
903
|
converter.stub(:need_to_modify_expectation_syntax_configuration?).and_return(true)
|
878
904
|
end
|
879
905
|
|
880
|
-
it 'invokes RSpecConfigure
|
881
|
-
rspec_configure.should_receive(:
|
906
|
+
it 'invokes RSpecConfigure.expectations.syntaxes= with :expect' do
|
907
|
+
rspec_configure.expectations.should_receive(:syntaxes=).with(:expect)
|
882
908
|
converter.process_rspec_configure(rspec_configure)
|
883
909
|
end
|
884
910
|
end
|
@@ -888,8 +914,8 @@ module Transpec
|
|
888
914
|
converter.stub(:need_to_modify_expectation_syntax_configuration?).and_return(false)
|
889
915
|
end
|
890
916
|
|
891
|
-
it 'does not invoke RSpecConfigure
|
892
|
-
rspec_configure.should_not_receive(:
|
917
|
+
it 'does not invoke RSpecConfigure.expectations.syntaxes=' do
|
918
|
+
rspec_configure.expectations.should_not_receive(:syntaxes=)
|
893
919
|
converter.process_rspec_configure(rspec_configure)
|
894
920
|
end
|
895
921
|
end
|
@@ -899,8 +925,8 @@ module Transpec
|
|
899
925
|
converter.stub(:need_to_modify_mock_syntax_configuration?).and_return(true)
|
900
926
|
end
|
901
927
|
|
902
|
-
it 'invokes RSpecConfigure
|
903
|
-
rspec_configure.should_receive(:
|
928
|
+
it 'invokes RSpecConfigure.mocks.syntaxes= with :expect' do
|
929
|
+
rspec_configure.mocks.should_receive(:syntaxes=).with(:expect)
|
904
930
|
converter.process_rspec_configure(rspec_configure)
|
905
931
|
end
|
906
932
|
end
|
@@ -910,18 +936,122 @@ module Transpec
|
|
910
936
|
converter.stub(:need_to_modify_mock_syntax_configuration?).and_return(false)
|
911
937
|
end
|
912
938
|
|
913
|
-
it 'does not invoke RSpecConfigure
|
914
|
-
rspec_configure.should_not_receive(:
|
939
|
+
it 'does not invoke RSpecConfigure.mocks.syntaxes=' do
|
940
|
+
rspec_configure.mocks.should_not_receive(:syntaxes=)
|
941
|
+
converter.process_rspec_configure(rspec_configure)
|
942
|
+
end
|
943
|
+
end
|
944
|
+
|
945
|
+
context 'when RSpecVersion#migration_term_of_any_instance_implementation_block? returns true' do
|
946
|
+
before do
|
947
|
+
rspec_version.stub(:migration_term_of_any_instance_implementation_block?).and_return(true)
|
948
|
+
end
|
949
|
+
|
950
|
+
context 'and Configuration#convert_deprecated_method? returns true' do
|
951
|
+
before { configuration.convert_deprecated_method = true }
|
952
|
+
|
953
|
+
context 'and Configuration#add_receiver_arg_to_any_instance_implementation_block? returns true' do
|
954
|
+
before { configuration.add_receiver_arg_to_any_instance_implementation_block = true }
|
955
|
+
|
956
|
+
it 'invokes RSpecConfigure.mocks.yield_receiver_to_any_instance_implementation_blocks= with true' do
|
957
|
+
rspec_configure.mocks.should_receive(:yield_receiver_to_any_instance_implementation_blocks=).with(true)
|
958
|
+
converter.process_rspec_configure(rspec_configure)
|
959
|
+
end
|
960
|
+
end
|
961
|
+
|
962
|
+
context 'and Configuration#add_receiver_arg_to_any_instance_implementation_block? returns false' do
|
963
|
+
before { configuration.add_receiver_arg_to_any_instance_implementation_block = false }
|
964
|
+
|
965
|
+
it 'invokes RSpecConfigure.mocks.yield_receiver_to_any_instance_implementation_blocks= with false' do
|
966
|
+
rspec_configure.mocks.should_receive(:yield_receiver_to_any_instance_implementation_blocks=).with(false)
|
967
|
+
converter.process_rspec_configure(rspec_configure)
|
968
|
+
end
|
969
|
+
end
|
970
|
+
end
|
971
|
+
|
972
|
+
context 'and Configuration#convert_deprecated_method? returns false' do
|
973
|
+
before { configuration.convert_deprecated_method = false }
|
974
|
+
|
975
|
+
it 'does not invoke RSpecConfigure.mocks.yield_receiver_to_any_instance_implementation_blocks=' do
|
976
|
+
rspec_configure.mocks.should_not_receive(:yield_receiver_to_any_instance_implementation_blocks=)
|
977
|
+
converter.process_rspec_configure(rspec_configure)
|
978
|
+
end
|
979
|
+
end
|
980
|
+
end
|
981
|
+
|
982
|
+
context 'when RSpecVersion#migration_term_of_any_instance_implementation_block? returns false' do
|
983
|
+
before do
|
984
|
+
rspec_version.stub(:migration_term_of_any_instance_implementation_block?).and_return(false)
|
985
|
+
end
|
986
|
+
|
987
|
+
it 'does not invoke RSpecConfigure.mocks.yield_receiver_to_any_instance_implementation_blocks=' do
|
988
|
+
rspec_configure.mocks.should_not_receive(:yield_receiver_to_any_instance_implementation_blocks=)
|
915
989
|
converter.process_rspec_configure(rspec_configure)
|
916
990
|
end
|
917
991
|
end
|
918
992
|
end
|
919
993
|
|
920
|
-
|
994
|
+
describe '#process_any_instance_block' do
|
995
|
+
let(:messaging_host) { double('messaging host').as_null_object }
|
996
|
+
|
997
|
+
context 'when RSpecVersion#migration_term_of_any_instance_implementation_block? returns true' do
|
998
|
+
before do
|
999
|
+
rspec_version.stub(:migration_term_of_any_instance_implementation_block?).and_return(true)
|
1000
|
+
end
|
1001
|
+
|
1002
|
+
context 'and Configuration#convert_deprecated_method? returns true' do
|
1003
|
+
before { configuration.convert_deprecated_method = true }
|
1004
|
+
|
1005
|
+
context 'and Configuration#add_receiver_arg_to_any_instance_implementation_block? returns true' do
|
1006
|
+
before { configuration.add_receiver_arg_to_any_instance_implementation_block = true }
|
1007
|
+
|
1008
|
+
it 'invokes #add_receiver_arg_to_any_instance_implementation_block!' do
|
1009
|
+
messaging_host.should_receive(:add_receiver_arg_to_any_instance_implementation_block!)
|
1010
|
+
converter.process_any_instance_block(messaging_host)
|
1011
|
+
end
|
1012
|
+
end
|
1013
|
+
|
1014
|
+
context 'and Configuration#add_receiver_arg_to_any_instance_implementation_block? returns false' do
|
1015
|
+
before { configuration.add_receiver_arg_to_any_instance_implementation_block = false }
|
1016
|
+
|
1017
|
+
it 'does nothing' do
|
1018
|
+
messaging_host.should_not_receive(:add_instance_arg_to_any_instance_implementation_block!)
|
1019
|
+
converter.process_any_instance_block(messaging_host)
|
1020
|
+
end
|
1021
|
+
end
|
1022
|
+
end
|
1023
|
+
|
1024
|
+
context 'and Configuration#convert_deprecated_method? returns false' do
|
1025
|
+
before { configuration.convert_deprecated_method = false }
|
1026
|
+
|
1027
|
+
context 'and Configuration#add_receiver_arg_to_any_instance_implementation_block? returns true' do
|
1028
|
+
before { configuration.add_receiver_arg_to_any_instance_implementation_block = true }
|
1029
|
+
|
1030
|
+
it 'does nothing' do
|
1031
|
+
messaging_host.should_not_receive(:add_instance_arg_to_any_instance_implementation_block!)
|
1032
|
+
converter.process_any_instance_block(messaging_host)
|
1033
|
+
end
|
1034
|
+
end
|
1035
|
+
end
|
1036
|
+
end
|
1037
|
+
|
1038
|
+
context 'when RSpecVersion#migration_term_of_any_instance_implementation_block? returns false' do
|
1039
|
+
before do
|
1040
|
+
rspec_version.stub(:migration_term_of_any_instance_implementation_block?).and_return(false)
|
1041
|
+
end
|
1042
|
+
|
1043
|
+
it 'does nothing' do
|
1044
|
+
messaging_host.should_not_receive(:add_instance_arg_to_any_instance_implementation_block!)
|
1045
|
+
converter.process_any_instance_block(messaging_host)
|
1046
|
+
end
|
1047
|
+
end
|
1048
|
+
end
|
1049
|
+
|
1050
|
+
shared_examples 'syntaxes' do |framework_type, expectations|
|
921
1051
|
expectations.each do |current_syntaxes, return_value|
|
922
|
-
context "and RSpecConfigure
|
1052
|
+
context "and RSpecConfigure.#{framework_type}.syntaxes returns #{current_syntaxes.inspect}" do
|
923
1053
|
before do
|
924
|
-
rspec_configure.
|
1054
|
+
rspec_configure.stub_chain(framework_type, :syntaxes).and_return(current_syntaxes)
|
925
1055
|
end
|
926
1056
|
|
927
1057
|
it "returns #{return_value}" do
|
@@ -930,9 +1060,10 @@ module Transpec
|
|
930
1060
|
end
|
931
1061
|
end
|
932
1062
|
|
933
|
-
context "and RSpecConfigure
|
1063
|
+
context "and RSpecConfigure.#{framework_type}.syntaxes raises UnknownSyntaxError" do
|
934
1064
|
before do
|
935
|
-
rspec_configure.
|
1065
|
+
rspec_configure.stub_chain(framework_type, :syntaxes)
|
1066
|
+
.and_raise(Syntax::RSpecConfigure::Framework::UnknownSyntaxError)
|
936
1067
|
end
|
937
1068
|
|
938
1069
|
it 'returns false' do
|
@@ -948,7 +1079,7 @@ module Transpec
|
|
948
1079
|
context 'when Configuration#convert_should? is true' do
|
949
1080
|
before { configuration.convert_should = true }
|
950
1081
|
|
951
|
-
include_examples 'syntaxes', :
|
1082
|
+
include_examples 'syntaxes', :expectations, {
|
952
1083
|
[] => false,
|
953
1084
|
[:should] => true,
|
954
1085
|
[:expect] => false,
|
@@ -959,7 +1090,7 @@ module Transpec
|
|
959
1090
|
context 'when Configuration#convert_should? is false' do
|
960
1091
|
before { configuration.convert_should = false }
|
961
1092
|
|
962
|
-
include_examples 'syntaxes', :
|
1093
|
+
include_examples 'syntaxes', :expectations, {
|
963
1094
|
[] => false,
|
964
1095
|
[:should] => false,
|
965
1096
|
[:expect] => false,
|
@@ -978,7 +1109,7 @@ module Transpec
|
|
978
1109
|
context 'and Configuration#convert_stub? is true' do
|
979
1110
|
before { configuration.convert_stub = true }
|
980
1111
|
|
981
|
-
include_examples 'syntaxes', :
|
1112
|
+
include_examples 'syntaxes', :mocks, {
|
982
1113
|
[] => false,
|
983
1114
|
[:should] => true,
|
984
1115
|
[:expect] => false,
|
@@ -989,7 +1120,7 @@ module Transpec
|
|
989
1120
|
context 'and Configuration#convert_stub? is false' do
|
990
1121
|
before { configuration.convert_stub = false }
|
991
1122
|
|
992
|
-
include_examples 'syntaxes', :
|
1123
|
+
include_examples 'syntaxes', :mocks, {
|
993
1124
|
[] => false,
|
994
1125
|
[:should] => true,
|
995
1126
|
[:expect] => false,
|
@@ -1004,7 +1135,7 @@ module Transpec
|
|
1004
1135
|
context 'and Configuration#convert_stub? is true' do
|
1005
1136
|
before { configuration.convert_stub = true }
|
1006
1137
|
|
1007
|
-
include_examples 'syntaxes', :
|
1138
|
+
include_examples 'syntaxes', :mocks, {
|
1008
1139
|
[] => false,
|
1009
1140
|
[:should] => true,
|
1010
1141
|
[:expect] => false,
|
@@ -1015,7 +1146,7 @@ module Transpec
|
|
1015
1146
|
context 'and Configuration#convert_stub? is false' do
|
1016
1147
|
before { configuration.convert_stub = false }
|
1017
1148
|
|
1018
|
-
include_examples 'syntaxes', :
|
1149
|
+
include_examples 'syntaxes', :mocks, {
|
1019
1150
|
[] => false,
|
1020
1151
|
[:should] => false,
|
1021
1152
|
[:expect] => false,
|