transpec 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1eedcc59f7b98fb3c4c65cba1a0be3165d9a7624
4
- data.tar.gz: 36621b66f200b3402caa0f31166d85e52f0e4c6c
3
+ metadata.gz: ce0f0f3624392da60bc26a32d10f32a93ed866af
4
+ data.tar.gz: c0492a785742c25c2f718c888253658b6fbe872d
5
5
  SHA512:
6
- metadata.gz: ec7769b9ee175b13949e59e2f1b8c05422212bdf59ec5a4d0a6f9cf9107fa6a352474a2f3b60e895e476b054a90474e86c4cd33704983f360d3e6fdcb7aa826c
7
- data.tar.gz: 894ca15f361e3393101470d8ea9ac70f4ebf81c46132396e02df028f835e79f91389aea4decab50fa429139ca90c2d4ec558720c1cf5ff67cb8fdcc1a75cdb24
6
+ metadata.gz: 069b02b6bfd111b9ac243fd0559c6281417ca8be7e0e40d9bbe10cbf46f1a63fc6819d31f0d439acaad3c2f60c0a5dc00eb3d0b59374a9e23d76f4b495829a40
7
+ data.tar.gz: 64212f1a93153c532e11dd6dc0d397a5f295c4064551663b8c43f2c70cac9f880bcf48b6893ef745a88fb3ec5378d7401384b23f91803708613f001b73519f2d
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Master
4
4
 
5
+ ## v0.0.8
6
+
7
+ * Support conversion from `not_to raise_error(SpecificErrorClass)` to `not_to raise_error`
8
+
5
9
  ## v0.0.7
6
10
 
7
11
  * Avoid confusing `Typhoeus.stub` with RSpec's `stub` ([#4](https://github.com/yujinakayama/transpec/issues/4))
@@ -7,6 +7,7 @@ require 'transpec/syntax/be_close'
7
7
  require 'transpec/syntax/double'
8
8
  require 'transpec/syntax/matcher'
9
9
  require 'transpec/syntax/method_stub'
10
+ require 'transpec/syntax/raise_error'
10
11
  require 'transpec/syntax/rspec_configure'
11
12
  require 'transpec/syntax/should'
12
13
  require 'transpec/syntax/should_receive'
@@ -127,6 +128,12 @@ module Transpec
127
128
  be_close.convert_to_be_within! if @configuration.replace_deprecated_method?
128
129
  end
129
130
 
131
+ def process_raise_error(raise_error)
132
+ if @configuration.replace_deprecated_method?
133
+ raise_error.remove_error_specification_with_negative_expectation!
134
+ end
135
+ end
136
+
130
137
  def process_rspec_configure(rspec_configure)
131
138
  if need_to_modify_expectation_syntax_configuration?(rspec_configure)
132
139
  rspec_configure.modify_expectation_syntaxes!(:expect)
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+
3
+ require 'transpec/syntax'
4
+ require 'transpec/syntax/send_node_syntax'
5
+
6
+ module Transpec
7
+ class Syntax
8
+ class RaiseError < Syntax
9
+ include SendNodeSyntax
10
+
11
+ def remove_error_specification_with_negative_expectation!
12
+ return if positive?
13
+
14
+ _receiver_node, _method_name, *arg_nodes = *node
15
+ return if arg_nodes.empty?
16
+
17
+ remove(parentheses_range)
18
+ end
19
+
20
+ def positive?
21
+ expectation_method_name = parent_node.children[1]
22
+ [:should, :to].include?(expectation_method_name)
23
+ end
24
+
25
+ private
26
+
27
+ def self.target_receiver_node?(node)
28
+ node.nil?
29
+ end
30
+
31
+ def self.target_method_names
32
+ [:raise_error]
33
+ end
34
+ end
35
+ end
36
+ end
@@ -32,6 +32,10 @@ module Transpec
32
32
  def arg_range
33
33
  arg_node.loc.expression
