transpec 0.1.1 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 84654b586ffec308305611b94645b31b0273c5fa
4
- data.tar.gz: 550b871976225f5b49b79ce3e098ac69bade0071
3
+ metadata.gz: 9a3e260298c65e466e7a7460347e7f30c0a21756
4
+ data.tar.gz: 2c1638289bf22ca3478ffe62c22419451ffe4dcd
5
5
  SHA512:
6
- metadata.gz: 2a363066e3a0ad769016ba1ce600530827fe5207c8df6113bb7ab34d2fc726d014951acb6f40038617d3f14f3e6ce0b03441cb6b2aef8d40a7c227df881ad66e
7
- data.tar.gz: efe834fdda78a29a07e461780b860107db23121be76beb2ece5529892d21b7945570e6d86888c541daaaf47300b57219cb1a383d0ad36145471c321eb779459b
6
+ metadata.gz: cf8a5e86460c68c9a5de1148dadab3af4edc88d775992e49069de3f17f689ececc22494c2e9c0ae52f5d4c73813c3d5beb3b7324faed94cd9163f0406d513e63
7
+ data.tar.gz: a0b827f6aa1aa0101a459440f2325f362509e6a8c5de0e88c741c93482ecb005d539ac2e61ee0312023ac6a6836589792d29de5f95b4bae616be917fca7b555a
@@ -2,6 +2,13 @@
2
2
 
3
3
  ## Master
4
4
 
5
+ ## v0.1.2
6
+
7
+ * Continue processing files even if a file has invalid syntax
8
+ * Fix a crash on source `variable::Const`
9
+ * Fix generating invalid code with here document followed by method
10
+ * Fix generating invalid code when converting `obj.should() == 1`
11
+
5
12
  ## v0.1.1
6
13
 
7
14
  * Fix a bug where `be > 1` was converted into `be be > 1`
@@ -65,6 +65,8 @@ module Transpec
65
65
  rewriter.errors.each do |error|
66
66
  warn_not_in_example_group_context_error(error)
67
67
  end
68
+ rescue Parser::SyntaxError => error
69
+ warn_syntax_error(error)
68
70
  end
69
71
 
70
72
  # rubocop:disable MethodLength
@@ -177,6 +179,10 @@ module Transpec
177
179
  fail 'The current Git repository is not clean. Aborting.'
178
180
  end
179
181
 
182
+ def warn_syntax_error(error)
183
+ warn "Syntax error at #{error.diagnostic.location}. Skipping the file.".color(:red)
184
+ end
185
+
180
186
  def warn_not_in_example_group_context_error(error)
181
187
  message = error.message.color(:yellow) + $RS
182
188
  message << highlighted_source(error)
@@ -38,7 +38,7 @@ module Transpec
38
38
  end
39
39
 
40
40
  def parenthesize!(always = true)
41
- return if here_document?(arg_node)
41
+ return if argument_is_here_document?
42
42
 
43
43
  case left_parenthesis_range.source
44
44
  when ' '
@@ -59,6 +59,11 @@ module Transpec
59
59
 
60
60
  private
61
61
 
62
+ def argument_is_here_document?
63
+ here_document?(arg_node) ||
64
+ arg_node.each_descendent_node.any? { |n| here_document?(n) }
65
+ end
66
+
62
67
  def prefixed_with_be?
63
68
  receiver_node == s(:send, nil, :be)
64
69
  end
@@ -25,7 +25,7 @@ module Transpec
25
25
  wrap_subject_in_expect!
26
26
  end
27
27
 
28
- replace(selector_range, positive? ? 'to' : negative_form)
28
+ replace(should_range, positive? ? 'to' : negative_form)
29
29
 
30
30
  matcher.correct_operator!(parenthesize_matcher_arg)
31
31
  end
@@ -53,6 +53,14 @@ module Transpec
53
53
  range_of_subject_method_taking_block = send_node.loc.expression
54
54
  replace(range_of_subject_method_taking_block, 'expect')
55
55
  end
56
+
57
+ def should_range
58
+ if arg_node
59
+ selector_range
60
+ else
61
+ selector_range.join(expression_range.end)
62
+ end
63
+ end
56
64
  end
