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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c5343469849e0419f91004d5beab3e1516f1d609
4
- data.tar.gz: 90469264e820a223d9d77a896f5899b10c67e3ba
3
+ metadata.gz: 51973702fc038f8cc5e9ebd3f324096da3cd7a1f
4
+ data.tar.gz: 503b028e51034731838313d04197abbae91eecb2
5
5
  SHA512:
6
- metadata.gz: dacd46d89ef227413d25bb3770dcd3bfad5b340f212a46cbd385fd9063d66fa7979fbb84a030600810acc95b1cefdd4a2c562bf7c2cbab47c6afb90fc5dabc77
7
- data.tar.gz: 73e2cac3ff5075e1cb1bc61d28c85e8a54d6e14174ad0dfcaf55cd3c1b419d916b3dad78c1a0e481a1aa57582e59ca3fb6e68030e72206820beff2bc681b38a3
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
@@ -1,3 +1,3 @@
1
1
  module SmartProperties
2
- VERSION = "1.10.0"
2
+ VERSION = "1.10.1"
3
3
  end
@@ -1,5 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
- require_relative 'lib/smart_properties/version'
2
+ require File.expand_path('../lib/smart_properties/version', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |gem|
5
5
  gem.authors = ["Konstantin Tennhard"]
@@ -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 = "Dummy does not accept :maybe as value for the property visible"
23
- further_expectations = lambda { |error| expect(error.to_hash[:visible]).to eq('does not accept :maybe as value') }
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 = 'Dummy does not accept 13 as value for the property title'
53
- further_expectations = lambda { |error| expect(error.to_hash[:title]).to eq('does not accept 13 as value') }
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 accpetance checking' do
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 = 'Dummy does not accept "invalid" as value for the property license_plate'
81
- further_expectations = lambda { |error| expect(error.to_hash[:license_plate]).to eq('does not accept "invalid" as value') }
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.0
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: 2015-10-11 00:00:00.000000000 Z
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.4.5
107
+ rubygems_version: 2.5.1
109
108
  signing_key:
110
109
  specification_version: 4
111
110
  summary: SmartProperties – Ruby accessors on steroids
data/.travis.yml DELETED
@@ -1,8 +0,0 @@
1
- rvm:
2
- - 2.2.0
3
- - 1.9.3
4
- - rbx-2
5
- - ruby-head
6
- - jruby-head
7
-
8
- bundler_args: --without documentation