Class: Transpec::Converter
Overview
rubocop:disable ClassLength
Instance Attribute Summary collapse
Instance Method Summary
collapse
#dispatch_node, #dispatch_syntax, #handler_names, #invoke_handler
create_source_rewriter, #rewrite, #rewrite_file!, #rewrite_source
Constructor Details
#initialize(spec_suite = nil, config = nil) ⇒ Converter
Returns a new instance of Converter.
22
23
24
25
26
|
# File 'lib/transpec/converter.rb', line 22
def initialize(spec_suite = nil, config = nil)
@spec_suite = spec_suite || SpecSuite.new
@config = config || Config.new
@report = Report.new
end
|
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
16
17
18
|
# File 'lib/transpec/converter.rb', line 16
def config
@config
end
|
#project ⇒ Object
Returns the value of attribute project.
16
17
18
|
# File 'lib/transpec/converter.rb', line 16
def project
@project
end
|
#report ⇒ Object
Returns the value of attribute report.
16
17
18
|
# File 'lib/transpec/converter.rb', line 16
def report
@report
end
|
#spec_suite ⇒ Object
Returns the value of attribute spec_suite.
16
17
18
|
# File 'lib/transpec/converter.rb', line 16
def spec_suite
@spec_suite
end
|
Instance Method Details
#need_to_modify_yield_receiver_to_any_instance_implementation_blocks_config? ⇒ Boolean
221
222
223
224
|
# File 'lib/transpec/converter.rb', line 221
def need_to_modify_yield_receiver_to_any_instance_implementation_blocks_config?
rspec_version.rspec_2_99? && config.convert?(:deprecated) &&
spec_suite.need_to_modify_yield_receiver_to_any_instance_implementation_blocks_config?
end
|
#process(ast, source_rewriter) ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/transpec/converter.rb', line 40
def process(ast, source_rewriter)
return unless ast
ast.each_node do |node|
begin
dispatch_node(node, runtime_data, project, source_rewriter, report)
rescue ConversionError => error
report.conversion_errors << error
end
end
end
|
#process_any_instance_block(messaging_host) ⇒ Object
213
214
215
216
217
218
219
|
# File 'lib/transpec/converter.rb', line 213
def process_any_instance_block(messaging_host)
return unless messaging_host
return unless rspec_version.rspec_2_99?
return unless config.convert?(:deprecated)
return unless config.add_receiver_arg_to_any_instance_implementation_block?
messaging_host.add_receiver_arg_to_any_instance_implementation_block!
end
|
#process_be_boolean(be_boolean) ⇒ Object
116
117
118
119
120
121
122
123
124
125
126
|
# File 'lib/transpec/converter.rb', line 116
def process_be_boolean(be_boolean)
return unless rspec_version.be_truthy_available?
return unless config.convert?(:deprecated)
case config.boolean_matcher_type
when :conditional
be_boolean.convert_to_conditional_matcher!(config.form_of_be_falsey)
when :exact
be_boolean.convert_to_exact_matcher!
end
end
|
#process_be_close(be_close) ⇒ Object
128
129
130
|
# File 'lib/transpec/converter.rb', line 128
def process_be_close(be_close)
be_close.convert_to_be_within! if config.convert?(:deprecated)
end
|
#process_current_example(current_example) ⇒ Object
153
154
155
156
|
# File 'lib/transpec/converter.rb', line 153
def process_current_example(current_example)
return unless rspec_version.yielded_example_available?
current_example.convert! if config.convert?(:deprecated)
end
|
#process_double(double) ⇒ Object
89
90
91
|
# File 'lib/transpec/converter.rb', line 89
def process_double(double)
double.convert_to_double! if config.convert?(:deprecated)
end
|
#process_example(example) ⇒ Object
143
144
145
146
|
# File 'lib/transpec/converter.rb', line 143
def process_example(example)
return if !rspec_version.rspec_2_99? || !config.convert?(:pending)
example.convert_pending_to_skip!
end
|
#process_example_group(example_group) ⇒ Object
163
164
165
166
167
168
169
170
171
172
|
# File 'lib/transpec/converter.rb', line 163
def process_example_group(example_group)
if rspec_version.non_monkey_patch_example_group_available? && config.convert?(:example_group)
example_group.convert_to_non_monkey_patch!
end
if rspec_version.implicit_spec_type_disablement_available? &&
config.add_explicit_type_metadata_to_example_group?
example_group.add_explicit_type_metadata!
end
end
|
#process_have(have) ⇒ Object
197
198
199
200
|
# File 'lib/transpec/converter.rb', line 197
def process_have(have)
return if !have || !config.convert?(:have_items)
have.convert_to_standard_expectation!(config.parenthesize_matcher_arg)
end
|
#process_hook(hook) ⇒ Object
202
203
204
205
|
# File 'lib/transpec/converter.rb', line 202
def process_hook(hook)
return if !config.convert?(:hook_scope) || !rspec_version.hook_scope_alias_available?
hook.convert_scope_name!
end
|
#process_its(its) ⇒ Object
139
140
141
|
# File 'lib/transpec/converter.rb', line 139
def process_its(its)
its.convert_to_describe_subject_it! if config.convert?(:its)
end
|
#process_matcher_definition(matcher_definition) ⇒ Object
158
159
160
161
|
# File 'lib/transpec/converter.rb', line 158
def process_matcher_definition(matcher_definition)
return unless rspec_version.non_should_matcher_protocol_available?
matcher_definition.convert_deprecated_method! if config.convert?(:deprecated)
end
|
#process_method_stub(method_stub) ⇒ Object
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
# File 'lib/transpec/converter.rb', line 93
def process_method_stub(method_stub)
if config.convert?(:stub)
if !method_stub.hash_arg? ||
rspec_version.receive_messages_available? ||
config.convert?(:stub_with_hash)
method_stub.allowize!
elsif config.convert?(:deprecated)
method_stub.convert_deprecated_method!
end
elsif config.convert?(:deprecated)
method_stub.convert_deprecated_method!
end
method_stub.remove_no_message_allowance! if config.convert?(:deprecated)
end
|
#process_oneliner_should(oneliner_should) ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/transpec/converter.rb', line 57
def process_oneliner_should(oneliner_should)
negative_form = config.negative_form_of_to
should_convert_have_items = config.convert?(:have_items) &&
oneliner_should.have_matcher.conversion_target?
if should_convert_have_items
if config.convert?(:should)
oneliner_should.convert_have_items_to_standard_expect!(negative_form)
else
oneliner_should.convert_have_items_to_standard_should!
end
elsif config.convert?(:oneliner) && rspec_version.oneliner_is_expected_available?
oneliner_should.expectize!(negative_form)
end
end
|
#process_operator(operator) ⇒ Object
109
110
111
112
113
114
|
# File 'lib/transpec/converter.rb', line 109
def process_operator(operator)
return unless config.convert?(:should)
return if operator.expectation.is_a?(Syntax::OnelinerShould) &&
!rspec_version.oneliner_is_expected_available?
operator.convert_operator!(config.parenthesize_matcher_arg?)
end
|
#process_pending(pending) ⇒ Object
148
149
150
151
|
# File 'lib/transpec/converter.rb', line 148
def process_pending(pending)
return if !rspec_version.rspec_2_99? || !config.convert?(:pending)
pending.convert_deprecated_syntax!
end
|
#process_raise_error(raise_error) ⇒ Object
132
133
134
135
136
137
|
# File 'lib/transpec/converter.rb', line 132
def process_raise_error(raise_error)
return unless raise_error
if config.convert?(:deprecated)
raise_error.remove_error_specification_with_negative_expectation!
end
end
|
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
# File 'lib/transpec/converter.rb', line 174
def process_rspec_configure(rspec_configure)
if config.convert?(:deprecated)
rspec_configure.convert_deprecated_options!
end
if spec_suite.main_rspec_configure_node?(rspec_configure.node)
if rspec_version.non_monkey_patch_example_group_available? &&
config.convert?(:example_group)
rspec_configure.expose_dsl_globally = false
end
if need_to_modify_yield_receiver_to_any_instance_implementation_blocks_config?
should_yield = config.add_receiver_arg_to_any_instance_implementation_block?
rspec_configure.mocks.yield_receiver_to_any_instance_implementation_blocks = should_yield
end
if rspec_version.implicit_spec_type_disablement_available? &&
!config.add_explicit_type_metadata_to_example_group?
rspec_configure.infer_spec_type_from_file_location!
end
end
end
|
#process_should(should) ⇒ Object
52
53
54
55
|
# File 'lib/transpec/converter.rb', line 52
def process_should(should)
return unless config.convert?(:should)
should.expectize!(config.negative_form_of_to)
end
|
#process_should_receive(should_receive) ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/transpec/converter.rb', line 73
def process_should_receive(should_receive)
if should_receive.useless_expectation?
if config.convert?(:deprecated)
if config.convert?(:stub)
should_receive.allowize_useless_expectation!(config.negative_form_of_to)
else
should_receive.stubize_useless_expectation!
end
elsif config.convert?(:should_receive)
should_receive.expectize!(config.negative_form_of_to)
end
elsif config.convert?(:should_receive)
should_receive.expectize!(config.negative_form_of_to)
end
end
|
#process_useless_and_return(messaging_host) ⇒ Object
207
208
209
210
211
|
# File 'lib/transpec/converter.rb', line 207
def process_useless_and_return(messaging_host)
return unless messaging_host
return unless config.convert?(:deprecated)
messaging_host.remove_useless_and_return!
end
|
#rspec_version ⇒ Object
36
37
38
|
# File 'lib/transpec/converter.rb', line 36
def rspec_version
project.rspec_version
end
|
#runtime_data ⇒ Object
32
33
34
|
# File 'lib/transpec/converter.rb', line 32
def runtime_data
spec_suite.runtime_data
end
|