transpec 2.2.3 → 2.2.4

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: 33c531039bdc9609412069c33d3e89135b4b2f86
4
- data.tar.gz: 8b4956401c3985d33cc37f6738141702eb9e6e86
3
+ metadata.gz: bea6a3efb55602879556ab0afcb57ff1afc5ad19
4
+ data.tar.gz: 4c9d3f104c8c8865565162539cee360343c6adc4
5
5
  SHA512:
6
- metadata.gz: af7da633d3f8f61ca7966e1b86ac732bf037e47e78e7241270daadad59582fcaec334bfd37d9426ae817618c1474afc6fe9e488b12aca349fa6ccb615c5e11eb
7
- data.tar.gz: e796cfb5e29b16ac5a636e0400771d4398d96a302676bfc4d7c19ad152d757d880348e5367a88c7f9e4835e7f8d560d9e589c31229705df020987234500e45a6
6
+ metadata.gz: 5c07e7a00f5a850dd2e67e02321d0ec2b4e5243f53de50af9d4d7176fc0747a0384a2bdd1eaab1e34b184f8d9668cfa11362030578dbc963def63592b52bb9eb
7
+ data.tar.gz: ef36576b3df8b682a823b81e0164b0be5cdc35fb0ff7219659e8487813acf4058c3a81b0ef60bb4a86cf09f15f62bd919dd68e464783f08162f82aae62496737
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Development
4
4
 
5
+ ## v2.2.4
6
+
7
+ * Avoid crash on invalid `expect` syntax expectations (e.g. `expect(obj)` without following `to` or `expect(obj).to` taking no matcher). ([#71](https://github.com/yujinakayama/transpec/issues/71))
8
+
5
9
  ## v2.2.3
6
10
 
7
11
  * Handle `its(:attr) { should have(n).items }`. ([#68](https://github.com/yujinakayama/transpec/pull/68))
@@ -9,7 +9,7 @@ module Transpec
9
9
  include Mixin::ExpectBase
10
10
 
11
11
  def dynamic_analysis_target?
12
- super && receiver_node.nil? && [:allow, :allow_any_instance_of].include?(method_name)
12
+ super && [:allow, :allow_any_instance_of].include?(method_name)
13
13
  end
14
14
 
15
15
  def method_name_for_instance
@@ -14,7 +14,7 @@ module Transpec
14
14
  add_matcher RaiseError
15
15
 
16
16
  def dynamic_analysis_target?
17
- super && receiver_node.nil? && [:expect, :expect_any_instance_of].include?(method_name)
17
+ super && [:expect, :expect_any_instance_of].include?(method_name)
18
18
  end
19
19
 
20
20
  def method_name_for_instance
@@ -17,6 +17,10 @@ module Transpec
17
17
  add_matcher Receive
18
18
  end
19
19
 
20
+ def dynamic_analysis_target?
21
+ super && receiver_node.nil? && matcher_node
22
+ end
23
+
20
24
  def current_syntax_type
21
25
  :expect
22
26
  end
@@ -36,15 +40,21 @@ module Transpec
36
40
  end
37
41
 
38
42
  def to_node
43
+ return nil unless parent_node
44
+
39
45
  if parent_node.block_type? && parent_node.children.first.equal?(node)
40
46
  parent_node.parent_node
41
- else
47
+ elsif parent_node.send_type? && parent_node.children.first.equal?(node)
42
48
  parent_node
49
+ else
50
+ nil
43
51
  end
44
52
  end
45
53
 
46
54
  def matcher_node
55
+ return nil unless to_node
47
56
  to_arg_node = to_node.children[2]
57
+ return nil unless to_arg_node
48
58
  Util.each_forward_chained_node(to_arg_node, :include_origin)
49
59
  .select(&:send_type?).to_a.last
50
60
  end
@@ -5,7 +5,7 @@ module Transpec
5
5
  module Version
6
6
  MAJOR = 2
7
7
  MINOR = 2
8
- PATCH = 3
8
+ PATCH = 4
9
9
 
10
10
  def self.to_s
11
11
  [MAJOR, MINOR, PATCH].join('.')
@@ -9,6 +9,96 @@ module Transpec
9
9
  include_context 'parsed objects'
10
10
  include_context 'syntax object', Expect, :expect_object
11
11
 
12
+ describe '#conversion_target?' do
13
+ let(:target_node) do
14
+ ast.each_node do |node|
15
+ next unless node.send_type?
16
+ method_name = node.children[1]
17
+ next unless method_name == :expect
18
+ return node
19
+ end
20
+ fail 'No #expect node is found!'
21
+ end
22
+
23
+ let(:expect_object) do
24
+ Expect.new(target_node)
25
+ end
26
+
27
+ subject { expect_object.conversion_target? }
28
+
29
+ context 'when the #expect node is chained by #to' do
30
+ context 'and taking a matcher properly' do
31
+ let(:source) do
32
+ <<-END
33
+ describe 'example' do
34
+ it 'is valid expectation' do
35
+ expect(obj).to matcher
36
+ end
37
+ end
38
+ END
39
+ end
40
+
41
+ it { should be_true }
42
+ end
43
+
44
+ context 'but taking no matcher' do
45
+ let(:source) do
46
+ <<-END
47
+ describe 'example' do
48
+ it 'is invalid expectation' do
49
+ expect(obj).to
50
+ end
51
+ end
52
+ END
53
+ end
54
+
55
+ it { should be_false }
56
+ end
57
+ end
58
+
59
+ context 'when the #expect node is chained by #not_to' do
60
+ let(:source) do
61
+ <<-END
62
+ describe 'example' do
63
+ it 'is valid expectation' do
64
+ expect(obj).not_to matcher
65
+ end
66
+ end
67
+ END
68
+ end
69
+
70
+ it { should be_true }
71
+ end
72
+
73
+ context 'when the #expect node is not chained' do
74
+ let(:source) do
75
+ <<-END
76
+ describe 'example' do
77
+ it 'is invalid expectation' do
78
+ expect(obj)
79
+ end
80
+ end
81
+ END
82
+ end
83
+
84
+ it { should be_false }
85
+ end
86
+
87
+ context 'when the #expect node is not chained and taken as a argument by another method' do
88
+ let(:source) do
89
+ <<-END
90
+ describe 'example' do
91
+ it 'is invalid expectation' do
92
+ do_something(expect(obj))
93
+ end
94
+ end
95
+ END
96
+ end
97
+
98
+ it { should be_false }
99
+ end
100
+ end
101
+
12
102
  describe '#subject_node' do
13
103
  context 'when the subject is a normal argument' do
14
104
  let(:source) do
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: 2.2.3
4
+ version: 2.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuji Nakayama