immutability 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -7
- data/CHANGELOG.md +10 -0
- data/README.md +28 -2
- data/lib/immutability/rspec.rb +1 -0
- data/lib/immutability/version.rb +1 -1
- data/spec/support/frozen_double.rb +18 -0
- data/spec/support/immutable.rb +2 -4
- metadata +53 -49
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
5
|
-
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b5b988e1aad5ffa23a6021cd8ef3a93eb996a8f0
|
4
|
+
data.tar.gz: 534a78582224f3587a0e72af50423c40d10fc9ad
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 50569698c05f0ff753b6a865c12aa2241653fa966fcf8404aba2781bf0c0553755520aeb7c02e4bcd5a7c4d4fb6508861a4af8beba4c595dcbb37075ff96fb49
|
7
|
+
data.tar.gz: 76ba454dc1c64cabefe26ad0baa6a584473564cc0ff234862e86a234655f3b400405ba6e0047f0411a6c7952679847c83e34c0b4866bb8b1c78d95bb6af6ae1f
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
## v0.0.4 2015-09-10
|
2
|
+
|
3
|
+
The small release (backward-compatible) adds `frozen_double` to rspec helper methods.
|
4
|
+
|
5
|
+
### Added
|
6
|
+
|
7
|
+
- The `frozen_double` helper for attributes of immutable objects' initializers (nepalez)
|
8
|
+
|
9
|
+
[Compare v0.0.3...v0.0.4](https://github.com/nepalez/immutability/compare/v0.0.3...v0.0.4)
|
10
|
+
|
1
11
|
## v0.0.3 2015-09-25
|
2
12
|
|
3
13
|
The patch fixes bug in matcher that broke gems:
|
data/README.md
CHANGED
@@ -141,8 +141,10 @@ reborn_andrew.version # => 0
|
|
141
141
|
reborn_andrew.parent # => nil
|
142
142
|
```
|
143
143
|
|
144
|
-
RSpec
|
145
|
-
|
144
|
+
RSpec
|
145
|
+
-----
|
146
|
+
|
147
|
+
### be_immutable
|
146
148
|
|
147
149
|
Include `immutability/rspec` and use `be_immutable` RSpec matcher to check, whether an instance is deeply immutable (with all its variables):
|
148
150
|
|
@@ -158,6 +160,30 @@ end
|
|
158
160
|
|
159
161
|
The matcher will pass if both the object and all its variables are immutable at any level of nesting.
|
160
162
|
|
163
|
+
### frozen_double
|
164
|
+
|
165
|
+
Initializers of immutable objects freeze their variables deeply. When you send doubles as arguments for this initializer, RSpec will warn you about trying to freeze that double. To avoid the problem, use `frozen_double` instead of `double`:
|
166
|
+
|
167
|
+
```ruby
|
168
|
+
include "immutability/rspec"
|
169
|
+
|
170
|
+
describe User, "#name" do
|
171
|
+
subject { User.new(name, 44).name }
|
172
|
+
|
173
|
+
let(:name) { frozen_double :name, to_s: "Andrew" }
|
174
|
+
|
175
|
+
it { is_expected.to eql "Andrew" }
|
176
|
+
end
|
177
|
+
```
|
178
|
+
|
179
|
+
The method returns an rspec double with two methods added:
|
180
|
+
|
181
|
+
```ruby
|
182
|
+
name = frozen_double :name, to_s: "Andrew"
|
183
|
+
name.frozen? # => true
|
184
|
+
name.freeze == name # => true
|
185
|
+
```
|
186
|
+
|
161
187
|
Installation
|
162
188
|
------------
|
163
189
|
|
data/lib/immutability/rspec.rb
CHANGED
data/lib/immutability/version.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
RSpec.configure do |config|
|
4
|
+
mod = Module.new do
|
5
|
+
# Returns the double with +#frozen?+ and +#freeze+ methods defined
|
6
|
+
#
|
7
|
+
def frozen_double(*args)
|
8
|
+
options = args.pop if args.last.instance_of?(Hash)
|
9
|
+
name = args.first
|
10
|
+
instance = double name, options.merge(frozen?: true)
|
11
|
+
allow(instance).to receive(:freeze).and_return(instance)
|
12
|
+
|
13
|
+
instance
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
config.include mod
|
18
|
+
end
|
data/spec/support/immutable.rb
CHANGED
@@ -13,14 +13,12 @@ RSpec::Matchers.define :be_immutable do
|
|
13
13
|
return false if value.nil?
|
14
14
|
return false if value.equal? true
|
15
15
|
return false if value.equal? false
|
16
|
-
return false
|
16
|
+
return false unless value.class.respond_to?(:new)
|
17
17
|
true
|
18
18
|
end
|
19
19
|
|
20
20
|
match do |instance|
|
21
|
-
if can_be_frozen?
|
22
|
-
expect(instance).to be_frozen
|
23
|
-
end
|
21
|
+
expect(instance).to be_frozen if can_be_frozen?(instance)
|
24
22
|
|
25
23
|
if instance.is_a? Hash
|
26
24
|
instance.each do |k, v|
|
metadata
CHANGED
@@ -1,53 +1,58 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: immutability
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
|
-
authors:
|
6
|
+
authors:
|
7
7
|
- Andrew Kozin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
- !ruby/object:Gem::Dependency
|
11
|
+
date: 2015-10-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
15
14
|
name: ice_nine
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Version
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
21
19
|
version: 0.11.1
|
22
20
|
type: :runtime
|
23
|
-
version_requirements: *id001
|
24
|
-
- !ruby/object:Gem::Dependency
|
25
|
-
name: hexx-rspec
|
26
21
|
prerelease: false
|
27
|
-
|
28
|
-
requirements:
|
29
|
-
- - ~>
|
30
|
-
- !ruby/object:Gem::Version
|
31
|
-
version:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.11.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: hexx-rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.5'
|
32
34
|
type: :development
|
33
|
-
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.5'
|
34
41
|
description:
|
35
42
|
email: andrew.kozin@gmail.com
|
36
43
|
executables: []
|
37
|
-
|
38
44
|
extensions: []
|
39
|
-
|
40
|
-
extra_rdoc_files:
|
45
|
+
extra_rdoc_files:
|
41
46
|
- README.md
|
42
47
|
- LICENSE
|
43
|
-
files:
|
44
|
-
- .coveralls.yml
|
45
|
-
- .gitignore
|
46
|
-
- .metrics
|
47
|
-
- .rspec
|
48
|
-
- .rubocop.yml
|
49
|
-
- .travis.yml
|
50
|
-
- .yardopts
|
48
|
+
files:
|
49
|
+
- ".coveralls.yml"
|
50
|
+
- ".gitignore"
|
51
|
+
- ".metrics"
|
52
|
+
- ".rspec"
|
53
|
+
- ".rubocop.yml"
|
54
|
+
- ".travis.yml"
|
55
|
+
- ".yardopts"
|
51
56
|
- CHANGELOG.md
|
52
57
|
- Gemfile
|
53
58
|
- Guardfile
|
@@ -73,42 +78,41 @@ files:
|
|
73
78
|
- lib/immutability/with_memory.rb
|
74
79
|
- spec/shared/user.rb
|
75
80
|
- spec/spec_helper.rb
|
81
|
+
- spec/support/frozen_double.rb
|
76
82
|
- spec/support/immutable.rb
|
77
83
|
- spec/unit/immutability/object_spec.rb
|
78
84
|
- spec/unit/immutability/with_memory_spec.rb
|
79
85
|
- spec/unit/immutability_spec.rb
|
80
86
|
homepage: https://github.com/nepalez/immutability
|
81
|
-
licenses:
|
87
|
+
licenses:
|
82
88
|
- MIT
|
83
89
|
metadata: {}
|
84
|
-
|
85
90
|
post_install_message:
|
86
91
|
rdoc_options: []
|
87
|
-
|
88
|
-
require_paths:
|
92
|
+
require_paths:
|
89
93
|
- lib
|
90
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
-
requirements:
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
92
96
|
- - ">="
|
93
|
-
- !ruby/object:Gem::Version
|
97
|
+
- !ruby/object:Gem::Version
|
94
98
|
version: 1.9.3
|
95
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
-
requirements:
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
97
101
|
- - ">="
|
98
|
-
- !ruby/object:Gem::Version
|
99
|
-
version:
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
100
104
|
requirements: []
|
101
|
-
|
102
105
|
rubyforge_project:
|
103
|
-
rubygems_version: 2.4.
|
106
|
+
rubygems_version: 2.4.8
|
104
107
|
signing_key:
|
105
108
|
specification_version: 4
|
106
109
|
summary: Make instances immutable (deeply frozen) and versioned
|
107
|
-
test_files:
|
110
|
+
test_files:
|
108
111
|
- spec/spec_helper.rb
|
109
112
|
- spec/unit/immutability_spec.rb
|
110
|
-
- spec/support/immutable.rb
|
111
|
-
- spec/shared/user.rb
|
112
113
|
- spec/unit/immutability/object_spec.rb
|
113
114
|
- spec/unit/immutability/with_memory_spec.rb
|
115
|
+
- spec/support/frozen_double.rb
|
116
|
+
- spec/support/immutable.rb
|
117
|
+
- spec/shared/user.rb
|
114
118
|
has_rdoc:
|