57
65
  end
58
66
  end
@@ -29,6 +29,7 @@ module Transpec
29
29
  namespace_node, name = *const_node
30
30
  const_names << name
31
31
  break unless namespace_node
32
+ break unless namespace_node.is_a?(Parser::AST::Node)
32
33
  break if namespace_node.type == :cbase
33
34
  const_node = namespace_node
34
35
  end
@@ -38,6 +39,7 @@ module Transpec
38
39
 
39
40
  def here_document?(node)
40
41
  return false unless [:str, :dstr].include?(node.type)
42
+ return false unless node.loc.begin
41
43
  node.loc.begin.source.start_with?('<<')
42
44
  end
43
45
 
@@ -5,7 +5,7 @@ module Transpec
5
5
  module Version
6
6
  MAJOR = 0
7
7
  MINOR = 1
8
- PATCH = 1
8
+ PATCH = 2
9
9
 
10
10
  def self.to_s
11
11
  [MAJOR, MINOR, PATCH].join('.')
@@ -5,6 +5,8 @@ require 'transpec/cli'
5
5
 
6
6
  module Transpec
7
7
  describe CLI do
8
+ include FileHelper
9
+
8
10
  subject(:cli) { CLI.new }
9
11
 
10
12
  describe '.run' do
@@ -28,7 +30,6 @@ module Transpec
28
30
  cli.stub(:puts)
29
31
  cli.stub(:warn)
30
32
  cli.stub(:target_files).and_return(args)
31
- Rewriter.stub(:new).and_return(rewriter)
32
33
  end
33
34
 
34
35
  subject { cli.run(args) }
@@ -46,7 +47,15 @@ module Transpec
46
47
  end
47
48
  end
48
49
 
50
+ shared_context 'stubbed rewriter' do
51
+ before do
52
+ Rewriter.stub(:new).and_return(rewriter)
53
+ end
54
+ end
55
+
49
56
  context 'when git is available' do
57
+ include_context 'stubbed rewriter'
58
+
50
59
  before { Git.stub(:command_available?).and_return(true) }
51
60
 
52
61
  context 'and inside of a repository' do
@@ -91,11 +100,41 @@ module Transpec
91
100
  end
92
101
 
93
102
  context 'when git is not available' do
103
+ include_context 'stubbed rewriter'
94
104
  before { Git.stub(:command_available?).and_return(false) }
95
105
  include_examples 'rewrites files'
96
106
  end
97
107
 
98
- context 'when an exception is raised while running' do
108
+ context 'when a syntax error is raised while processing files' do
109
+ include_context 'isolated environment'
110
+
111
+ let(:args) { [invalid_syntax_file_path, valid_syntax_file_path] }
112
+ let(:invalid_syntax_file_path) { 'invalid_example.rb' }
113
+ let(:valid_syntax_file_path) { 'valid_example.rb' }
114
+
115
+ before do
116
+ create_file(invalid_syntax_file_path, 'This is invalid syntax <')
117
+ create_file(valid_syntax_file_path, 'this_is_valid_syntax')
118
+ end
119
+
120
+ it 'warns to the user' do
121
+ cli.should_receive(:warn) do |message|
122
+ message.should include('Syntax error')
123
+ end
124
+
125
+ cli.run(args)
126
+ end
127
+
128
+ it 'continues processing files' do
129
+ cli.should_receive(:puts).with("Processing #{invalid_syntax_file_path}")
130
+ cli.should_receive(:puts).with("Processing #{valid_syntax_file_path}")
131
+ cli.run(args)
132
+ end
133
+ end
134
+
135
+ context 'when any other error is raised while running' do
136
+ include_context 'stubbed rewriter'
137
+
99
138
  before do
100
139
  cli.stub(:parse_options).and_raise(ArgumentError, 'No such file or directory - non-existent-file')
101
140
  end
@@ -112,6 +151,7 @@ module Transpec
112
151
 
113
152
  context 'when no target paths are specified' do
114
153
  include_context 'isolated environment'
154
+ include_context 'stubbed rewriter'
115
155
 
116
156
  let(:args) { [] }
117
157
 
