transpec 1.6.1 → 1.7.0

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 (63) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +0 -4
  3. data/.travis.yml +2 -1
  4. data/CHANGELOG.md +4 -0
  5. data/Guardfile +1 -1
  6. data/README.md +168 -18
  7. data/README.md.erb +154 -18
  8. data/lib/transpec/ast/node.rb +47 -0
  9. data/lib/transpec/cli.rb +1 -1
  10. data/lib/transpec/commit_message.rb +11 -1
  11. data/lib/transpec/configuration.rb +11 -10
  12. data/lib/transpec/converter.rb +36 -14
  13. data/lib/transpec/dynamic_analyzer/rewriter.rb +2 -2
  14. data/lib/transpec/option_parser.rb +11 -0
  15. data/lib/transpec/report.rb +16 -9
  16. data/lib/transpec/rspec_version.rb +9 -0
  17. data/lib/transpec/static_context_inspector.rb +4 -4
  18. data/lib/transpec/syntax/allow.rb +20 -0
  19. data/lib/transpec/syntax/example.rb +1 -1
  20. data/lib/transpec/syntax/expect.rb +5 -20
  21. data/lib/transpec/syntax/its.rb +2 -8
  22. data/lib/transpec/syntax/method_stub.rb +72 -37
  23. data/lib/transpec/syntax/mixin/allow_no_message.rb +8 -17
  24. data/lib/transpec/syntax/mixin/any_instance_block.rb +34 -0
  25. data/lib/transpec/syntax/mixin/expect_base.rb +70 -0
  26. data/lib/transpec/syntax/mixin/expectizable.rb +3 -0
  27. data/lib/transpec/syntax/mixin/have_matcher_owner.rb +5 -2
  28. data/lib/transpec/syntax/mixin/monkey_patch.rb +6 -0
  29. data/lib/transpec/syntax/mixin/{any_instance.rb → monkey_patch_any_instance.rb} +12 -8
  30. data/lib/transpec/syntax/mixin/send.rb +16 -3
  31. data/lib/transpec/syntax/mixin/should_base.rb +8 -2
  32. data/lib/transpec/syntax/oneliner_should.rb +2 -4
  33. data/lib/transpec/syntax/operator_matcher.rb +2 -2
  34. data/lib/transpec/syntax/raise_error.rb +2 -2
  35. data/lib/transpec/syntax/receive.rb +49 -0
  36. data/lib/transpec/syntax/rspec_configure.rb +8 -96
  37. data/lib/transpec/syntax/rspec_configure/expectations.rb +15 -0
  38. data/lib/transpec/syntax/rspec_configure/framework.rb +166 -0
  39. data/lib/transpec/syntax/rspec_configure/mocks.rb +19 -0
  40. data/lib/transpec/syntax/should.rb +1 -4
  41. data/lib/transpec/syntax/should_receive.rb +89 -43
  42. data/lib/transpec/util.rb +21 -7
  43. data/lib/transpec/version.rb +2 -2
  44. data/spec/transpec/ast/node_spec.rb +52 -0
  45. data/spec/transpec/commit_message_spec.rb +2 -2
  46. data/spec/transpec/configuration_spec.rb +14 -13
  47. data/spec/transpec/converter_spec.rb +151 -20
  48. data/spec/transpec/option_parser_spec.rb +10 -0
  49. data/spec/transpec/rspec_version_spec.rb +20 -6
  50. data/spec/transpec/static_context_inspector_spec.rb +2 -2
  51. data/spec/transpec/syntax/allow_spec.rb +140 -0
  52. data/spec/transpec/syntax/double_spec.rb +1 -1
  53. data/spec/transpec/syntax/expect_spec.rb +103 -10
  54. data/spec/transpec/syntax/have_spec.rb +4 -4
  55. data/spec/transpec/syntax/method_stub_spec.rb +41 -1
  56. data/spec/transpec/syntax/operator_matcher_spec.rb +6 -6
  57. data/spec/transpec/syntax/receive_spec.rb +270 -0
  58. data/spec/transpec/syntax/rspec_configure_spec.rb +241 -30
  59. data/spec/transpec/syntax/should_receive_spec.rb +93 -2
  60. data/spec/transpec/syntax/should_spec.rb +2 -2
  61. data/spec/transpec/util_spec.rb +2 -6
  62. data/transpec.gemspec +5 -3
  63. metadata +37 -14
@@ -187,13 +187,13 @@ module Transpec
187
187
 
