transpec 2.3.2 → 2.3.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e2ca68d2ec61ab33ba2a0111a03728a08925606d
4
- data.tar.gz: df0d66e1266197c0fe17a3533cafa4a6cd1649ee
3
+ metadata.gz: 585693816f02d6ca49a0a8a4e0ccec79e5514b96
4
+ data.tar.gz: 082314811f1021acf7036e0bccd4f88c99348f07
5
5
  SHA512:
6
- metadata.gz: 7221ef0ade502c3ab43987fc1fcb24c671795f840ebe4e29d073803f417592e616dc97130a12e8bcd4b75c78fb21b1b693bd7630522577b084c090747656092d
7
- data.tar.gz: 5aa6b286c235b51e47ab7bba1ac8f26bc25a26e85e3632f3305bdcd0f4c12bc39e04096fe4ee76b71bcc47652c78b53810e6a4a3c178bee42867bc425f77e2ec
6
+ metadata.gz: e7c2c4e9b46e0a3e70939acbcda80531511edab54637e75ff1e070e88490e648f36ff69a55dd86af680d0b355c67537f2e86747e392b86d3e1889bfb8e40fc54
7
+ data.tar.gz: 648882d9a093d0be7abc399922f3d1deadef1af0386e0028fd25b7cfc0f7aee5c71af05e050940c3e12d7bb34e8e5013f1523d1dd06a68b6737fc3531b96a286
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Development
4
4
 
5
+ ## v2.3.3
6
+
7
+ * Fix failure on dynamic analysis when there's a RSpec-like method invocation in a context that undefines `Object` methods (e.g. `after` callback in [factory_girl definition context](https://github.com/thoughtbot/factory_girl/blob/v4.4.0/lib/factory_girl/definition_proxy.rb#L3-L7)). ([#66](https://github.com/yujinakayama/transpec/issues/66))
8
+
5
9
  ## v2.3.2
6
10
 
