active_mocker 2.4.0.pre3 → 2.4.0.pre4

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: add34a8a0b3a70e3f30fdb54b802ba7534e98466
4
- data.tar.gz: 878db3b1876606382669d6a59de99b1de6656e15
3
+ metadata.gz: bc207130a0c46ded87f8d86a71bf1cdc8519998e
4
+ data.tar.gz: db15587b7ba52220b56090f7772a2d2886c8133e
5
5
  SHA512:
6
- metadata.gz: 015b6289ee812e58635eee81ea72d0a9f4949c9b4a50a9e655baab50721083d1a1434248a015074386d763c6bf26671835faa4b8635f9f169ca3f4a3a92f4084
7
- data.tar.gz: fa75df7c31f75875ef129d4a0cdb71af18dff93750d318efc31da834804e5a58d027164b8c60fc618e907284c25e72df70903b9cc359487314b54ea288774bdf
6
+ metadata.gz: ba893dcaf811234838ff1c6b3f68f3924d79081d2ac6684e7d349006e1830dc212c2ef0806c6525e9292a33a79cdac0dc059ac681f043a64f08eb949722264e4
7
+ data.tar.gz: 31f2c55772b8862c114fc8da4ea410e24024281942e7e8b52a11ed22e2f1525e79e134be02aaef58e5699297b7fe89cbcec3ebb2fdc02c63bf7c41951dac86a7
@@ -1,6 +1,18 @@
1
1
  # Changelog
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## 2.4.0.pre4 - 2016-10-20
5
+ ### Enhancement
6
+ - Whitelist methods to import into mock code by adding a comment with `ActiveMocker.safe_methods(*methods)`
7
+ ```ruby
8
+ # ActiveMocker.safe_methods :full_name
9
+ class User < ActiveRecord::Base
10
+ def full_name
11
+ "#{last_name}, #{first_name}"
12
+ end
13
+ end
14
+ ```
15
+
4
16
  ## 2.4.0.pre3 - 2016-10-18
5
17
  ### Fix
6
18
  - Add missing requires
@@ -102,6 +102,13 @@ module ActiveMocker
102
102
 
103
103
  # -- END defaults -- #
104
104
 
105
+ def parent_class_constant
106
+ v = ParentClass.new(parsed_source: class_introspector.parsed_source,
107
+ klasses_to_be_mocked: klasses_to_be_mocked,
108
+ mock_append_name: mock_append_name).call
109
+ @parent_class_constant = v.parent_class
110
+ end
111
+
105
112
  def verify_class
106
113
  v = ParentClass.new(parsed_source: class_introspector.parsed_source,
107
114
  klasses_to_be_mocked: klasses_to_be_mocked,
@@ -320,13 +327,13 @@ module ActiveMocker
320
327
  end
321
328
  end
322
329
 
323
- Method = Struct.new(:name, :arguments)
330
+ Method = Struct.new(:name, :arguments, :body)
324
331
 
325
332
  module Scopes
326
333
  def scope_methods
327
334
  class_introspector.class_macros.select { |h| h.keys.first == :scope }.map do |h|
328
335
  a = h.values.first.first
329
- Method.new(a[0], ReverseParameters.new(a[1], blocks_as_values: true))
336
+ Method.new(a[0], ReverseParameters.new(a[1], blocks_as_values: true), nil)
330
337
  end
331
338
  end
332
339
  end
@@ -352,11 +359,11 @@ module ActiveMocker
352
359
 
353
360
  module DefinedMethods
354
361
  def instance_methods
355
- class_introspector
356
- .get_class
357
- .public_instance_methods(false)
358
- .sort
359
- .map { |m| create_method(m, :instance_method) }
362
+ meths = class_introspector.get_class.public_instance_methods(false).sort
363
+ if safe_methods.include?(:initialize)
364
+ meths << :initialize
365
+ end
366
+ meths.map { |m| create_method(m, :instance_method) }
360
367
  end
361
368
 
362
369
  def class_methods
@@ -369,10 +376,38 @@ module ActiveMocker
369
376
 
370
377
  private
371
378
 
379
+ def safe_methods
380
+ @safe_methods ||= class_introspector.parsed_source.comments.flat_map do |comment|
381
+ if comment.text.include?("ActiveMocker.safe_methods")
382
+ ActiveMocker.module_eval(comment.text.delete("#"))
383
+ end
384
+ end
385
+ end
386
+
387
+ module ActiveMocker
388
+ def self.safe_methods(*methods)
389
+ methods
390
+ end
391
+ end
392
+
372
393
  def create_method(m, type)
373
- Method.new(m,
374
- ReverseParameters.new(class_introspector.get_class.send(type, m).parameters,
375
- blocks_as_values: true))
394
+ if safe_methods.include?(m)
395
+ def_method = class_introspector.parsed_source.defs.detect { |meth| meth.name == m }
396
+ Method.new(
397
+ m,
398
+ def_method.arguments,
399
+ def_method.body
400
+ )
401
+ else
402
+ Method.new(
403
+ m,
404
+ ReverseParameters.new(
405
+ class_introspector.get_class.send(type, m).parameters,
406
+ blocks_as_values: true
407
+ ).parameters,
408
+ "call_mock_method(method: __method__, caller: Kernel.caller, arguments: [])"
409
+ )
410
+ end
376
411
  end
377
412
  end
378
413
 
@@ -1,10 +1,10 @@
1
1
  <% instance_methods.each do |method| -%>
2
- def <%= method.name %><%= "(#{method.arguments.parameters})" unless method.arguments.parameters.to_a.empty? %>
3
- call_mock_method(method: __method__, caller: Kernel.caller, arguments: [<%= method.arguments.arguments %>])
2
+ def <%= method.name %><%= "(#{method.arguments})" unless method.arguments.blank? %>
3
+ <%= method.body %>
4
4
  end
5
5
  <% end -%>
6
6
  <% class_methods.each do |method| -%>
7
- def self.<%= method.name %><%= "(#{method.arguments.parameters})" unless method.arguments.parameters.to_a.empty? %>
8
- call_mock_method(method: __method__, caller: Kernel.caller, arguments: [<%= method.arguments.arguments %>])
7
+ def self.<%= method.name %><%= "(#{method.arguments})" unless method.arguments.blank? %>
8
+ <%= method.body %>
9
9
  end
10
- <% end -%>
10
+ <% end -%>
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module ActiveMocker
3
- VERSION = "2.4.0.pre3"
3
+ VERSION = "2.4.0.pre4"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_mocker
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0.pre3
4
+ version: 2.4.0.pre4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dustin Zeisler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-18 00:00:00.000000000 Z
11
+ date: 2016-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -114,14 +114,14 @@ dependencies:
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: 0.5.0
117
+ version: 0.7.1
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: 0.5.0
124
+ version: 0.7.1
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: bundler
127
127
  requirement: !ruby/object:Gem::Requirement