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 CHANGED
@@ -1,7 +1,7 @@
1
- ---
2
- SHA1:
3
- metadata.gz: f8d657925469b79af0254ac672766659aad0406d
4
- data.tar.gz: 9f00806f764b8f16ae948453f212347d29d0939d
5
- SHA512:
6
- metadata.gz: 77ba2967808ef4d0ef6904209edd9ef490dc171de94f55933d80e816305320c0118f65540c375bdba416139f76d548b1b9477f3da9e84a0875247f6c7b12a7f3
7
- data.tar.gz: f2bad0c884a0591e27c44d6dc5df7a2ff4eacbddb007afbb668f1a33ecfb6b323151b6e84670296162c4e968bec098f1e282160b6a48362fc59ac4965a1d1054
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 helper
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
 
@@ -2,3 +2,4 @@
2
2
 
3
3
  # Loads spec matcher to check the immutability
4
4
  require_relative "../../spec/support/immutable"
5
+ require_relative "../../spec/support/frozen_double"
@@ -4,6 +4,6 @@ module Immutability
4
4
 
5
5
  # The semantic version of the gem.
6
6
  # @see http://semver.org/ Semantic versioning 2.0
7
- VERSION = "0.0.3".freeze
7
+ VERSION = "0.0.4".freeze
8
8
 
9
9
  end # module Immutability
@@ -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
@@ -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 if !value.class.respond_to?(:new)
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? instance
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
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
- date: 2015-09-24 00:00:00 Z
13
- dependencies:
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
- prerelease: false
17
- requirement: &id001 !ruby/object:Gem::Requirement
18
- requirements:
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
- requirement: &id002 !ruby/object:Gem::Requirement
28
- requirements:
29
- - - ~>
30
- - !ruby/object:Gem::Version
31
- version: "0.5"
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
- version_requirements: *id002
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: "0"
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
100
104
  requirements: []
101
-
102
105
  rubyforge_project:
103
- rubygems_version: 2.4.6
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: