attribute_matcher 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
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2d9fe1a54b6439a4d7990d7ce99a9de95299e8dc
4
- data.tar.gz: 02bf7adf7356c9aa7d0ce97308c592c89a74adf4
3
+ metadata.gz: bc23f4e6106aa331f25240fde33cac763b8c3df8
4
+ data.tar.gz: 51de53282e826a0020ba13c68425a4982eb3ddd3
5
5
  SHA512:
6
- metadata.gz: c6dcbb2fbc6a87e0e951f792a910d003edf06bdca4a8121324807b4bc3e96a7ac92f019c4bedb034a75f9aa1748361f62391c833ca2b391f7f1e7e05d230826e
7
- data.tar.gz: 0db41f2d5ee2e53da1308723393d67dd83ec6009deca585c7637eff7dda98fb86cc6487ee6c428f3941a410d7ba35561c1e8866b50438fdc90d62de12a48464d
6
+ metadata.gz: 51c252381c04d4c76d4c41edc2e049382d6ca4eb8cdb628a912020a90e1d48aa54e5d8e0a7a5bb064d81e4dbf1e7403511a249bc3cfdbd13b1c2acd9a5ddc40f
7
+ data.tar.gz: d148cda1e11614e1ed015cb940ecaaa41966b82e7308bd12f5d0103978972a382807f402f698de7cbf23162c0be0adca7425a93b86381663b558b1dfe763809a
data/README.md CHANGED
@@ -31,6 +31,10 @@ class Person
31
31
  attr_reader :age
32
32
  attr_writer :status
33
33
 
34
+ def initialize
35
+ self.name = 'Joe'
36
+ end
37
+
34
38
  protected
35
39
 
36
40
  attr_accessor :address
@@ -41,19 +45,27 @@ class Person
41
45
  end
42
46
 
43
47
  describe Person do
44
- it { is_expected.to have_attribute(:name) }
45
- it { is_expected.to have_attribute(:age) }
48
+ it { is_expected.to have_attribute(:name) }
49
+ it { is_expected.to have_attribute(:age) }
46
50
  it { is_expected.to have_attribute(:status) }
47
51
 
48
- it { is_expected.to have_attribute(:name).read_write }
49
- it { is_expected.to have_attribute(:age).read_only }
50
- it { is_expected.to have_attribute(:status).write_only }
51
-
52
- it { is_expected.to have_attribute(:address).with_reader(:protected) }
53
- it { is_expected.to have_attribute(:address).with_writer(:protected) }
54
-
55
- it { is_expected.to have_attribute(:ssn).with_reader(:private) }
56
- it { is_expected.to have_attribute(:ssn).with_writer(:private) }
52
+ describe 'accessors' do
53
+ it { is_expected.to have_attribute(:name).read_write }
54
+ it { is_expected.to have_attribute(:age).read_only }
55
+ it { is_expected.to have_attribute(:status).write_only }
56
+ end
57
+
58
+ describe 'visibility' do
59
+ it { is_expected.to have_attribute(:address).with_reader(:protected) }
60
+ it { is_expected.to have_attribute(:address).with_writer(:protected) }
61
+ it { is_expected.to have_attribute(:ssn).with_reader(:private) }
62
+ it { is_expected.to have_attribute(:ssn).with_writer(:private) }
63
+ end
64
+
65
+ describe 'values' do
66
+ it { is_expected.to have_attribute(:name).with_value('Joe') }
67
+ it { is_expected.to have_attribute(:age).with_value(nil) }
68
+ end
57
69
  end