34
34
  end
35
+
36
+ def parentheses_range
37
+ selector_range.end.join(expression_range.end)
38
+ end
35
39
  end
36
40
  end
37
41
  end
@@ -5,7 +5,7 @@ module Transpec
5
5
  module Version
6
6
  MAJOR = 0
7
7
  MINOR = 0
8
- PATCH = 7
8
+ PATCH = 8
9
9
 
10
10
  def self.to_s
11
11
  [MAJOR, MINOR, PATCH].join('.')
@@ -419,6 +419,28 @@ module Transpec
419
419
  end
420
420
  end
421
421
 
422
+ describe '#process_raise_error' do
423
+ let(:raise_error_object) { double('raise_error_object').as_null_object }
424
+
425
+ context 'when Configuration#replace_deprecated_method? is true' do
426
+ before { configuration.replace_deprecated_method = true }
427
+
428
+ it 'invokes RaiseError#remove_error_specification_with_negative_expectation!' do
429
+ raise_error_object.should_receive(:remove_error_specification_with_negative_expectation!)
430
+ rewriter.process_raise_error(raise_error_object)
431
+ end
432
+ end
433
+
434
+ context 'when Configuration#replace_deprecated_method? is true' do
435
+ before { configuration.replace_deprecated_method = false }
436
+
437
+ it 'does not invoke BeClose#convert_to_be_within!' do
438
+ raise_error_object.should_not_receive(:remove_error_specification_with_negative_expectation!)
439
+ rewriter.process_raise_error(raise_error_object)
440
+ end
441
+ end
442
+ end
443
+
422
444
  describe '#process_rspec_configure' do
423
445
  let(:rspec_configure) { double('rspec_configure').as_null_object }
424
446
 
