transpec 2.2.1 → 2.2.2
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/CHANGELOG.md +4 -0
- data/README.md +2 -1
- data/README.md.erb +2 -1
- data/lib/transpec/base_rewriter.rb +13 -5
- data/lib/transpec/converter.rb +0 -1
- data/lib/transpec/dynamic_analyzer.rb +37 -25
- data/lib/transpec/dynamic_analyzer/rewriter.rb +0 -1
- data/lib/transpec/dynamic_analyzer/{helper.rb.erb → transpec_analysis_helper.rb.erb} +1 -1
- data/lib/transpec/syntax/be_boolean.rb +3 -3
- data/lib/transpec/syntax/be_close.rb +2 -2
- data/lib/transpec/syntax/current_example.rb +2 -2
- data/lib/transpec/syntax/double.rb +2 -2
- data/lib/transpec/syntax/example.rb +6 -6
- data/lib/transpec/syntax/have.rb +2 -2
- data/lib/transpec/syntax/hook.rb +2 -2
- data/lib/transpec/syntax/its.rb +2 -2
- data/lib/transpec/syntax/method_stub.rb +6 -6
- data/lib/transpec/syntax/oneliner_should.rb +2 -2
- data/lib/transpec/syntax/operator.rb +5 -5
- data/lib/transpec/syntax/pending.rb +3 -3
- data/lib/transpec/syntax/raise_error.rb +2 -2
- data/lib/transpec/syntax/should.rb +2 -2
- data/lib/transpec/syntax/should_receive.rb +6 -6
- data/lib/transpec/version.rb +1 -1
- data/spec/transpec/converter_spec.rb +1 -1
- data/spec/transpec/dynamic_analyzer_spec.rb +55 -21
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ed03b5875402e2f2a94f50eb8ebdd856f61aa84
|
4
|
+
data.tar.gz: e81942f93e064ebac963ff6d17090bbe2e0b05f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26f7db5953c2390bcd8da34b50b8a7c99252a032fdf8027de238de7f186f585e41c82cb0f749588709ff754ca7dd1b7c6df641cd0dd6a7a1b3a7a062d49ed328
|
7
|
+
data.tar.gz: f936d2b514378479df192efe6980d56865477ab749f1e593878f1b98b285d22d3cf26ebf8ff888e1b1107699e2b13c05e0ed94cefcbcffb54640f3eaea2d13b1
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
|
3
3
|
## Development
|
4
4
|
|
5
|
+
## v2.2.2
|
6
|
+
|
7
|
+
* Fix error on dynamic analysis when the project have `.rspec` file containing some `--require` options and the required file contains some RSpec API.
|
8
|
+
|
5
9
|
## v2.2.1
|
6
10
|
|
7
11
|
* Fix invalid conversion of `pending` with block including an empty line.
|
data/README.md
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
# Transpec
|
8
8
|
|
9
|
-
**Transpec** is a tool for converting your specs to the latest [RSpec](
|
9
|
+
**Transpec** is a tool for converting your specs to the latest [RSpec](https://relishapp.com/rspec/) syntax with static and dynamic code analysis.
|
10
10
|
|
11
11
|
With Transpec you can upgrade your RSpec 2 specs to RSpec 3 in no time.
|
12
12
|
It supports [conversions](#supported-conversions) for almost all of the RSpec 3 changes – not only the `expect` syntax.
|
@@ -728,6 +728,7 @@ Targets:
|
|
728
728
|
lambda { do_something }.should raise_error
|
729
729
|
proc { do_something }.should raise_error
|
730
730
|
-> { do_something }.should raise_error
|
731
|
+
expect { do_something }.should raise_error
|
731
732
|
```
|
732
733
|
|
733
734
|
Will be converted to:
|
data/README.md.erb
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
# Transpec
|
8
8
|
|
9
|
-
**Transpec** is a tool for converting your specs to the latest [RSpec](
|
9
|
+
**Transpec** is a tool for converting your specs to the latest [RSpec](https://relishapp.com/rspec/) syntax with static and dynamic code analysis.
|
10
10
|
|
11
11
|
With Transpec you can upgrade your RSpec 2 specs to RSpec 3 in no time.
|
12
12
|
It supports [conversions](#supported-conversions) for almost all of the RSpec 3 changes – not only the `expect` syntax.
|
@@ -799,6 +799,7 @@ example = <<END
|
|
799
799
|
lambda { do_something }.should raise_error
|
800
800
|
proc { do_something }.should raise_error
|
801
801
|
-> { do_something }.should raise_error
|
802
|
+
expect { do_something }.should raise_error
|
802
803
|
END
|
803
804
|
-%>
|
804
805
|
```
|
@@ -26,15 +26,15 @@ module Transpec
|
|
26
26
|
def rewrite(processed_source)
|
27
27
|
fail processed_source.syntax_error if processed_source.syntax_error
|
28
28
|
|
29
|
-
source_rewriter =
|
29
|
+
source_rewriter = create_source_rewriter(processed_source)
|
30
30
|
incomplete = false
|
31
|
-
|
31
|
+
|
32
|
+
begin
|
33
|
+
process(processed_source.ast, source_rewriter)
|
34
|
+
rescue OverlappedRewriteError
|
32
35
|
incomplete = true
|
33
|
-
fail OverlappedRewriteError
|
34
36
|
end
|
35
37
|
|
36
|
-
process(processed_source.ast, source_rewriter)
|
37
|
-
|
38
38
|
rewritten_source = source_rewriter.process
|
39
39
|
rewritten_source = rewrite_source(rewritten_source, processed_source.path) if incomplete
|
40
40
|
|
@@ -43,6 +43,14 @@ module Transpec
|
|
43
43
|
|
44
44
|
private
|
45
45
|
|
46
|
+
def create_source_rewriter(processed_source)
|
47
|
+
Parser::Source::Rewriter.new(processed_source.buffer).tap do |source_rewriter|
|
48
|
+
source_rewriter.diagnostics.consumer = proc do
|
49
|
+
fail OverlappedRewriteError
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
46
54
|
def process(ast, source_rewriter) # rubocop:disable UnusedMethodArgument
|
47
55
|
fail NotImplementedError
|
48
56
|
end
|
data/lib/transpec/converter.rb
CHANGED
@@ -15,7 +15,7 @@ require 'English'
|
|
15
15
|
module Transpec
|
16
16
|
class DynamicAnalyzer
|
17
17
|
ANALYSIS_METHOD = 'transpec_analyze'
|
18
|
-
|
18
|
+
HELPER_TEMPLATE_FILE = 'transpec_analysis_helper.rb.erb'
|
19
19
|
RESULT_FILE = 'transpec_analysis_result.json'
|
20
20
|
|
21
21
|
attr_reader :project, :rspec_command, :silent
|
@@ -44,9 +44,8 @@ module Transpec
|
|
44
44
|
def analyze(paths = [])
|
45
45
|
in_copied_project do
|
46
46
|
rewrite_specs(paths)
|
47
|
-
|
48
|
-
|
49
|
-
|
47
|
+
put_analysis_helper
|
48
|
+
modify_dot_rspec
|
50
49
|
run_rspec(paths)
|
51
50
|
|
52
51
|
begin
|
@@ -59,6 +58,24 @@ module Transpec
|
|
59
58
|
end
|
60
59
|
end
|
61
60
|
|
61
|
+
def copy_recursively(source_root, destination_root)
|
62
|
+
source_root = File.expand_path(source_root)
|
63
|
+
source_root_pathname = Pathname.new(source_root)
|
64
|
+
|
65
|
+
destination_root = File.expand_path(destination_root)
|
66
|
+
if File.directory?(destination_root)
|
67
|
+
destination_root = File.join(destination_root, File.basename(source_root))
|
68
|
+
end
|
69
|
+
|
70
|
+
Find.find(source_root) do |source_path|
|
71
|
+
relative_path = Pathname.new(source_path).relative_path_from(source_root_pathname).to_s
|
72
|
+
destination_path = File.join(destination_root, relative_path)
|
73
|
+
copy(source_path, destination_path)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
private
|
78
|
+
|
62
79
|
def in_copied_project
|
63
80
|
return yield if @in_copied_project
|
64
81
|
|
@@ -77,8 +94,6 @@ module Transpec
|
|
77
94
|
|
78
95
|
def run_rspec(paths)
|
79
96
|
project.with_bundler_clean_env do
|
80
|
-
ENV['SPEC_OPTS'] = ['-r', "./#{HELPER_FILE}"].shelljoin
|
81
|
-
|
82
97
|
command = "#{rspec_command} #{paths.shelljoin}"
|
83
98
|
|
84
99
|
if silent?
|
@@ -89,24 +104,6 @@ module Transpec
|
|
89
104
|
end
|
90
105
|
end
|
91
106
|
|
92
|
-
def copy_recursively(source_root, destination_root)
|
93
|
-
source_root = File.expand_path(source_root)
|
94
|
-
source_root_pathname = Pathname.new(source_root)
|
95
|
-
|
96
|
-
destination_root = File.expand_path(destination_root)
|
97
|
-
if File.directory?(destination_root)
|
98
|
-
destination_root = File.join(destination_root, File.basename(source_root))
|
99
|
-
end
|
100
|
-
|
101
|
-
Find.find(source_root) do |source_path|
|
102
|
-
relative_path = Pathname.new(source_path).relative_path_from(source_root_pathname).to_s
|
103
|
-
destination_path = File.join(destination_root, relative_path)
|
104
|
-
copy(source_path, destination_path)
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
private
|
109
|
-
|
110
107
|
def rewrite_specs(paths)
|
111
108
|
rewriter = Rewriter.new
|
112
109
|
|
@@ -118,12 +115,27 @@ module Transpec
|
|
118
115
|
end
|
119
116
|
end
|
120
117
|
|
118
|
+
def helper_filename
|
119
|
+
File.basename(HELPER_TEMPLATE_FILE, '.erb')
|
120
|
+
end
|
121
|
+
|
121
122
|
def helper_source
|
122
|
-
erb_path = File.join(File.dirname(__FILE__), 'dynamic_analyzer',
|
123
|
+
erb_path = File.join(File.dirname(__FILE__), 'dynamic_analyzer', HELPER_TEMPLATE_FILE)
|
123
124
|
erb = ERB.new(File.read(erb_path), nil)
|
124
125
|
erb.result(binding)
|
125
126
|
end
|
126
127
|
|
128
|
+
def put_analysis_helper
|
129
|
+
File.write(helper_filename, helper_source)
|
130
|
+
end
|
131
|
+
|
132
|
+
def modify_dot_rspec
|
133
|
+
filename = '.rspec'
|
134
|
+
content = "--require ./#{helper_filename}\n"
|
135
|
+
content << File.read(filename) if File.exist?(filename)
|
136
|
+
File.write(filename, content)
|
137
|
+
end
|
138
|
+
|
127
139
|
def copy(source, destination)
|
128
140
|
if File.symlink?(source)
|
129
141
|
File.symlink(File.readlink(source), destination)
|
@@ -19,18 +19,18 @@ module Transpec
|
|
19
19
|
def convert_to_conditional_matcher!(form_of_be_falsey = 'be_falsey')
|
20
20
|
replacement = be_true? ? 'be_truthy' : form_of_be_falsey
|
21
21
|
replace(expression_range, replacement)
|
22
|
-
|
22
|
+
add_record(replacement)
|
23
23
|
end
|
24
24
|
|
25
25
|
def convert_to_exact_matcher!
|
26
26
|
replacement = be_true? ? 'be true' : 'be false'
|
27
27
|
replace(expression_range, replacement)
|
28
|
-
|
28
|
+
add_record(replacement)
|
29
29
|
end
|
30
30
|
|
31
31
|
private
|
32
32
|
|
33
|
-
def
|
33
|
+
def add_record(converted_syntax)
|
34
34
|
report.records << Record.new(method_name.to_s, converted_syntax)
|
35
35
|
end
|
36
36
|
end
|
@@ -23,12 +23,12 @@ module Transpec
|
|
23
23
|
|
24
24
|
replace(expression_range, be_within_source)
|
25
25
|
|
26
|
-
|
26
|
+
add_record
|
27
27
|
end
|
28
28
|
|
29
29
|
private
|
30
30
|
|
31
|
-
def
|
31
|
+
def add_record
|
32
32
|
report.records << Record.new('be_close(expected, delta)', 'be_within(delta).of(expected)')
|
33
33
|
end
|
34
34
|
end
|
@@ -28,7 +28,7 @@ module Transpec
|
|
28
28
|
replace(selector_range, 'RSpec.current_example')
|
29
29
|
end
|
30
30
|
|
31
|
-
|
31
|
+
add_record
|
32
32
|
end
|
33
33
|
|
34
34
|
private
|
@@ -69,7 +69,7 @@ module Transpec
|
|
69
69
|
send_node.children[1]
|
70
70
|
end
|
71
71
|
|
72
|
-
def
|
72
|
+
def add_record
|
73
73
|
if block_node
|
74
74
|
prefix = "#{block_method_name}"
|
75
75
|
prefix << '(:name)' if HELPER_METHODS.include?(block_method_name)
|
@@ -15,12 +15,12 @@ module Transpec
|
|
15
15
|
def convert_to_double!
|
16
16
|
return if method_name == :double
|
17
17
|
replace(selector_range, 'double')
|
18
|
-
|
18
|
+
add_record
|
19
19
|
end
|
20
20
|
|
21
21
|
private
|
22
22
|
|
23
|
-
def
|
23
|
+
def add_record
|
24
24
|
report.records << Record.new("#{method_name}('something')", "double('something')")
|
25
25
|
end
|
26
26
|
end
|
@@ -28,7 +28,7 @@ module Transpec
|
|
28
28
|
def convert_pending_selector_to_skip!
|
29
29
|
return unless method_name == :pending
|
30
30
|
replace(selector_range, 'skip')
|
31
|
-
|
31
|
+
add_record("pending 'is an example' { }", "skip 'is an example' { }")
|
32
32
|
end
|
33
33
|
|
34
34
|
def convert_pending_metadata_to_skip!
|
@@ -36,11 +36,11 @@ module Transpec
|
|
36
36
|
next unless pending_symbol?(node)
|
37
37
|
replace(symbol_range_without_colon(node), 'skip')
|
38
38
|
if node.parent_node.pair_type?
|
39
|
-
|
40
|
-
|
39
|
+
add_record("it 'is an example', :pending => value { }",
|
40
|
+
"it 'is an example', :skip => value { }")
|
41
41
|
else
|
42
|
-
|
43
|
-
|
42
|
+
add_record("it 'is an example', :pending { }",
|
43
|
+
"it 'is an example', :skip { }")
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end
|
@@ -60,7 +60,7 @@ module Transpec
|
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
-
def
|
63
|
+
def add_record(original_syntax, converted_syntax)
|
64
64
|
report.records << Record.new(original_syntax, converted_syntax)
|
65
65
|
end
|
66
66
|
end
|
data/lib/transpec/syntax/have.rb
CHANGED
@@ -37,7 +37,7 @@ module Transpec
|
|
37
37
|
def convert_to_standard_expectation!(parenthesize_matcher_arg = true)
|
38
38
|
replace(expectation.subject_range, replacement_subject_source) if explicit_subject?
|
39
39
|
replace(matcher_range, source_builder.replacement_matcher_source(parenthesize_matcher_arg))
|
40
|
-
|
40
|
+
add_record if explicit_subject?
|
41
41
|
end
|
42
42
|
|
43
43
|
def explicit_subject?
|
@@ -131,7 +131,7 @@ module Transpec
|
|
131
131
|
end
|
132
132
|
end
|
133
133
|
|
134
|
-
def
|
134
|
+
def add_record
|
135
135
|
report.records << HaveRecord.new(self)
|
136
136
|
end
|
137
137
|
end
|
data/lib/transpec/syntax/hook.rb
CHANGED
@@ -21,7 +21,7 @@ module Transpec
|
|
21
21
|
def convert_scope_name!
|
22
22
|
return if !scope_name || !replacement_scope_name
|
23
23
|
replace(arg_range, replacement_scope_name.inspect)
|
24
|
-
|
24
|
+
add_record
|
25
25
|
end
|
26
26
|
|
27
27
|
private
|
@@ -35,7 +35,7 @@ module Transpec
|
|
35
35
|
SCOPE_ALIASES[scope_name]
|
36
36
|
end
|
37
37
|
|
38
|
-
def
|
38
|
+
def add_record
|
39
39
|
original_syntax = "#{method_name}(#{scope_name.inspect}) { }"
|
40
40
|
converted_syntax = "#{method_name}(#{replacement_scope_name.inspect}) { }"
|
41
41
|
report.records << Record.new(original_syntax, converted_syntax)
|
data/lib/transpec/syntax/its.rb
CHANGED
@@ -30,7 +30,7 @@ module Transpec
|
|
30
30
|
replace(range_from_its_to_front_of_block, 'it ')
|
31
31
|
insert_after(block_node.loc.expression, rear)
|
32
32
|
|
33
|
-
|
33
|
+
add_record
|
34
34
|
end
|
35
35
|
|
36
36
|
def attribute_expression
|
@@ -93,7 +93,7 @@ module Transpec
|
|
93
93
|
expression_range.join(block_node.loc.begin.begin)
|
94
94
|
end
|
95
95
|
|
96
|
-
def
|
96
|
+
def add_record
|
97
97
|
report.records << Record.new(original_syntax, converted_syntax)
|
98
98
|
end
|
99
99
|
|
@@ -71,7 +71,7 @@ module Transpec
|
|
71
71
|
|
72
72
|
replace(expression_range, source)
|
73
73
|
|
74
|
-
|
74
|
+
add_record(type)
|
75
75
|
end
|
76
76
|
|
77
77
|
def convert_deprecated_method!
|
@@ -79,21 +79,21 @@ module Transpec
|
|
79
79
|
|
80
80
|
replace(selector_range, replacement_method_for_deprecated_method)
|
81
81
|
|
82
|
-
|
82
|
+
add_record(:deprecated)
|
83
83
|
end
|
84
84
|
|
85
85
|
def remove_no_message_allowance!
|
86
86
|
return unless allow_no_message?
|
87
87
|
super
|
88
|
-
|
88
|
+
add_record(:no_message_allowance)
|
89
89
|
end
|
90
90
|
|
91
91
|
def remove_useless_and_return!
|
92
|
-
super &&
|
92
|
+
super && add_record(:useless_and_return)
|
93
93
|
end
|
94
94
|
|
95
95
|
def add_receiver_arg_to_any_instance_implementation_block!
|
96
|
-
super &&
|
96
|
+
super && add_record(:any_instance_block)
|
97
97
|
end
|
98
98
|
|
99
99
|
private
|
@@ -169,7 +169,7 @@ module Transpec
|
|
169
169
|
end
|
170
170
|
end
|
171
171
|
|
172
|
-
def
|
172
|
+
def add_record(conversion_type)
|
173
173
|
record_class = case conversion_type
|
174
174
|
when :deprecated then DeprecatedMethodRecord
|
175
175
|
when :no_message_allowance then NoMessageAllowanceRecord
|
@@ -31,7 +31,7 @@ module Transpec
|
|
31
31
|
|
32
32
|
@current_syntax_type = :expect
|
33
33
|
|
34
|
-
|
34
|
+
add_record(negative_form)
|
35
35
|
end
|
36
36
|
|
37
37
|
def convert_have_items_to_standard_should!
|
@@ -140,7 +140,7 @@ module Transpec
|
|
140
140
|
expand_range_to_adjacent_whitespaces(example_block_node.loc.end, :begin)
|
141
141
|
end
|
142
142
|
|
143
|
-
def
|
143
|
+
def add_record(negative_form_of_to)
|
144
144
|
original_syntax = 'it { should'
|
145
145
|
converted_syntax = 'it { is_expected.'
|
146
146
|
|
@@ -64,13 +64,13 @@ module Transpec
|
|
64
64
|
handle_anterior_of_operator!
|
65
65
|
replace(selector_range, 'eq')
|
66
66
|
parenthesize!(parenthesize_arg)
|
67
|
-
|
67
|
+
add_record(nil, 'eq(expected)')
|
68
68
|
end
|
69
69
|
|
70
70
|
def convert_to_be_operator!
|
71
71
|
return if prefixed_with_be?
|
72
72
|
insert_before(selector_range, 'be ')
|
73
|
-
|
73
|
+
add_record(nil, "be #{method_name} expected")
|
74
74
|
end
|
75
75
|
|
76
76
|
def convert_to_match!(parenthesize_arg)
|
@@ -89,9 +89,9 @@ module Transpec
|
|
89
89
|
# Need to register record after all source rewrites are done
|
90
90
|
# to avoid false record when failed with overlapped rewrite.
|
91
91
|
if enumerable_arg?
|
92
|
-
|
92
|
+
add_record('=~ [1, 2]', 'match_array([1, 2])', accurate)
|
93
93
|
else
|
94
|
-
|
94
|
+
add_record('=~ /pattern/', 'match(/pattern/)', accurate)
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
@@ -157,7 +157,7 @@ module Transpec
|
|
157
157
|
end
|
158
158
|
end
|
159
159
|
|
160
|
-
def
|
160
|
+
def add_record(original_syntax, converted_syntax, accurate = true)
|
161
161
|
original_syntax ||= "#{method_name} expected"
|
162
162
|
annotation = AccuracyAnnotation.new(matcher_range) unless accurate
|
163
163
|
report.records << Record.new(original_syntax, converted_syntax, annotation)
|
@@ -29,7 +29,7 @@ module Transpec
|
|
29
29
|
|
30
30
|
def convert_to_skip!
|
31
31
|
replace(selector_range, 'skip')
|
32
|
-
|
32
|
+
add_record('pending', 'skip')
|
33
33
|
end
|
34
34
|
|
35
35
|
def unblock!
|
@@ -46,7 +46,7 @@ module Transpec
|
|
46
46
|
remove(line_range(block_node.loc.end))
|
47
47
|
end
|
48
48
|
|
49
|
-
|
49
|
+
add_record('pending { do_something_fail }', 'pending; do_something_fail')
|
50
50
|
end
|
51
51
|
|
52
52
|
def outdent!(target_node, base_node)
|
@@ -97,7 +97,7 @@ module Transpec
|
|
97
97
|
block_body_node.loc.expression.end.join(block_node.loc.end)
|
98
98
|
end
|
99
99
|
|
100
|
-
def
|
100
|
+
def add_record(original_syntax, converted_syntax)
|
101
101
|
report.records << Record.new(original_syntax, converted_syntax)
|
102
102
|
end
|
103
103
|
end
|
@@ -42,7 +42,7 @@ module Transpec
|
|
42
42
|
replace(should_range, positive? ? 'to' : negative_form)
|
43
43
|
|
44
44
|
@current_syntax_type = :expect
|
45
|
-
|
45
|
+
add_record(negative_form)
|
46
46
|
end
|
47
47
|
|
48
48
|
private
|
@@ -64,7 +64,7 @@ module Transpec
|
|
64
64
|
send_node.loc.expression
|
65
65
|
end
|
66
66
|
|
67
|
-
def
|
67
|
+
def add_record(negative_form_of_to)
|
68
68
|
if proc_subject?
|
69
69
|
original_syntax = "#{range_of_subject_method_taking_block.source} { }.should"
|
70
70
|
converted_syntax = 'expect { }.'
|
@@ -51,7 +51,7 @@ module Transpec
|
|
51
51
|
end
|
52
52
|
|
53
53
|
convert_to_syntax!('expect', negative_form)
|
54
|
-
|
54
|
+
add_record(ExpectRecord, negative_form)
|
55
55
|
end
|
56
56
|
|
57
57
|
def allowize_useless_expectation!(negative_form = 'not_to')
|
@@ -64,7 +64,7 @@ module Transpec
|
|
64
64
|
convert_to_syntax!('allow', negative_form)
|
65
65
|
remove_no_message_allowance!
|
66
66
|
|
67
|
-
|
67
|
+
add_record(AllowRecord, negative_form)
|
68
68
|
end
|
69
69
|
|
70
70
|
def stubize_useless_expectation!
|
@@ -73,15 +73,15 @@ module Transpec
|
|
73
73
|
replace(selector_range, 'stub')
|
74
74
|
remove_no_message_allowance!
|
75
75
|
|
76
|
-
|
76
|
+
add_record(StubRecord)
|
77
77
|
end
|
78
78
|
|
79
79
|
def remove_useless_and_return!
|
80
|
-
super &&
|
80
|
+
super && add_record(MonkeyPatchUselessAndReturnRecord)
|
81
81
|
end
|
82
82
|
|
83
83
|
def add_receiver_arg_to_any_instance_implementation_block!
|
84
|
-
super &&
|
84
|
+
super && add_record(MonkeyPatchAnyInstanceBlockRecord)
|
85
85
|
end
|
86
86
|
|
87
87
|
private
|
@@ -158,7 +158,7 @@ module Transpec
|
|
158
158
|
end
|
159
159
|
end
|
160
160
|
|
161
|
-
def
|
161
|
+
def add_record(record_class, negative_form_of_to = nil)
|
162
162
|
report.records << record_class.new(self, negative_form_of_to)
|
163
163
|
end
|
164
164
|
|
data/lib/transpec/version.rb
CHANGED
@@ -9,6 +9,11 @@ module Transpec
|
|
9
9
|
include ::AST::Sexp
|
10
10
|
include_context 'isolated environment'
|
11
11
|
|
12
|
+
def find_node_in_file(file_path, &block)
|
13
|
+
processed_source = ProcessedSource.parse_file(file_path)
|
14
|
+
processed_source.ast.each_node.find(&block)
|
15
|
+
end
|
16
|
+
|
12
17
|
subject(:dynamic_analyzer) { DynamicAnalyzer.new(rspec_command: rspec_command, silent: true) }
|
13
18
|
let(:rspec_command) { nil }
|
14
19
|
|
@@ -65,6 +70,12 @@ module Transpec
|
|
65
70
|
end
|
66
71
|
|
67
72
|
describe '#analyze' do
|
73
|
+
before do
|
74
|
+
create_file(spec_file_path, source)
|
75
|
+
end
|
76
|
+
|
77
|
+
let(:spec_file_path) { 'spec/example_spec.rb' }
|
78
|
+
|
68
79
|
let(:source) do
|
69
80
|
<<-END
|
70
81
|
describe [1, 2] do
|
@@ -75,12 +86,6 @@ module Transpec
|
|
75
86
|
END
|
76
87
|
end
|
77
88
|
|
78
|
-
let(:file_path) { 'spec/example_spec.rb' }
|
79
|
-
|
80
|
-
before do
|
81
|
-
create_file(file_path, source)
|
82
|
-
end
|
83
|
-
|
84
89
|
context 'when already in copied project directory' do
|
85
90
|
it 'does not change working directory' do
|
86
91
|
DynamicAnalyzer.new(silent: true) do |analyzer|
|
@@ -93,7 +98,7 @@ module Transpec
|
|
93
98
|
context 'when no path is passed' do
|
94
99
|
it 'rewrites all files in the "spec" directory' do
|
95
100
|
DynamicAnalyzer::Rewriter.any_instance.should_receive(:rewrite_file!) do |spec|
|
96
|
-
spec.path.should ==
|
101
|
+
spec.path.should == spec_file_path
|
97
102
|
end
|
98
103
|
|
99
104
|
dynamic_analyzer.analyze
|
@@ -107,10 +112,10 @@ module Transpec
|
|
107
112
|
|
108
113
|
it 'rewrites only files in the passed paths' do
|
109
114
|
DynamicAnalyzer::Rewriter.any_instance.should_receive(:rewrite_file!) do |spec|
|
110
|
-
spec.path.should ==
|
115
|
+
spec.path.should == spec_file_path
|
111
116
|
end
|
112
117
|
|
113
|
-
dynamic_analyzer.analyze([
|
118
|
+
dynamic_analyzer.analyze([spec_file_path])
|
114
119
|
end
|
115
120
|
end
|
116
121
|
|
@@ -156,6 +161,45 @@ module Transpec
|
|
156
161
|
end
|
157
162
|
end
|
158
163
|
|
164
|
+
context 'when there is a .rspec file containing `--require spec_helper`' do
|
165
|
+
before do
|
166
|
+
create_file('.rspec', '--require spec_helper')
|
167
|
+
end
|
168
|
+
|
169
|
+
context 'and the spec/spec_helper.rb contains some code that is dynamic analysis target' do
|
170
|
+
before do
|
171
|
+
create_file('spec/spec_helper.rb', <<-END)
|
172
|
+
RSpec.configure { }
|
173
|
+
|
174
|
+
def some_helper_method_used_in_each_spec
|
175
|
+
end
|
176
|
+
END
|
177
|
+
end
|
178
|
+
|
179
|
+
let(:source) do
|
180
|
+
<<-END
|
181
|
+
some_helper_method_used_in_each_spec
|
182
|
+
|
183
|
+
describe 'something' do
|
184
|
+
end
|
185
|
+
END
|
186
|
+
end
|
187
|
+
|
188
|
+
it 'does not raise error' do
|
189
|
+
-> { dynamic_analyzer.analyze }.should_not raise_error
|
190
|
+
end
|
191
|
+
|
192
|
+
it 'preserves the existing `--require`' do
|
193
|
+
describe_node = find_node_in_file(spec_file_path) do |node|
|
194
|
+
node.send_type? && node.children[1] == :describe
|
195
|
+
end
|
196
|
+
|
197
|
+
runtime_data = dynamic_analyzer.analyze
|
198
|
+
runtime_data.run?(describe_node).should be_true
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
159
203
|
runtime_data_cache = {}
|
160
204
|
|
161
205
|
subject(:runtime_data) do
|
@@ -171,19 +215,9 @@ module Transpec
|
|
171
215
|
end
|
172
216
|
|
173
217
|
describe 'an element of the runtime data' do
|
174
|
-
let(:ast) do
|
175
|
-
source_buffer = Parser::Source::Buffer.new(file_path)
|
176
|
-
source_buffer.source = source
|
177
|
-
|
178
|
-
builder = AST::Builder.new
|
179
|
-
|
180
|
-
parser = Parser::CurrentRuby.new(builder)
|
181
|
-
parser.parse(source_buffer)
|
182
|
-
end
|
183
|
-
|
184
218
|
let(:target_node) do
|
185
|
-
|
186
|
-
|
219
|
+
find_node_in_file(spec_file_path) do |node|
|
220
|
+
node == s(:send, nil, :subject)
|
187
221
|
end
|
188
222
|
end
|
189
223
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: transpec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuji Nakayama
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|
@@ -262,10 +262,10 @@ files:
|
|
262
262
|
- lib/transpec/conversion_error.rb
|
263
263
|
- lib/transpec/converter.rb
|
264
264
|
- lib/transpec/dynamic_analyzer.rb
|
265
|
-
- lib/transpec/dynamic_analyzer/helper.rb.erb
|
266
265
|
- lib/transpec/dynamic_analyzer/node_util.rb
|
267
266
|
- lib/transpec/dynamic_analyzer/rewriter.rb
|
268
267
|
- lib/transpec/dynamic_analyzer/runtime_data.rb
|
268
|
+
- lib/transpec/dynamic_analyzer/transpec_analysis_helper.rb.erb
|
269
269
|
- lib/transpec/file_finder.rb
|
270
270
|
- lib/transpec/git.rb
|
271
271
|
- lib/transpec/option_parser.rb
|