anima 0.3.1 → 0.3.2

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
  SHA256:
3
- metadata.gz: e28b3bf5fb2361a433db0d65938c2a5880921fcffd122e56da5e2a81d4c3bcbd
4
- data.tar.gz: 4966ec506c17918b5c2d05ca6c4f41cf02b8227bb18c50dc41edbbce0b098bb4
3
+ metadata.gz: 56e64bf9fa6d98eacb6fbee0c76efd33a60e7493bff45d1672ae5c2f16dcb69d
4
+ data.tar.gz: 560ecd27777601ad003518606d67031875c8cf58f337054d39d89ae1eb5815ee
5
5
  SHA512:
6
- metadata.gz: afcb05d47ba54ade5f45f889221fba44c64864d60021e74471a5b4f13c760d379295487a3f7165bfcf08272424be9f7daac49773908657823fe4fd427c5f0e29
7
- data.tar.gz: b884903b68754c6f1afbc64ab2df7baab2c74db82462ed46ed54fd2c4b00db11b6ef418617691a78c490ce00642d58f7ed806b8750ceb495c547f08d4a03cc58
6
+ metadata.gz: 69d90b65d31f7214b28a9b2b70dd6f9f9248adca8c95438d41b172971548fca719bc8421e227a4c21dcb7472c51edecf79103c2bbb9c0f05195bfd8bf44c4d6f
7
+ data.tar.gz: 7cfdcef4ca9bbc3f82e43530885643af1a9c5ea87cc77014c883714aead23ff47091c8265ea3b626914d439e3b5b37417eb01d5051c8c44f436324c154f4d469
data/README.md CHANGED
@@ -1,10 +1,7 @@
1
1
  anima
2
2
  =====
3
3
 