58
70
  ```
59
71
 
@@ -1,15 +1,22 @@
1
1
  RSpec::Matchers.define(:have_attribute) do
2
2
  match do
3
- exists? && access_match? && visibility_match?(:reader) && visibility_match?(:writer)
3
+ exists? && access_match? && visibility_match?(:reader) && visibility_match?(:writer) && value_match?
4
4
  end
5
5
 
6
6
  chain_group :access, :read_only, :write_only, :read_write
7
7
 
8
- chain(:with_reader) { |visibility| @reader_visibility = ensure_valid_visibility(visibility) }
9
- chain(:with_writer) { |visibility| @writer_visibility = ensure_valid_visibility(visibility) }
8
+ chain(:with_reader) { |visibility| self.reader_visibility = ensure_valid_visibility(visibility) }
9
+ chain(:with_writer) { |visibility| self.writer_visibility = ensure_valid_visibility(visibility) }
10
+
11
+ chain(:with_value) do |value|
12
+ self.value = value
13
+ self.value_set = true
14
+ end
10
15
 
11
16
  private
12
17
 
18
+ attr_accessor :value, :value_set, :reader_visibility, :writer_visibility
19
+
13
20
  def exists?
14
21
  reader || writer
15
22
  end
@@ -61,7 +68,7 @@ RSpec::Matchers.define(:have_attribute) do
61
68
 
62
69
  def visibility_match?(accessor)
63
70
  method = accessor == :reader ? reader : writer
64
- expected_visibility = instance_variable_get(:"@#{accessor}_visibility")
71
+ expected_visibility = send("#{accessor}_visibility")
65
72
 
66
73
  method.nil? || expected_visibility.nil? || expected_visibility == visibility(method)
67
74
  end
@@ -85,4 +92,8 @@ RSpec::Matchers.define(:have_attribute) do
85
92
  fail format('%s is an invalid visibility; should be one of %s', visibility, VALID_VISIBILITIES.join(', ')) unless VALID_VISIBILITIES.include?(visibility)
86
93
  visibility
87
94
  end
95
+
96
+ def value_match?
97
+ value_set.nil? || actual.send(expected).eql?(value)
98
+ end
88
99
  end
@@ -7,7 +7,7 @@ module RSpec
7
7
  def failure_messages(&block)
8
8
  define_method :failure_message do
9
9
  failures = instance_eval(&block).compact.join(' and ')
10
- [super(), failures].join(' but ')
10
+ [super(), failures].reject(&:empty?).join(' but ')
11
11
  end
12
12
  end
13
13
  end
@@ -1,3 +1,3 @@
1
1
  module HaveAttributeMatcher
2
- VERSION ||= '0.0.3'
2
+ VERSION ||= '0.0.4'
3
3
  end
@@ -41,14 +41,14 @@ describe 'have_attribute matcher' do
41
41
 
42
42
  it_behaves_like 'matcher messages' do
43
43
  {
44
- :'have_attribute(:name)' => 'have attribute :name',
45
- :'have_attribute(:name).read_only' => 'have attribute :name read only',
44
+ :'have_attribute(:name)' => 'have attribute :name',
45
+ :'have_attribute(:name).read_only' => 'have attribute :name read only',
46
46
  :'have_attribute(:name).write_only' => 'have attribute :name write only',
47
47
  :'have_attribute(:name).read_write' => 'have attribute :name read write',
48
- :'have_attribute(:rw).read_only' => 'have attribute :rw read only',
49
- :'have_attribute(:rw).write_only' => 'have attribute :rw write only',
50
- :'have_attribute(:w).read_only' => 'have attribute :w read only',
51
- :'have_attribute(:r).write_only' => 'have attribute :r write only',
48
+ :'have_attribute(:rw).read_only' => 'have attribute :rw read only',
49
+ :'have_attribute(:rw).write_only' => 'have attribute :rw write only',
50
+ :'have_attribute(:w).read_only' => 'have attribute :w read only',
51
+ :'have_attribute(:r).write_only' => 'have attribute :r write only',
52
52
  }.each do |expectation, expected_description|
53
53
  describe(expectation) do
54
54
  its(:description) { is_expected.to eql expected_description }
@@ -58,8 +58,8 @@ describe 'have_attribute matcher' do
58
58
  end
59
59
 
60
60
  {
61
- :'have_attribute(:rw)' => 'expected .+ not to have attribute :rw',
62
- :'have_attribute(:r).read_only' => 'expected .+ not to have attribute :r read only',
61
+ :'have_attribute(:rw)' => 'expected .+ not to have attribute :rw',
62
+ :'have_attribute(:r).read_only' => 'expected .+ not to have attribute :r read only',
63
63
  :'have_attribute(:w).write_only' => 'expected .+ not to have attribute :w write only',
64
64
  }.each do |expectation, expected_description|
65
65
  describe(expectation) do
@@ -97,8 +97,8 @@ describe 'have_attribute matcher' do
97
97
  it_behaves_like 'matcher messages' do
98
98
  {
99
99
  :'have_attribute(:no_args).write_only' => 'have attribute :no_args write only but no_args=\(\) takes 0 arguments instead of 1',
100
- :'have_attribute(:one_arg).read_only' => 'have attribute :one_arg read only but one_arg\(\) takes 1 argument instead of 0',
101
- :'have_attribute(:two_args)' => 'have attribute :two_args but two_args\(\) takes 2 arguments instead of 0 and two_args=\(\) takes 2 arguments instead of 1',
100
+ :'have_attribute(:one_arg).read_only' => 'have attribute :one_arg read only but one_arg\(\) takes 1 argument instead of 0',
101
+ :'have_attribute(:two_args)' => 'have attribute :two_args but two_args\(\) takes 2 arguments instead of 0 and two_args=\(\) takes 2 arguments instead of 1',
102
102
  }.each do |expectation, expected_description|
103
103
  describe(expectation) do
104
104
  its(:failure_message) { is_expected.to match /expected .+ to #{expected_description}/ }
@@ -141,10 +141,9 @@ describe 'have_attribute matcher' do
141
141
 
142
142
  it_behaves_like 'matcher messages' do
143
143
  {
144
- :'have_attribute(:private_reader).with_reader(:private)' => 'have attribute :private_reader with reader :private',
144
+ :'have_attribute(:private_reader).with_reader(:private)' => 'have attribute :private_reader with reader :private',
145
145
  :'have_attribute(:protected_reader).with_reader(:protected)' => 'have attribute :protected_reader with reader :protected',
146
- :'have_attribute(:public_reader).with_reader(:public)' => 'have attribute :public_reader with reader :public',
147
-
146
+ :'have_attribute(:public_reader).with_reader(:public)' => 'have attribute :public_reader with reader :public',
148
147
  }.each do |expectation, expected_description|
149
148
  describe(expectation) do
150
149
  its(:description) { is_expected.to eql expected_description }
@@ -166,4 +165,20 @@ describe 'have_attribute matcher' do
166
165
  end
167
166
  end
168
167
  end
168
+
169
+ describe 'with_value' do
170
+ let(:klass) do
171
+ Class.new do
172
+ def initialize
173
+ @name = 'John'
174
+ end
175
+
176
+ attr_reader :name
177
+ attr_reader :address
178
+ end
179
+ end
180
+
181
+ it { is_expected.to have_attribute(:name).with_value('John') }
182
+ it { is_expected.not_to have_attribute(:name).with_value(nil) }
183
+ end
169
184
  end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ class Person
4
+ attr_accessor :name
5
+ attr_reader :age
6
+ attr_writer :status
7
+
8
+ def initialize
9
+ self.name = 'Joe'
10
+ end
11
+
12
+ protected
13
+
14
+ attr_accessor :address
15
+
16
+ private
17
+
18
+ attr_accessor :ssn
19
+ end
20
+
21
+ describe Person do
22
+ it { is_expected.to have_attribute(:name) }
23
+ it { is_expected.to have_attribute(:age) }
24
+ it { is_expected.to have_attribute(:status) }
25
+
26
+ describe 'accessors' do
27
+ it { is_expected.to have_attribute(:name).read_write }
28
+ it { is_expected.to have_attribute(:age).read_only }
29
+ it { is_expected.to have_attribute(:status).write_only }
30
+ end
31
+
32
+ describe 'visibility' do
33
+ it { is_expected.to have_attribute(:address).with_reader(:protected) }
34
+ it { is_expected.to have_attribute(:address).with_writer(:protected) }
35
+ it { is_expected.to have_attribute(:ssn).with_reader(:private) }
36
+ it { is_expected.to have_attribute(:ssn).with_writer(:private) }
37
+ end
38
+
39
+ describe 'values' do
40
+ it { is_expected.to have_attribute(:name).with_value('Joe') }
41
+ it { is_expected.to have_attribute(:age).with_value(nil) }
42
+ end
43
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: attribute_matcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Declan Whelan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-22 00:00:00.000000000 Z
11
+ date: 2015-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -129,9 +129,9 @@ files:
129
129
  - lib/attribute_matcher/ext/rspec/chain_group.rb
130
130
  - lib/attribute_matcher/ext/rspec/failure_messages.rb
131
131
  - lib/attribute_matcher/version.rb
132
- - spec/lib/have_attribute_matcher/have_attribute_matcher_spec.rb
133
- - spec/lib/have_attribute_matcher/usage_spec.rb
134
- - spec/lib/have_attribute_matcher/version_spec.rb
132
+ - spec/lib/attribute_matcher/attribute_matcher_spec.rb
133
+ - spec/lib/attribute_matcher/usage_spec.rb
134
+ - spec/lib/attribute_matcher/version_spec.rb
135
135
  - spec/spec_helper.rb
136
136
  homepage: https://github.com/dwhelan/attribute_matcher
137
137
  licenses:
@@ -158,7 +158,7 @@ signing_key:
158
158
  specification_version: 4
159
159
  summary: A matcher for testing object attributes.
160
160
  test_files:
161
- - spec/lib/have_attribute_matcher/have_attribute_matcher_spec.rb
162
- - spec/lib/have_attribute_matcher/usage_spec.rb
163
- - spec/lib/have_attribute_matcher/version_spec.rb
161
+ - spec/lib/attribute_matcher/attribute_matcher_spec.rb
162
+ - spec/lib/attribute_matcher/usage_spec.rb
163
+ - spec/lib/attribute_matcher/version_spec.rb
164
164
  - spec/spec_helper.rb
@@ -1,31 +0,0 @@
1
- require 'spec_helper'
2
-
3
- class Person
4
- attr_accessor :name
5
- attr_reader :age
6
- attr_writer :status
7
-
8
- protected
9
-
10
- attr_accessor :address
11
-
12
- private
13
-
14
- attr_accessor :ssn
15
- end
16
-
17
- describe Person do
18
- it { is_expected.to have_attribute(:name) }
19
- it { is_expected.to have_attribute(:age) }
20
- it { is_expected.to have_attribute(:status) }
21
-
22
- it { is_expected.to have_attribute(:name).read_write }
23
- it { is_expected.to have_attribute(:age).read_only }
24
- it { is_expected.to have_attribute(:status).write_only }
25
-
26
- it { is_expected.to have_attribute(:address).with_reader(:protected) }
27
- it { is_expected.to have_attribute(:address).with_writer(:protected) }
28
-
29
- it { is_expected.to have_attribute(:ssn).with_reader(:private) }
30
- it { is_expected.to have_attribute(:ssn).with_writer(:private) }
31
- end