transpec 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +6 -6
- data/README.md.erb +6 -6
- data/lib/transpec/ast/node.rb +4 -4
- data/lib/transpec/converter.rb +5 -11
- data/lib/transpec/dynamic_analyzer.rb +14 -5
- data/lib/transpec/dynamic_analyzer/rewriter.rb +25 -12
- data/lib/transpec/static_context_inspector.rb +4 -5
- data/lib/transpec/syntax.rb +4 -5
- data/lib/transpec/syntax/mixin/allow_no_message.rb +1 -1
- data/lib/transpec/syntax/operator_matcher.rb +0 -7
- data/lib/transpec/syntax/raise_error.rb +1 -1
- data/lib/transpec/syntax/should.rb +1 -1
- data/lib/transpec/version.rb +1 -1
- data/spec/spec_helper.rb +0 -2
- data/spec/support/shared_context.rb +4 -15
- data/spec/transpec/ast/node_spec.rb +95 -3
- data/spec/transpec/dynamic_analyzer_spec.rb +16 -0
- data/spec/transpec/static_context_inspector_spec.rb +5 -5
- data/spec/transpec/syntax/be_close_spec.rb +2 -6
- data/spec/transpec/syntax/double_spec.rb +2 -6
- data/spec/transpec/syntax/its_spec.rb +2 -6
- data/spec/transpec/syntax/method_stub_spec.rb +2 -7
- data/spec/transpec/syntax/raise_error_spec.rb +2 -6
- data/spec/transpec/syntax/rspec_configure_spec.rb +2 -6
- data/spec/transpec/syntax/should_receive_spec.rb +2 -7
- data/transpec.gemspec +2 -1
- metadata +3 -6
- data/lib/transpec/ast/scanner.rb +0 -41
- data/spec/transpec/ast/scanner_spec.rb +0 -124
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d51fbf6111c8bb052b53353d56c3f50016252f70
|
4
|
+
data.tar.gz: 79b7518a8f6b3f70cc019196e874ef342a4b3b69
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb6b058d22be9aa35e1503982c4527ebe44ea19d87f8f2574190d025a9d2721e7ea1bee327be30dcba0ba4bdaf7395d658def09682d4349aa58476b4fc46564c
|
7
|
+
data.tar.gz: de624193ea2e966b865e4c1102ff0be66fd813b8af4a3843ee650401122eb1607fcaee113050c1d12972f77e66263eccf0a5c70f7583d3ed5083c6f894edfd23
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -12,8 +12,8 @@ See the following pages for the new RSpec syntax and the plan for RSpec 3:
|
|
12
12
|
* [RSpec's new message expectation syntax - Tea is awesome.](http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/)
|
13
13
|
* [Myron Marston » The Plan for RSpec 3](http://myronmars.to/n/dev-blog/2013/07/the-plan-for-rspec-3)
|
14
14
|
|
15
|
-
|
16
|
-
|
15
|
+
Transpec now supports almost all conversions for the RSpec changes,
|
16
|
+
but the changes for RSpec 3 is not fixed and may vary in the future.
|
17
17
|
So it's recommended to follow updates of both RSpec and Transpec.
|
18
18
|
|
19
19
|
## Examples
|
@@ -91,7 +91,7 @@ describe Account do
|
|
91
91
|
end
|
92
92
|
```
|
93
93
|
|
94
|
-
### Actual
|
94
|
+
### Actual examples
|
95
95
|
|
96
96
|
You can see actual conversion examples below:
|
97
97
|
|
@@ -346,10 +346,10 @@ expect([1, 2, 3]).to match_array([2, 1, 3])
|
|
346
346
|
|
347
347
|
```ruby
|
348
348
|
# Targets
|
349
|
-
(1.0 / 3.0).
|
349
|
+
expect(1.0 / 3.0).to be_close(0.333, 0.001)
|
350
350
|
|
351
351
|
# Converted
|
352
|
-
(1.0 / 3.0).
|
352
|
+
expect(1.0 / 3.0).to be_within(0.001).of(0.333)
|
353
353
|
```
|
354
354
|
|
355
355
|
* Disabled by: `--keep deprecated`
|
@@ -388,7 +388,7 @@ If you choose so, disable this conversion with `--keep have_items`.
|
|
388
388
|
* Disabled by: `--keep have_items`
|
389
389
|
* See also: [Expectations: have(x).items matchers will be moved into an external gem - The Plan for RSpec 3](http://myronmars.to/n/dev-blog/2013/07/the-plan-for-rspec-3#expectations__matchers_will_be_moved_into_an_external_gem)
|
390
390
|
|
391
|
-
### Expectations on
|
391
|
+
### Expectations on block
|
392
392
|
|
393
393
|
```ruby
|
394
394
|
# Targets
|
data/README.md.erb
CHANGED
@@ -12,8 +12,8 @@ See the following pages for the new RSpec syntax and the plan for RSpec 3:
|
|
12
12
|
* [RSpec's new message expectation syntax - Tea is awesome.](http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/)
|
13
13
|
* [Myron Marston » The Plan for RSpec 3](http://myronmars.to/n/dev-blog/2013/07/the-plan-for-rspec-3)
|
14
14
|
|
15
|
-
|
16
|
-
|
15
|
+
Transpec now supports almost all conversions for the RSpec changes,
|
16
|
+
but the changes for RSpec 3 is not fixed and may vary in the future.
|
17
17
|
So it's recommended to follow updates of both RSpec and Transpec.
|
18
18
|
|
19
19
|
## Examples
|
@@ -64,7 +64,7 @@ Transpec would convert it to the following form:
|
|
64
64
|
<%= Transpec::Converter.new.convert(example) -%>
|
65
65
|
```
|
66
66
|
|
67
|
-
### Actual
|
67
|
+
### Actual examples
|
68
68
|
|
69
69
|
You can see actual conversion examples below:
|
70
70
|
|
@@ -342,10 +342,10 @@ expect([1, 2, 3]).to match_array([2, 1, 3])
|
|
342
342
|
|
343
343
|
```ruby
|
344
344
|
# Targets
|
345
|
-
(1.0 / 3.0).
|
345
|
+
expect(1.0 / 3.0).to be_close(0.333, 0.001)
|
346
346
|
|
347
347
|
# Converted
|
348
|
-
(1.0 / 3.0).
|
348
|
+
expect(1.0 / 3.0).to be_within(0.001).of(0.333)
|
349
349
|
```
|
350
350
|
|
351
351
|
* Disabled by: `--keep deprecated`
|
@@ -384,7 +384,7 @@ If you choose so, disable this conversion with `--keep have_items`.
|
|
384
384
|
* Disabled by: `--keep have_items`
|
385
385
|
* See also: [Expectations: have(x).items matchers will be moved into an external gem - The Plan for RSpec 3](http://myronmars.to/n/dev-blog/2013/07/the-plan-for-rspec-3#expectations__matchers_will_be_moved_into_an_external_gem)
|
386
386
|
|
387
|
-
### Expectations on
|
387
|
+
### Expectations on block
|
388
388
|
|
389
389
|
```ruby
|
390
390
|
# Targets
|
data/lib/transpec/ast/node.rb
CHANGED
@@ -68,10 +68,10 @@ module Transpec
|
|
68
68
|
each_descendent_node.to_a
|
69
69
|
end
|
70
70
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
71
|
+
def each_node(&block)
|
72
|
+
return to_enum(__method__) unless block_given?
|
73
|
+
yield self
|
74
|
+
each_descendent_node(&block)
|
75
75
|
end
|
76
76
|
end
|
77
77
|
end
|
data/lib/transpec/converter.rb
CHANGED
@@ -3,7 +3,6 @@
|
|
3
3
|
require 'transpec/base_rewriter'
|
4
4
|
require 'transpec/configuration'
|
5
5
|
require 'transpec/report'
|
6
|
-
require 'transpec/ast/scanner'
|
7
6
|
require 'transpec/syntax'
|
8
7
|
require 'transpec/syntax/be_close'
|
9
8
|
require 'transpec/syntax/double'
|
@@ -30,22 +29,17 @@ module Transpec
|
|
30
29
|
end
|
31
30
|
|
32
31
|
def process(ast, source_rewriter)
|
33
|
-
|
34
|
-
|
32
|
+
return unless ast
|
33
|
+
ast.each_node do |node|
|
34
|
+
dispatch_node(node, source_rewriter)
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
def dispatch_node(node,
|
38
|
+
def dispatch_node(node, source_rewriter)
|
39
39
|
Syntax.standalone_syntaxes.each do |syntax_class|
|
40
40
|
next unless syntax_class.target_node?(node, @runtime_data)
|
41
41
|
|
42
|
-
syntax = syntax_class.new(
|
43
|
-
node,
|
44
|
-
ancestor_nodes,
|
45
|
-
source_rewriter,
|
46
|
-
@runtime_data,
|
47
|
-
@report
|
48
|
-
)
|
42
|
+
syntax = syntax_class.new(node, source_rewriter, @runtime_data, @report)
|
49
43
|
|
50
44
|
handler_name = "process_#{syntax_class.snake_case_name}"
|
51
45
|
send(handler_name, syntax)
|
@@ -20,7 +20,7 @@ module Transpec
|
|
20
20
|
require 'pathname'
|
21
21
|
|
22
22
|
module TranspecAnalysis
|
23
|
-
@
|
23
|
+
@base_path = Dir.pwd
|
24
24
|
|
25
25
|
def self.data
|
26
26
|
@data ||= {}
|
@@ -28,12 +28,17 @@ module Transpec
|
|
28
28
|
|
29
29
|
def self.node_id(filename, begin_pos, end_pos)
|
30
30
|
absolute_path = File.expand_path(filename)
|
31
|
-
relative_path = Pathname.new(absolute_path).relative_path_from(
|
31
|
+
relative_path = Pathname.new(absolute_path).relative_path_from(base_pathname).to_s
|
32
32
|
[relative_path, begin_pos, end_pos].join('_')
|
33
33
|
end
|
34
34
|
|
35
|
+
def self.base_pathname
|
36
|
+
@base_pathname ||= Pathname.new(@base_path)
|
37
|
+
end
|
38
|
+
|
35
39
|
at_exit do
|
36
|
-
File.
|
40
|
+
path = File.join(@base_path, '#{RESULT_FILE}')
|
41
|
+
File.open(path, 'w') do |file|
|
37
42
|
Marshal.dump(data, file)
|
38
43
|
end
|
39
44
|
end
|
@@ -82,13 +87,17 @@ module Transpec
|
|
82
87
|
end
|
83
88
|
|
84
89
|
def default_rspec_command
|
85
|
-
if
|
90
|
+
if project_requires_bundler?
|
86
91
|
'bundle exec rspec'
|
87
92
|
else
|
88
93
|
'rspec'
|
89
94
|
end
|
90
95
|
end
|
91
96
|
|
97
|
+
def project_requires_bundler?
|
98
|
+
File.exist?('Gemfile')
|
99
|
+
end
|
100
|
+
|
92
101
|
def analyze(paths = [])
|
93
102
|
in_copied_project do
|
94
103
|
rewriter = Rewriter.new
|
@@ -152,7 +161,7 @@ module Transpec
|
|
152
161
|
end
|
153
162
|
|
154
163
|
def with_bundler_clean_env
|
155
|
-
if defined?(Bundler)
|
164
|
+
if defined?(Bundler) && project_requires_bundler?
|
156
165
|
Bundler.with_clean_env do
|
157
166
|
# Bundler.with_clean_env cleans environment variables
|
158
167
|
# which are set after bundler is loaded.
|
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
require 'transpec/base_rewriter'
|
4
4
|
require 'transpec/util'
|
5
|
-
require 'transpec/ast/scanner'
|
6
5
|
|
7
6
|
module Transpec
|
8
7
|
class DynamicAnalyzer
|
@@ -36,11 +35,13 @@ module Transpec
|
|
36
35
|
private
|
37
36
|
|
38
37
|
def collect_requests(ast)
|
39
|
-
|
38
|
+
return unless ast
|
39
|
+
|
40
|
+
ast.each_node do |node|
|
40
41
|
Syntax.standalone_syntaxes.each do |syntax_class|
|
41
42
|
syntax_class.register_request_for_dynamic_analysis(node, self)
|
42
43
|
next unless syntax_class.target_node?(node)
|
43
|
-
syntax = syntax_class.new(node
|
44
|
+
syntax = syntax_class.new(node)
|
44
45
|
syntax.register_request_for_dynamic_analysis(self)
|
45
46
|
end
|
46
47
|
end
|
@@ -53,24 +54,31 @@ module Transpec
|
|
53
54
|
end
|
54
55
|
|
55
56
|
def inject_analysis_method(node, analysis_codes, source_rewriter)
|
57
|
+
front, rear = build_wrapper_codes(node, analysis_codes)
|
58
|
+
|
59
|
+
source_range = if taking_block?(node)
|
60
|
+
node.parent_node.loc.expression
|
61
|
+
else
|
62
|
+
node.loc.expression
|
63
|
+
end
|
64
|
+
|
65
|
+
source_rewriter.insert_before(source_range, front)
|
66
|
+
source_rewriter.insert_after(source_range, rear)
|
67
|
+
rescue OverlappedRewriteError # rubocop:disable HandleExceptions
|
68
|
+
end
|
69
|
+
|
70
|
+
def build_wrapper_codes(node, analysis_codes)
|
56
71
|
source_range = node.loc.expression
|
57
72
|
|
58
73
|
front = "#{ANALYSIS_METHOD}(("
|
74
|
+
|
59
75
|
rear = format(
|
60
76
|
'), self, %s, __FILE__, %d, %d)',
|
61
77
|
hash_literal(analysis_codes), source_range.begin_pos, source_range.end_pos
|
62
78
|
)
|
63
79
|
rear = "\n" + indentation_of_line(source_range.end) + rear if contain_here_document?(node)
|
64
80
|
|
65
|
-
|
66
|
-
|
67
|
-
if parent_node && parent_node.type == :block && parent_node.children.first.equal?(node)
|
68
|
-
source_range = node.parent_node.loc.expression
|
69
|
-
end
|
70
|
-
|
71
|
-
source_rewriter.insert_before(source_range, front)
|
72
|
-
source_rewriter.insert_after(source_range, rear)
|
73
|
-
rescue OverlappedRewriteError # rubocop:disable HandleExceptions
|
81
|
+
[front, rear]
|
74
82
|
end
|
75
83
|
|
76
84
|
# Hash#inspect generates invalid literal with following example:
|
@@ -89,6 +97,11 @@ module Transpec
|
|
89
97
|
|
90
98
|
literal << ' }'
|
91
99
|
end
|
100
|
+
|
101
|
+
def taking_block?(node)
|
102
|
+
parent_node = node.parent_node
|
103
|
+
parent_node && parent_node.type == :block && parent_node.children.first.equal?(node)
|
104
|
+
end
|
92
105
|
end
|
93
106
|
end
|
94
107
|
end
|
@@ -47,16 +47,15 @@ module Transpec
|
|
47
47
|
[:module, :def]
|
48
48
|
].freeze
|
49
49
|
|
50
|
-
attr_reader :
|
50
|
+
attr_reader :node
|
51
51
|
|
52
|
-
|
53
|
-
|
54
|
-
@nodes = nodes
|
52
|
+
def initialize(node)
|
53
|
+
@node = node
|
55
54
|
end
|
56
55
|
|
57
56
|
def scopes
|
58
57
|
@scopes ||= begin
|
59
|
-
scopes = @
|
58
|
+
scopes = @node.each_ancestor_node.reverse_each.map { |node| scope_type(node) }
|
60
59
|
scopes.compact!
|
61
60
|
scopes.extend(ArrayExtension)
|
62
61
|
end
|
data/lib/transpec/syntax.rb
CHANGED
@@ -6,7 +6,7 @@ require 'transpec/report'
|
|
6
6
|
|
7
7
|
module Transpec
|
8
8
|
class Syntax
|
9
|
-
attr_reader :node, :
|
9
|
+
attr_reader :node, :source_rewriter, :runtime_data, :report
|
10
10
|
|
11
11
|
def self.inherited(subclass)
|
12
12
|
all_syntaxes << subclass
|
@@ -38,9 +38,8 @@ module Transpec
|
|
38
38
|
false
|
39
39
|
end
|
40
40
|
|
41
|
-
def initialize(node,
|
41
|
+
def initialize(node, source_rewriter = nil, runtime_data = nil, report = nil)
|
42
42
|
@node = node
|
43
|
-
@ancestor_nodes = ancestor_nodes
|
44
43
|
@source_rewriter = source_rewriter
|
45
44
|
@runtime_data = runtime_data
|
46
45
|
@report = report || Report.new
|
@@ -50,11 +49,11 @@ module Transpec
|
|
50
49
|
end
|
51
50
|
|
52
51
|
def static_context_inspector
|
53
|
-
@static_context_inspector ||= StaticContextInspector.new(@
|
52
|
+
@static_context_inspector ||= StaticContextInspector.new(@node)
|
54
53
|
end
|
55
54
|
|
56
55
|
def parent_node
|
57
|
-
@
|
56
|
+
@node.parent_node
|
58
57
|
end
|
59
58
|
|
60
59
|
def expression_range
|
@@ -59,7 +59,7 @@ module Transpec
|
|
59
59
|
def each_following_chained_method_node
|
60
60
|
return to_enum(__method__) unless block_given?
|
61
61
|
|
62
|
-
@
|
62
|
+
@node.each_ancestor_node.reduce(@node) do |child_node, parent_node|
|
63
63
|
return unless [:send, :block].include?(parent_node.type)
|
64
64
|
return unless parent_node.children.first == child_node
|
65
65
|
yield parent_node, child_node
|
@@ -19,13 +19,6 @@ module Transpec
|
|
19
19
|
!receiver_node.nil? && OPERATORS.include?(method_name)
|
20
20
|
end
|
21
21
|
|
22
|
-
def initialize(node, source_rewriter = nil, runtime_data = nil, report = nil)
|
23
|
-
@node = node
|
24
|
-
@source_rewriter = source_rewriter
|
25
|
-
@runtime_data = runtime_data
|
26
|
-
@report = report || Report.new
|
27
|
-
end
|
28
|
-
|
29
22
|
def register_request_for_dynamic_analysis(rewriter)
|
30
23
|
return unless method_name == :=~
|
31
24
|
rewriter.register_request(arg_node, :arg_is_enumerable?, 'is_a?(Enumerable)')
|
@@ -24,7 +24,7 @@ module Transpec
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def positive?
|
27
|
-
|
27
|
+
@node.each_ancestor_node do |ancestor_node|
|
28
28
|
next unless ancestor_node.type == :send
|
29
29
|
expectation_method_name = ancestor_node.children[1]
|
30
30
|
return [:should, :to].include?(expectation_method_name)
|
@@ -19,7 +19,7 @@ module Transpec
|
|
19
19
|
!receiver_node.nil? && [:should, :should_not].include?(method_name)
|
20
20
|
end
|
21
21
|
|
22
|
-
def initialize(node,
|
22
|
+
def initialize(node, source_rewriter = nil, runtime_data = nil, report = nil)
|
23
23
|
super
|
24
24
|
@current_syntax_type = :should
|
25
25
|
end
|
data/lib/transpec/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -15,8 +15,6 @@ RSpec.configure do |config|
|
|
15
15
|
config.color_enabled = true
|
16
16
|
config.treat_symbols_as_metadata_keys_with_true_values = true
|
17
17
|
|
18
|
-
config.filter_run_excluding :skip_on_jruby if RUBY_ENGINE == 'jruby'
|
19
|
-
|
20
18
|
config.before(:all) do
|
21
19
|
require 'rainbow'
|
22
20
|
Sickill::Rainbow.enabled = false
|
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
require 'transpec/dynamic_analyzer'
|
4
4
|
require 'transpec/ast/builder'
|
5
|
-
require 'transpec/ast/scanner'
|
6
5
|
require 'transpec/syntax/should'
|
7
6
|
require 'transpec/syntax/expect'
|
8
7
|
require 'parser'
|
@@ -55,14 +54,9 @@ end
|
|
55
54
|
|
56
55
|
shared_context 'should object' do
|
57
56
|
let(:should_object) do
|
58
|
-
|
57
|
+
ast.each_node do |node|
|
59
58
|
next unless Transpec::Syntax::Should.target_node?(node)
|
60
|
-
return Transpec::Syntax::Should.new(
|
61
|
-
node,
|
62
|
-
ancestor_nodes,
|
63
|
-
source_rewriter,
|
64
|
-
runtime_data
|
65
|
-
)
|
59
|
+
return Transpec::Syntax::Should.new(node, source_rewriter, runtime_data)
|
66
60
|
end
|
67
61
|
|
68
62
|
fail 'No should node is found!'
|
@@ -73,14 +67,9 @@ end
|
|
73
67
|
|
74
68
|
shared_context 'expect object' do
|
75
69
|
let(:expect_object) do
|
76
|
-
|
70
|
+
ast.each_node do |node|
|
77
71
|
next unless Transpec::Syntax::Expect.target_node?(node)
|
78
|
-
return Transpec::Syntax::Expect.new(
|
79
|
-
node,
|
80
|
-
ancestor_nodes,
|
81
|
-
source_rewriter,
|
82
|
-
runtime_data
|
83
|
-
)
|
72
|
+
return Transpec::Syntax::Expect.new(node, source_rewriter, runtime_data)
|
84
73
|
end
|
85
74
|
|
86
75
|
fail 'No expect node is found!'
|
@@ -50,7 +50,7 @@ module Transpec
|
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
-
|
53
|
+
shared_context 'ancestor nodes' do
|
54
54
|
let(:target_node) do
|
55
55
|
ast.each_descendent_node do |node|
|
56
56
|
return node if node == s(:args)
|
@@ -58,6 +58,10 @@ module Transpec
|
|
58
58
|
end
|
59
59
|
|
60
60
|
let(:expected_types) { [:block, :def] }
|
61
|
+
end
|
62
|
+
|
63
|
+
describe '#each_ancestor_node' do
|
64
|
+
include_context 'ancestor nodes'
|
61
65
|
|
62
66
|
context 'when a block is given' do
|
63
67
|
it 'yields each ancestor node' do
|
@@ -95,8 +99,25 @@ module Transpec
|
|
95
99
|
end
|
96
100
|
end
|
97
101
|
|
98
|
-
describe '#
|
102
|
+
describe '#ancestor_nodes' do
|
103
|
+
include_context 'ancestor nodes'
|
104
|
+
|
105
|
+
it 'returns an array' do
|
106
|
+
target_node.ancestor_nodes.should be_an(Array)
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'returns same nodes as #each_ancestor_node' do
|
110
|
+
types = target_node.ancestor_nodes.map(&:type)
|
111
|
+
types.should == expected_types
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
shared_context 'child nodes' do
|
99
116
|
let(:expected_types) { [:args, :block] }
|
117
|
+
end
|
118
|
+
|
119
|
+
describe '#each_child_node' do
|
120
|
+
include_context 'child nodes'
|
100
121
|
|
101
122
|
context 'when a block is given' do
|
102
123
|
it 'yields each child node' do
|
@@ -134,10 +155,27 @@ module Transpec
|
|
134
155
|
end
|
135
156
|
end
|
136
157
|
|
137
|
-
describe '#
|
158
|
+
describe '#child_nodes' do
|
159
|
+
include_context 'child nodes'
|
160
|
+
|
161
|
+
it 'returns an array' do
|
162
|
+
ast.child_nodes.should be_an(Array)
|
163
|
+
end
|
164
|
+
|
165
|
+
it 'returns same nodes as #each_child_node' do
|
166
|
+
types = ast.child_nodes.map(&:type)
|
167
|
+
types.should == expected_types
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
shared_context 'descendent nodes' do
|
138
172
|
let(:expected_types) do
|
139
173
|
[:args, :arg, :arg, :block, :send, :int, :args, :send, :lvar]
|
140
174
|
end
|
175
|
+
end
|
176
|
+
|
177
|
+
describe '#each_descendent_node' do
|
178
|
+
include_context 'descendent nodes'
|
141
179
|
|
142
180
|
context 'when a block is given' do
|
143
181
|
it 'yields each descendent node with depth first order' do
|
@@ -174,6 +212,60 @@ module Transpec
|
|
174
212
|
end
|
175
213
|
end
|
176
214
|
end
|
215
|
+
|
216
|
+
describe '#descendent_nodes' do
|
217
|
+
include_context 'descendent nodes'
|
218
|
+
|
219
|
+
it 'returns an array' do
|
220
|
+
ast.descendent_nodes.should be_an(Array)
|
221
|
+
end
|
222
|
+
|
223
|
+
it 'returns same nodes as #each_descendent_node' do
|
224
|
+
types = ast.descendent_nodes.map(&:type)
|
225
|
+
types.should == expected_types
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
describe '#each_node' do
|
230
|
+
let(:expected_types) do
|
231
|
+
[:def, :args, :arg, :arg, :block, :send, :int, :args, :send, :lvar]
|
232
|
+
end
|
233
|
+
|
234
|
+
context 'when a block is given' do
|
235
|
+
it 'yields itself and each descendent node with depth first order' do
|
236
|
+
index = 0
|
237
|
+
|
238
|
+
ast.each_node do |node|
|
239
|
+
expected_type = expected_types[index]
|
240
|
+
node.type.should == expected_type
|
241
|
+
index += 1
|
242
|
+
end
|
243
|
+
|
244
|
+
index.should_not == 0
|
245
|
+
end
|
246
|
+
|
247
|
+
it 'returns itself' do
|
248
|
+
returned_value = ast.each_node { }
|
249
|
+
returned_value.should be(ast)
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
context 'when no block is given' do
|
254
|
+
it 'returns enumerator' do
|
255
|
+
ast.each_node.should be_a(Enumerator)
|
256
|
+
end
|
257
|
+
|
258
|
+
describe 'the returned enumerator' do
|
259
|
+
it 'enumerates the child nodes' do
|
260
|
+
enumerator = ast.each_node
|
261
|
+
|
262
|
+
expected_types.each do |expected_type|
|
263
|
+
enumerator.next.type.should == expected_type
|
264
|
+
end
|
265
|
+
end
|
266
|
+
end
|
267
|
+
end
|
268
|
+
end
|
177
269
|
end
|
178
270
|
end
|
179
271
|
end
|
@@ -118,6 +118,22 @@ module Transpec
|
|
118
118
|
end
|
119
119
|
end
|
120
120
|
|
121
|
+
context 'when rspec exited with non-0 status' do
|
122
|
+
let(:source) { 'This is invalid syntax <' }
|
123
|
+
|
124
|
+
it 'raises error' do
|
125
|
+
-> { dynamic_analyzer.analyze }.should raise_error(/Dynamic analysis failed/)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
context 'when working directory has been changed at exit of rspec' do
|
130
|
+
let(:source) { "Dir.chdir('spec')" }
|
131
|
+
|
132
|
+
it 'does not raise error' do
|
133
|
+
-> { dynamic_analyzer.analyze }.should_not raise_error
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
121
137
|
runtime_data_cache = {}
|
122
138
|
|
123
139
|
subject(:runtime_data) do
|
@@ -4,7 +4,7 @@ require 'spec_helper'
|
|
4
4
|
require 'transpec/static_context_inspector'
|
5
5
|
|
6
6
|
module Transpec
|
7
|
-
describe StaticContextInspector
|
7
|
+
describe StaticContextInspector do
|
8
8
|
include CacheHelper
|
9
9
|
include ::AST::Sexp
|
10
10
|
include_context 'parsed objects'
|
@@ -51,7 +51,7 @@ module Transpec
|
|
51
51
|
end
|
52
52
|
|
53
53
|
it 'returns scope stack' do
|
54
|
-
|
54
|
+
ast.each_node do |node|
|
55
55
|
expected_scopes = begin
|
56
56
|
case node_id(node)
|
57
57
|
when 'send nil :top_level'
|
@@ -90,7 +90,7 @@ module Transpec
|
|
90
90
|
|
91
91
|
next unless expected_scopes
|
92
92
|
|
93
|
-
context_inspector = StaticContextInspector.new(
|
93
|
+
context_inspector = StaticContextInspector.new(node)
|
94
94
|
context_inspector.scopes.should == expected_scopes
|
95
95
|
end
|
96
96
|
end
|
@@ -98,9 +98,9 @@ module Transpec
|
|
98
98
|
|
99
99
|
shared_examples 'context inspection methods' do
|
100
100
|
let(:context_inspector) do
|
101
|
-
|
101
|
+
ast.each_node do |node|
|
102
102
|
next unless node == s(:send, nil, :target)
|
103
|
-
return StaticContextInspector.new(
|
103
|
+
return StaticContextInspector.new(node)
|
104
104
|
end
|
105
105
|
|
106
106
|
fail 'Target node not found!'
|
@@ -9,13 +9,9 @@ module Transpec
|
|
9
9
|
include_context 'parsed objects'
|
10
10
|
|
11
11
|
subject(:be_close_object) do
|
12
|
-
|
12
|
+
ast.each_node do |node|
|
13
13
|
next unless BeClose.target_node?(node)
|
14
|
-
return BeClose.new(
|
15
|
-
node,
|
16
|
-
ancestor_nodes,
|
17
|
-
source_rewriter
|
18
|
-
)
|
14
|
+
return BeClose.new(node, source_rewriter)
|
19
15
|
end
|
20
16
|
fail 'No be_close node is found!'
|
21
17
|
end
|
@@ -9,13 +9,9 @@ module Transpec
|
|
9
9
|
include_context 'parsed objects'
|
10
10
|
|
11
11
|
subject(:double_object) do
|
12
|
-
|
12
|
+
ast.each_node do |node|
|
13
13
|
next unless Double.target_node?(node)
|
14
|
-
return Double.new(
|
15
|
-
node,
|
16
|
-
ancestor_nodes,
|
17
|
-
source_rewriter
|
18
|
-
)
|
14
|
+
return Double.new(node, source_rewriter)
|
19
15
|
end
|
20
16
|
fail 'No double node is found!'
|
21
17
|
end
|
@@ -9,13 +9,9 @@ module Transpec
|
|
9
9
|
include_context 'parsed objects'
|
10
10
|
|
11
11
|
subject(:its_object) do
|
12
|
-
|
12
|
+
ast.each_node do |node|
|
13
13
|
next unless Its.target_node?(node)
|
14
|
-
return Its.new(
|
15
|
-
node,
|
16
|
-
ancestor_nodes,
|
17
|
-
source_rewriter
|
18
|
-
)
|
14
|
+
return Its.new(node, source_rewriter)
|
19
15
|
end
|
20
16
|
fail 'No #its node is found!'
|
21
17
|
end
|
@@ -9,14 +9,9 @@ module Transpec
|
|
9
9
|
include_context 'parsed objects'
|
10
10
|
|
11
11
|
subject(:method_stub_object) do
|
12
|
-
|
12
|
+
ast.each_node do |node|
|
13
13
|
next unless MethodStub.target_node?(node)
|
14
|
-
return MethodStub.new(
|
15
|
-
node,
|
16
|
-
ancestor_nodes,
|
17
|
-
source_rewriter,
|
18
|
-
runtime_data
|
19
|
-
)
|
14
|
+
return MethodStub.new(node, source_rewriter, runtime_data)
|
20
15
|
end
|
21
16
|
fail 'No method stub node is found!'
|
22
17
|
end
|
@@ -9,13 +9,9 @@ module Transpec
|
|
9
9
|
include_context 'parsed objects'
|
10
10
|
|
11
11
|
subject(:raise_error_object) do
|
12
|
-
|
12
|
+
ast.each_node do |node|
|
13
13
|
next unless RaiseError.target_node?(node)
|
14
|
-
return RaiseError.new(
|
15
|
-
node,
|
16
|
-
ancestor_nodes,
|
17
|
-
source_rewriter
|
18
|
-
)
|
14
|
+
return RaiseError.new(node, source_rewriter)
|
19
15
|
end
|
20
16
|
fail 'No raise_error node is found!'
|
21
17
|
end
|
@@ -9,13 +9,9 @@ module Transpec
|
|
9
9
|
include_context 'parsed objects'
|
10
10
|
|
11
11
|
subject(:rspec_configure) do
|
12
|
-
|
12
|
+
ast.each_node do |node|
|
13
13
|
next unless RSpecConfigure.target_node?(node)
|
14
|
-
return RSpecConfigure.new(
|
15
|
-
node,
|
16
|
-
ancestor_nodes,
|
17
|
-
source_rewriter
|
18
|
-
)
|
14
|
+
return RSpecConfigure.new(node, source_rewriter)
|
19
15
|
end
|
20
16
|
fail 'No RSpec.configure node is found!'
|
21
17
|
end
|
@@ -9,14 +9,9 @@ module Transpec
|
|
9
9
|
include_context 'parsed objects'
|
10
10
|
|
11
11
|
subject(:should_receive_object) do
|
12
|
-
|
12
|
+
ast.each_node do |node|
|
13
13
|
next unless ShouldReceive.target_node?(node)
|
14
|
-
return ShouldReceive.new(
|
15
|
-
node,
|
16
|
-
ancestor_nodes,
|
17
|
-
source_rewriter,
|
18
|
-
runtime_data
|
19
|
-
)
|
14
|
+
return ShouldReceive.new(node, source_rewriter, runtime_data)
|
20
15
|
end
|
21
16
|
fail 'No should_receive node is found!'
|
22
17
|
end
|
data/transpec.gemspec
CHANGED
@@ -10,7 +10,8 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.authors = ['Yuji Nakayama']
|
11
11
|
spec.email = ['nkymyj@gmail.com']
|
12
12
|
spec.summary = 'RSpec syntax converter'
|
13
|
-
spec.description = 'Transpec automatically converts your specs into latest RSpec syntax
|
13
|
+
spec.description = 'Transpec automatically converts your specs into latest RSpec syntax ' +
|
14
|
+
'with static and dynamic code analysis.'
|
14
15
|
spec.homepage = 'https://github.com/yujinakayama/transpec'
|
15
16
|
spec.license = 'MIT'
|
16
17
|
|
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: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuji Nakayama
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-11-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|
@@ -165,7 +165,7 @@ dependencies:
|
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: '0.3'
|
167
167
|
description: Transpec automatically converts your specs into latest RSpec syntax with
|
168
|
-
static analysis.
|
168
|
+
static and dynamic code analysis.
|
169
169
|
email:
|
170
170
|
- nkymyj@gmail.com
|
171
171
|
executables:
|
@@ -187,7 +187,6 @@ files:
|
|
187
187
|
- lib/transpec.rb
|
188
188
|
- lib/transpec/ast/builder.rb
|
189
189
|
- lib/transpec/ast/node.rb
|
190
|
-
- lib/transpec/ast/scanner.rb
|
191
190
|
- lib/transpec/base_rewriter.rb
|
192
191
|
- lib/transpec/cli.rb
|
193
192
|
- lib/transpec/commit_message.rb
|
@@ -228,7 +227,6 @@ files:
|
|
228
227
|
- spec/support/file_helper.rb
|
229
228
|
- spec/support/shared_context.rb
|
230
229
|
- spec/transpec/ast/node_spec.rb
|
231
|
-
- spec/transpec/ast/scanner_spec.rb
|
232
230
|
- spec/transpec/cli_spec.rb
|
233
231
|
- spec/transpec/commit_message_spec.rb
|
234
232
|
- spec/transpec/configuration_spec.rb
|
@@ -291,7 +289,6 @@ test_files:
|
|
291
289
|
- spec/support/file_helper.rb
|
292
290
|
- spec/support/shared_context.rb
|
293
291
|
- spec/transpec/ast/node_spec.rb
|
294
|
-
- spec/transpec/ast/scanner_spec.rb
|
295
292
|
- spec/transpec/cli_spec.rb
|
296
293
|
- spec/transpec/commit_message_spec.rb
|
297
294
|
- spec/transpec/configuration_spec.rb
|
data/lib/transpec/ast/scanner.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
module Transpec
|
4
|
-
module AST
|
5
|
-
class Scanner
|
6
|
-
attr_reader :context
|
7
|
-
|
8
|
-
def self.scan(origin_node, &block)
|
9
|
-
instance = new(&block)
|
10
|
-
instance.scan(origin_node, true)
|
11
|
-
nil
|
12
|
-
end
|
13
|
-
|
14
|
-
def initialize(&block)
|
15
|
-
@callback = block
|
16
|
-
@ancestor_nodes = []
|
17
|
-
end
|
18
|
-
|
19
|
-
def scan(origin_node, yield_origin_node = false)
|
20
|
-
return unless origin_node
|
21
|
-
|
22
|
-
yield_node(origin_node) if yield_origin_node
|
23
|
-
|
24
|
-
@ancestor_nodes.push(origin_node)
|
25
|
-
|
26
|
-
origin_node.each_child_node do |child_node|
|
27
|
-
yield_node(child_node)
|
28
|
-
scan(child_node)
|
29
|
-
end
|
30
|
-
|
31
|
-
@ancestor_nodes.pop
|
32
|
-
end
|
33
|
-
|
34
|
-
private
|
35
|
-
|
36
|
-
def yield_node(node)
|
37
|
-
@callback.call(node, @ancestor_nodes)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,124 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
require 'transpec/ast/scanner'
|
5
|
-
|
6
|
-
module Transpec
|
7
|
-
module AST
|
8
|
-
describe Scanner do
|
9
|
-
include_context 'parsed objects'
|
10
|
-
|
11
|
-
let(:source) do
|
12
|
-
<<-END
|
13
|
-
some_var = 1
|
14
|
-
|
15
|
-
RSpec.configure do |config|
|
16
|
-
config.before do
|
17
|
-
prepare_something
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
module SomeModule
|
22
|
-
SOME_CONST = 1
|
23
|
-
|
24
|
-
describe 'something' do
|
25
|
-
def some_method(some_arg)
|
26
|
-
do_something
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'is 1' do
|
30
|
-
something.should == 1
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
END
|
35
|
-
end
|
36
|
-
|
37
|
-
# (begin
|
38
|
-
# (lvasgn :some_var
|
39
|
-
# (int 1))
|
40
|
-
# (block
|
41
|
-
# (send
|
42
|
-
# (const nil :RSpec) :configure)
|
43
|
-
# (args
|
44
|
-
# (arg :config))
|
45
|
-
# (block
|
46
|
-
# (send
|
47
|
-
# (lvar :config) :before)
|
48
|
-
# (args)
|
49
|
-
# (send nil :prepare_something)))
|
50
|
-
# (module
|
51
|
-
# (const nil :SomeModule)
|
52
|
-
# (begin
|
53
|
-
# (casgn nil :SOME_CONST
|
54
|
-
# (int 1))
|
55
|
-
# (block
|
56
|
-
# (send nil :describe
|
57
|
-
# (str "something"))
|
58
|
-
# (args)
|
59
|
-
# (begin
|
60
|
-
# (def :some_method
|
61
|
-
# (args
|
62
|
-
# (arg :some_arg))
|
63
|
-
# (send nil :do_something))
|
64
|
-
# (block
|
65
|
-
# (send nil :it
|
66
|
-
# (str "is 1"))
|
67
|
-
# (args)
|
68
|
-
# (send
|
69
|
-
# (send
|
70
|
-
# (send nil :something) :should) :==
|
71
|
-
# (int 1))))))))
|
72
|
-
|
73
|
-
describe '.scan' do
|
74
|
-
it 'scans nodes with depth first order' do
|
75
|
-
expected_node_type_order = [
|
76
|
-
:begin,
|
77
|
-
:lvasgn,
|
78
|
-
:int,
|
79
|
-
:block,
|
80
|
-
:send,
|
81
|
-
:const,
|
82
|
-
:args
|
83
|
-
]
|
84
|
-
|
85
|
-
index = 0
|
86
|
-
|
87
|
-
Scanner.scan(ast) do |node|
|
88
|
-
expected_node_type = expected_node_type_order[index]
|
89
|
-
node.type.should == expected_node_type if expected_node_type
|
90
|
-
index += 1
|
91
|
-
end
|
92
|
-
|
93
|
-
index.should_not == 0
|
94
|
-
end
|
95
|
-
|
96
|
-
it 'passes ancestor nodes of the current node to the block' do
|
97
|
-
each_expected_ancestor_nodes_types = [
|
98
|
-
[],
|
99
|
-
[:begin],
|
100
|
-
[:begin, :lvasgn],
|
101
|
-
[:begin],
|
102
|
-
[:begin, :block],
|
103
|
-
[:begin, :block, :send],
|
104
|
-
[:begin, :block],
|
105
|
-
[:begin, :block, :args]
|
106
|
-
]
|
107
|
-
|
108
|
-
index = 0
|
109
|
-
|
110
|
-
Scanner.scan(ast) do |node, ancestor_nodes|
|
111
|
-
expected_ancestor_node_types = each_expected_ancestor_nodes_types[index]
|
112
|
-
if expected_ancestor_node_types
|
113
|
-
ancestor_node_types = ancestor_nodes.map(&:type)
|
114
|
-
ancestor_node_types.should == expected_ancestor_node_types
|
115
|
-
end
|
116
|
-
index += 1
|
117
|
-
end
|
118
|
-
|
119
|
-
index.should_not == 0
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|