@@ -0,0 +1,193 @@
1
+ # coding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'transpec/syntax/raise_error'
5
+
6
+ module Transpec
7
+ class Syntax
8
+ describe RaiseError do
9
+ include_context 'parsed objects'
10
+
11
+ subject(:raise_error_object) do
12
+ AST::Scanner.scan(ast) do |node, ancestor_nodes|
13
+ next unless RaiseError.target_node?(node)
14
+ return RaiseError.new(
15
+ node,
16
+ ancestor_nodes,
17
+ in_example_group_context?,
18
+ source_rewriter
19
+ )
20
+ end
21
+ fail 'No raise_error node is found!'
22
+ end
23
+
24
+ let(:in_example_group_context?) { true }
25
+
26
+ describe '#remove_error_specification_with_negative_expectation!' do
27
+ before do
28
+ raise_error_object.remove_error_specification_with_negative_expectation!
29
+ end
30
+
31
+ context 'when it is `lambda { ... }.should raise_error(SomeErrorClass)` form' do
32
+ let(:source) do
33
+ <<-END
34
+ it 'raises SomeErrorClass' do
35
+ lambda { do_something }.should raise_error(SomeErrorClass)
36
+ end
37
+ END
38
+ end
39
+
40
+ it 'does nothing' do
41
+ rewritten_source.should == source
42
+ end
43
+ end
44
+
45
+ context 'when it is `expect { ... }.to raise_error(SomeErrorClass)` form' do
46
+ let(:source) do
47
+ <<-END
48
+ it 'raises SomeErrorClass' do
49
+ expect { do_something }.to raise_error(SomeErrorClass)
50
+ end
51
+ END
52
+ end
53
+
54
+ it 'does nothing' do
55
+ rewritten_source.should == source
56
+ end
57
+ end
58
+
59
+ context 'when it is `lambda { ... }.should_not raise_error(SomeErrorClass)` form' do
60
+ let(:source) do
61
+ <<-END
62
+ it 'does not raise error' do
63
+ lambda { do_something }.should_not raise_error(SomeErrorClass)
64
+ end
65
+ END
66
+ end
67
+
68
+ let(:expected_source) do
69
+ <<-END
70
+ it 'does not raise error' do
71
+ lambda { do_something }.should_not raise_error
72
+ end
73
+ END
74
+ end
75
+
76
+ it 'converts into `lambda { ... }.should_not raise_error` form' do
77
+ rewritten_source.should == expected_source
78
+ end
79
+ end
80
+
81
+ context 'when it is `expect { ... }.not_to raise_error(SomeErrorClass)` form' do
82
+ let(:source) do
83
+ <<-END
84
+ it 'does not raise error' do
85
+ expect { do_something }.not_to raise_error(SomeErrorClass)
86
+ end
87
+ END
88
+ end
89
+
90
+ let(:expected_source) do
91
+ <<-END
92
+ it 'does not raise error' do
93
+ expect { do_something }.not_to raise_error
94
+ end
95
+ END
96
+ end
97
+
98
+ it 'converts into `expect { ... }.not_to raise_error` form' do
99
+ rewritten_source.should == expected_source
100
+ end
101
+ end
102
+
103
+ context 'when it is `expect { ... }.to_not raise_error(SomeErrorClass)` form' do
104
+ let(:source) do
105
+ <<-END
106
+ it 'does not raise error' do
107
+ expect { do_something }.to_not raise_error(SomeErrorClass)
108
+ end
109
+ END
110
+ end
111
+
112
+ let(:expected_source) do
113
+ <<-END
114
+ it 'does not raise error' do
115
+ expect { do_something }.to_not raise_error
116
+ end
117
+ END
118
+ end
119
+
120
+ it 'converts into `expect { ... }.to_not raise_error` form' do
121
+ rewritten_source.should == expected_source
122
+ end
123
+ end
124
+
125
+ context 'when it is `expect { ... }.not_to raise_error SomeErrorClass` form' do
126
+ let(:source) do
127
+ <<-END
128
+ it 'does not raise error' do
129
+ expect { do_something }.not_to raise_error SomeErrorClass
130
+ end
131
+ END
132
+ end
133
+
134
+ let(:expected_source) do
135
+ <<-END
136
+ it 'does not raise error' do
137
+ expect { do_something }.not_to raise_error
138
+ end
139
+ END
140
+ end
141
+
142
+ it 'converts into `expect { ... }.not_to raise_error` form' do
143
+ rewritten_source.should == expected_source
144
+ end
145
+ end
146
+
147
+ context "when it is `expect { ... }.not_to raise_error(SomeErrorClass, 'message')` form" do
148
+ let(:source) do
149
+ <<-END
150
+ it 'does not raise error' do
151
+ expect { do_something }.not_to raise_error(SomeErrorClass, 'message')
152
+ end
153
+ END
154
+ end
155
+
156
+ let(:expected_source) do
157
+ <<-END
158
+ it 'does not raise error' do
159
+ expect { do_something }.not_to raise_error
160
+ end
161
+ END
162
+ end
163
+
164
+ it 'converts into `expect { ... }.not_to raise_error` form' do
165
+ rewritten_source.should == expected_source
166
+ end
167
+ end
168
+
169
+ context "when it is `expect { ... }.not_to raise_error(nil, 'message')` form" do
170
+ let(:source) do
171
+ <<-END
172
+ it 'does not raise error' do
173
+ expect { do_something }.not_to raise_error(nil, 'message')
174
+ end
175
+ END
176
+ end
177
+
178
+ let(:expected_source) do
179
+ <<-END
180
+ it 'does not raise error' do
181
+ expect { do_something }.not_to raise_error
182
+ end
183
+ END
184
+ end
185
+
186
+ it 'converts into `expect { ... }.not_to raise_error` form' do
187
+ rewritten_source.should == expected_source
188
+ end
189
+ end
190
+ end
191
+ end
192
+ end
193
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: transpec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuji Nakayama
@@ -14,140 +14,140 @@ dependencies:
14
14
  name: parser
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: 2.0.0.pre1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: 2.0.0.pre1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
33
  version: '2.14'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: '2.14'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
