Class: Transpec::Converter
- Inherits:
-
BaseRewriter
- Object
- BaseRewriter
- Transpec::Converter
- Defined in:
- lib/transpec/converter.rb
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#context_errors ⇒ Object
readonly
Returns the value of attribute context_errors.
-
#report ⇒ Object
readonly
Returns the value of attribute report.
-
#rspec_version ⇒ Object
readonly
Returns the value of attribute rspec_version.
-
#runtime_data ⇒ Object
readonly
Returns the value of attribute runtime_data.
Instance Method Summary collapse
- #dispatch_node(node, source_rewriter) ⇒ Object
-
#initialize(configuration = nil, rspec_version = nil, runtime_data = nil, report = nil) ⇒ Converter
constructor
A new instance of Converter.
- #need_to_modify_expectation_syntax_configuration?(rspec_configure) ⇒ Boolean
- #need_to_modify_mock_syntax_configuration?(rspec_configure) ⇒ Boolean
- #process(ast, source_rewriter) ⇒ Object
- #process_be_boolean(be_boolean) ⇒ Object
- #process_be_close(be_close) ⇒ Object
- #process_double(double) ⇒ Object
- #process_example(example) ⇒ Object
- #process_expect(expect) ⇒ Object
- #process_its(its) ⇒ Object
- #process_method_stub(method_stub) ⇒ Object
- #process_oneliner_should(oneliner_should) ⇒ Object
- #process_raise_error(raise_error) ⇒ Object
- #process_rspec_configure(rspec_configure) ⇒ Object
- #process_should(should) ⇒ Object
- #process_should_receive(should_receive) ⇒ Object
Methods inherited from BaseRewriter
Constructor Details
#initialize(configuration = nil, rspec_version = nil, runtime_data = nil, report = nil) ⇒ Converter
Returns a new instance of Converter.
28 29 30 31 32 33 34 |
# File 'lib/transpec/converter.rb', line 28 def initialize(configuration = nil, rspec_version = nil, runtime_data = nil, report = nil) @configuration = configuration || Configuration.new @rspec_version = rspec_version || Transpec.current_rspec_version @runtime_data = runtime_data @report = report || Report.new @context_errors = [] end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
23 24 25 |
# File 'lib/transpec/converter.rb', line 23 def configuration @configuration end |
#context_errors ⇒ Object (readonly)
Returns the value of attribute context_errors.
23 24 25 |
# File 'lib/transpec/converter.rb', line 23 def context_errors @context_errors end |
#report ⇒ Object (readonly)
Returns the value of attribute report.
23 24 25 |
# File 'lib/transpec/converter.rb', line 23 def report @report end |
#rspec_version ⇒ Object (readonly)
Returns the value of attribute rspec_version.
23 24 25 |
# File 'lib/transpec/converter.rb', line 23 def rspec_version @rspec_version end |
#runtime_data ⇒ Object (readonly)
Returns the value of attribute runtime_data.
23 24 25 |
# File 'lib/transpec/converter.rb', line 23 def runtime_data @runtime_data end |
Instance Method Details
#dispatch_node(node, source_rewriter) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/transpec/converter.rb', line 43 def dispatch_node(node, source_rewriter) Syntax.standalone_syntaxes.each do |syntax_class| next unless syntax_class.conversion_target_node?(node, @runtime_data) syntax = syntax_class.new(node, source_rewriter, @runtime_data, @report) handler_name = "process_#{syntax_class.snake_case_name}" send(handler_name, syntax) break end rescue OverlappedRewriteError # rubocop:disable HandleExceptions rescue ContextError => error @context_errors << error end |
#need_to_modify_expectation_syntax_configuration?(rspec_configure) ⇒ Boolean
172 173 174 175 176 177 |
# File 'lib/transpec/converter.rb', line 172 def need_to_modify_expectation_syntax_configuration?(rspec_configure) return false unless @configuration.convert_should? rspec_configure.expectation_syntaxes == [:should] rescue Syntax::RSpecConfigure::UnknownSyntaxError false end |
#need_to_modify_mock_syntax_configuration?(rspec_configure) ⇒ Boolean
179 180 181 182 183 184 185 |
# File 'lib/transpec/converter.rb', line 179 def need_to_modify_mock_syntax_configuration?(rspec_configure) return false if !@configuration.convert_should_receive? && !@configuration.convert_stub? rspec_configure.mock_syntaxes == [:should] rescue Syntax::RSpecConfigure::UnknownSyntaxError false end |
#process(ast, source_rewriter) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/transpec/converter.rb', line 36 def process(ast, source_rewriter) return unless ast ast.each_node do |node| dispatch_node(node, source_rewriter) end end |
#process_be_boolean(be_boolean) ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/transpec/converter.rb', line 131 def process_be_boolean(be_boolean) return unless @rspec_version.be_truthy_available? return unless @configuration.convert_deprecated_method? case @configuration.boolean_matcher_type when :conditional be_boolean.convert_to_conditional_matcher!(@configuration.form_of_be_falsey) when :exact be_boolean.convert_to_exact_matcher! end end |
#process_be_close(be_close) ⇒ Object
143 144 145 |
# File 'lib/transpec/converter.rb', line 143 def process_be_close(be_close) be_close.convert_to_be_within! if @configuration.convert_deprecated_method? end |
#process_double(double) ⇒ Object
117 118 119 |
# File 'lib/transpec/converter.rb', line 117 def process_double(double) double.convert_to_double! if @configuration.convert_deprecated_method? end |
#process_example(example) ⇒ Object
157 158 159 160 |
# File 'lib/transpec/converter.rb', line 157 def process_example(example) return unless @rspec_version.yielded_example_available? example.convert! if @configuration.convert_deprecated_method? end |
#process_expect(expect) ⇒ Object
94 95 96 97 98 99 |
# File 'lib/transpec/converter.rb', line 94 def process_expect(expect) if expect.have_matcher && @configuration.convert_have_items? parenthesize_matcher_arg = @configuration.parenthesize_matcher_arg expect.have_matcher.convert_to_standard_expectation!(parenthesize_matcher_arg) end end |
#process_its(its) ⇒ Object
153 154 155 |
# File 'lib/transpec/converter.rb', line 153 def process_its(its) its.convert_to_describe_subject_it! if @configuration.convert_its? end |
#process_method_stub(method_stub) ⇒ Object
121 122 123 124 125 126 127 128 129 |
# File 'lib/transpec/converter.rb', line 121 def process_method_stub(method_stub) if @configuration.convert_stub? method_stub.allowize!(@rspec_version) elsif @configuration.convert_deprecated_method? method_stub.convert_deprecated_method! end method_stub. if @configuration.convert_deprecated_method? end |
#process_oneliner_should(oneliner_should) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/transpec/converter.rb', line 73 def process_oneliner_should(oneliner_should) negative_form = @configuration.negative_form_of_to parenthesize = @configuration.parenthesize_matcher_arg? # TODO: Referencing oneliner_should.have_matcher.project_requires_collection_matcher? # from this converter is considered bad design. should_convert_have_items = @configuration.convert_have_items? && oneliner_should.have_matcher && !oneliner_should.have_matcher.project_requires_collection_matcher? if should_convert_have_items if @configuration.convert_should? oneliner_should.convert_have_items_to_standard_expect!(negative_form, parenthesize) else oneliner_should.convert_have_items_to_standard_should! end elsif @configuration.convert_oneliner? && @rspec_version.one_liner_is_expected_available? oneliner_should.expectize!(negative_form, parenthesize) end end |
#process_raise_error(raise_error) ⇒ Object
147 148 149 150 151 |
# File 'lib/transpec/converter.rb', line 147 def process_raise_error(raise_error) if @configuration.convert_deprecated_method? raise_error.remove_error_specification_with_negative_expectation! end end |
#process_rspec_configure(rspec_configure) ⇒ Object
162 163 164 165 166 167 168 169 170 |
# File 'lib/transpec/converter.rb', line 162 def process_rspec_configure(rspec_configure) if need_to_modify_expectation_syntax_configuration?(rspec_configure) rspec_configure.modify_expectation_syntaxes!(:expect) end if need_to_modify_mock_syntax_configuration?(rspec_configure) rspec_configure.modify_mock_syntaxes!(:expect) end end |
#process_should(should) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/transpec/converter.rb', line 59 def process_should(should) if @configuration.convert_should? should.expectize!( @configuration.negative_form_of_to, @configuration.parenthesize_matcher_arg? ) end if should.have_matcher && @configuration.convert_have_items? parenthesize_matcher_arg = @configuration.parenthesize_matcher_arg should.have_matcher.convert_to_standard_expectation!(parenthesize_matcher_arg) end end |
#process_should_receive(should_receive) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/transpec/converter.rb', line 101 def process_should_receive(should_receive) if should_receive.useless_expectation? if @configuration.convert_deprecated_method? if @configuration.convert_stub? should_receive.allowize_useless_expectation!(@configuration.negative_form_of_to) else should_receive.stubize_useless_expectation! end elsif @configuration.convert_should_receive? should_receive.expectize!(@configuration.negative_form_of_to) end elsif @configuration.convert_should_receive? should_receive.expectize!(@configuration.negative_form_of_to) end end |