transpec 1.10.3 → 1.10.4

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 (60) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +4 -0
  3. data/CHANGELOG.md +5 -0
  4. data/Gemfile +2 -0
  5. data/README.md +11 -5
  6. data/README.md.erb +11 -5
  7. data/lib/transpec.rb +1 -19
  8. data/lib/transpec/base_rewriter.rb +1 -1
  9. data/lib/transpec/converter.rb +2 -3
  10. data/lib/transpec/dynamic_analyzer/rewriter.rb +2 -2
  11. data/lib/transpec/option_parser.rb +2 -2
  12. data/lib/transpec/parser.rb +9 -0
  13. data/lib/transpec/record.rb +45 -7
  14. data/lib/transpec/syntax.rb +15 -21
  15. data/lib/transpec/syntax/allow.rb +2 -2
  16. data/lib/transpec/syntax/be_boolean.rb +2 -2
  17. data/lib/transpec/syntax/be_close.rb +2 -2
  18. data/lib/transpec/syntax/current_example.rb +5 -6
  19. data/lib/transpec/syntax/double.rb +2 -2
  20. data/lib/transpec/syntax/example.rb +13 -14
  21. data/lib/transpec/syntax/expect.rb +2 -2
  22. data/lib/transpec/syntax/have.rb +5 -8
  23. data/lib/transpec/syntax/have/{dynamic_inspector.rb → dynamic_analysis.rb} +25 -47
  24. data/lib/transpec/syntax/have/have_record.rb +12 -16
  25. data/lib/transpec/syntax/its.rb +5 -5
  26. data/lib/transpec/syntax/matcher_definition.rb +2 -2
  27. data/lib/transpec/syntax/method_stub.rb +29 -28
  28. data/lib/transpec/syntax/mixin/any_instance_block.rb +2 -2
  29. data/lib/transpec/syntax/mixin/matcher_owner.rb +16 -13
  30. data/lib/transpec/syntax/mixin/monkey_patch.rb +2 -2
  31. data/lib/transpec/syntax/mixin/monkey_patch_any_instance.rb +1 -1
  32. data/lib/transpec/syntax/mixin/send.rb +42 -30
  33. data/lib/transpec/syntax/mixin/useless_and_return.rb +2 -4
  34. data/lib/transpec/syntax/oneliner_should.rb +17 -19
  35. data/lib/transpec/syntax/operator.rb +9 -14
  36. data/lib/transpec/syntax/pending.rb +27 -18
  37. data/lib/transpec/syntax/raise_error.rb +2 -2
  38. data/lib/transpec/syntax/receive.rb +2 -2
  39. data/lib/transpec/syntax/rspec_configure.rb +2 -2
  40. data/lib/transpec/syntax/should.rb +9 -9
  41. data/lib/transpec/syntax/should_receive.rb +18 -16
  42. data/lib/transpec/version.rb +1 -1
  43. data/spec/spec_helper.rb +7 -0
  44. data/spec/support/shared_context.rb +4 -4
  45. data/spec/transpec/cli_spec.rb +1 -1
  46. data/spec/transpec/converter_spec.rb +1 -1
  47. data/spec/transpec/dynamic_analyzer/rewriter_spec.rb +8 -8
  48. data/spec/transpec/syntax/current_example_spec.rb +75 -19
  49. data/spec/transpec/syntax/double_spec.rb +11 -11
  50. data/spec/transpec/syntax/example_spec.rb +8 -4
  51. data/spec/transpec/syntax/have_spec.rb +1 -1
  52. data/spec/transpec/syntax/method_stub_spec.rb +14 -20
  53. data/spec/transpec/syntax/oneliner_should_spec.rb +51 -0
  54. data/spec/transpec/syntax/pending_spec.rb +8 -4
  55. data/spec/transpec_spec.rb +4 -6
  56. data/tasks/demo.rake +2 -2
  57. data/tasks/lib/transpec_demo.rb +1 -1
  58. data/tasks/lib/transpec_test.rb +1 -1
  59. data/tasks/test.rake +2 -2
  60. metadata +4 -3
@@ -11,6 +11,79 @@ module Transpec
11
11
 
12
12
  let(:record) { current_example_object.report.records.last }
13
13
 