7
11
  * Fix a bug where explicit spec type metadata are added to wrong position when the `describe` has multiple non-metadata arguments (e.g. `describe Something, '#some_method' { }`). ([#77](https://github.com/yujinakayama/transpec/issues/77))
@@ -12,7 +12,8 @@ require 'English'
12
12
 
13
13
  module Transpec
14
14
  class DynamicAnalyzer
15
- ANALYSIS_METHOD = 'transpec_analyze'
15
+ ANALYSIS_MODULE = 'TranspecAnalysis'
16
+ ANALYSIS_METHOD = 'analyze'
16
17
  HELPER_TEMPLATE_FILE = 'transpec_analysis_helper.rb.erb'
17
18
  RESULT_FILE = 'transpec_analysis_result.json'
18
19
 
@@ -82,7 +82,7 @@ module Transpec
82
82
  end
83
83
 
84
84
  def build_wrapper_codes(node, analysis_codes)
85
- front = "#{ANALYSIS_METHOD}(("
85
+ front = "#{ANALYSIS_MODULE}.#{ANALYSIS_METHOD}(("
86
86
  rear = format('), self, %s, %s)', node_id(node).inspect, hash_literal(analysis_codes))
87
87
  [front, rear]
88
88
  end
@@ -1,14 +1,36 @@
1
- module TranspecAnalysis
1
+ module <%= ANALYSIS_MODULE %>
2
2
  @base_path = Dir.pwd
3
3
 
4
- def self.temporary_data
4
+ module_function
5
+
6
+ def temporary_data
5
7
  @temporary_data ||= {}
6
8
  end
7
9
 
8
- def self.data
10
+ def data
9
11
  @data ||= {}
10
12
  end
11
13
 
14
+ def <%= ANALYSIS_METHOD %>(object, context, node_id, analysis_codes)
15
+ node_data = {}
16
+
17
+ analysis_codes.each do |key, (target_type, code)|
18
+ target = case target_type
19
+ when :object then object
20
+ when :context then context
21
+ end
22
+
23
+ begin
24
+ node_data[key] = target.instance_eval(code)
25
+ rescue Exception
26
+ end
27
+ end
28
+
29
+ data[node_id] = node_data
30
+
31
+ object
32
+ end
33
+
12
34
  at_exit do
13
35
  # Use JSON rather than Marshal so that:
14
36
  # * Unknown third-party class information won't be serialized.
@@ -22,23 +44,3 @@ module TranspecAnalysis
22
44
  end
23
45
  end
24
46
  end
25
-
26
- def <%= ANALYSIS_METHOD %>(object, context, node_id, analysis_codes)
27
- node_data = {}
28
-
29
- analysis_codes.each do |key, (target_type, code)|
30
- target = case target_type
31
- when :object then object
32
- when :context then context
33
- end
34
-
35
- begin
36
- node_data[key] = target.instance_eval(code)
37
- rescue Exception
38
- end
39
- end
40
-
41
- TranspecAnalysis.data[node_id] = node_data
42
-
43
- object
44
- end
@@ -5,7 +5,7 @@ module Transpec
5
5
  module Version
6
6
  MAJOR = 2
7
7
  MINOR = 3
8
- PATCH = 2
8
+ PATCH = 3
9
9
 
10
10
  def self.to_s
11
11
  [MAJOR, MINOR, PATCH].join('.')
@@ -22,7 +22,7 @@ module Transpec
22
22
  # rubocop:disable LineLength
23
23
  let(:expected_source) do
24
24
  <<-'END'
25
- transpec_analyze((transpec_analyze((subject), self, "(string)_12_19", { :should_source_location => [:object, "method(:should).source_location"], :should_example_method_defined_by_user? => [:object, "owner = method(:should).owner\nowner != RSpec::Core::ExampleGroup &&\n owner.ancestors.include?(RSpec::Core::ExampleGroup)"] }).should be(foo)), self, "(string)_12_34", { :expect_available? => [:context, "self.class.ancestors.any? { |a| a.name.start_with?('RSpec::') } && respond_to?(:expect)"] })
25
+ TranspecAnalysis.analyze((TranspecAnalysis.analyze((subject), self, "(string)_12_19", { :should_source_location => [:object, "method(:should).source_location"], :should_example_method_defined_by_user? => [:object, "owner = method(:should).owner\nowner != RSpec::Core::ExampleGroup &&\n owner.ancestors.include?(RSpec::Core::ExampleGroup)"] }).should be(foo)), self, "(string)_12_34", { :expect_available? => [:context, "self.class.ancestors.any? { |a| a.name.start_with?('RSpec::') } && respond_to?(:expect)"] })
26
26
  END
27
27
  end
28
28
  # rubocop:enable LineLength
@@ -43,7 +43,7 @@ module Transpec
43
43
  # rubocop:disable LineLength
44
44
  let(:expected_source) do
45
45
  <<-'END'
46
- transpec_analyze((transpec_analyze((subject), self, "(string)_14_21", { :should_source_location => [:object, "method(:should).source_location"], :should_example_method_defined_by_user? => [:object, "owner = method(:should).owner\nowner != RSpec::Core::ExampleGroup &&\n owner.ancestors.include?(RSpec::Core::ExampleGroup)"] }).should), self, "(string)_14_28", { :expect_available? => [:context, "self.class.ancestors.any? { |a| a.name.start_with?('RSpec::') } && respond_to?(:expect)"], :"=~_source_location" => [:object, "method(:=~).source_location"], :"=~_example_method_defined_by_user?" => [:object, "owner = method(:=~).owner\nowner != RSpec::Core::ExampleGroup &&\n owner.ancestors.include?(RSpec::Core::ExampleGroup)"] }) =~ transpec_analyze((<<-HEREDOC.gsub('foo', 'bar')), self, "(string)_32_61", { :enumerable_arg? => [:object, "is_a?(Enumerable)"] })
46
+ TranspecAnalysis.analyze((TranspecAnalysis.analyze((subject), self, "(string)_14_21", { :should_source_location => [:object, "method(:should).source_location"], :should_example_method_defined_by_user? => [:object, "owner = method(:should).owner\nowner != RSpec::Core::ExampleGroup &&\n owner.ancestors.include?(RSpec::Core::ExampleGroup)"] }).should), self, "(string)_14_28", { :expect_available? => [:context, "self.class.ancestors.any? { |a| a.name.start_with?('RSpec::') } && respond_to?(:expect)"], :"=~_source_location" => [:object, "method(:=~).source_location"], :"=~_example_method_defined_by_user?" => [:object, "owner = method(:=~).owner\nowner != RSpec::Core::ExampleGroup &&\n owner.ancestors.include?(RSpec::Core::ExampleGroup)"] }) =~ TranspecAnalysis.analyze((<<-HEREDOC.gsub('foo', 'bar')), self, "(string)_32_61", { :enumerable_arg? => [:object, "is_a?(Enumerable)"] })
47
47
  foo
48
48
  HEREDOC
49
49
  END
@@ -65,7 +65,7 @@ module Transpec
65
65
  # rubocop:disable LineLength
66
66
  let(:expected_source) do
67
67
  <<-'END'
68
- transpec_analyze((expect { do_something }), self, "(string)_14_20", { :expect_source_location => [:context, "method(:expect).source_location"], :expect_example_method_defined_by_user? => [:context, "owner = method(:expect).owner\nowner != RSpec::Core::ExampleGroup &&\n owner.ancestors.include?(RSpec::Core::ExampleGroup)"] }).to throw_symbol
68
+ TranspecAnalysis.analyze((expect { do_something }), self, "(string)_14_20", { :expect_source_location => [:context, "method(:expect).source_location"], :expect_example_method_defined_by_user? => [:context, "owner = method(:expect).owner\nowner != RSpec::Core::ExampleGroup &&\n owner.ancestors.include?(RSpec::Core::ExampleGroup)"] }).to throw_symbol
69
69
  END
70
70
  end
71
71
  # rubocop:enable LineLength
@@ -85,7 +85,7 @@ module Transpec
85
85
  # rubocop:disable LineLength
86
86
  let(:expected_source) do
87
87
  <<-'END'
88
- transpec_analyze((double 'something'), self, "(string)_14_32", { :double_source_location => [:context, "method(:double).source_location"], :double_example_method_defined_by_user? => [:context, "owner = method(:double).owner\nowner != RSpec::Core::ExampleGroup &&\n owner.ancestors.include?(RSpec::Core::ExampleGroup)"] })
88
+ TranspecAnalysis.analyze((double 'something'), self, "(string)_14_32", { :double_source_location => [:context, "method(:double).source_location"], :double_example_method_defined_by_user? => [:context, "owner = method(:double).owner\nowner != RSpec::Core::ExampleGroup &&\n owner.ancestors.include?(RSpec::Core::ExampleGroup)"] })
89
89
  END
90
90
  end
91
91
  # rubocop:enable LineLength
@@ -215,6 +215,39 @@ module Transpec
215
215
  end
216
216
  end
217
217
 
218
+ context 'when there is a proxy/delegator Class that undefines Object methods' do
219
+ let(:source) do
220
+ # https://github.com/thoughtbot/factory_girl/blob/v4.4.0/lib/factory_girl/definition_proxy.rb#L3-L7
221
+ <<-END
222
+ class SomeProxy
223
+ UNPROXIED_METHODS = %w(__send__ object_id initialize instance_eval).map(&:to_sym)
224
+
225
+ (instance_methods + private_instance_methods).each do |method|
226
+ undef_method(method) unless UNPROXIED_METHODS.include?(method)
227
+ end
228
+ end
229
+
230
+ describe 'example' do
231
+ it 'is 1' do
232
+ proxy = SomeProxy.new
233
+ proxy.instance_eval do
234
+ 1.should == 1
235
+ end
236
+ end
237
+ end
238
+ END
239
+ end
240
+
241
+ it 'properly analyzes even in such context' do
242
+ should_node = find_node_in_file(spec_file_path) do |node|
243
+ node.send_type? && node.children[1] == :should
244
+ end
245
+
246
+ runtime_data = dynamic_analyzer.analyze
247
+ runtime_data.run?(should_node).should be_true
248
+ end
249
+ end
250
+
218
251
  runtime_data_cache = {}
219
252
 
220
253
  subject(:runtime_data) 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.3.2
4
+ version: 2.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuji Nakayama