47
  version: '1.3'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ~>
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.3'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ~>
60
60
  - !ruby/object:Gem::Version
61
61
  version: '10.1'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ~>
67
67
  - !ruby/object:Gem::Version
68
68
  version: '10.1'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: simplecov
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ~>
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0.7'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ~>
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0.7'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rubocop
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - "~>"
87
+ - - ~>
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0.10'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - "~>"
94
+ - - ~>
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0.10'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: guard-rspec
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - "~>"
101
+ - - ~>
102
102
  - !ruby/object:Gem::Version
103
103
  version: '3.0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - "~>"
108
+ - - ~>
109
109
  - !ruby/object:Gem::Version
110
110
  version: '3.0'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: guard-rubocop
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - "~>"
115
+ - - ~>
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0.2'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - "~>"
122
+ - - ~>
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0.2'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: guard-shell
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - "~>"
129
+ - - ~>
130
130
  - !ruby/object:Gem::Version
131
131
  version: '0.5'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - "~>"
136
+ - - ~>
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0.5'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: ruby_gntp
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - "~>"
143
+ - - ~>
144
144
  - !ruby/object:Gem::Version
145
145
  version: '0.3'
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - "~>"
150
+ - - ~>
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0.3'
153
153
  description: Transpec automatically converts your specs into latest RSpec syntax with
@@ -159,9 +159,9 @@ executables:
159
159
  extensions: []
160
160
  extra_rdoc_files: []
161
161
  files:
162
- - ".gitignore"
163
- - ".rubocop.yml"
164
- - ".travis.yml"
162
+ - .gitignore
163
+ - .rubocop.yml
164
+ - .travis.yml
165
165
  - CHANGELOG.md
166
166
  - Gemfile
167
167
  - Guardfile
@@ -185,6 +185,7 @@ files:
185
185
  - lib/transpec/syntax/expectizable.rb
186
186
  - lib/transpec/syntax/matcher.rb
187
187
  - lib/transpec/syntax/method_stub.rb
188
+ - lib/transpec/syntax/raise_error.rb
188
189
  - lib/transpec/syntax/rspec_configure.rb
189
190
  - lib/transpec/syntax/send_node_syntax.rb
190
191
  - lib/transpec/syntax/should.rb
@@ -207,6 +208,7 @@ files:
207
208
  - spec/transpec/syntax/double_spec.rb
208
209
  - spec/transpec/syntax/matcher_spec.rb
209
210
  - spec/transpec/syntax/method_stub_spec.rb
211
+ - spec/transpec/syntax/raise_error_spec.rb
210
212
  - spec/transpec/syntax/rspec_configure_spec.rb
211
213
  - spec/transpec/syntax/should_receive_spec.rb
212
214
  - spec/transpec/syntax/should_spec.rb
@@ -222,12 +224,12 @@ require_paths:
222
224
  - lib
223
225
  required_ruby_version: !ruby/object:Gem::Requirement
224
226
  requirements:
225
- - - ">="
227
+ - - '>='
226
228
  - !ruby/object:Gem::Version
227
229
  version: '0'
228
230
  required_rubygems_version: !ruby/object:Gem::Requirement
229
231
  requirements:
230
- - - ">="
232
+ - - '>='
231
233
  - !ruby/object:Gem::Version
232
234
  version: '0'
233
235
  requirements: []
@@ -253,6 +255,7 @@ test_files:
253
255
  - spec/transpec/syntax/double_spec.rb
254
256
  - spec/transpec/syntax/matcher_spec.rb
255
257
  - spec/transpec/syntax/method_stub_spec.rb
258
+ - spec/transpec/syntax/raise_error_spec.rb
256
259
  - spec/transpec/syntax/rspec_configure_spec.rb
257
260
  - spec/transpec/syntax/should_receive_spec.rb
258
261
  - spec/transpec/syntax/should_spec.rb