14
+ describe '#conversion_target?' do
15
+ let(:target_node) do
16
+ ast.each_descendent_node do |node|
17
+ next unless node.send_type?
18
+ method_name = node.children[1]
19
+ next unless method_name == :example
20
+ return node
21
+ end
22
+ fail 'No #example node is found!'
23
+ end
24
+
25
+ let(:current_example_object) do
26
+ CurrentExample.new(target_node, source_rewriter, runtime_data)
27
+ end
28
+
29
+ subject { current_example_object.conversion_target? }
30
+
31
+ context 'with #example node that returns current example object' do
32
+ let(:source) do
33
+ <<-END
34
+ describe 'example' do
35
+ after do
36
+ do_something if example.metadata[:foo]
37
+ end
38
+ end
39
+ END
40
+ end
41
+
42
+ it { should be_true }
43
+ end
44
+
45
+ context 'when #example node that defines a spec example is passed' do
46
+ let(:source) do
47
+ <<-END
48
+ describe 'example' do
49
+ example 'it does something' do
50
+ do_something
51
+ end
52
+ end
53
+ END
54
+ end
55
+
56
+ it { should be_false }
57
+ end
58
+
59
+ context 'when #example node defined with #let by user is passed' do
60
+ let(:source) do
61
+ <<-END
62
+ describe 'example' do
63
+ let(:example) { 'This is not current example object' }
64
+
65
+ it 'does something' do
66
+ example
67
+ end
68
+ end
69
+ END
70
+ end
71
+
72
+ it 'unfortunately returns true ' \
73
+ "since it's impossible to differentiate them without runtime information" do
74
+ should be_true
75
+ end
76
+
77
+ context 'with runtime information' do
78
+ include_context 'dynamic analysis objects'
79
+
80
+ it 'returns false properly' do
81
+ should be_false
82
+ end
83
+ end
84
+ end
85
+ end
86
+
14
87
  describe '#convert!' do
15
88
  before do
16
89
  current_example_object.convert! unless example.metadata[:no_auto_convert]
@@ -159,9 +232,8 @@ module Transpec
159
232
 
160
233
  let(:current_example_objects) do
161
234
  ast.each_node.reduce([]) do |objects, node|
162
- if CurrentExample.conversion_target_node?(node)
163
- objects << CurrentExample.new(node, source_rewriter, runtime_data)
164
- end
235
+ current_example_object = CurrentExample.new(node, source_rewriter, runtime_data)
236
+ objects << current_example_object if current_example_object.conversion_target?
165
237
  objects
166
238
  end
167
239
  end
@@ -199,22 +271,6 @@ module Transpec
199
271
  end
200
272
  end
201
273
 
202
- context "with expression `example 'it does something' do do_something end`", :no_auto_convert do
203
- let(:source) do
204
- <<-END
205
- describe 'example' do
206
- example 'it does something' do
207
- do_something
208
- end
209
- end
210
- END
211
- end
212
-
213
- it 'does nothing' do
214
- rewritten_source.should == source
215
- end
216
- end
217
-
218
274
  context 'with expression `def helper_method example; end`' do
219
275
  let(:source) do
220
276
  <<-END
@@ -9,8 +9,8 @@ module Transpec
9
9
  include_context 'parsed objects'
10
10
  include_context 'syntax object', Double, :double_object
11
11
 
12
- describe '.conversion_target_node?' do
13
- let(:send_node) do
12
+ describe '#conversion_target?' do
13
+ let(:target_node) do
14
14
  ast.each_descendent_node do |node|
15
15
  next unless node.send_type?
16
16
  method_name = node.children[1]
@@ -20,6 +20,12 @@ module Transpec
20
20
  fail 'No #double node is found!'
21
21
  end
22
22
 
23
+ let(:double_object) do
24
+ Double.new(target_node, source_rewriter, runtime_data)
25
+ end
26
+
27
+ subject { double_object.conversion_target? }
28
+
23
29
  context 'when #double node is passed' do
24
30
  let(:source) do
25
31
  <<-END
@@ -32,9 +38,7 @@ module Transpec
32
38
  END
33
39
  end
34
40
 
35
- it 'returns true' do
36
- Double.conversion_target_node?(send_node).should be_true
37
- end
41
+ it { should be_true }
38
42
  end
39
43
 
40
44
  context 'with runtime information' do
@@ -52,9 +56,7 @@ module Transpec
52
56
  END
53
57
  end
54
58
 
55
- it 'returns true' do
56
- Double.conversion_target_node?(send_node).should be_true
57
- end
59
+ it { should be_true }
58
60
  end
59
61
 
60
62
  context 'when another #double node is passed' do
@@ -87,9 +89,7 @@ module Transpec
87
89
  END
88
90
  end
89
91
 
90
- it 'returns false' do
91
- Double.conversion_target_node?(send_node, runtime_data).should be_false
92
- end
92
+ it { should be_false }
93
93
  end
94
94
  end
95
95
  end
@@ -13,10 +13,8 @@ module Transpec
13
13
 
14
14
  let(:record) { example_object.report.records.last }
15
15
 
