active_mocker 2.3.4 → 2.4.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +21 -4
- data/README.md +16 -0
- data/lib/active_mocker/loaded_mocks.rb +6 -0
- data/lib/active_mocker/loaded_mocks/features.rb +52 -0
- data/lib/active_mocker/mock/base.rb +18 -0
- data/lib/active_mocker/mock/collection.rb +1 -1
- data/lib/active_mocker/rspec_helper.rb +8 -0
- data/lib/active_mocker/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d76ea3471b67a416239349d655e5e3e9061e2cf3
|
4
|
+
data.tar.gz: 1f10949f52554aa237ae3cf60ed7e7b56cc0c2fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 357f966e759449cf9ae50fba27ac6f319ddee7d06f719a3c5311c33666f6b385ed0291238c2f516b20d3baf9d171b96c6ae0030865839ff94379b0039882423e
|
7
|
+
data.tar.gz: f056acf32872ddcb7ec7c3f349241c7a93c459b8abf70cc14b3da61de3d1f0f5e982c4d97ddd33bc69d6ba9775f99ebdf38dd5f7b8e49bafb064eec0eef0cdc2
|
data/CHANGELOG.md
CHANGED
@@ -1,10 +1,27 @@
|
|
1
1
|
# Changelog
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
-
## 2.
|
5
|
-
###
|
6
|
-
-
|
7
|
-
|
4
|
+
## 2.4.0.pre1 - 2016-10-13
|
5
|
+
### Enhancement
|
6
|
+
- Option to delete all records before each example
|
7
|
+
It can be enabled for specific test context.
|
8
|
+
```ruby
|
9
|
+
before(:all) { active_mocker.features.enable(:delete_all_before_example) }
|
10
|
+
after(:all) { active_mocker.features.disable(:delete_all_before_example) }
|
11
|
+
```
|
12
|
+
|
13
|
+
Or it can be enabled as the default
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
ActiveMocker::LoadedMocks.features.enable(:delete_all_before_example)
|
17
|
+
```
|
18
|
+
|
19
|
+
- Option to enable timestamps
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
ActiveMocker::LoadedMocks.features.enable(:timestamps)
|
23
|
+
```
|
24
|
+
|
8
25
|
## 2.3.3 - 2016-10-13
|
9
26
|
### Enhancement
|
10
27
|
- Auto stubbing of ActiveRecord::RecordNotFound with requiring "active_mocker/rspec_helper"
|
data/README.md
CHANGED
@@ -25,6 +25,7 @@ Examples from a real apps
|
|
25
25
|
* [Generate](#generate_mocks)
|
26
26
|
* [Dependencies](#dependencies)
|
27
27
|
* [Usage](#usage)
|
28
|
+
* [Optional Features](#optional-features)
|
28
29
|
* [Mocking Methods](#mocking-methods)
|
29
30
|
* [Managing Mocks](#managing-mocks)
|
30
31
|
* [ActiveRecord supported methods](#activerecord-supported-methods)
|
@@ -188,6 +189,21 @@ This give the full query API (ie. find_by, where, etc).
|
|
188
189
|
This is not feature available in ActiveRecord as such do not include this where you intend to swap in ActiveRecord.
|
189
190
|
|
190
191
|
|
192
|
+
## Optional Features
|
193
|
+
|
194
|
+
Use theses defaults if you are starting fresh
|
195
|
+
|
196
|
+
```ruby
|
197
|
+
ActiveMocker::LoadedMocks.features.enable(:timestamps)
|
198
|
+
ActiveMocker::LoadedMocks.features.enable(:delete_all_before_example)
|
199
|
+
```
|
200
|
+
|
201
|
+
### timestamps
|
202
|
+
Enables created_at and updated_at to be update on save and create
|
203
|
+
|
204
|
+
### delete_all_before_example
|
205
|
+
When using "active_mocker/rspec_helper" it delete all records from all mocks before each example.
|
206
|
+
|
191
207
|
## Mocking Methods
|
192
208
|
|
193
209
|
#### Rspec 3 Mocks - verify double
|
@@ -1,4 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
require_relative "loaded_mocks/features"
|
3
|
+
|
2
4
|
module ActiveMocker
|
3
5
|
class LoadedMocks
|
4
6
|
class << self
|
@@ -25,6 +27,10 @@ module ActiveMocker
|
|
25
27
|
# @deprecated Use {#delete_all} instead of this method.
|
26
28
|
alias clear_all delete_all
|
27
29
|
|
30
|
+
def features
|
31
|
+
@features ||= Features.instance
|
32
|
+
end
|
33
|
+
|
28
34
|
class Collection
|
29
35
|
include Enumerable
|
30
36
|
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "singleton"
|
3
|
+
|
4
|
+
module ActiveMocker
|
5
|
+
class LoadedMocks
|
6
|
+
class Features
|
7
|
+
include Singleton
|
8
|
+
DEFAULTS = {
|
9
|
+
timestamps: false,
|
10
|
+
delete_all_before_example: false,
|
11
|
+
}.freeze
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
reset
|
15
|
+
end
|
16
|
+
|
17
|
+
def each(&block)
|
18
|
+
@features.each(&block)
|
19
|
+
end
|
20
|
+
|
21
|
+
def enable(feature)
|
22
|
+
update(feature, true)
|
23
|
+
end
|
24
|
+
|
25
|
+
def disable(feature)
|
26
|
+
update(feature, false)
|
27
|
+
end
|
28
|
+
|
29
|
+
def [](feature)
|
30
|
+
@features[feature]
|
31
|
+
end
|
32
|
+
|
33
|
+
def reset
|
34
|
+
@features = DEFAULTS.dup
|
35
|
+
end
|
36
|
+
|
37
|
+
def to_h
|
38
|
+
@features
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def update(feature, value)
|
44
|
+
if @features.key?(feature)
|
45
|
+
@features[feature] = value
|
46
|
+
else
|
47
|
+
raise KeyError, "#{feature} is not an available feature."
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -37,7 +37,9 @@ module ActiveMocker
|
|
37
37
|
attributes.collect { |attr| create(attr, &block) }
|
38
38
|
else
|
39
39
|
record = new(id: attributes.delete(:id) || attributes.delete("id"))
|
40
|
+
|
40
41
|
record.save
|
42
|
+
record.touch(:created_at, :created_on) if ActiveMocker::LoadedMocks.features[:timestamps]
|
41
43
|
record.assign_attributes(attributes, &block)
|
42
44
|
record._create_caller_locations = caller_locations
|
43
45
|
record
|
@@ -228,11 +230,27 @@ module ActiveMocker
|
|
228
230
|
|
229
231
|
def save(*_args)
|
230
232
|
self.class.send(:insert, self) unless self.class.exists?(self)
|
233
|
+
touch if ActiveMocker::LoadedMocks.features[:timestamps]
|
231
234
|
true
|
232
235
|
end
|
233
236
|
|
234
237
|
alias save! save
|
235
238
|
|
239
|
+
def touch(*names)
|
240
|
+
raise ActiveMocker::Error, "cannot touch on a new record object" unless persisted?
|
241
|
+
|
242
|
+
attributes = [:updated_at, :update_on]
|
243
|
+
attributes.concat(names)
|
244
|
+
|
245
|
+
current_time = Time.now.utc
|
246
|
+
|
247
|
+
attributes.each do |column|
|
248
|
+
column = column.to_s
|
249
|
+
write_attribute(column, current_time) if self.class.attribute_names.include?(column)
|
250
|
+
end
|
251
|
+
true
|
252
|
+
end
|
253
|
+
|
236
254
|
def records
|
237
255
|
self.class.send(:records)
|
238
256
|
end
|
@@ -19,4 +19,12 @@ RSpec.configure do |config|
|
|
19
19
|
config.before(:all, active_mocker: true) do
|
20
20
|
ActiveMocker::LoadedMocks.delete_all
|
21
21
|
end
|
22
|
+
|
23
|
+
config.after(:each, active_mocker: true) do
|
24
|
+
ActiveMocker::LoadedMocks.delete_all if active_mocker.features[:delete_all_before_example]
|
25
|
+
end
|
26
|
+
|
27
|
+
config.before(:each, active_mocker: true) do
|
28
|
+
ActiveMocker::LoadedMocks.delete_all if active_mocker.features[:delete_all_before_example]
|
29
|
+
end
|
22
30
|
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
|
+
version: 2.4.0.pre1
|
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-
|
11
|
+
date: 2016-10-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -202,6 +202,7 @@ files:
|
|
202
202
|
- lib/active_mocker/inspectable/struct.rb
|
203
203
|
- lib/active_mocker/inspectable/time.rb
|
204
204
|
- lib/active_mocker/loaded_mocks.rb
|
205
|
+
- lib/active_mocker/loaded_mocks/features.rb
|
205
206
|
- lib/active_mocker/mock.rb
|
206
207
|
- lib/active_mocker/mock/alias_attribute.rb
|
207
208
|
- lib/active_mocker/mock/association.rb
|
@@ -256,9 +257,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
256
257
|
version: '2.1'
|
257
258
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
258
259
|
requirements:
|
259
|
-
- - "
|
260
|
+
- - ">"
|
260
261
|
- !ruby/object:Gem::Version
|
261
|
-
version:
|
262
|
+
version: 1.3.1
|
262
263
|
requirements: []
|
263
264
|
rubyforge_project:
|
264
265
|
rubygems_version: 2.5.1
|