smart_properties 1.10.0 → 1.10.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/smart_properties/errors.rb +14 -2
- data/lib/smart_properties/version.rb +1 -1
- data/smart_properties.gemspec +1 -1
- data/spec/acceptance_checking_spec.rb +35 -8
- metadata +3 -4
- data/.travis.yml +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 51973702fc038f8cc5e9ebd3f324096da3cd7a1f
|
4
|
+
data.tar.gz: 503b028e51034731838313d04197abbae91eecb2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4107bbacae8c70445914acbacfa7b294fab58e81aecdf83fc3084aa57f5448bfcd0be73d5ad1a13e29da0a99498d188c8499bb740e05a7f501cb66bc21d37cfc
|
7
|
+
data.tar.gz: 1cb798b2e0c8a984f5a4779d16e2c0f20fb35228b5de80c4e0926bb9cb5700d5b08944447b77cd7ed47d77fdfd2d5317f630d42226743d18dfe3550ed6caf277
|
@@ -35,13 +35,15 @@ module SmartProperties
|
|
35
35
|
|
36
36
|
def initialize(sender, property, value)
|
37
37
|
@value = value
|
38
|
+
|
38
39
|
super(
|
39
40
|
sender,
|
40
41
|
property,
|
41
|
-
"%s does not accept %s as value for the property %s" % [
|
42
|
+
"%s does not accept %s as value for the property %s. Only accepts: %s" % [
|
42
43
|
sender.class.name,
|
43
44
|
value.inspect,
|
44
|
-
property.name
|
45
|
+
property.name,
|
46
|
+
acceptor_message(sender, property)
|
45
47
|
]
|
46
48
|
)
|
47
49
|
end
|
@@ -49,6 +51,16 @@ module SmartProperties
|
|
49
51
|
def to_hash
|
50
52
|
Hash[property.name, "does not accept %s as value" % value.inspect]
|
51
53
|
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def acceptor_message(sender, property)
|
58
|
+
acceptor = sender.class.properties[property.name].accepter
|
59
|
+
if acceptor.is_a?(Proc)
|
60
|
+
return "Values passing lambda defined in #{acceptor.source_location.join(' at line ')}"
|
61
|
+
end
|
62
|
+
acceptor
|
63
|
+
end
|
52
64
|
end
|
53
65
|
|
54
66
|
class InitializationError < Error
|
data/smart_properties.gemspec
CHANGED
@@ -19,8 +19,10 @@ RSpec.describe SmartProperties, 'acceptance checking' do
|
|
19
19
|
|
20
20
|
it "should not allow to set :maybe as value for visible" do
|
21
21
|
exception = SmartProperties::InvalidValueError
|
22
|
-
message =
|
23
|
-
further_expectations = lambda
|
22
|
+
message = /Dummy does not accept \:maybe as value for the property visible/
|
23
|
+
further_expectations = lambda do |error|
|
24
|
+
expect(error.to_hash[:visible]).to eq('does not accept :maybe as value')
|
25
|
+
end
|
24
26
|
|
25
27
|
expect { klass.new visible: :maybe }.to raise_error(exception, message, &further_expectations)
|
26
28
|
expect { klass.new { |i| i.visible = :maybe } }.to raise_error(exception, message, &further_expectations)
|
@@ -28,6 +30,13 @@ RSpec.describe SmartProperties, 'acceptance checking' do
|
|
28
30
|
expect { instance.visible = :maybe }.to raise_error(exception, message, &further_expectations)
|
29
31
|
expect { instance[:visible] = :maybe }.to raise_error(exception, message, &further_expectations)
|
30
32
|
end
|
33
|
+
|
34
|
+
it 'should give the user a list of what it accepts on InvalidValueError' do
|
35
|
+
exception = SmartProperties::InvalidValueError
|
36
|
+
message = /Only accepts\: \[true, false\]/
|
37
|
+
|
38
|
+
expect { klass.new visible: :maybe }.to raise_error(exception, message)
|
39
|
+
end
|
31
40
|
end
|
32
41
|
end
|
33
42
|
|
@@ -47,10 +56,12 @@ RSpec.describe SmartProperties, 'acceptance checking' do
|
|
47
56
|
expect { subject[:title] = :test }.to_not raise_error
|
48
57
|
end
|
49
58
|
|
50
|
-
it 'should not an instance of any other type' do
|
59
|
+
it 'should not accept an instance of any other type' do
|
51
60
|
exception = SmartProperties::InvalidValueError
|
52
|
-
message =
|
53
|
-
further_expectations = lambda
|
61
|
+
message = /Dummy does not accept 13 as value for the property title/
|
62
|
+
further_expectations = lambda do |error|
|
63
|
+
expect(error.to_hash[:title]).to match(/does not accept 13 as value/)
|
64
|
+
end
|
54
65
|
|
55
66
|
expect { klass.new title: 13 }.to raise_error(exception, message, &further_expectations)
|
56
67
|
expect { klass.new { |i| i.title = 13 } }.to raise_error(exception, message, &further_expectations)
|
@@ -58,10 +69,17 @@ RSpec.describe SmartProperties, 'acceptance checking' do
|
|
58
69
|
expect { instance.title = 13 }.to raise_error(exception, message, &further_expectations)
|
59
70
|
expect { instance[:title] = 13 }.to raise_error(exception, message, &further_expectations)
|
60
71
|
end
|
72
|
+
|
73
|
+
it 'should give the user a list of what it accepts on InvalidValueError' do
|
74
|
+
exception = SmartProperties::InvalidValueError
|
75
|
+
message = /Only accepts\: \[String, Symbol\]/
|
76
|
+
|
77
|
+
expect { klass.new title: 13 }.to raise_error(exception, message)
|
78
|
+
end
|
61
79
|
end
|
62
80
|
end
|
63
81
|
|
64
|
-
context 'when used to build a class that has a property called :license_plate which uses a lambda statement for
|
82
|
+
context 'when used to build a class that has a property called :license_plate which uses a lambda statement for acceptance checking' do
|
65
83
|
subject(:klass) do
|
66
84
|
DummyClass.new do
|
67
85
|
property :license_plate, accepts: lambda { |v| license_plate_pattern.match(v) }
|
@@ -77,8 +95,10 @@ RSpec.describe SmartProperties, 'acceptance checking' do
|
|
77
95
|
|
78
96
|
it 'should not a accept "invalid" as value for license_plate' do
|
79
97
|
exception = SmartProperties::InvalidValueError
|
80
|
-
message =
|
81
|
-
further_expectations = lambda
|
98
|
+
message = /Dummy does not accept "invalid" as value for the property license_plate/
|
99
|
+
further_expectations = lambda do |error|
|
100
|
+
expect(error.to_hash[:license_plate]).to match(/does not accept "invalid" as value/)
|
101
|
+
end
|
82
102
|
|
83
103
|
expect { klass.new license_plate: "invalid" }.to raise_error(exception, message, &further_expectations)
|
84
104
|
expect { klass.new { |i| i.license_plate = "invalid" } }.to raise_error(exception, message, &further_expectations)
|
@@ -87,6 +107,13 @@ RSpec.describe SmartProperties, 'acceptance checking' do
|
|
87
107
|
expect { instance[:license_plate] = "invalid" }.to raise_error(exception, message, &further_expectations)
|
88
108
|
end
|
89
109
|
|
110
|
+
it 'should give the user the location of the proc determining what it accepts on InvalidValueError' do
|
111
|
+
exception = SmartProperties::InvalidValueError
|
112
|
+
message = /spec\/acceptance_checking_spec\.rb at line 85/
|
113
|
+
|
114
|
+
expect { klass.new license_plate: 'slurp' }.to raise_error(exception, message)
|
115
|
+
end
|
116
|
+
|
90
117
|
it 'should accept "NE RD 1337" as license plate' do
|
91
118
|
expect { klass.new.license_plate = "NE RD 1337" }.to_not raise_error
|
92
119
|
expect { klass.new { |i| i.license_plate = "NE RD 1337" } }.to_not raise_error
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smart_properties
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.10.
|
4
|
+
version: 1.10.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Konstantin Tennhard
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-04-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -63,7 +63,6 @@ extensions: []
|
|
63
63
|
extra_rdoc_files: []
|
64
64
|
files:
|
65
65
|
- ".gitignore"
|
66
|
-
- ".travis.yml"
|
67
66
|
- ".yardopts"
|
68
67
|
- Gemfile
|
69
68
|
- LICENSE
|
@@ -105,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
105
104
|
version: '0'
|
106
105
|
requirements: []
|
107
106
|
rubyforge_project:
|
108
|
-
rubygems_version: 2.
|
107
|
+
rubygems_version: 2.5.1
|
109
108
|
signing_key:
|
110
109
|
specification_version: 4
|
111
110
|
summary: SmartProperties – Ruby accessors on steroids
|