16
- describe '.conversion_target_node?' do
17
- subject { Example.conversion_target_node?(pending_node, runtime_data) }
18
-
19
- let(:pending_node) do
16
+ describe '#conversion_target?' do
17
+ let(:target_node) do
20
18
  ast.each_descendent_node do |node|
21
19
  next unless node.send_type?
22
20
  method_name = node.children[1]
@@ -25,6 +23,12 @@ module Transpec
25
23
  fail 'No #pending node is found!'
26
24
  end
27
25
 
26
+ let(:example_object) do
27
+ Example.new(target_node, source_rewriter, runtime_data)
28
+ end
29
+
30
+ subject { example_object.conversion_target? }
31
+
28
32
  context 'when #pending example node is passed' do
29
33
  let(:source) do
30
34
  <<-END
@@ -1141,7 +1141,7 @@ module Transpec
1141
1141
 
1142
1142
  let(:have_object) { expect_object.have_matcher }
1143
1143
 
1144
- fit "converts to `expect(hash['some_key'].size).to eq(2)` form" do
1144
+ it "converts to `expect(hash['some_key'].size).to eq(2)` form" do
1145
1145
  have_object.convert_to_standard_expectation!
1146
1146
  rewritten_source.should == expected_source
1147
1147
  end
@@ -12,8 +12,8 @@ module Transpec
12
12
 
13
13
  let(:record) { method_stub_object.report.records.first }
14
14
 
15
- describe '.conversion_target_node?' do
16
- let(:send_node) do
15
+ describe '#conversion_target?' do
16
+ let(:target_node) do
17
17
  ast.each_descendent_node do |node|
18
18
  next unless node.send_type?
19
19
  method_name = node.children[1]
@@ -23,6 +23,12 @@ module Transpec
23
23
  fail 'No #stub node is found!'
24
24
  end
25
25
 
26
+ let(:method_stub_object) do
27
+ MethodStub.new(target_node, source_rewriter, runtime_data)
28
+ end
29
+
30
+ subject { method_stub_object.conversion_target? }
31
+
26
32
  context 'when #stub node is passed' do
27
33
  let(:source) do
28
34
  <<-END
@@ -34,9 +40,7 @@ module Transpec
34
40
  END
35
41
  end
36
42
 
37
- it 'returns true' do
38
- MethodStub.conversion_target_node?(send_node).should be_true
39
- end
43
+ it { should be_true }
40
44
  end
41
45
 
42
46
  context 'when Factory.stub node is passed' do
@@ -50,9 +54,7 @@ module Transpec
50
54
  END
51
55
  end
52
56
 
53
- it 'returns false' do
54
- MethodStub.conversion_target_node?(send_node).should be_false
55
- end
57
+ it { should be_false }
56
58
  end
57
59
 
58
60
  context 'with runtime information' do
@@ -69,9 +71,7 @@ module Transpec
69
71
  END
70
72
  end
71
73
 
72
- it 'returns true' do
73
- MethodStub.conversion_target_node?(send_node, runtime_data).should be_true
74
- end
74
+ it { should be_true }
75
75
  end
76
76
 
77
77
  context 'when another #stub node is passed' do
@@ -90,9 +90,7 @@ module Transpec
90
90
  END
91
91
  end
92
92
 
93
- it 'returns false' do
94
- MethodStub.conversion_target_node?(send_node, runtime_data).should be_false
95
- end
93
+ it { should be_false }
96
94
  end
97
95
 
98
96
  context "when Factory.stub node is passed and it's RSpec's #stub" do
@@ -109,9 +107,7 @@ module Transpec
109
107
  END
110
108
  end
111
109
 
112
- it 'returns true' do
113
- MethodStub.conversion_target_node?(send_node, runtime_data).should be_true
114
- end
110
+ it { should be_true }
115
111
  end
116
112
 
117
113
  context 'when Factory.stub node is passed and it has not been run' do
@@ -128,9 +124,7 @@ module Transpec
128
124
  END
129
125
  end
130
126
 
131
- it 'returns false' do
132
- MethodStub.conversion_target_node?(send_node, runtime_data).should be_false
133
- end
127
+ it { should be_false }
134
128
  end
135
129
  end
136
130
  end
@@ -11,6 +11,57 @@ module Transpec
11
11
 
12
12
  let(:record) { should_object.report.records.first }
13
13
 
