transpec 1.10.4 → 1.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -3
- data/CHANGELOG.md +9 -0
- data/README.md +96 -18
- data/README.md.erb +117 -51
- data/lib/transpec/base_rewriter.rb +25 -28
- data/lib/transpec/cli.rb +27 -14
- data/lib/transpec/configuration.rb +2 -1
- data/lib/transpec/converter.rb +54 -32
- data/lib/transpec/dynamic_analyzer/helper.rb.erb +44 -0
- data/lib/transpec/dynamic_analyzer/node_util.rb +17 -0
- data/lib/transpec/dynamic_analyzer/rewriter.rb +12 -4
- data/lib/transpec/dynamic_analyzer/runtime_data.rb +3 -4
- data/lib/transpec/dynamic_analyzer.rb +14 -52
- data/lib/transpec/option_parser.rb +89 -81
- data/lib/transpec/processed_source.rb +48 -0
- data/lib/transpec/record.rb +2 -2
- data/lib/transpec/report.rb +5 -1
- data/lib/transpec/rspec_dsl.rb +12 -2
- data/lib/transpec/rspec_version.rb +8 -7
- data/lib/transpec/spec_suite.rb +114 -0
- data/lib/transpec/syntax/example.rb +4 -20
- data/lib/transpec/syntax/example_group.rb +38 -0
- data/lib/transpec/syntax/have.rb +6 -9
- data/lib/transpec/syntax/its.rb +5 -7
- data/lib/transpec/syntax/method_stub.rb +12 -13
- data/lib/transpec/syntax/mixin/any_instance_block.rb +14 -6
- data/lib/transpec/syntax/mixin/context_sensitive.rb +41 -0
- data/lib/transpec/syntax/mixin/matcher_owner.rb +16 -26
- data/lib/transpec/syntax/mixin/monkey_patch_any_instance.rb +1 -1
- data/lib/transpec/syntax/mixin/no_message_allowance.rb +2 -2
- data/lib/transpec/syntax/mixin/useless_and_return.rb +2 -2
- data/lib/transpec/syntax/oneliner_should.rb +9 -13
- data/lib/transpec/syntax/operator.rb +3 -7
- data/lib/transpec/syntax/pending.rb +4 -20
- data/lib/transpec/syntax/rspec_configure/configuration_modification.rb +86 -0
- data/lib/transpec/syntax/rspec_configure/framework.rb +45 -86
- data/lib/transpec/syntax/rspec_configure.rb +18 -6
- data/lib/transpec/syntax/should.rb +3 -5
- data/lib/transpec/syntax/should_receive.rb +1 -1
- data/lib/transpec/syntax.rb +8 -0
- data/lib/transpec/util.rb +0 -8
- data/lib/transpec/version.rb +2 -2
- data/spec/acceptance/configuration_modification_spec.rb +132 -0
- data/spec/acceptance/conversion_spec.rb +114 -0
- data/spec/support/shared_context.rb +6 -12
- data/spec/transpec/cli_spec.rb +21 -23
- data/spec/transpec/configuration_spec.rb +2 -1
- data/spec/transpec/converter_spec.rb +292 -213
- data/spec/transpec/dynamic_analyzer/rewriter_spec.rb +3 -3
- data/spec/transpec/dynamic_analyzer_spec.rb +8 -2
- data/spec/transpec/option_parser_spec.rb +42 -4
- data/spec/transpec/processed_source_spec.rb +67 -0
- data/spec/transpec/rspec_version_spec.rb +8 -2
- data/spec/transpec/spec_suite_spec.rb +107 -0
- data/spec/transpec/syntax/allow_spec.rb +9 -27
- data/spec/transpec/syntax/example_group_spec.rb +172 -0
- data/spec/transpec/syntax/expect_spec.rb +18 -54
- data/spec/transpec/syntax/have_spec.rb +35 -14
- data/spec/transpec/syntax/its_spec.rb +27 -7
- data/spec/transpec/syntax/method_stub_spec.rb +31 -8
- data/spec/transpec/syntax/oneliner_should_spec.rb +22 -131
- data/spec/transpec/syntax/rspec_configure_spec.rb +118 -15
- data/spec/transpec/syntax/should_spec.rb +51 -82
- data/tasks/fixtures/guard/COMMIT_EDITMSG +80 -0
- data/tasks/fixtures/mail/COMMIT_EDITMSG +84 -0
- data/tasks/fixtures/twitter/COMMIT_EDITMSG +36 -0
- data/tasks/lib/transpec_test.rb +23 -2
- data/tasks/readme.rake +35 -0
- metadata +22 -4
- data/lib/transpec/parser.rb +0 -9
@@ -29,7 +29,7 @@ module Transpec
|
|
29
29
|
|
30
30
|
def dynamic_analysis_target?
|
31
31
|
super &&
|
32
|
-
|
32
|
+
receiver_node &&
|
33
33
|
[:stub, :stub!, :stub_chain, :unstub, :unstub!].include?(method_name)
|
34
34
|
end
|
35
35
|
|
@@ -55,9 +55,11 @@ module Transpec
|
|
55
55
|
arg_node.hash_type?
|
56
56
|
end
|
57
57
|
|
58
|
+
def unstub?
|
59
|
+
[:unstub, :unstub!].include?(method_name)
|
60
|
+
end
|
61
|
+
|
58
62
|
def allowize!(rspec_version)
|
59
|
-
# There's no way of unstubbing in #allow syntax.
|
60
|
-
return unless [:stub, :stub!, :stub_chain].include?(method_name)
|
61
63
|
return if method_name == :stub_chain && !rspec_version.receive_message_chain_available?
|
62
64
|
|
63
65
|
unless allow_to_receive_available?
|
@@ -133,6 +135,7 @@ module Transpec
|
|
133
135
|
expression << message_source(message_node)
|
134
136
|
expression << (keep_form_around_arg ? range_after_arg.source : ')')
|
135
137
|
expression << ".and_return(#{value_node.loc.expression.source})" if value_node
|
138
|
+
expression << '.and_call_original' if unstub?
|
136
139
|
expression
|
137
140
|
end
|
138
141
|
|
@@ -168,16 +171,11 @@ module Transpec
|
|
168
171
|
|
169
172
|
def register_record(conversion_type)
|
170
173
|
record_class = case conversion_type
|
171
|
-
when :deprecated
|
172
|
-
|
173
|
-
when :
|
174
|
-
|
175
|
-
|
176
|
-
MonkeyPatchUselessAndReturnRecord
|
177
|
-
when :any_instance_block
|
178
|
-
MonkeyPatchAnyInstanceBlockRecord
|
179
|
-
else
|
180
|
-
AllowRecord
|
174
|
+
when :deprecated then DeprecatedMethodRecord
|
175
|
+
when :no_message_allowance then NoMessageAllowanceRecord
|
176
|
+
when :useless_and_return then MonkeyPatchUselessAndReturnRecord
|
177
|
+
when :any_instance_block then MonkeyPatchAnyInstanceBlockRecord
|
178
|
+
else AllowRecord
|
181
179
|
end
|
182
180
|
report.records << record_class.new(self, conversion_type)
|
183
181
|
end
|
@@ -207,6 +205,7 @@ module Transpec
|
|
207
205
|
when :allow_to_receive
|
208
206
|
syntax << 'receive(:message)'
|
209
207
|
syntax << '.and_return(value)' if @method_stub.hash_arg?
|
208
|
+
syntax << '.and_call_original' if @method_stub.unstub?
|
210
209
|
when :allow_to_receive_messages
|
211
210
|
syntax << 'receive_messages(:message => value)'
|
212
211
|
when :allow_to_receive_message_chain
|
@@ -11,18 +11,26 @@ module Transpec
|
|
11
11
|
extend ActiveSupport::Concern
|
12
12
|
include Send
|
13
13
|
|
14
|
-
def
|
15
|
-
|
16
|
-
|
17
|
-
return unless first_arg_node
|
14
|
+
def need_to_add_receiver_arg_to_any_instance_implementation_block?
|
15
|
+
first_arg_node = any_instance_block_first_arg_node
|
16
|
+
return false unless first_arg_node
|
18
17
|
first_arg_name = first_arg_node.children.first
|
19
|
-
|
20
|
-
|
18
|
+
first_arg_name != :instance
|
19
|
+
end
|
20
|
+
|
21
|
+
def add_receiver_arg_to_any_instance_implementation_block!
|
22
|
+
return unless need_to_add_receiver_arg_to_any_instance_implementation_block?
|
23
|
+
insert_before(any_instance_block_first_arg_node.loc.expression, 'instance, ')
|
21
24
|
true
|
22
25
|
end
|
23
26
|
|
24
27
|
private
|
25
28
|
|
29
|
+
def any_instance_block_first_arg_node
|
30
|
+
return nil unless any_instance_block_node
|
31
|
+
any_instance_block_node.children[1].children[0]
|
32
|
+
end
|
33
|
+
|
26
34
|
def any_instance_block_node
|
27
35
|
return unless any_instance?
|
28
36
|
Util.each_backward_chained_node(node).find(&:block_type?)
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'active_support/concern'
|
4
|
+
require 'transpec/syntax/mixin/send'
|
5
|
+
|
6
|
+
module Transpec
|
7
|
+
class Syntax
|
8
|
+
module Mixin
|
9
|
+
module ContextSensitive
|
10
|
+
extend ActiveSupport::Concern
|
11
|
+
include Send
|
12
|
+
|
13
|
+
included do
|
14
|
+
define_dynamic_analysis do |rewriter|
|
15
|
+
code = "is_a?(Class) && ancestors.any? { |a| a.name == 'RSpec::Core::ExampleGroup' }"
|
16
|
+
rewriter.register_request(node, :example_group_context?, code, :context)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def conversion_target?
|
21
|
+
return false unless dynamic_analysis_target?
|
22
|
+
|
23
|
+
in_example_group_context = if runtime_data.run?(node)
|
24
|
+
# If we have runtime data, check with it.
|
25
|
+
return false unless defined_by_rspec?
|
26
|
+
runtime_data[node, :example_group_context?]
|
27
|
+
else
|
28
|
+
# Otherwise check statically.
|
29
|
+
static_context_inspector.scopes.last == :example_group
|
30
|
+
end
|
31
|
+
|
32
|
+
in_example_group_context == should_be_in_example_group_context?
|
33
|
+
end
|
34
|
+
|
35
|
+
def should_be_in_example_group_context?
|
36
|
+
fail NotImplementedError
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -9,37 +9,27 @@ module Transpec
|
|
9
9
|
extend ActiveSupport::Concern
|
10
10
|
|
11
11
|
module ClassMethods
|
12
|
-
def add_matcher(matcher_class)
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
matcher =
|
19
|
-
|
20
|
-
matcher.register_dynamic_analysis_request(rewriter)
|
21
|
-
end
|
12
|
+
def add_matcher(matcher_class)
|
13
|
+
accessor = "#{matcher_class.snake_case_name}_matcher"
|
14
|
+
ivar = "@#{accessor}"
|
15
|
+
|
16
|
+
define_method(accessor) do
|
17
|
+
return instance_variable_get(ivar) if instance_variable_defined?(ivar)
|
18
|
+
matcher = matcher_class.new(matcher_node, self, source_rewriter, runtime_data, report)
|
19
|
+
instance_variable_set(ivar, matcher)
|
22
20
|
end
|
23
21
|
|
24
|
-
|
25
|
-
|
26
|
-
return instance_variable_get(matcher_ivar)
|
27
|
-
end
|
28
|
-
|
29
|
-
matcher = send(matcher_creator)
|
30
|
-
|
31
|
-
if matcher.conversion_target?
|
32
|
-
instance_variable_set(matcher_ivar, matcher)
|
33
|
-
else
|
34
|
-
instance_variable_set(matcher_ivar, nil)
|
35
|
-
end
|
36
|
-
end
|
22
|
+
matcher_accessors << accessor
|
23
|
+
end
|
37
24
|
|
38
|
-
|
39
|
-
|
40
|
-
end
|
25
|
+
def matcher_accessors
|
26
|
+
@matcher_accessors ||= []
|
41
27
|
end
|
42
28
|
end
|
29
|
+
|
30
|
+
def dependent_syntaxes
|
31
|
+
super + self.class.matcher_accessors.map { |accessor| send(accessor) }
|
32
|
+
end
|
43
33
|
end
|
44
34
|
end
|
45
35
|
end
|
@@ -27,11 +27,11 @@ module Transpec
|
|
27
27
|
|
28
28
|
def and_return_with_block?
|
29
29
|
block_node = Util.block_node_taken_by_method(and_return_node)
|
30
|
-
|
30
|
+
block_node
|
31
31
|
end
|
32
32
|
|
33
33
|
def and_return?
|
34
|
-
|
34
|
+
and_return_node
|
35
35
|
end
|
36
36
|
|
37
37
|
def and_return_node
|
@@ -13,7 +13,7 @@ module Transpec
|
|
13
13
|
|
14
14
|
attr_reader :current_syntax_type
|
15
15
|
|
16
|
-
def initialize(
|
16
|
+
def initialize(*)
|
17
17
|
super
|
18
18
|
@current_syntax_type = :should
|
19
19
|
end
|
@@ -22,34 +22,29 @@ module Transpec
|
|
22
22
|
super && receiver_node.nil? && [:should, :should_not].include?(method_name)
|
23
23
|
end
|
24
24
|
|
25
|
-
def expectize!(negative_form = 'not_to'
|
25
|
+
def expectize!(negative_form = 'not_to')
|
26
26
|
replacement = 'is_expected.'
|
27
27
|
replacement << (positive? ? 'to' : negative_form)
|
28
28
|
replace(should_range, replacement)
|
29
29
|
|
30
30
|
@current_syntax_type = :expect
|
31
|
-
operator_matcher.convert_operator!(parenthesize_matcher_arg) if operator_matcher
|
32
31
|
|
33
32
|
register_record(negative_form)
|
34
33
|
end
|
35
34
|
|
36
35
|
def convert_have_items_to_standard_should!
|
37
|
-
return
|
36
|
+
return unless have_matcher.conversion_target?
|
38
37
|
|
39
38
|
insert_example_description!
|
40
39
|
|
41
40
|
subject_source = have_matcher.replacement_subject_source('subject')
|
42
41
|
insert_before(expression_range, "#{subject_source}.")
|
43
42
|
|
44
|
-
have_matcher.convert_to_standard_expectation!
|
45
|
-
|
46
43
|
report.records << OnelinerShouldHaveRecord.new(self, have_matcher)
|
47
44
|
end
|
48
45
|
|
49
|
-
|
50
|
-
|
51
|
-
# rubocop:enable LineLength
|
52
|
-
return if have_matcher.project_requires_collection_matcher?
|
46
|
+
def convert_have_items_to_standard_expect!(negative_form = 'not_to')
|
47
|
+
return unless have_matcher.conversion_target?
|
53
48
|
|
54
49
|
insert_example_description!
|
55
50
|
|
@@ -59,14 +54,13 @@ module Transpec
|
|
59
54
|
replace(should_range, expect_to_source)
|
60
55
|
|
61
56
|
@current_syntax_type = :expect
|
62
|
-
have_matcher.convert_to_standard_expectation!
|
63
57
|
|
64
58
|
report.records << OnelinerShouldHaveRecord.new(self, have_matcher, negative_form)
|
65
59
|
end
|
66
60
|
|
67
61
|
def example_has_description?
|
68
62
|
send_node = example_block_node.children.first
|
69
|
-
|
63
|
+
send_node.children[2]
|
70
64
|
end
|
71
65
|
|
72
66
|
def build_description(size)
|
@@ -91,7 +85,9 @@ module Transpec
|
|
91
85
|
private
|
92
86
|
|
93
87
|
def insert_example_description!
|
94
|
-
|
88
|
+
unless have_matcher.conversion_target?
|
89
|
+
fail 'This one-liner #should does not have #have matcher!'
|
90
|
+
end
|
95
91
|
|
96
92
|
unless example_has_description?
|
97
93
|
insert_before(example_block_node.loc.begin, "'#{generated_description}' ")
|
@@ -21,10 +21,6 @@ module Transpec
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
def self.standalone?
|
25
|
-
false
|
26
|
-
end
|
27
|
-
|
28
24
|
def initialize(node, expectation, source_rewriter = nil, runtime_data = nil, report = nil)
|
29
25
|
operator_node = if node == BE_NODE
|
30
26
|
node.parent_node
|
@@ -36,7 +32,7 @@ module Transpec
|
|
36
32
|
end
|
37
33
|
|
38
34
|
def dynamic_analysis_target?
|
39
|
-
super &&
|
35
|
+
super && receiver_node && OPERATORS.include?(method_name)
|
40
36
|
end
|
41
37
|
|
42
38
|
def convert_operator!(parenthesize_arg = true)
|
@@ -88,7 +84,7 @@ module Transpec
|
|
88
84
|
|
89
85
|
parenthesize!(parenthesize_arg)
|
90
86
|
|
91
|
-
accurate = !enumerable_arg?.nil?
|
87
|
+
accurate = !enumerable_arg?.nil? # rubocop:disable NonNilCheck
|
92
88
|
|
93
89
|
# Need to register record after all source rewrites are done
|
94
90
|
# to avoid false record when failed with overlapped rewrite.
|
@@ -137,7 +133,7 @@ module Transpec
|
|
137
133
|
end
|
138
134
|
|
139
135
|
def prefixed_with_be?
|
140
|
-
|
136
|
+
be_node
|
141
137
|
end
|
142
138
|
|
143
139
|
def remove_be!
|
@@ -1,36 +1,20 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
3
|
require 'transpec/syntax'
|
4
|
-
require 'transpec/syntax/mixin/
|
4
|
+
require 'transpec/syntax/mixin/context_sensitive'
|
5
5
|
require 'transpec/util'
|
6
6
|
|
7
7
|
module Transpec
|
8
8
|
class Syntax
|
9
9
|
class Pending < Syntax
|
10
|
-
include Mixin::
|
11
|
-
|
12
|
-
define_dynamic_analysis do |rewriter|
|
13
|
-
code = 'is_a?(RSpec::Core::ExampleGroup)'
|
14
|
-
rewriter.register_request(node, :example_context?, code, :context)
|
15
|
-
end
|
10
|
+
include Mixin::ContextSensitive, Util
|
16
11
|
|
17
12
|
def dynamic_analysis_target?
|
18
13
|
super && receiver_node.nil? && method_name == :pending
|
19
14
|
end
|
20
15
|
|
21
|
-
def
|
22
|
-
|
23
|
-
|
24
|
-
# Check whether the context is example group to differenciate
|
25
|
-
# RSpec::Core::ExampleGroup.pending (a relative of #it) and
|
26
|
-
# RSpec::Core::ExampleGroup#pending (marks the example as pending in #it block).
|
27
|
-
if runtime_data.run?(node)
|
28
|
-
# If we have runtime data, check with it.
|
29
|
-
runtime_data[node, :example_context?]
|
30
|
-
else
|
31
|
-
# Otherwise check statically.
|
32
|
-
static_context_inspector.scopes.last == :example
|
33
|
-
end
|
16
|
+
def should_be_in_example_group_context?
|
17
|
+
false
|
34
18
|
end
|
35
19
|
|
36
20
|
def convert_deprecated_syntax!
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'transpec/util'
|
4
|
+
require 'ast'
|
5
|
+
|
6
|
+
module Transpec
|
7
|
+
class Syntax
|
8
|
+
class RSpecConfigure
|
9
|
+
module ConfigurationModification
|
10
|
+
include Util, ::AST::Sexp
|
11
|
+
|
12
|
+
def block_node
|
13
|
+
fail NotImplementedError
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def set_configuration!(config_name, value)
|
19
|
+
setter_node = find_configuration_node("#{config_name}=")
|
20
|
+
|
21
|
+
if setter_node
|
22
|
+
arg_node = setter_node.children[2]
|
23
|
+
source_rewriter.replace(arg_node.loc.expression, value.to_s)
|
24
|
+
else
|
25
|
+
add_configuration!(config_name, value)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def find_configuration_node(configuration_method_name)
|
30
|
+
return nil unless block_node
|
31
|
+
|
32
|
+
configuration_method_name = configuration_method_name.to_sym
|
33
|
+
|
34
|
+
block_node.each_descendent_node.find do |node|
|
35
|
+
next unless node.send_type?
|
36
|
+
receiver_node, method_name, = *node
|
37
|
+
next unless receiver_node == s(:lvar, block_arg_name)
|
38
|
+
method_name == configuration_method_name
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def block_arg_name
|
43
|
+
return nil unless block_node
|
44
|
+
first_block_arg_name(block_node)
|
45
|
+
end
|
46
|
+
|
47
|
+
module ConfigurationAddition
|
48
|
+
def add_configuration!(config_name, value)
|
49
|
+
lines = generate_configuration_lines(config_name, value)
|
50
|
+
lines.unshift('') unless empty_block_body?
|
51
|
+
lines.map! { |line| line + "\n" }
|
52
|
+
|
53
|
+
insertion_position = beginning_of_line_range(block_node_to_insert_code.loc.end)
|
54
|
+
source_rewriter.insert_before(insertion_position, lines.join(''))
|
55
|
+
|
56
|
+
block_node_to_insert_code.metadata[:added_configuration] = true
|
57
|
+
end
|
58
|
+
|
59
|
+
def generate_configuration_lines(config_name, value)
|
60
|
+
[body_indentation + "#{config_variable_name}.#{config_name} = #{value}"]
|
61
|
+
end
|
62
|
+
|
63
|
+
def config_variable_name
|
64
|
+
block_arg_name
|
65
|
+
end
|
66
|
+
|
67
|
+
def body_indentation
|
68
|
+
indentation_of_line(block_node) + (' ' * 2)
|
69
|
+
end
|
70
|
+
|
71
|
+
def block_node_to_insert_code
|
72
|
+
block_node
|
73
|
+
end
|
74
|
+
|
75
|
+
def empty_block_body?
|
76
|
+
block_node = block_node_to_insert_code
|
77
|
+
(block_node.loc.end.line - block_node.loc.begin.line <= 1) &&
|
78
|
+
!block_node.metadata[:added_configuration]
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
include ConfigurationAddition
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -1,13 +1,12 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
require 'transpec/
|
4
|
-
require 'ast'
|
3
|
+
require 'transpec/syntax/rspec_configure/configuration_modification'
|
5
4
|
|
6
5
|
module Transpec
|
7
6
|
class Syntax
|
8
7
|
class RSpecConfigure
|
9
8
|
class Framework
|
10
|
-
include
|
9
|
+
include ConfigurationModification
|
11
10
|
|
12
11
|
attr_reader :rspec_configure, :source_rewriter
|
13
12
|
|
@@ -16,45 +15,10 @@ module Transpec
|
|
16
15
|
@source_rewriter = source_rewriter
|
17
16
|
end
|
18
17
|
|
19
|
-
private
|
20
|
-
|
21
|
-
def block_method_name
|
22
|
-
fail NotImplementedError
|
23
|
-
end
|
24
|
-
|
25
|
-
def set_configuration!(config_name, value)
|
26
|
-
setter_node = find_configuration_node("#{config_name}=")
|
27
|
-
|
28
|
-
if setter_node
|
29
|
-
arg_node = setter_node.children[2]
|
30
|
-
source_rewriter.replace(arg_node.loc.expression, value.to_s)
|
31
|
-
else
|
32
|
-
add_configuration!(config_name, value)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def find_configuration_node(configuration_method_name)
|
37
|
-
return nil unless block_node
|
38
|
-
|
39
|
-
configuration_method_name = configuration_method_name.to_sym
|
40
|
-
|
41
|
-
block_node.each_descendent_node.find do |node|
|
42
|
-
next unless node.send_type?
|
43
|
-
receiver_node, method_name, = *node
|
44
|
-
next unless receiver_node == s(:lvar, block_arg_name)
|
45
|
-
method_name == configuration_method_name
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def block_arg_name
|
50
|
-
return nil unless block_node
|
51
|
-
first_block_arg_name(block_node)
|
52
|
-
end
|
53
|
-
|
54
18
|
def block_node
|
55
19
|
return @block_node if instance_variable_defined?(:@block_node)
|
56
20
|
|
57
|
-
@block_node = rspec_configure.
|
21
|
+
@block_node = rspec_configure.block_node.each_descendent_node.find do |node|
|
58
22
|
next unless node.block_type?
|
59
23
|
send_node = node.children.first
|
60
24
|
receiver_node, method_name, *_ = *send_node
|
@@ -64,68 +28,63 @@ module Transpec
|
|
64
28
|
end
|
65
29
|
end
|
66
30
|
|
67
|
-
|
68
|
-
def add_configuration!(config_name, value)
|
69
|
-
lines = [body_indentation + "#{config_variable_name}.#{config_name} = #{value}"]
|
70
|
-
|
71
|
-
unless block_node
|
72
|
-
lines.unshift(framework_begin_code)
|
73
|
-
lines << framework_end_code
|
74
|
-
end
|
31
|
+
private
|
75
32
|
|
76
|
-
|
77
|
-
|
33
|
+
def block_method_name
|
34
|
+
fail NotImplementedError
|
35
|
+
end
|
78
36
|
|
79
|
-
|
80
|
-
|
81
|
-
end
|
37
|
+
def generate_configuration_lines(config_name, value)
|
38
|
+
lines = super
|
82
39
|
|
83
|
-
|
84
|
-
|
40
|
+
unless block_node
|
41
|
+
lines.unshift(framework_begin_code)
|
42
|
+
lines << framework_end_code
|
85
43
|
end
|
86
44
|
|
87
|
-
|
88
|
-
|
89
|
-
when :rspec then self.class.name.split('::').last.downcase
|
90
|
-
when :c then 'config'
|
91
|
-
else 'c'
|
92
|
-
end
|
93
|
-
end
|
45
|
+
lines
|
46
|
+
end
|
94
47
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
else
|
99
|
-
indentation_of_line(rspec_configure.node) + (' ' * 4)
|
100
|
-
end
|
101
|
-
end
|
48
|
+
def config_variable_name
|
49
|
+
super || new_config_variable_name
|
50
|
+
end
|
102
51
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
52
|
+
def new_config_variable_name
|
53
|
+
framework_name = self.class.name.split('::').last.downcase
|
54
|
+
if rspec_configure.block_arg_name.to_s == framework_name
|
55
|
+
'config'
|
56
|
+
else
|
57
|
+
framework_name
|
109
58
|
end
|
59
|
+
end
|
110
60
|
|
111
|
-
|
112
|
-
|
61
|
+
def body_indentation
|
62
|
+
if block_node
|
63
|
+
super
|
64
|
+
else
|
65
|
+
rspec_configure_body_indentation + (' ' * 2)
|
113
66
|
end
|
67
|
+
end
|
114
68
|
|
115
|
-
|
116
|
-
|
117
|
-
|
69
|
+
def block_node_to_insert_code
|
70
|
+
super || rspec_configure.block_node
|
71
|
+
end
|
118
72
|
|
119
|
-
|
120
|
-
|
121
|
-
|
73
|
+
def framework_begin_code
|
74
|
+
code = format(
|
75
|
+
'%s.%s :rspec do |%s|',
|
76
|
+
rspec_configure.block_arg_name, block_method_name, config_variable_name
|
77
|
+
)
|
78
|
+
rspec_configure_body_indentation + code
|
79
|
+
end
|
122
80
|
|
123
|
-
|
124
|
-
|
125
|
-
end
|
81
|
+
def framework_end_code
|
82
|
+
rspec_configure_body_indentation + 'end'
|
126
83
|
end
|
127
84
|
|
128
|
-
|
85
|
+
def rspec_configure_body_indentation
|
86
|
+
indentation_of_line(rspec_configure.node) + (' ' * 2)
|
87
|
+
end
|
129
88
|
|
130
89
|
module SyntaxConfiguration
|
131
90
|
def syntaxes
|