transpec 3.0.2 → 3.0.3

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: 130f69705bf8dfb8dff588176c1b0a9233499ba9
4
- data.tar.gz: 3824c963a6ae862b7672b0e1285800b2da5c350d
3
+ metadata.gz: 202c5b3a6677c5a08f53787a4b92a1da72a16d6d
4
+ data.tar.gz: 7cde03bd6520c7a25a890f436ece6644d182cfdf
5
5
  SHA512:
6
- metadata.gz: 7d405ecd3074077e69c480f5802a62bf416710d75bdd523c3bb1b5fe5f745baf4a6efb9b6efb57cba767852e5bd5b5973fa162111ca6ac618e5468fee2442330
7
- data.tar.gz: 90249324f5804315dd1cc99322b365001054346184c2a722414965bb5290f91d92ea1c8879741313a2d4aba948f3af279ddfe8aa0fdde37ecd199f06eb3a8113
6
+ metadata.gz: 21c3b3fce8aa0a69802afef630b80b074143cbb0573c035b277ac69e3be9da12f5b66ed95a8a2a7f5263ea3cc24fec1e32d4a9545cd7b38743097ae9c22a2d60
7
+ data.tar.gz: fe8b7f7d45c7eb1ee68c449dca9f457fe91fa32fe0e548836c1e8d6ef9e0bff459d599055f5cff2a2c51d890dce88739972f68b5cfdde70ee45ccadc191cd57c
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Development
4
4
 
5
+ ## v3.0.3
6
+
7
+ * Fix a bug where `obj.should =~ an_activerecord_relation` was converted to `expect(obj).to match(an_activerecord_relation)` rather than `match_array`. ([#92](https://github.com/yujinakayama/transpec/issues/92))
8
+
5
9
  ## v3.0.2
6
10
 
7
11
  * Fix a bug where `have(n).errors_on(:attr)` was unintentionally converted when combined with one-liner `should`. ([#95](https://github.com/yujinakayama/transpec/issues/95))
@@ -17,7 +17,11 @@ module Transpec
17
17
 
18
18
  define_dynamic_analysis do |rewriter|
19
19
  if method_name == :=~
20
- rewriter.register_request(arg_node, :enumerable_arg?, 'is_a?(Enumerable)')
20
+ # https://github.com/rspec/rspec-expectations/blob/v2.14.5/lib/rspec/matchers.rb#L692
21
+ # https://github.com/rspec/rspec-rails/blob/v2.14.2/lib/rspec/rails/matchers/relation_match_array.rb
22
+ code = 'is_a?(Enumerable) || ' \
23
+ 'self.class.ancestors.any? { |klass| klass.name == "ActiveRecord::Relation" }'
24
+ rewriter.register_request(arg_node, :using_match_array?, code)
21
25
  end
22
26
  end
23
27
 
@@ -78,7 +82,7 @@ module Transpec
78
82
  def convert_to_match!(parenthesize_arg)
79
83
  handle_anterior_of_operator!
80
84
 
81
- if enumerable_arg?
85
+ if using_match_array?
82
86
  replace(selector_range, 'match_array')
83
87
  else
84
88
  replace(selector_range, 'match')
@@ -86,11 +90,11 @@ module Transpec
86
90
 
87
91
  parenthesize!(parenthesize_arg)
88
92
 
89
- accurate = !enumerable_arg?.nil? # rubocop:disable NonNilCheck
93
+ accurate = !using_match_array?.nil? # rubocop:disable NonNilCheck
90
94
 
91
95
  # Need to register record after all source rewrites are done
92
96
  # to avoid false record when failed with overlapped rewrite.
93
- if enumerable_arg?
97
+ if using_match_array?
94
98
  add_record('=~ [1, 2]', 'match_array([1, 2])', accurate)
95
99
  else
96
100
  add_record('=~ /pattern/', 'match(/pattern/)', accurate)
@@ -105,14 +109,14 @@ module Transpec
105
109
  end
106
110
  end
107
111
 
108
- def enumerable_arg?
112
+ def using_match_array?
109
113
  case arg_node.type
110
114
  when :array
111
115
  true
112
116
  when :regexp
113
117
  false
114
118
  else
115
- runtime_data[arg_node, :enumerable_arg?]
119
+ runtime_data[arg_node, :using_match_array?]
116
120
  end
117
121
  end
118
122
 
@@ -5,7 +5,7 @@ module Transpec
5
5
  module Version
6
6
  MAJOR = 3
7
7
  MINOR = 0
8
- PATCH = 2
8
+ PATCH = 3
9
9
 
10
10
  def self.to_s
11
11
  [MAJOR, MINOR, PATCH].join('.')
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: 3.0.2
4
+ version: 3.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuji Nakayama