transpec 0.0.1

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.
Files changed (45) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +18 -0
  3. data/.rubocop.yml +13 -0
  4. data/.travis.yml +6 -0
  5. data/Gemfile +9 -0
  6. data/Guardfile +14 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +37 -0
  9. data/Rakefile +27 -0
  10. data/bin/transpec +8 -0
  11. data/lib/transpec/ast/scanner.rb +51 -0
  12. data/lib/transpec/ast/scope_stack.rb +76 -0
  13. data/lib/transpec/cli.rb +162 -0
  14. data/lib/transpec/configuration.rb +40 -0
  15. data/lib/transpec/git.rb +24 -0
  16. data/lib/transpec/rewriter.rb +109 -0
  17. data/lib/transpec/syntax/double.rb +21 -0
  18. data/lib/transpec/syntax/matcher.rb +60 -0
  19. data/lib/transpec/syntax/method_stub.rb +142 -0
  20. data/lib/transpec/syntax/send_node_syntax.rb +39 -0
  21. data/lib/transpec/syntax/should.rb +49 -0
  22. data/lib/transpec/syntax/should_receive.rb +120 -0
  23. data/lib/transpec/syntax.rb +58 -0
  24. data/lib/transpec/util.rb +50 -0
  25. data/lib/transpec/version.rb +14 -0
  26. data/lib/transpec.rb +17 -0
  27. data/spec/.rubocop.yml +19 -0
  28. data/spec/spec_helper.rb +33 -0
  29. data/spec/spec_spec.rb +54 -0
  30. data/spec/support/file_helper.rb +25 -0
  31. data/spec/support/shared_context.rb +63 -0
  32. data/spec/transpec/ast/scanner_spec.rb +177 -0
  33. data/spec/transpec/ast/scope_stack_spec.rb +94 -0
  34. data/spec/transpec/cli_spec.rb +290 -0
  35. data/spec/transpec/configuration_spec.rb +52 -0
  36. data/spec/transpec/git_spec.rb +85 -0
  37. data/spec/transpec/rewriter_spec.rb +203 -0
  38. data/spec/transpec/syntax/double_spec.rb +88 -0
  39. data/spec/transpec/syntax/matcher_spec.rb +407 -0
  40. data/spec/transpec/syntax/method_stub_spec.rb +386 -0
  41. data/spec/transpec/syntax/should_receive_spec.rb +286 -0
  42. data/spec/transpec/syntax/should_spec.rb +262 -0
  43. data/spec/transpec/util_spec.rb +48 -0
  44. data/transpec.gemspec +32 -0
  45. metadata +233 -0
@@ -0,0 +1,262 @@
1
+ # coding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ module Transpec
6
+ class Syntax
7
+ describe Should do
8
+ include_context 'parsed objects'
9
+ include_context 'should object'
10
+
11
+ describe '#matcher_node' do
12
+ context 'when it is taking operator matcher' do
13
+ let(:source) do
14
+ <<-END
15
+ it 'is 1' do
16
+ subject.should == 1
17
+ end
18
+ END
19
+ end
20
+
21
+ # (block
22
+ # (send nil :it
23
+ # (str "is 1"))
24
+ # (args)
25
+ # (send
26
+ # (send
27
+ # (send nil :subject) :should) :==
28
+ # (int 1)))
29
+
30
+ it 'returns its parent node' do
31
+ should_object.parent_node.children[1].should == :==
32
+ should_object.matcher_node.should == should_object.parent_node
33
+ end
34
+ end
35
+
36
+ context 'when it is taking non-operator matcher without argument' do
37
+ let(:source) do
38
+ <<-END
39
+ it 'is empty' do
40
+ subject.should be_empty
41
+ end
42
+ END
43
+ end
44
+
45
+ # (block
46
+ # (send nil :it
47
+ # (str "is empty"))
48
+ # (args)
49
+ # (send
50
+ # (send nil :subject) :should
51
+ # (send nil :be_empty)))
52
+
53
+ it 'returns its argument node' do
54
+ should_object.arg_node.children[1].should == :be_empty
55
+ should_object.matcher_node.should == should_object.arg_node
56
+ end
57
+ end
58
+
59
+ context 'when it is taking non-operator matcher with argument' do
60
+ let(:source) do
61
+ <<-END
62
+ it 'is 1' do
63
+ subject.should eq(1)
64
+ end
65
+ END
66
+ end
67
+
68
+ # (block
69
+ # (send nil :it
70
+ # (str "is 1"))
71
+ # (args)
72
+ # (send
73
+ # (send nil :subject) :should
74
+ # (send nil :eq
75
+ # (int 1))))
76
+
77
+ it 'returns its argument node' do
78
+ should_object.arg_node.children[1].should == :eq
79
+ should_object.matcher_node.should == should_object.arg_node
80
+ end
81
+ end
82
+ end
83
+
84
+ describe '#expectize!' do
85
+ let(:source) do
86
+ <<-END
87
+ it 'is 1' do
88
+ subject.should == 1
89
+ end
90
+ END
91
+ end
92
+
93
+ it 'invokes Matcher#correct_operator!' do
94
+ should_object.matcher.should_receive(:correct_operator!)
95
+ should_object.expectize!
96
+ end
97
+
98
+ context 'when it is `subject.should` form' do
99
+ let(:source) do
100
+ <<-END
101
+ it 'is 1' do
102
+ subject.should eq(1)
103
+ end
104
+ END
105
+ end
106
+
107
+ let(:expected_source) do
108
+ <<-END
109
+ it 'is 1' do
110
+ expect(subject).to eq(1)
111
+ end
112
+ END
113
+ end
114
+
115
+ it 'converts into `expect(subject).to` form' do
116
+ should_object.expectize!
117
+ rewritten_source.should == expected_source
118
+ end
119
+ end
120
+
121
+ context 'when it is `subject.should_not` form' do
122
+ let(:source) do
123
+ <<-END
124
+ it 'is not 1' do
125
+ subject.should_not eq(1)
126
+ end
127
+ END
128
+ end
129
+
130
+ let(:expected_source) do
131
+ <<-END
132
+ it 'is not 1' do
133
+ expect(subject).not_to eq(1)
134
+ end
135
+ END
136
+ end
137
+
138
+ it 'converts into `expect(subject).not_to` form' do
139
+ should_object.expectize!
140
+ rewritten_source.should == expected_source
141
+ end
142
+
143
+ context 'and "to_not" is passed as negative form' do
144
+ let(:expected_source) do
145
+ <<-END
146
+ it 'is not 1' do
147
+ expect(subject).to_not eq(1)
148
+ end
149
+ END
150
+ end
151
+
152
+ it 'converts into `expect(subject).to_not` form' do
153
+ should_object.expectize!('to_not')
154
+ rewritten_source.should == expected_source
155
+ end
156
+ end
157
+ end
158
+
159
+ context 'when it is `(subject).should` form' do
160
+ let(:source) do
161
+ <<-END
162
+ it 'is true' do
163
+ (1 == 1).should be_true
164
+ end
165
+ END
166
+ end
167
+
168
+ let(:expected_source) do
169
+ <<-END
170
+ it 'is true' do
171
+ expect(1 == 1).to be_true
172
+ end
173
+ END
174
+ end
175
+
176
+ it 'converts into `expect(subject).to` form without superfluous parentheses' do
177
+ should_object.expectize!
178
+ rewritten_source.should == expected_source
179
+ end
180
+ end
181
+
182
+ [
183
+ 'lambda', 'Kernel.lambda', '::Kernel.lambda',
184
+ 'proc', 'Kernel.proc', '::Kernel.proc',
185
+ 'Proc.new', '::Proc.new',
186
+ '->'
187
+ ].each do |method|
188
+ context "when it is `#{method} { ... }.should` form" do
189
+ let(:source) do
190
+ <<-END
191
+ it 'raises error' do
192
+ #{method} { fail }.should raise_error
193
+ end
194
+ END
195
+ end
196
+
197
+ let(:expected_source) do
198
+ <<-END
199
+ it 'raises error' do
200
+ expect { fail }.to raise_error
201
+ end
202
+ END
203
+ end
204
+
205
+ it 'converts into `expect {...}.to` form' do
206
+ should_object.expectize!
207
+ rewritten_source.should == expected_source
208
+ end
209
+ end
210
+ end
211
+
212
+ ['MyObject.lambda', 'MyObject.proc', 'MyObject.new'].each do |method|
213
+ context "when it is `#{method} { ... }.should` form" do
214
+ let(:source) do
215
+ <<-END
216
+ it 'is 1' do
217
+ #{method} { fail }.should eq(1)
218
+ end
219
+ END
220
+ end
221
+
222
+ let(:expected_source) do
223
+ <<-END
224
+ it 'is 1' do
225
+ expect(#{method} { fail }).to eq(1)
226
+ end
227
+ END
228
+ end
229
+
230
+ it "converts into `expect(#{method} { ... }).to` form" do
231
+ should_object.expectize!
232
+ rewritten_source.should == expected_source
233
+ end
234
+ end
235
+ end
236
+
237
+ context 'when it is `method { ... }.should` form but the subject value is not proc' do
238
+ let(:source) do
239
+ <<-END
240
+ it 'increments all elements' do
241
+ [1, 2].map { |i| i + 1 }.should eq([2, 3])
242
+ end
243
+ END
244
+ end
245
+
246
+ let(:expected_source) do
247
+ <<-END
248
+ it 'increments all elements' do
249
+ expect([1, 2].map { |i| i + 1 }).to eq([2, 3])
250
+ end
251
+ END
252
+ end
253
+
254
+ it 'converts into `expect(method { ... }).to` form' do
255
+ should_object.expectize!
256
+ rewritten_source.should == expected_source
257
+ end
258
+ end
259
+ end
260
+ end
261
+ end
262
+ end
@@ -0,0 +1,48 @@
1
+ # coding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ module Transpec
6
+ describe Util do
7
+ include_context 'parsed objects'
8
+ include ::AST::Sexp
9
+
10
+ describe '#const_name' do
11
+ subject { Util.const_name(const_node) }
12
+
13
+ let(:const_node) do
14
+ AST::Scanner.scan(ast) do |node|
15
+ return node if node.type == :const
16
+ end
17
+ fail 'No const node is found!'
18
+ end
19
+
20
+ context 'when the passed node is not :const type' do
21
+ let(:const_node) do
22
+ s(:lvasgn, :foo,
23
+ s(:int, 1))
24
+ end
25
+
26
+ it 'returns nil' do
27
+ should be_nil
28
+ end
29
+ end
30
+
31
+ [
32
+ ['Foo', 'Foo'],
33
+ ['Foo::Bar', 'Foo::Bar'],
34
+ ['Foo::Bar::Baz', 'Foo::Bar::Baz'],
35
+ ['::Foo', 'Foo'],
36
+ ['::Foo::Bar', 'Foo::Bar']
37
+ ].each do |source, expected_return_value|
38
+ context "when the source is #{source.inspect}" do
39
+ let(:source) { source }
40
+
41
+ it "returns #{expected_return_value.inspect}" do
42
+ should == expected_return_value
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
data/transpec.gemspec ADDED
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'transpec/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'transpec'
9
+ spec.version = Transpec::Version.to_s
10
+ spec.authors = ['Yuji Nakayama']
11
+ spec.email = ['nkymyj@gmail.com']
12
+ spec.summary = 'Transpec converts your specs into latest RSpec syntax'
13
+ spec.description = 'Transpec automatically converts your specs into latest RSpec syntax with static analysis.'
14
+ spec.homepage = 'https://github.com/yujinakayama/transpec'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files`.split($/)
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_runtime_dependency 'parser', '~> 2.0.0.pre1'
23
+ spec.add_runtime_dependency 'rspec', '~> 2.14'
24
+
25
+ spec.add_development_dependency 'bundler', '~> 1.3'
26
+ spec.add_development_dependency 'rake', '~> 10.1'
27
+ spec.add_development_dependency 'simplecov', '~> 0.7'
28
+ spec.add_development_dependency 'rubocop', '~> 0.10'
29
+ spec.add_development_dependency 'guard-rspec', '~> 3.0'
30
+ spec.add_development_dependency 'guard-rubocop', '~> 0.2'
31
+ spec.add_development_dependency 'ruby_gntp', '~> 0.3'
32
+ end
metadata ADDED
@@ -0,0 +1,233 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: transpec
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Yuji Nakayama
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: parser
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 2.0.0.pre1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 2.0.0.pre1
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '2.14'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '2.14'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '10.1'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '10.1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '0.7'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '0.7'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: '0.10'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: '0.10'
97
+ - !ruby/object:Gem::Dependency
98
+ name: guard-rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: '3.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: guard-rubocop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: '0.2'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ~>
123
+ - !ruby/object:Gem::Version
124
+ version: '0.2'
125
+ - !ruby/object:Gem::Dependency
126
+ name: ruby_gntp
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ~>
130
+ - !ruby/object:Gem::Version
131
+ version: '0.3'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ~>
137
+ - !ruby/object:Gem::Version
138
+ version: '0.3'
139
+ description: Transpec automatically converts your specs into latest RSpec syntax with
140
+ static analysis.
141
+ email:
142
+ - nkymyj@gmail.com
143
+ executables:
144
+ - transpec
145
+ extensions: []
146
+ extra_rdoc_files: []
147
+ files:
148
+ - .gitignore
149
+ - .rubocop.yml
150
+ - .travis.yml
151
+ - Gemfile
152
+ - Guardfile
153
+ - LICENSE.txt
154
+ - README.md
155
+ - Rakefile
156
+ - bin/transpec
157
+ - lib/transpec.rb
158
+ - lib/transpec/ast/scanner.rb
159
+ - lib/transpec/ast/scope_stack.rb
160
+ - lib/transpec/cli.rb
161
+ - lib/transpec/configuration.rb
162
+ - lib/transpec/git.rb
163
+ - lib/transpec/rewriter.rb
164
+ - lib/transpec/syntax.rb
165
+ - lib/transpec/syntax/double.rb
166
+ - lib/transpec/syntax/matcher.rb
167
+ - lib/transpec/syntax/method_stub.rb
168
+ - lib/transpec/syntax/send_node_syntax.rb
169
+ - lib/transpec/syntax/should.rb
170
+ - lib/transpec/syntax/should_receive.rb
171
+ - lib/transpec/util.rb
172
+ - lib/transpec/version.rb
173
+ - spec/.rubocop.yml
174
+ - spec/spec_helper.rb
175
+ - spec/spec_spec.rb
176
+ - spec/support/file_helper.rb
177
+ - spec/support/shared_context.rb
178
+ - spec/transpec/ast/scanner_spec.rb
179
+ - spec/transpec/ast/scope_stack_spec.rb
180
+ - spec/transpec/cli_spec.rb
181
+ - spec/transpec/configuration_spec.rb
182
+ - spec/transpec/git_spec.rb
183
+ - spec/transpec/rewriter_spec.rb
184
+ - spec/transpec/syntax/double_spec.rb
185
+ - spec/transpec/syntax/matcher_spec.rb
186
+ - spec/transpec/syntax/method_stub_spec.rb
187
+ - spec/transpec/syntax/should_receive_spec.rb
188
+ - spec/transpec/syntax/should_spec.rb
189
+ - spec/transpec/util_spec.rb
190
+ - transpec.gemspec
191
+ homepage: https://github.com/yujinakayama/transpec
192
+ licenses:
193
+ - MIT
194
+ metadata: {}
195
+ post_install_message:
196
+ rdoc_options: []
197
+ require_paths:
198
+ - lib
199
+ required_ruby_version: !ruby/object:Gem::Requirement
200
+ requirements:
201
+ - - '>='
202
+ - !ruby/object:Gem::Version
203
+ version: '0'
204
+ required_rubygems_version: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - '>='
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
209
+ requirements: []
210
+ rubyforge_project:
211
+ rubygems_version: 2.0.3
212
+ signing_key:
213
+ specification_version: 4
214
+ summary: Transpec converts your specs into latest RSpec syntax
215
+ test_files:
216
+ - spec/.rubocop.yml
217
+ - spec/spec_helper.rb
218
+ - spec/spec_spec.rb
219
+ - spec/support/file_helper.rb
220
+ - spec/support/shared_context.rb
221
+ - spec/transpec/ast/scanner_spec.rb
222
+ - spec/transpec/ast/scope_stack_spec.rb
223
+ - spec/transpec/cli_spec.rb
224
+ - spec/transpec/configuration_spec.rb
225
+ - spec/transpec/git_spec.rb
226
+ - spec/transpec/rewriter_spec.rb
227
+ - spec/transpec/syntax/double_spec.rb
228
+ - spec/transpec/syntax/matcher_spec.rb
229
+ - spec/transpec/syntax/method_stub_spec.rb
230
+ - spec/transpec/syntax/should_receive_spec.rb
231
+ - spec/transpec/syntax/should_spec.rb
232
+ - spec/transpec/util_spec.rb
233
+ has_rdoc: