active_mocker 1.8.3 → 1.8.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: ae00f4e9e6d46b5a085a6d536cf47b3947417f2b
4
- data.tar.gz: 24c2eb0336c786d222f9518b3f70b6a5e40c1e7f
3
+ metadata.gz: ae228af179be61ae85b6dcacebff1adbad0c2de3
4
+ data.tar.gz: d4b1cc0d7d6209bbe2ca6210534e54348746d7ef
5
5
  SHA512:
6
- metadata.gz: 47d4cdc06da8d6c3696ed5a454681367138532f1bb7101b38573849f311adbcec439b7bc046f7dd599a03cbf3e792af545ade199c2bea33467048c141e125466
7
- data.tar.gz: ae43867bd1997997f98bc607046ca7a3042d97a9950b64e27f3f64a9e7bcbcdebce7ae2faa4fb66f4c7b3efa3ca90008725b99c68ae311be44648438370f1ba9
6
+ metadata.gz: b68c2749a6ec8ef1c1617345bca88413cc22ca5f2ff4b7feadd9120d38a2dea9839fc6fc1352b336d966d93119b67b3e330d1b7d2f5dc1092bd16cf5f5e26628
7
+ data.tar.gz: 01f7f45c33a3ec713045d38114653bf5a345b27836ff9ed3ced1a222528e3d50e0cbaf5289ea426097eda7209bee880d11db22c34bc87d164f7cc45b6d57335e
data/CHANGELOG.md CHANGED
@@ -1,6 +1,11 @@
1
1
  # Changelog
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## 1.8.4 - 2015-10-06
5
+ ### Fix
6
+ - Calling scoped method that has not been stubbed raises incorrect error. https://github.com/zeisler/active_mocker/issues/22
7
+ - Not closing file stream while writing mocks. https://github.com/zeisler/active_mocker/pull/29
8
+
4
9
  ## 1.8.3 - 2015-03-03
5
10
  ### Fix
6
11
  - When AR model ended in 's' it would result in failing to create the mock file.
