valid_attribute 1.3.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,8 @@
1
1
  # ValidAttribute #
2
2
 
3
3
  [![Build Status](http://travis-ci.org/bcardarella/valid_attribute.png)](http://travis-ci.org/bcardarella/valid_attribute)
4
+ [![Dependency Status](https://gemnasium.com/bcardarella/valid_attribute.png?travis)](https://gemnasium.com/bcardarella/valid_attribute)
5
+ [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/bcardarella/valid_attribute)
4
6
 
5
7
  ValidAttribute is a minimalist matcher for validation BDD.
6
8
 
@@ -6,25 +6,23 @@ module ValidAttribute
6
6
  self.attr = attr
7
7
  end
8
8
 
9
+ # The collection of values to test against for the given
10
+ # attribute
11
+ #
12
+ # @params [Array]
13
+ #
14
+ # @return [ValidAttribute::Matcher]
9
15
  def when(*values)
10
16
  self.values = values
11
17
  self
12
18
  end
13
19
 
14
20
  def failure_message
15
- if failed_values.size == 1
16
- " expected #{subject.class}##{attr} to accept the value: #{quote_values(failed_values)}"
17
- else
18
- " expected #{subject.class}##{attr} to accept the values: #{quote_values(failed_values)}"
19
- end
21
+ message(failed_values, 'accept')
20
22
  end
21
23
 
22
24
  def negative_failure_message
23
- if passed_values.size == 1
24
- " expected #{subject.class}##{attr} to reject the value: #{quote_values(passed_values)}"
25
- else
26
- " expected #{subject.class}##{attr} to reject the values: #{quote_values(passed_values)}"
27
- end
25
+ message(passed_values, 'reject')
28
26
  end
29
27
 
30
28
  def description
@@ -45,6 +43,13 @@ module ValidAttribute
45
43
  !!@clone
46
44
  end
47
45
 
46
+ # Force the matcher to clone the subject in between
47
+ # testing each value.
48
+ #
49
+ # *Warning* This could lead to unintended results. The clone
50
+ # is not a deep copy
51
+ #
52
+ # @return [ValidAttribute::Matcher]
48
53
  def clone
49
54
  @clone = true
50
55
  end
@@ -89,5 +94,8 @@ module ValidAttribute
89
94
  values.map { |value| value.inspect }.join(', ')
90
95
  end
91
96
 
97
+ def message(values, verb)
98
+ " expected #{subject.class}##{attr} to #{verb} the value#{values.size == 1 ? nil : 's'}: #{quote_values(values)}"
99
+ end
92
100
  end
93
101
  end
@@ -1,3 +1,3 @@
1
1
  module ValidAttribute
2
- VERSION = '1.3.0'
2
+ VERSION = '1.3.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: valid_attribute
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-10 00:00:00.000000000 Z
12
+ date: 2012-08-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -91,22 +91,6 @@ dependencies:
91
91
  - - ! '>='
92
92
  - !ruby/object:Gem::Version
93
93
  version: '0'
94
- - !ruby/object:Gem::Dependency
95
- name: debugger
96
- requirement: !ruby/object:Gem::Requirement
97
- none: false
98
- requirements:
99
- - - ! '>='
100
- - !ruby/object:Gem::Version
101
- version: '0'
102
- type: :development
103
- prerelease: false
104
- version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
- requirements:
107
- - - ! '>='
108
- - !ruby/object:Gem::Version
109
- version: '0'
110
94
  description: Minimalist validation matcher
111
95
  email:
112
96
  - bcardarella@gmail.com
@@ -114,16 +98,6 @@ executables: []
114
98
  extensions: []
115
99
  extra_rdoc_files: []
116
100
  files:
117
- - .gitignore
118
- - .rspec
119
- - .rvmrc
120
- - .travis.yml
121
- - .yardopts
122
- - Gemfile
123
- - HISTORY
124
- - README.markdown
125
- - Rakefile
126
- - lib/valid_attribute.rb
127
101
  - lib/valid_attribute/matcher.rb
128
102
  - lib/valid_attribute/method.rb
129
103
  - lib/valid_attribute/minitest.rb
@@ -131,12 +105,8 @@ files:
131
105
  - lib/valid_attribute/spec.rb
132
106
  - lib/valid_attribute/test_unit.rb
133
107
  - lib/valid_attribute/version.rb
134
- - spec/minitest_spec.rb
135
- - spec/spec_helper.rb
136
- - spec/test_unit_spec.rb
137
- - spec/user.rb
138
- - spec/valid_attribute_spec.rb
139
- - valid_attribute.gemspec
108
+ - lib/valid_attribute.rb
109
+ - README.md
140
110
  homepage: https://github.com/bcardarella/valid_attribute
141
111
  licenses: []
142
112
  post_install_message:
@@ -151,7 +121,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
151
121
  version: '0'
152
122
  segments:
153
123
  - 0
154
- hash: 2438991157879859276
124
+ hash: 1648759370003077665
155
125
  required_rubygems_version: !ruby/object:Gem::Requirement
156
126
  none: false
157
127
  requirements:
@@ -160,16 +130,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
160
130
  version: '0'
161
131
  segments:
162
132
  - 0
163
- hash: 2438991157879859276
133
+ hash: 1648759370003077665
164
134
  requirements: []
165
- rubyforge_project: valid_attribute
135
+ rubyforge_project:
166
136
  rubygems_version: 1.8.23
167
137
  signing_key:
168
138
  specification_version: 3
169
139
  summary: Minimalist validation matcher
170
- test_files:
171
- - spec/minitest_spec.rb
172
- - spec/spec_helper.rb
173
- - spec/test_unit_spec.rb
174
- - spec/user.rb
175
- - spec/valid_attribute_spec.rb
140
+ test_files: []
data/.gitignore DELETED
@@ -1,7 +0,0 @@
1
- *.gem
2
- .bundle
3
- *.lock
4
- pkg/*
5
- doc/
6
- .yardoc
7
- bin/*
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --color
2
- --debugger
data/.rvmrc DELETED
@@ -1 +0,0 @@
1
- rvm --create default@valid_attribute > /dev/null
@@ -1,7 +0,0 @@
1
- rvm:
2
- - 1.8.7
3
- - 1.9.2
4
- - 1.9.3
5
- - rbx-18mode
6
- - ree
7
- - jruby
data/.yardopts DELETED
@@ -1,2 +0,0 @@
1
- --markup-provider=redcarpet
2
- --markup=markdown
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source "http://rubygems.org"
2
-
3
- # Specify your gem's dependencies in valid_attribute.gemspec
4
- gemspec
data/HISTORY DELETED
@@ -1,30 +0,0 @@
1
- == 1.2.0
2
- MiniTest::Spec support [wojtekmach]
3
-
4
- == 1.1.0
5
- #when is not necessary [davisre]
6
-
7
- == 1.0.0
8
- Gold!
9
-
10
- == 0.2.1
11
- Better value quoting using #inspect
12
-
13
- == 0.2.0
14
- Test::Unit::TestCase support. You should use shoulda-context
15
- Fixed logic bug with #does_not_match?
16
-
17
- == 0.1.0
18
- Version bump. API is stable
19
-
20
- == 0.0.4
21
- fix for multiple should_not values
22
-
23
- == 0.0.3
24
- should_not fix for when the validation key doesn't exist yet
25
- removed .message method. Not good BDD
26
- will test all values instead of stopping at the first invalid value
27
-
28
- == 0.0.2
29
- Removed default value, allways required to pass value
30
- Changed #with to #when
data/Rakefile DELETED
@@ -1,8 +0,0 @@
1
- require 'bundler'
2
- require 'rspec/core/rake_task'
3
- Bundler::GemHelper.install_tasks
4
-
5
- RSpec::Core::RakeTask.new('default') do |t|
6
- t.pattern = FileList['spec/**/*_spec.rb']
7
- end
8
-
@@ -1,10 +0,0 @@
1
- require 'spec_helper'
2
- require 'minitest/spec'
3
- require 'valid_attribute/minitest'
4
-
5
- describe 'MiniTest::Spec' do
6
- it '.have_valid' do
7
- have_valid(:name).should be_instance_of(ValidAttribute::Matcher)
8
- end
9
- end
10
-
@@ -1,17 +0,0 @@
1
- require 'rubygems'
2
- require 'bundler'
3
- Bundler.require
4
-
5
- $LOAD_PATH.unshift(File.dirname(__FILE__))
6
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
7
- require 'rspec'
8
- require 'rspec/autorun'
9
- require 'bourne'
10
- require 'valid_attribute'
11
- require 'debugger'
12
-
13
- RSpec.configure do |config|
14
- config.mock_with :mocha
15
- end
16
-
17
-
@@ -1,12 +0,0 @@
1
- # This is a RSpec spec to test TestUnit... yeah that's right
2
-
3
- require 'spec_helper'
4
- require 'test/unit'
5
- require 'valid_attribute/test_unit'
6
-
7
- describe 'Test::Unit::TestCase' do
8
- it '.have_valid' do
9
- Test::Unit::TestCase.have_valid(:name).should be_instance_of(ValidAttribute::Matcher)
10
- end
11
- end
12
-
@@ -1,12 +0,0 @@
1
- class User
2
- attr_accessor :name
3
- attr_accessor :email
4
-
5
- def errors
6
- @error ||= {}
7
- end
8
-
9
- def valid?
10
- errors.empty?
11
- end
12
- end
@@ -1,179 +0,0 @@
1
- require 'spec_helper'
2
- require 'user'
3
-
4
- class Should
5
- include ValidAttribute::Method
6
- end
7
-
8
- describe 'ValidAttribute' do
9
-
10
- before do
11
- @should = Should.new
12
- @user = User.new
13
- end
14
-
15
- describe 'matcher result' do
16
- context 'data is valid' do
17
- before do
18
- @user.stubs(:valid?).returns(true)
19
- @user.stubs(:errors).returns({})
20
- @matcher = @should.have_valid(:name).when('abc', 123)
21
- end
22
-
23
- it 'matches? returns true' do
24
- @matcher.matches?(@user).should be_true
25
- end
26
-
27
- it 'does_not_match? returns false' do
28
- @matcher.does_not_match?(@user).should be_false
29
- end
30
-
31
- describe 'messages' do
32
- it '#negative_failure_message' do
33
- @matcher.matches?(@user)
34
- @matcher.negative_failure_message.should == " expected User#name to reject the values: \"abc\", 123"
35
- end
36
- end
37
- end
38
-
39
- context 'data is invalid' do
40
- before do
41
- @user.stubs(:valid?).returns(false)
42
- @user.stubs(:errors).returns({:name => ["can't be blank"]})
43
- @matcher = @should.have_valid(:name).when(:abc, nil)
44
- end
45
-
46
- it 'matches? returns false' do
47
- @matcher.matches?(@user).should be_false
48
- end
49
-
50
- it 'does_not_match? returns true' do
51
- @matcher.does_not_match?(@user).should be_true
52
- end
53
-
54
- describe 'messages' do
55
- it '#failure_message' do
56
- @matcher.matches?(@user)
57
- @matcher.failure_message.should == " expected User#name to accept the values: :abc, nil"
58
- end
59
- end
60
- end
61
-
62
- context 'data is valid then invalid' do
63
- before do
64
- @user.stubs(:valid?).returns(true).then.returns(false)
65
- @user.stubs(:errors).returns({}).then.returns({:name => ["can't be blank"]})
66
- @matcher = @should.have_valid(:name).when('abc', 123)
67
- end
68
-
69
- it 'matches? returns false' do
70
- @matcher.matches?(@user).should be_false
71
- end
72
-
73
- it 'does_not_match? returns false' do
74
- @matcher.does_not_match?(@user).should be_false
75
- end
76
-
77
- describe 'messages' do
78
- it '#failure_message' do
79
- @matcher.matches?(@user)
80
- @matcher.failure_message.should == " expected User#name to accept the value: 123"
81
- end
82
-
83
- it '#negative_failure_message' do
84
- @matcher.matches?(@user)
85
- @matcher.negative_failure_message.should == " expected User#name to reject the value: \"abc\""
86
- end
87
-
88
- it '#description' do
89
- @matcher.description.should == "be valid when name is: \"abc\", 123"
90
- end
91
- end
92
- end
93
-
94
- context 'no values are specified with .when' do
95
- context 'data is not set' do
96
- before do
97
- @user.stubs(:valid?).returns(true)
98
- @user.stubs(:name).returns(nil)
99
- @matcher = @should.have_valid(:name)
100
- end
101
-
102
- subject do
103
- @matcher.matches?(@user)
104
- @matcher
105
- end
106
-
107
- its(:description) { should eq('be valid when name is: nil') }
108
- end
109
-
110
- context 'data is valid' do
111
- before do
112
- @user.stubs(:valid?).returns(true)
113
- @user.stubs(:name).returns(:abc)
114
- @matcher = @should.have_valid(:name)
115
- end
116
-
117
- it 'matches? returns true' do
118
- @matcher.matches?(@user).should be_true
119
- end
120
-
121
- it 'does_not_match? returns false' do
122
- @matcher.does_not_match?(@user).should be_false
123
- end
124
-
125
- describe 'messages' do
126
- it '#negative_failure_message' do
127
- @matcher.matches?(@user)
128
- @matcher.negative_failure_message.should == " expected User#name to reject the value: :abc"
129
- end
130
- end
131
- end
132
-
133
- context 'data is invalid' do
134
- before do
135
- @user.stubs(:valid?).returns(false)
136
- @user.stubs(:errors).returns({:name => ["can't be a symbol"]})
137
- @user.stubs(:name).returns(:abc)
138
- @matcher = @should.have_valid(:name)
139
- end
140
-
141
- it 'matches? returns false' do
142
- @matcher.matches?(@user).should be_false
143
- end
144
-
145
- it 'does_not_match? returns true' do
146
- @matcher.does_not_match?(@user).should be_true
147
- end
148
-
149
- describe 'messages' do
150
- it '#failure_message' do
151
- @matcher.matches?(@user)
152
- @matcher.failure_message.should == " expected User#name to accept the value: :abc"
153
- end
154
- end
155
- end
156
- end
157
-
158
- describe 'cloning' do
159
- before do
160
- @matcher = @should.have_valid(:name)
161
- end
162
-
163
- context 'when no cloning' do
164
- it 'returns false' do
165
- @matcher.clone?.should be_false
166
- end
167
- end
168
- context 'when cloned' do
169
- before do
170
- @matcher.clone
171
- end
172
- it 'returns true' do
173
- @matcher.clone?.should be_true
174
- end
175
- end
176
- end
177
- end
178
-
179
- end
@@ -1,28 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "valid_attribute/version"
4
-
5
- Gem::Specification.new do |s|
6
- s.name = "valid_attribute"
7
- s.version = ValidAttribute::VERSION
8
- s.platform = Gem::Platform::RUBY
9
- s.authors = ["Brian Cardarella"]
10
- s.email = ["bcardarella@gmail.com"]
11
- s.homepage = "https://github.com/bcardarella/valid_attribute"
12
- s.summary = %q{Minimalist validation matcher}
13
- s.description = %q{Minimalist validation matcher}
14
-
15
- s.rubyforge_project = "valid_attribute"
16
-
17
- s.files = `git ls-files`.split("\n")
18
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
- s.require_paths = ["lib"]
21
-
22
- s.add_development_dependency 'rake'
23
- s.add_development_dependency 'rspec'
24
- s.add_development_dependency 'bourne'
25
- s.add_development_dependency 'minitest'
26
- s.add_development_dependency 'minitest-matchers'
27
- s.add_development_dependency 'debugger'
28
- end