14
+ describe '#conversion_target?' do
15
+ let(:target_node) do
16
+ ast.each_descendent_node do |node|
17
+ next unless node.send_type?
18
+ method_name = node.children[1]
19
+ next unless method_name == :should
20
+ return node
21
+ end
22
+ fail 'No #should node is found!'
23
+ end
24
+
25
+ let(:should_object) do
26
+ OnelinerShould.new(target_node, source_rewriter, runtime_data)
27
+ end
28
+
29
+ subject { should_object.conversion_target? }
30
+
31
+ context 'when one-liner #should node is passed' do
32
+ let(:source) do
33
+ <<-END
34
+ describe 'example' do
35
+ subject { 1 }
36
+ it { should == 1 }
37
+ end
38
+ END
39
+ end
40
+
41
+ it { should be_true }
42
+
43
+ context 'with runtime information' do
44
+ include_context 'dynamic analysis objects'
45
+ it { should be_true }
46
+ end
47
+ end
48
+
49
+ context 'when monkey-patched #should node is passed' do
50
+ let(:source) do
51
+ <<-END
52
+ describe 'example' do
53
+ subject { 1 }
54
+ it 'is 1' do
55
+ subject.should == 1
56
+ end
57
+ end
58
+ END
59
+ end
60
+
61
+ it { should be_false }
62
+ end
63
+ end
64
+
14
65
  describe '#matcher_node' do
15
66
  context 'when it is taking operator matcher' do
16
67
  let(:source) do
@@ -11,10 +11,8 @@ module Transpec
11
11
 
12
12
  let(:record) { pending_object.report.records.last }
13
13
 
14
- describe '.conversion_target_node?' do
15
- subject { Pending.conversion_target_node?(pending_node, runtime_data) }
16
-
17
- let(:pending_node) do
14
+ describe '#conversion_target?' do
15
+ let(:target_node) do
18
16
  ast.each_descendent_node do |node|
19
17
  next unless node.send_type?
20
18
  method_name = node.children[1]
@@ -23,6 +21,12 @@ module Transpec
23
21
  fail 'No #pending node is found!'
24
22
  end
25
23
 
24
+ let(:pending_object) do
25
+ Pending.new(target_node, source_rewriter, runtime_data)
26
+ end
27
+
28
+ subject { pending_object.conversion_target? }
29
+
26
30
  context 'when #pending specification node inside of an example is passed' do
27
31
  let(:source) do
28
32
  <<-END
@@ -4,13 +4,11 @@ require 'spec_helper'
4
4
  require 'transpec'
5
5
 
6
6
  module Transpec
7
- [:required_rspec_version, :current_rspec_version].each do |method|
8
- describe ".#{method}" do
9
- subject { Transpec.send(method) }
7
+ describe '.required_rspec_version' do
8
+ subject { Transpec.required_rspec_version }
10
9
 
11
- it 'returns an instance of RSpecVersion' do
12
- should be_a(RSpecVersion)
13
- end
10
+ it 'returns an instance of RSpecVersion' do
11
+ should be_a(RSpecVersion)
14
12
  end
15
13
  end
16
14
  end
data/tasks/demo.rake CHANGED
@@ -11,11 +11,11 @@ namespace :demo do
11
11
  ]
12
12
  # rubocop:enable LineLength
13
13
 
14
- desc 'Publish conversion example on all projects'
14
+ desc 'Publish conversion examples of all projects'
15
15
  task all: demos.map(&:name)
16
16
 
17
17
  demos.each do |demo|
18
- desc "Publish conversion example on #{demo.name} project"
18
+ desc "Publish conversion example of #{demo.name} project"
19
19
  task demo.name do
20
20
  demo.run
21
21
  end
@@ -12,7 +12,7 @@ class TranspecDemo < TranspecTest
12
12
  def run
13
13
  require 'transpec'
14
14
 
15
- puts " Running demo on #{name} project ".center(80, '=')
15
+ puts " Publishing conversion example of #{name} project ".center(80, '=')
16
16
 
17
17
  prepare_project
18
18
  run_demo
@@ -36,7 +36,7 @@ class TranspecTest
36
36
 
37
37
  def run
38
38
  require 'transpec'
39
- puts " Testing on #{name} project ".center(80, '=')
39
+ puts " Testing transpec on #{name} project ".center(80, '=')
40
40
  prepare_project
41
41
  run_test(%w(--force))
42
42
  end
data/tasks/test.rake CHANGED
@@ -23,11 +23,11 @@ namespace :test do
23
23
  end
24
24
  # rubocop:enable LineLength
25
25
 
26
- desc 'Test Transpec on all projects'
26
+ desc 'Test transpec on all projects'
27
27
  task all: tests.map(&:name)
28
28
 
29
29
  tests.each do |test|
30
- desc "Test Transpec on #{test.name} project"
30
+ desc "Test transpec on #{test.name} project"
31
31
  task test.name do
32
32
  test.run
33
33
  end