188
188
  context 'and "to_not" is passed as negative form' do
189
189
  let(:expected_source) do
190
- <<-END
190
+ <<-END
191
191
  describe 'example' do
192
192
  it 'does not receive #foo' do
193
193
  expect(subject).to_not receive(:foo)
194
194
  end
195
195
  end
196
- END
196
+ END
197
197
  end
198
198
 
199
199
  it 'converts into `expect(subject).to_not receive(:method)` form' do
@@ -936,6 +936,97 @@ module Transpec
936
936
  end
937
937
  end
938
938
  end
939
+
940
+ describe '#add_receiver_arg_to_any_instance_implementation_block!' do
941
+ before do
942
+ should_receive_object.add_receiver_arg_to_any_instance_implementation_block!
943
+ end
944
+
945
+ context 'when it is `Klass.any_instance.should_receive(:method) do |arg| .. end` form' do
946
+ let(:source) do
947
+ <<-END
948
+ describe 'example' do
949
+ it 'receives #foo' do
950
+ Klass.any_instance.should_receive(:foo) do |arg|
951
+ end
952
+ end
953
+ end
954
+ END
955
+ end
956
+
957
+ let(:expected_source) do
958
+ <<-END
959
+ describe 'example' do
960
+ it 'receives #foo' do
961
+ Klass.any_instance.should_receive(:foo) do |instance, arg|
962
+ end
963
+ end
964
+ end
965
+ END
966
+ end
967
+
968
+ it 'converts into `Klass.any_instance.should_receive(:method) do |instance, arg| .. end` form' do
969
+ rewritten_source.should == expected_source
970
+ end
971
+
972
+ it 'adds record `Klass.any_instance.should_receive(:message) { |arg| }` ' +
973
+ '-> `Klass.any_instance.should_receive(:message) { |instance, arg| }`' do
974
+ record.original_syntax.should == 'Klass.any_instance.should_receive(:message) { |arg| }'
975
+ record.converted_syntax.should == 'Klass.any_instance.should_receive(:message) { |instance, arg| }'
976
+ end
977
+ end
978
+
979
+ context 'when it is `Klass.any_instance.should_receive(:method) do .. end` form' do
980
+ let(:source) do
981
+ <<-END
982
+ describe 'example' do
983
+ it 'receives #foo' do
984
+ Klass.any_instance.should_receive(:foo) do
985
+ end
986
+ end
987
+ end
988
+ END
989
+ end
990
+
991
+ it 'does nothing' do
992
+ rewritten_source.should == source
993
+ end
994
+ end
995
+
996
+ context 'when it is `Klass.any_instance.should_receive(:method) do |instance| .. end` form' do
997
+ let(:source) do
998
+ <<-END
999
+ describe 'example' do
1000
+ it 'receives #foo' do
1001
+ Klass.any_instance.should_receive(:foo) do |instance|
1002
+ end
1003
+ end
1004
+ end
1005
+ END
1006
+ end
1007
+
1008
+ it 'does nothing' do
1009
+ rewritten_source.should == source
1010
+ end
1011
+ end
1012
+
1013
+ context 'when it is `subject.should_receive(:method) do |arg| .. end` form' do
1014
+ let(:source) do
1015
+ <<-END
1016
+ describe 'example' do
1017
+ it 'receives #foo' do
1018
+ subject.should_receive(:foo) do |arg|
1019
+ end
1020
+ end
1021
+ end
1022
+ END
1023
+ end
1024
+
1025
+ it 'does nothing' do
1026
+ rewritten_source.should == source
1027
+ end
1028
+ end
1029
+ end
939
1030
  end
940
1031
  end
941
1032
  end
@@ -361,13 +361,13 @@ module Transpec
361
361
 
362
362
  context 'and "to_not" is passed as negative form' do
363
363
  let(:expected_source) do
364
- <<-END
364
+ <<-END
365
365
  describe 'example' do
366
366
  it 'is not 1' do
367
367
  expect(subject).to_not eq(1)
368
368
  end
369
369
  end
370
- END
370
+ END
371
371
  end
372
372
 
373
373
  it 'converts into `expect(subject).to_not` form' do
@@ -7,16 +7,12 @@ require 'ast'
7
7
  module Transpec
8
8
  describe Util do
9
9
  include_context 'parsed objects'
10
- include ::AST::Sexp
11
10
 
12
11
  describe '#const_name' do
13
12
  subject { Util.const_name(ast) }
14
13
 