@@ -138,7 +178,7 @@ module Transpec
138
178
  let(:file_path) { 'example.rb' }
139
179
 
140
180
  before do
141
- FileHelper.create_file(file_path, source)
181
+ create_file(file_path, source)
142
182
  cli.stub(:puts)
143
183
  end
144
184
 
@@ -290,7 +330,7 @@ module Transpec
290
330
 
291
331
  before do
292
332
  ['file', 'file.rb', 'dir/file', 'dir/file.rb'].each do |path|
293
- FileHelper.create_file(path, '')
333
+ create_file(path, '')
294
334
  end
295
335
  end
296
336
 
@@ -428,6 +428,34 @@ module Transpec
428
428
  end
429
429
  end
430
430
 
431
+ context 'when its argument is a here document with chained method' do
432
+ let(:source) do
433
+ <<-END
434
+ it 'returns the document' do
435
+ subject.should eq <<-HEREDOC.gsub('foo', 'bar')
436
+ foo
437
+ HEREDOC
438
+ end
439
+ END
440
+ end
441
+
442
+ # (block
443
+ # (send nil :it
444
+ # (str "returns the document"))
445
+ # (args)
446
+ # (send
447
+ # (send nil :subject) :should
448
+ # (send nil :eq
449
+ # (send
450
+ # (str " foo\n") :gsub
451
+ # (str "foo")
452
+ # (str "bar")))))
453
+
454
+ it 'does nothing' do
455
+ rewritten_source.should == source
456
+ end
457
+ end
458
+
431
459
  context 'when its argument is a here document with interpolation' do
432
460
  let(:source) do
433
461
  <<-'END'
@@ -180,6 +180,29 @@ module Transpec
180
180
  end
181
181
  end
182
182
 
183
+ context 'when it is `subject.should() == 1` form' do
184
+ let(:source) do
185
+ <<-END
186
+ it 'is 1' do
187
+ subject.should() == 1
188
+ end
189
+ END
190
+ end
191
+
192
+ let(:expected_source) do
193
+ <<-END
194
+ it 'is 1' do
195
+ expect(subject).to eq(1)
196
+ end
197
+ END
198
+ end
199
+
200
+ it 'converts into `expect(subject).to eq(1)` form' do
201
+ should_object.expectize!
202
+ rewritten_source.should == expected_source
203
+ end
204
+ end
205
+
183
206
  [
184
207
  'lambda', 'Kernel.lambda', '::Kernel.lambda',
185
208
  'proc', 'Kernel.proc', '::Kernel.proc',
@@ -34,7 +34,8 @@ module Transpec
34
34
  ['Foo::Bar', 'Foo::Bar'],
35
35
  ['Foo::Bar::Baz', 'Foo::Bar::Baz'],
36
36
  ['::Foo', 'Foo'],
37
- ['::Foo::Bar', 'Foo::Bar']
37
+ ['::Foo::Bar', 'Foo::Bar'],
38
+ ['variable::Foo', 'variable::Foo']
38
39
  ].each do |source, expected_return_value|
39
40
  context "when the source is #{source.inspect}" do
40
41
  let(:source) { source }
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.version = Transpec::Version.to_s
10
10
  spec.authors = ['Yuji Nakayama']
11
11
  spec.email = ['nkymyj@gmail.com']
12
- spec.summary = 'Transpec converts your specs into latest RSpec syntax'
12
+ spec.summary = 'RSpec syntax converter'
13
13
  spec.description = 'Transpec automatically converts your specs into latest RSpec syntax with static analysis.'
14
14
  spec.homepage = 'https://github.com/yujinakayama/transpec'
15
15
  spec.license = 'MIT'
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: 0.1.1
4
+ version: 0.1.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: 2013-09-28 00:00:00.000000000 Z
11
+ date: 2013-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser
@@ -253,7 +253,7 @@ rubyforge_project:
253
253
  rubygems_version: 2.0.3
254
254
  signing_key:
255
255
  specification_version: 4
256
- summary: Transpec converts your specs into latest RSpec syntax
256
+ summary: RSpec syntax converter
257
257
  test_files:
258
258
  - spec/.rubocop.yml
259
259
  - spec/spec_helper.rb