4
- [![Build Status](https://secure.travis-ci.org/mbj/anima.png?branch=master)](http://travis-ci.org/mbj/anima)
5
- [![Dependency Status](https://gemnasium.com/mbj/anima.png)](https://gemnasium.com/mbj/anima)
6
- [![Code Climate](https://codeclimate.com/github/mbj/anima.png)](https://codeclimate.com/github/mbj/anima)
7
- [![Gem Version](https://img.shields.io/gem/v/anima.svg)](https://rubygems.org/gems/anima)
4
+ ![CI](https://github.com/mbj/anima/workflows/CI/badge.svg)
8
5
 
9
6
  Simple library to declare read only attributes on value-objects that are initialized via attributes hash.
10
7
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: anima
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Markus Schirp
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-15 00:00:00.000000000 Z
11
+ date: 2020-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: adamantium
@@ -58,50 +58,30 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.1.23
61
+ version: 0.1.24
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 0.1.23
69
- description:
68
+ version: 0.1.24
69
+ description:
70
70
  email: mbj@schirp-dso.com
71
71
  executables: []
72
72
  extensions: []
73
73
  extra_rdoc_files:
74
74
  - README.md
75
75
  files:
76
- - ".circleci/config.yml"
77
- - ".gitignore"
78
- - ".rspec"
79
- - ".rubocop.yml"
80
- - ".travis.yml"
81
- - Changelog.md
82
- - Gemfile
83
76
  - README.md
84
- - Rakefile
85
- - anima.gemspec
86
- - config/flay.yml
87
- - config/flog.yml
88
- - config/mutant.yml
89
- - config/reek.yml
90
- - config/rubocop.yml
91
- - config/yardstick.yml
92
77
  - lib/anima.rb
93
78
  - lib/anima/attribute.rb
94
79
  - lib/anima/error.rb
95
- - spec/integration/simple_spec.rb
96
- - spec/spec_helper.rb
97
- - spec/unit/anima/attribute_spec.rb
98
- - spec/unit/anima/error_spec.rb
99
- - spec/unit/anima_spec.rb
100
80
  homepage: http://github.com/mbj/anima
101
81
  licenses:
102
82
  - MIT
103
83
  metadata: {}
104
- post_install_message:
84
+ post_install_message:
105
85
  rdoc_options: []
106
86
  require_paths:
107
87
  - lib
@@ -116,13 +96,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
96
  - !ruby/object:Gem::Version
117
97
  version: '0'
118
98
  requirements: []
119
- rubygems_version: 3.0.1
120
- signing_key:
99
+ rubygems_version: 3.1.2
100
+ signing_key:
121
101
  specification_version: 4
122
102
  summary: Initialize object attributes via attributes hash
123
- test_files:
124
- - spec/integration/simple_spec.rb
125
- - spec/spec_helper.rb
126
- - spec/unit/anima/attribute_spec.rb
127
- - spec/unit/anima/error_spec.rb
128
- - spec/unit/anima_spec.rb
103
+ test_files: []
@@ -1,32 +0,0 @@
1
- defaults: &defaults
2
- working_directory: ~/anima
3
- docker:
4
- - image: circleci/ruby:2.6.0
5
- version: 2
6
- jobs:
7
- unit_specs:
8
- <<: *defaults
9
- steps:
10
- - checkout
11
- - run: bundle install
12
- - run: bundle exec rspec spec/unit
13
- metrics:
14
- <<: *defaults
15
- steps:
16
- - checkout
17
- - run: bundle install
18
- - run: bundle exec rake metrics:rubocop
19
- - run: bundle exec rake metrics:reek
20
- mutant:
21
- <<: *defaults
22
- steps:
23
- - checkout
24
- - run: bundle install
25
- - run: bundle exec rake metrics:mutant
26
- workflows:
27
- version: 2
28
- test:
29
- jobs:
30
- - unit_specs
31
- - metrics
32
- - mutant
data/.gitignore DELETED
@@ -1,5 +0,0 @@
1
- /.rspec
2
- /Gemfile.lock
3
- /.rbx
4
- /.bundle
5
- /vendor
@@ -1,6 +0,0 @@
1
- AllCops:
2
- Include:
3
- - 'Gemfile'
4
- Exclude:
5
- - 'Gemfile.devtools'
6
- - 'vendor/**/*'
@@ -1,11 +0,0 @@
1
- language: ruby
2
- cache: bundler
3
- bundler_args: --without yard guard benchmarks
4
- script: "bundle exec rake ci:metrics"
5
- rvm:
6
- - '2.1'
7
- - '2.2'
8
- matrix:
9
- allowed_failures:
10
- - jruby # Travis jruby does not run in >= 2.1 ruby yet
11
- - rbx # segfault
@@ -1,53 +0,0 @@
1
- # v0.3.1 2018-02-15
2
-
3
- * Fix falsy key match detection
4
-
5
- # v0.3.0 2015-09-04
6
-
7
- Changes:
8
-
9
- * Drop support for ruby < 2.1
10
- * Drop support for Anima::Update
11
- * Add #with as a replacement that is active by default [#13]
12
-
13
- # v0.2.1 2014-04-10
14
-
15
- Changes:
16
-
17
- * Require ruby version >= 1.9.3 in gemspec.
18
-
19
- # v0.2.0 2014-01-13
20
-
21
- Breaking changes:
22
-
23
- * Remove AnimaInfectedClass.attributes_hash(instance)
24
- * Replace with AnimaInfectedClass#to_h
25
-
26
- # v0.1.1 2013-09-08
27
-
28
- * [change] Refactor internals.
29
-
30
- # v0.1.0 2013-09-08
31
-
32
- * [change] Update dependencies
33
-
34
- # v0.0.6 2013-02-18
35
-
36
- * [add] Support for updates via Anima::Update mixin
37
- * [change] Update dependencies
38
-
39
- # v0.0.5 2013-02-17
40
-
41
- * [changed] Update dependencies
42
-
43
- # v0.0.4 2013-01-21
44
-
45
- * [changed] Update dependencies
46
-
47
- # v0.0.3 2012-12-13
48
-
49
- * [changed] Use the attributes_hash naming consistently.
50
-
51
- # v0.0.2 2012-12-13
52
-
53
- First public release!
data/Gemfile DELETED
@@ -1,3 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
data/Rakefile DELETED
@@ -1,19 +0,0 @@
1
- require 'devtools'
2
- Devtools.init_rake_tasks
3
-
4
- Rake.application.load_imports
5
- task('metrics:mutant').clear
6
-
7
- namespace :metrics do
8
- task :mutant => :coverage do
9
- system(*%w[
10
- bundle exec mutant
11
- --include lib
12
- --require anima
13
- --use rspec
14
- --zombie
15
- --
16
- Anima*
17
- ]) or fail "Mutant task failed"
18
- end
19
- end
@@ -1,23 +0,0 @@
1
- Gem::Specification.new do |s|
2
- s.name = 'anima'
3
- s.version = '0.3.1'
4
-
5
- s.authors = ['Markus Schirp']
6
- s.email = 'mbj@schirp-dso.com'
7
- s.summary = 'Initialize object attributes via attributes hash'
8
- s.homepage = 'http://github.com/mbj/anima'
9
- s.license = 'MIT'
10
-
11
- s.files = `git ls-files`.split("\n")
12
- s.test_files = `git ls-files -- {spec,features}/*`.split("\n")
13
- s.require_paths = %w(lib)
14
- s.extra_rdoc_files = %w(README.md)
15
-
16
- s.required_ruby_version = '>= 2.1.0'
17
-
18
- s.add_dependency('adamantium', '~> 0.2')
19
- s.add_dependency('equalizer', '~> 0.0.11')
20
- s.add_dependency('abstract_type', '~> 0.0.7')
21
-
22
- s.add_development_dependency('devtools', '~> 0.1.23')
23
- end
@@ -1,3 +0,0 @@
1
- ---
2
- threshold: 6
3
- total_score: 29
@@ -1,2 +0,0 @@
1
- ---
2
- threshold: 11.9
@@ -1,4 +0,0 @@
1
- ---
2
- name: anima
3
- namespace: Anima
4
- zombify: true
@@ -1,98 +0,0 @@
1
- ---
2
- detectors:
3
- UncommunicativeParameterName:
4
- accept: []
5
- exclude: []
6
- enabled: true
7
- reject:
8
- - '/^.$/'
9
- - '/[0-9]$/'
10
- - '/[A-Z]/'
11
- TooManyMethods:
12
- max_methods: 9
13
- exclude: []
14
- enabled: true
15
- UncommunicativeMethodName:
16
- accept: []
17
- exclude: []
18
- enabled: true
19
- reject:
20
- - '/^[a-z]$/'
21
- - '/[0-9]$/'
22
- - '/[A-Z]/'
23
- LongParameterList:
24
- max_params: 2 # TODO: decrease max_params to 2
25
- exclude:
26
- - Anima::Error#initialize # 3 params
27
- enabled: true
28
- overrides: {}
29
- FeatureEnvy:
30
- exclude:
31
- - Anima#attributes_hash
32
- enabled: true
33
- ClassVariable:
34
- exclude: []
35
- enabled: true
36
- BooleanParameter:
37
- exclude: []
38
- enabled: true
39
- # Buggy like hell
40
- IrresponsibleModule:
41
- exclude: []
42
- enabled: false
43
- UncommunicativeModuleName:
44
- accept: []
45
- exclude: []
46
- enabled: true
47
- reject:
48
- - '/^.$/'
49
- - '/[0-9]$/'
50
- NestedIterators:
51
- ignore_iterators: []
52
- exclude:
53
- - Anima::Attribute#define_reader # 2 levels
54
- - Anima#included # 2 levels
55
- enabled: true
56
- max_allowed_nesting: 1
57
- TooManyStatements:
58
- max_statements: 7 # TODO: decrease max_statements to 5 or less
59
- exclude: []
60
- enabled: true
61
- DuplicateMethodCall:
62
- allow_calls: []
63
- exclude: []
64
- enabled: true
65
- max_calls: 1
66
- UtilityFunction:
67
- exclude: []
68
- enabled: true
69
- Attribute:
70
- exclude: []
71
- enabled: false
72
- UncommunicativeVariableName:
73
- accept: []
74
- exclude: []
75
- enabled: true
76
- reject:
77
- - '/^.$/'
78
- - '/[0-9]$/'
79
- - '/[A-Z]/'
80
- RepeatedConditional:
81
- exclude: []
82
- enabled: true
83
- max_ifs: 1
84
- DataClump:
85
- exclude: []
86
- enabled: true
87
- max_copies: 1
88
- min_clump_size: 3
89
- ControlParameter:
90
- exclude: []
91
- enabled: true
92
- LongYieldList:
93
- max_params: 1
94
- exclude: []
95
- enabled: true
96
- # Thats the whole point of this lib, oOo.
97
- ModuleInitialize:
98
- enabled: false
@@ -1,137 +0,0 @@
1
- inherit_from: ../.rubocop.yml
2
-
3
- # Avoid parameter lists longer than five parameters.
4
- ParameterLists:
5
- Max: 3
6
- CountKeywordArgs: true
7
-
8
- # Avoid more than `Max` levels of nesting.
9
- BlockNesting:
10
- Max: 3
11
-
12
- # Align with the style guide.
13
- CollectionMethods:
14
- PreferredMethods:
15
- collect: 'map'
16
- inject: 'reduce'
17
- find: 'detect'
18
- find_all: 'select'
19
- Exclude:
20
- # The Pathname#find method is mistakenly identified as Enumberable#find
21
- - lib/tasks/assets_precompile_nodigest.rake
22
-
23
- # Do not force public/protected/private keyword to be indented at the same
24
- # level as the def keyword. My personal preference is to outdent these keywords
25
- # because I think when scanning code it makes it easier to identify the
26
- # sections of code and visually separate them. When the keyword is at the same
27
- # level I think it sort of blends in with the def keywords and makes it harder
28
- # to scan the code and see where the sections are.
29
- AccessModifierIndentation:
30
- Enabled: false
31
-
32
- # Limit line length
33
- LineLength:
34
- Max: 79
35
-
36
- # Disable documentation checking until a class needs to be documented once
37
- Documentation:
38
- Enabled: false
39
-
40
- # Do not always use &&/|| instead of and/or.
41
- AndOr:
42
- Enabled: false
43
-
44
- # Do not favor modifier if/unless usage when you have a single-line body
45
- IfUnlessModifier:
46
- Enabled: false
47
-
48
- # Allow case equality operator (in limited use within the specs)
49
- CaseEquality:
50
- Enabled: false
51
-
52
- # Constants do not always have to use SCREAMING_SNAKE_CASE
53
- ConstantName:
54
- Enabled: false
55
-
56
- # Not all trivial readers/writers can be defined with attr_* methods
57
- TrivialAccessors:
58
- Enabled: false
59
-
60
- # Allow empty lines around class body
61
- EmptyLinesAroundClassBody:
62
- Enabled: false
63
-
64
- # Allow empty lines around module body
65
- EmptyLinesAroundModuleBody:
66
- Enabled: false
67
-
68
- # Allow empty lines around block body
69
- EmptyLinesAroundBlockBody:
70
- Enabled: false
71
-
72
- # Allow multiple line operations to not require indentation
73
- MultilineOperationIndentation:
74
- Enabled: false
75
-
76
- # Prefer String#% over Kernel#sprintf
77
- FormatString:
78
- Enabled: false
79
-
80
- # Use square brackets for literal Array objects
81
- PercentLiteralDelimiters:
82
- PreferredDelimiters:
83
- '%': '{}'
84
- '%i': '[]'
85
- '%q': ()
86
- '%Q': ()
87
- '%r': '{}'
88
- '%s': ()
89
- '%w': '[]'
90
- '%W': '[]'
91
- '%x': ()
92
-
93
- # Use %i[...] for arrays of symbols
94
- SymbolArray:
95
- Enabled: true
96
-
97
- # Align if/else blocks with the variable assignment
98
- EndAlignment:
99
- EnforcedStyleAlignWith: variable
100
-
101
- # Do not always align parameters when it is easier to read
102
- AlignParameters:
103
- Exclude:
104
- - spec/**/*_spec.rb
105
-
106
- # Prefer #kind_of? over #is_a?
107
- ClassCheck:
108
- EnforcedStyle: kind_of?
109
-
110
- # Do not prefer double quotes to be used when %q or %Q is more appropriate
111
- UnneededPercentQ:
112
- Enabled: false
113
-
114
- # Allow a maximum ABC score
115
- Metrics/AbcSize:
116
- Max: 21.02
117
-
118
- # Do not prefer lambda.call(...) over lambda.(...)
119
- LambdaCall:
120
- Enabled: false
121
-
122
- # Buggy cop, returns false positive for our code base
123
- NonLocalExitFromIterator:
124
- Enabled: false
125
-
126
- # To allow alignment of similar expressions we want to allow more than one
127
- # space around operators:
128
- #
129
- # let(:a) { bar + something }
130
- # let(:b) { foobar + something }
131
- #
132
- SpaceAroundOperators:
133
- Enabled: false
134
-
135
- # We use parallel assignments with great success
136
- ParallelAssignment:
137
- Enabled: false
@@ -1,2 +0,0 @@
1
- ---
2
- threshold: 100
@@ -1,47 +0,0 @@
1
- class TestClass
2
- include Anima.new(:firstname, :lastname)
3
- end
4
-
5
- describe Anima, 'simple integration' do
6
- subject { TestClass.new(attributes) }
7
-
8
- context 'when instantiated with all attributes' do
9
- let(:attributes) do
10
- {
11
- firstname: 'Markus',
12
- lastname: 'Schirp'
13
- }
14
- end
15
-
16
- its(:firstname) { should eql('Markus') }
17
- its(:lastname) { should eql('Schirp') }
18
- end
19
-
20
- context 'with instantiated with extra attributes' do
21
- let(:attributes) do
22
- {
23
- firstname: 'Markus',
24
- lastname: 'Schirp',
25
- extra: 'Foo'
26
- }
27
- end
28
-
29
- it 'should raise error' do
30
- expect { subject }.to raise_error(
31
- Anima::Error,
32
- 'TestClass attributes missing: [], unknown: [:extra]'
33
- )
34
- end
35
- end
36
-
37
- context 'when instantiated with missing attributes' do
38
- let(:attributes) { {} }
39
-
40
- it 'should raise error' do
41
- expect { subject }.to raise_error(
42
- Anima::Error,
43
- 'TestClass attributes missing: [:firstname, :lastname], unknown: []'
44
- )
45
- end
46
- end
47
- end
@@ -1,2 +0,0 @@
1
- require 'anima'
2
- require 'devtools/spec_helper'
@@ -1,62 +0,0 @@
1
- describe Anima::Attribute do
2
- let(:object) { described_class.new(:foo) }
3
-
4
- describe '#get' do
5
- subject { object.get(target) }
6
-
7
- let(:target_class) do
8
- Class.new do
9
- attr_reader :foo
10
-
11
- def initialize(foo)
12
- @foo = foo
13
- end
14
- end
15
- end
16
-
17
- let(:target) { target_class.new(value) }
18
- let(:value) { double('Value') }
19
-
20
- it 'should return value' do
21
- should be(value)
22
- end
23
- end
24
-
25
- describe '#load' do
26
- subject { object.load(target, attribute_hash) }
27
-
28
- let(:target) { Object.new }
29
- let(:value) { double('Value') }
30
- let(:attribute_hash) { { foo: value } }
31
-
32
- it 'should set value as instance variable' do
33
- subject
34
- expect(target.instance_variable_get(:@foo)).to be(value)
35
- end
36
-
37
- it_should_behave_like 'a command method'
38
- end
39
-
40
- describe '#instance_variable_name' do
41
- subject { object.instance_variable_name }
42
-
43
- it { should be(:@foo) }
44
-
45
- it_should_behave_like 'an idempotent method'
46
- end
47
-
48
- describe '#set' do
49
- subject { object.set(target, value) }
50
-
51
- let(:target) { Object.new }
52
-
53
- let(:value) { double('Value') }
54
-
55
- it_should_behave_like 'a command method'
56
-
57
- it 'should set value as instance variable' do
58
- subject
59
- expect(target.instance_variable_get(:@foo)).to be(value)
60
- end
61
- end
62
- end
@@ -1,16 +0,0 @@
1
- describe Anima::Error do
2
- describe '#message' do
3
- let(:object) { described_class.new(Anima, missing, unknown) }
4
-
5
- let(:missing) { %i[missing] }
6
- let(:unknown) { %i[unknown] }
7
-
8
- subject { object.message }
9
-
10
- it 'should return the message string' do
11
- should eql('Anima attributes missing: [:missing], unknown: [:unknown]')
12
- end
13
-
14
- it_should_behave_like 'an idempotent method'
15
- end
16
- end
@@ -1,207 +0,0 @@
1
- describe Anima do
2
- let(:object) { described_class.new(:foo) }
3
-
4
- describe '#attributes_hash' do
5
- let(:value) { double('Value') }
6
- let(:instance) { double(foo: value) }
7
-
8
- subject { object.attributes_hash(instance) }
9
-
10
- it { should eql(foo: value) }
11
- end
12
-
13
- describe '#remove' do
14
- let(:object) { described_class.new(:foo, :bar) }
15
-
16
- context 'with single attribute' do
17
- subject { object.remove(:bar) }
18
-
19
- it { should eql(described_class.new(:foo)) }
20
- end
21
-
22
- context 'with multiple attributes' do
23
- subject { object.remove(:foo, :bar) }
24
-
25
- it { should eql(described_class.new) }
26
- end
27
-
28
- context 'with inexisting attribute' do
29
- subject { object.remove(:baz) }
30
-
31
- it { should eql(object) }
32
- end
33
- end
34
-
35
- describe '#add' do
36
- context 'with single attribute' do
37
- subject { object.add(:bar) }
38
-
39
- it { should eql(described_class.new(:foo, :bar)) }
40
- end
41
-
42
- context 'with multiple attributes' do
43
- subject { object.add(:bar, :baz) }
44
-
45
- it { should eql(described_class.new(:foo, :bar, :baz)) }
46
- end
47
-
48
- context 'with duplicate attribute ' do
49
- subject { object.add(:foo) }
50
-
51
- it { should eql(object) }
52
- end
53
- end
54
-
55
- describe '#attributes' do
56
- subject { object.attributes }
57
-
58
- it { should eql([Anima::Attribute.new(:foo)]) }
59
- it { should be_frozen }
60
- end
61
-
62
- describe '#included' do
63
- let(:target) do
64
- object = self.object
65
- Class.new do
66
- include object
67
- end
68
- end
69
-
70
- let(:value) { double('Value') }
71
- let(:instance) { target.new(foo: value) }
72
- let(:instance_b) { target.new(foo: value) }
73
- let(:instance_c) { target.new(foo: double('Bar')) }
74
-
75
- context 'on instance' do
76
- subject { instance }
77
-
78
- its(:foo) { should be(value) }
79
-
80
- it { should eql(instance_b) }
81
- it { should_not eql(instance_c) }
82
- end
83
-
84
- context 'on singleton' do
85
- subject { target }
86
-
87
- it 'should define attribute hash reader' do
88
- expect(instance.to_h).to eql(foo: value)
89
- end
90
-
91
- its(:anima) { should be(object) }
92
- end
93
- end
94
-
95
- describe '#initialize_instance' do
96
- let(:object) { Anima.new(:foo, :bar) }
97
- let(:target) { Object.new }
98
- let(:foo) { double('Foo') }
99
- let(:bar) { double('Bar') }
100
-
101
- subject { object.initialize_instance(target, attribute_hash) }
102
-
103
- context 'when all keys are present in attribute hash' do
104
- let(:attribute_hash) { { foo: foo, bar: bar } }
105
-
106
- it 'should initialize target instance variables' do
107
- subject
108
-
109
- expect(
110
- target
111
- .instance_variables
112
- .map(&:to_sym)
113
- .to_set
114
- ).to eql(%i[@foo @bar].to_set)
115
- expect(target.instance_variable_get(:@foo)).to be(foo)
116
- expect(target.instance_variable_get(:@bar)).to be(bar)
117
- end
118
-
119
- it_should_behave_like 'a command method'
120
- end
121
-
122
- context 'when an extra key is present in attribute hash' do
123
- let(:attribute_hash) { { foo: foo, bar: bar, baz: double('Baz') } }
124
-
125
- it 'should raise error' do
126
- expect { subject }.to raise_error(
127
- Anima::Error,
128
- Anima::Error.new(target.class, [], [:baz]).message
129
- )
130
- end
131
-
132
- context 'and the extra key is falsy' do
133
- let(:attribute_hash) { { foo: foo, bar: bar, nil => double('Baz') } }
134
-
135
- it 'should raise error' do
136
- expect { subject }.to raise_error(
137
- Anima::Error,
138
- Anima::Error.new(target.class, [], [nil]).message
139
- )
140
- end
141
- end
142
- end
143
-
144
- context 'when a key is missing in attribute hash' do
145
- let(:attribute_hash) { { bar: bar } }
146
-
147
- it 'should raise error' do
148
- expect { subject }.to raise_error(
149
- Anima::Error.new(target.class, [:foo], []).message
150
- )
151
- end
152
- end
153
- end
154
-
155
- describe 'using super in initialize' do
156
- subject { klass.new }
157
-
158
- let(:klass) do
159
- Class.new do
160
- include Anima.new(:foo)
161
- def initialize(attributes = { foo: :bar })
162
- super
163
- end
164
- end
165
- end
166
-
167
- its(:foo) { should eql(:bar) }
168
- end
169
-
170
- describe '#to_h on an anima infected instance' do
171
- subject { instance.to_h }
172
-
173
- let(:instance) { klass.new(params) }
174
- let(:params) { Hash[foo: :bar] }
175
- let(:klass) do
176
- Class.new do
177
- include Anima.new(:foo)
178
- end
179
- end
180
-
181
- it { should eql(params) }
182
- end
183
-
184
- describe '#with' do
185
- subject { object.with(attributes) }
186
-
187
- let(:klass) do
188
- Class.new do
189
- include Anima.new(:foo, :bar)
190
- end
191
- end
192
-
193
- let(:object) { klass.new(foo: 1, bar: 2) }
194
-
195
- context 'with empty attributes' do
196
- let(:attributes) { {} }
197
-
198
- it { should eql(object) }
199
- end
200
-
201
- context 'with updated attribute' do
202
- let(:attributes) { { foo: 3 } }
203
-
204
- it { should eql(klass.new(foo: 3, bar: 2)) }
205
- end
206
- end
207
- end