15
14
  context 'when the passed node is not :const type' do
16
- let(:ast) do
17
- s(:lvasgn, :foo,
18
- s(:int, 1))
19
- end
15
+ let(:source) { 'foo = 1' }
20
16
 
21
17
  it 'returns nil' do
22
18
  should be_nil
@@ -52,7 +48,7 @@ module Transpec
52
48
  end
53
49
 
54
50
  describe '#expand_range_to_adjacent_whitespaces' do
55
- let(:node) { ast.each_node.find { |n| n.type == :block } }
51
+ let(:node) { ast.each_node.find(&:block_type?) }
56
52
  let(:range) { node.loc.begin }
57
53
  subject(:expanded_range) { Util.expand_range_to_adjacent_whitespaces(range) }
58
54
 
data/transpec.gemspec CHANGED
@@ -20,9 +20,11 @@ Gem::Specification.new do |spec|
20
20
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
21
  spec.require_paths = ['lib']
22
22
 
23
- spec.add_runtime_dependency 'parser', '~> 2.1'
23
+ spec.required_ruby_version = '>= 1.9.3'
24
+
25
+ spec.add_runtime_dependency 'parser', '>= 2.1.3', '< 3.0'
24
26
  spec.add_runtime_dependency 'bundler', '~> 1.3'
25
- spec.add_runtime_dependency 'rainbow', '~> 1.99'
27
+ spec.add_runtime_dependency 'rainbow', '~> 1.99.1'
26
28
  spec.add_runtime_dependency 'json', '~> 1.8'
27
29
  spec.add_runtime_dependency 'activesupport', '~> 4.0'
28
30
 
@@ -30,7 +32,7 @@ Gem::Specification.new do |spec|
30
32
  spec.add_development_dependency 'rspec', '~> 2.14'
31
33
  spec.add_development_dependency 'simplecov', '~> 0.7'
32
34
  spec.add_development_dependency 'rubocop', '~> 0.16'
33
- spec.add_development_dependency 'guard-rspec', '~> 4.0'
35
+ spec.add_development_dependency 'guard-rspec', '>= 4.2.3', '< 5.0'
34
36
  spec.add_development_dependency 'guard-rubocop', '~> 1.0'
35
37
  spec.add_development_dependency 'guard-shell', '~> 0.5'
36
38
  spec.add_development_dependency 'ruby_gntp', '~> 0.3'
metadata CHANGED
@@ -1,29 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: transpec
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.1
4
+ version: 1.7.0
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-12-27 00:00:00.000000000 Z
11
+ date: 2014-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 2.1.3
20
+ - - "<"
18
21
  - !ruby/object:Gem::Version
19
- version: '2.1'
22
+ version: '3.0'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
25
28
  - !ruby/object:Gem::Version
26
- version: '2.1'
29
+ version: 2.1.3
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '3.0'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: bundler
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -44,14 +50,14 @@ dependencies:
44
50
  requirements:
45
51
  - - "~>"
46
52
  - !ruby/object:Gem::Version
47
- version: '1.99'
53
+ version: 1.99.1
48
54
  type: :runtime
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
51
57
  requirements:
52
58
  - - "~>"
53
59
  - !ruby/object:Gem::Version
54
- version: '1.99'
60
+ version: 1.99.1
55
61
  - !ruby/object:Gem::Dependency
56
62
  name: json
57
63
  requirement: !ruby/object:Gem::Requirement
@@ -140,16 +146,22 @@ dependencies:
140
146
  name: guard-rspec
141
147
  requirement: !ruby/object:Gem::Requirement
142
148
  requirements:
143
- - - "~>"
149
+ - - ">="
144
150
  - !ruby/object:Gem::Version
145
- version: '4.0'
151
+ version: 4.2.3
152
+ - - "<"
153
+ - !ruby/object:Gem::Version
154
+ version: '5.0'
146
155
  type: :development
147
156
  prerelease: false
148
157
  version_requirements: !ruby/object:Gem::Requirement
149
158
  requirements:
150
- - - "~>"
159
+ - - ">="
151
160
  - !ruby/object:Gem::Version
152
- version: '4.0'
161
+ version: 4.2.3
162
+ - - "<"
163
+ - !ruby/object:Gem::Version
164
+ version: '5.0'
153
165
  - !ruby/object:Gem::Dependency
154
166
  name: guard-rubocop
155
167
  requirement: !ruby/object:Gem::Requirement