data/README.md CHANGED
@@ -5,13 +5,15 @@
5
5
  [![Dependency Status](https://gemnasium.com/zeisler/active_mocker.svg)](https://gemnasium.com/zeisler/active_mocker)
6
6
  [![Gitter chat](https://badges.gitter.im/zeisler/active_mocker.png)](https://gitter.im/zeisler/active_mocker)
7
7
 
8
- ActiveMocker creates mocks classes from ActiveRecord models. Allowing your test suite to run very fast by not loading Rails a database. It parses the schema.rb and the defined methods on a model then generates a ruby file that can be included within a test. The mock file can be run by themselves and come with a partial implementation of ActiveRecord. Attributes and associations can be used just the same as in ActiveRecord. Methods will have the correct arguments but raise an NotImplementedError when called. Mocks are regenerated when the schema is modified so your mocks will not go stale; preventing the case where your units tests pass but production code fails.
8
+ ActiveMocker creates mocks classes from ActiveRecord models. Allowing your test suite to run very fast by not loading Rails or a database. It parses the schema.rb and the defined methods on a model then generates a ruby file that can be included within a test. The mock file can be run by themselves and come with a partial implementation of ActiveRecord. Attributes and associations can be used just the same as in ActiveRecord. Methods will have the correct arguments but raise an NotImplementedError when called. Mocks are regenerated when the schema is modified so your mocks will not go stale; preventing the case where your units tests pass but production code fails.
9
9
 
10
10
  Examples from a real apps
11
11
 
12
12
  Finished in 1 seconds
13
13
  374 examples, 0 failures
14
14
 
15
+ ## Around the web
16
+ ["Mocking ActiveRecord with ActiveMocker" by Envy](http://madewithenvy.com/ecosystem/articles/2015/mocking-activerecord-with-activemocker/)
15
17
 
16
18
  ------------------------------------------
17
19
 
@@ -63,7 +65,7 @@ Or install it yourself as:
63
65
  $ gem install active_mocker
64
66
 
65
67
  ## Dependencies
66
- * Tested with Rails 4.0, 4.1, 4.2beta2
68
+ * Tested with Rails 4.0, 4.1, 4.2
67
69
  * Requires Ruby MRI >= 2.1.
68
70
 
69
71
 
@@ -93,7 +93,9 @@ class Generate
93
93
  end
94
94
 
95
95
  def save_mock_file(klass_str, model)
96
- File.open(File.join(Config.mock_dir, "#{model.class_name.underscore}_mock.rb"), 'w').write(klass_str)
96
+ File.open(File.join(Config.mock_dir, "#{model.class_name.underscore}_mock.rb"), 'w') do |f|
97
+ f.write(klass_str)
98
+ end
97
99
  end
98
100
 
99
101
  def generate_mock_string(model)
@@ -55,7 +55,7 @@ module ActiveMocker
55
55
 
56
56
  alias_method :stub_class_method, :mock_class_method
57
57
 
58
- def call_mock_method(method, caller, *arguments)
58
+ def call_mock_method(method:, caller:, arguments: [])
59
59
  mock_method = mockable_class_methods[method.to_sym]
60
60
  is_implemented(mock_method, method, '::', caller)
61
61
  mock_method.arguments = arguments
@@ -68,7 +68,7 @@ module ActiveMocker
68
68
 
69
69
  include InstanceAndClassMethods
70
70
 
71
- def call_mock_method(method, caller, *arguments)
71
+ def call_mock_method(method:, caller:, arguments: [])
72
72
  mock_method = mockable_instance_methods[method.to_sym]
73
73
  mock_method = self.class.send(:mockable_instance_methods)[method.to_sym] if mock_method.nil?
74
74
  is_implemented(mock_method, method, '#', caller)
@@ -152,7 +152,7 @@ class <%= class_name + @mock_append_name %> < <%= parent_class %>
152
152
 
153
153
  <% scope_methods.each do |method| -%>
154
154
  def <%= method.name %><%= "(#{method.arguments})" unless method.arguments.empty? %>
155
- ActiveMocker::LoadedMocks.find('<%= class_name %>').send(:call_mock_method, '<%= method.name %>', <%= method.arguments.passable %>)
155
+ ActiveMocker::LoadedMocks.find('<%= class_name %>').send(:call_mock_method, method: '<%= method.name %>', caller: Kernel.caller, arguments: [<%= method.arguments.passable %>])
156
156
  end
157
157
 
158
158
  <% end -%>
@@ -178,12 +178,12 @@ class <%= class_name + @mock_append_name %> < <%= parent_class %>
178
178
 
179
179
  <% instance_methods.each do |method| %>
180
180
  def <%= method.name %><%= "(#{method.arguments})" unless method.arguments.empty? %>
181
- call_mock_method :<%= method.name %>, Kernel.caller<%= ', ' unless method.arguments.empty? %><%= method.arguments.passable %>
181
+ call_mock_method(method: __method__, caller: Kernel.caller, arguments: [<%= method.arguments.passable %>])
182
182
  end
183
183
  <% end -%>
184
184
  <% class_methods.each do |method| %>
185
185
  def self.<%= method.name %><%= "(#{method.arguments})" unless method.arguments.empty? %>
186
- call_mock_method :<%= method.name %>, Kernel.caller<%= ', ' unless method.arguments.empty? %><%= method.arguments.passable %>
186
+ call_mock_method(method: __method__, caller: Kernel.caller, arguments: [<%= method.arguments.passable %>])
187
187
  end
188
188
  <% end -%>
189
189
 
@@ -269,11 +269,11 @@ module ActiveMocker
269
269
  end
270
270
 
271
271
  def to_s
272
- Reparameterize.call(arguments)
272
+ Reparameterize.method_arguments(arguments)
273
273
  end
274
274
 
275
275
  def passable
276
- Reparameterize.call(arguments, param_list: true)
276
+ Reparameterize.method_parameters(arguments)
277
277
  end
278
278
 
279
279
  end
@@ -1,40 +1,41 @@
1
1
  module ActiveMocker
2
2
  # @api private
3
- class Reparameterize
3
+ class Reparameterize
4
4
 
5
- def self.call(params, param_list:nil)
6
- return param_list(params) unless param_list.nil?
7
- method_arguments(params)
8
- end
5
+ def self.call(params, method_parameters: nil)
6
+ return method_parameters(params) unless method_parameters.nil?
7
+ method_arguments(params)
8
+ end
9
9
 
10
- def self.method_arguments(params)
11
- params.map do |state, param|
12
- case state
13
- when :req
14
- param
15
- when :rest
16
- "*#{param}"
17
- when :opt
18
- "#{param}=nil"
19
- when :keyreq
20
- "#{param}:"
21
- when :key
22
- "#{param}: nil"
23
- end
24
- end.join(', ')
10
+ # Method arguments are the real values passed to (and received by) the function.
11
+ def self.method_arguments(params)
12
+ params.map do |state, param|
13
+ case state
14
+ when :req
15
+ param
16
+ when :rest
17
+ "*#{param}"
18
+ when :opt
19
+ "#{param}=nil"
20
+ when :keyreq
21
+ "#{param}:"
22
+ when :key
23
+ "#{param}: nil"
24
+ end
25
+ end.join(', ')
26
+ end
25
27
 
26
- end
28
+ # Method parameters are the names listed in the function definition.
29
+ def self.method_parameters(params)
30
+ params.map do |state, param|
31
+ case state
32
+ when :key, :keyreq
33
+ "#{param}: #{param}"
34
+ else
35
+ param
36
+ end
37
+ end.join(', ')
38
+ end
27
39
 
28
- def self.param_list(params)
29
- params.map do |state, param|
30
- case state
31
- when :key, :keyreq
32
- "#{param}: #{param}"
33
- else
34
- param
35
- end
36
- end.join(', ')
37
40
  end
38
-
39
- end
40
41
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveMocker
2
- VERSION = "1.8.3"
2
+ VERSION = "1.8.4"
3
3
  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: 1.8.3
4
+ version: 1.8.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dustin Zeisler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-03 00:00:00.000000000 Z
11
+ date: 2015-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -276,7 +276,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
276
276
  version: '0'
277
277
  requirements: []
278
278
  rubyforge_project:
279
- rubygems_version: 2.4.5
279
+ rubygems_version: 2.2.5
280
280
  signing_key:
281
281
  specification_version: 4
282
282
  summary: Creates mocks from Active Record models. Allows your test suite to run very