@@ -234,6 +246,7 @@ files:
234
246
  - lib/transpec/rspec_version.rb
235
247
  - lib/transpec/static_context_inspector.rb
236
248
  - lib/transpec/syntax.rb
249
+ - lib/transpec/syntax/allow.rb
237
250
  - lib/transpec/syntax/be_boolean.rb
238
251
  - lib/transpec/syntax/be_close.rb
239
252
  - lib/transpec/syntax/double.rb
@@ -244,16 +257,22 @@ files:
244
257
  - lib/transpec/syntax/matcher_definition.rb
245
258
  - lib/transpec/syntax/method_stub.rb
246
259
  - lib/transpec/syntax/mixin/allow_no_message.rb
247
- - lib/transpec/syntax/mixin/any_instance.rb
260
+ - lib/transpec/syntax/mixin/any_instance_block.rb
261
+ - lib/transpec/syntax/mixin/expect_base.rb
248
262
  - lib/transpec/syntax/mixin/expectizable.rb
249
263
  - lib/transpec/syntax/mixin/have_matcher_owner.rb
250
264
  - lib/transpec/syntax/mixin/monkey_patch.rb
265
+ - lib/transpec/syntax/mixin/monkey_patch_any_instance.rb
251
266
  - lib/transpec/syntax/mixin/send.rb
252
267
  - lib/transpec/syntax/mixin/should_base.rb
253
268
  - lib/transpec/syntax/oneliner_should.rb
254
269
  - lib/transpec/syntax/operator_matcher.rb
255
270
  - lib/transpec/syntax/raise_error.rb
271
+ - lib/transpec/syntax/receive.rb
256
272
  - lib/transpec/syntax/rspec_configure.rb
273
+ - lib/transpec/syntax/rspec_configure/expectations.rb
274
+ - lib/transpec/syntax/rspec_configure/framework.rb
275
+ - lib/transpec/syntax/rspec_configure/mocks.rb
257
276
  - lib/transpec/syntax/should.rb
258
277
  - lib/transpec/syntax/should_receive.rb
259
278
  - lib/transpec/util.rb
@@ -278,6 +297,7 @@ files:
278
297
  - spec/transpec/report_spec.rb
279
298
  - spec/transpec/rspec_version_spec.rb
280
299
  - spec/transpec/static_context_inspector_spec.rb
300
+ - spec/transpec/syntax/allow_spec.rb
281
301
  - spec/transpec/syntax/be_boolean_spec.rb
282
302
  - spec/transpec/syntax/be_close_spec.rb
283
303
  - spec/transpec/syntax/double_spec.rb
@@ -290,6 +310,7 @@ files:
290
310
  - spec/transpec/syntax/oneliner_should_spec.rb
291
311
  - spec/transpec/syntax/operator_matcher_spec.rb
292
312
  - spec/transpec/syntax/raise_error_spec.rb
313
+ - spec/transpec/syntax/receive_spec.rb
293
314
  - spec/transpec/syntax/rspec_configure_spec.rb
294
315
  - spec/transpec/syntax/should_receive_spec.rb
295
316
  - spec/transpec/syntax/should_spec.rb
@@ -314,7 +335,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
314
335
  requirements:
315
336
  - - ">="
316
337
  - !ruby/object:Gem::Version
317
- version: '0'
338
+ version: 1.9.3
318
339
  required_rubygems_version: !ruby/object:Gem::Requirement
319
340
  requirements:
320
341
  - - ">="
@@ -347,6 +368,7 @@ test_files:
347
368
  - spec/transpec/report_spec.rb
348
369
  - spec/transpec/rspec_version_spec.rb
349
370
  - spec/transpec/static_context_inspector_spec.rb
371
+ - spec/transpec/syntax/allow_spec.rb
350
372
  - spec/transpec/syntax/be_boolean_spec.rb
351
373
  - spec/transpec/syntax/be_close_spec.rb
352
374
  - spec/transpec/syntax/double_spec.rb
@@ -359,6 +381,7 @@ test_files:
359
381
  - spec/transpec/syntax/oneliner_should_spec.rb
360
382
  - spec/transpec/syntax/operator_matcher_spec.rb
361
383
  - spec/transpec/syntax/raise_error_spec.rb
384
+ - spec/transpec/syntax/receive_spec.rb
362
385
  - spec/transpec/syntax/rspec_configure_spec.rb
363
386
  - spec/transpec/syntax/should_receive_spec.rb
364
387
  - spec/transpec/syntax/should_spec.rb