valid_attribute 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,6 +1,7 @@
1
1
  *.gem
2
2
  .bundle
3
- Gemfile.lock
3
+ *.lock
4
4
  pkg/*
5
5
  doc/
6
6
  .yardoc
7
+ bin/*
data/.rspec CHANGED
@@ -1 +1,2 @@
1
1
  --color
2
+ --debugger
@@ -1,7 +1,7 @@
1
1
  rvm:
2
2
  - 1.8.7
3
3
  - 1.9.2
4
- - rbx
5
- - rbx-2.0
4
+ - 1.9.3
5
+ - rbx-18mode
6
6
  - ree
7
7
  - jruby
@@ -0,0 +1,2 @@
1
+ --markup-provider=redcarpet
2
+ --markup=markdown
@@ -6,7 +6,7 @@ ValidAttribute is a minimalist matcher for validation BDD.
6
6
 
7
7
  Supported ORMs
8
8
 
9
- * ActiveModel based (ActiveRecord >= 3.0, Mongoid >= 2.0, MongoMapper >= 0.9
9
+ * ActiveModel based (ActiveRecord >= 3.0, Mongoid >= 2.0, MongoMapper >= 0.9)
10
10
  * ActiveRecord <= 2.3
11
11
  * DataMapper
12
12
  * Custom (with compatible API, see below)
@@ -43,7 +43,6 @@ If you want to you use it with `MiniTest::Spec` you can use either `shoulda-cont
43
43
  gem 'minitest-matchers'
44
44
 
45
45
  # test_helper.rb
46
- require 'minitest/matchers'
47
46
  require 'valid_attribute'
48
47
  ```
49
48
 
@@ -106,20 +105,16 @@ require 'minitest/matchers'
106
105
  describe User do
107
106
  subject { User.new }
108
107
 
109
- # The .when method can take any number of values that you want to pass
110
- must { have_valid(:email).when('test@test.com', 'test+spam@gmail.com') }
111
- wont { have_valid(:email).when('fail', 123) }
112
- must { have_valid(:name).when('TestName') }
113
- wont { have_valid(:name).when('Test') }
108
+ it { must have_valid(:email).when('test@test.com', 'test+spam@gmail.com') }
109
+ it { wont have_valid(:email).when('fail', 123) }
110
+ it { must have_valid(:name).when('TestName') }
111
+ it { wont have_valid(:name).when('Test') }
114
112
 
115
113
  describe 'password' do
116
- subject { User.new(:password_confirmation => 'password') }
117
- must { have_valid(:password).when('password') }
118
- wont { have_valid(:password).when(nil) }
114
+ subject { User.new.tap { |u| u.password_confirmation = "password" } }
115
+ it { must have_valid(:password).when('password') }
116
+ it { wont have_valid(:password).when(nil) }
119
117
  end
120
-
121
- # Using .when is optional. Without it, the existing value is examined.
122
- wont have_valid(:email)
123
118
  end
124
119
  ```
125
120
 
@@ -146,10 +141,23 @@ class User
146
141
  end
147
142
  ```
148
143
 
144
+ ## Cloning ##
145
+
146
+ If you feel that the setters are mutating parts of the object when
147
+ testing multiple values you can force the test subject be cloned in
148
+ between each test
149
+
150
+ ```ruby
151
+ it { should have_valid(:name).when('Brian').clone }
152
+ ```
153
+
154
+ Be aware the cloning can cause some unpredicatable results and may lead
155
+ to more pain than help
156
+
149
157
  ## Legal ##
150
158
 
151
- Brian Cardarella &copy; 2011
159
+ [DockYard](http://dockyard.com), LLC &copy; 2012
152
160
 
153
- [@bcardarella](http://twitter.com/bcardarella)
161
+ [@dockyard](http://twitter.com/dockyard)
154
162
 
155
163
  [Licensed under the MIT license](http://www.opensource.org/licenses/mit-license.php)
@@ -7,8 +7,10 @@ end
7
7
 
8
8
  if defined?(RSpec)
9
9
  require 'valid_attribute/rspec'
10
+ elsif defined?(Spec)
11
+ require 'valid_attribute/spec'
10
12
  elsif defined?(MiniTest::Matchers)
11
13
  require 'valid_attribute/minitest'
12
- else
14
+ elsif defined?(Test::Unit)
13
15
  require 'valid_attribute/test_unit'
14
16
  end
@@ -41,6 +41,14 @@ module ValidAttribute
41
41
  !failed_values.empty? && passed_values.empty?
42
42
  end
43
43
 
44
+ def clone?
45
+ !!@clone
46
+ end
47
+
48
+ def clone
49
+ @clone = true
50
+ end
51
+
44
52
  private
45
53
 
46
54
  def check_values(subject)
@@ -61,19 +69,19 @@ module ValidAttribute
61
69
  end
62
70
 
63
71
  def check_value(value)
64
- cloned_subject = subject.clone
65
- cloned_subject.send("#{attr}=", value)
66
- cloned_subject.valid?
72
+ _subject = clone? ? subject.clone : subject
73
+ _subject.send("#{attr}=", value)
74
+ _subject.valid?
67
75
 
68
- if invalid_attribute?(cloned_subject, attr)
76
+ if invalid_attribute?(_subject, attr)
69
77
  self.failed_values << value
70
78
  else
71
79
  self.passed_values << value
72
80
  end
73
81
  end
74
82
 
75
- def invalid_attribute?(cloned_subject, attr)
76
- errors = cloned_subject.errors[attr]
83
+ def invalid_attribute?(_subject, attr)
84
+ errors = _subject.errors[attr]
77
85
  errors.respond_to?(:empty?) ? !errors.empty? : !!errors
78
86
  end
79
87
 
@@ -1,3 +1,3 @@
1
1
  class MiniTest::Spec
2
- extend ::ValidAttribute::Method
2
+ include ::ValidAttribute::Method
3
3
  end
@@ -0,0 +1,3 @@
1
+ Spec::Runner.configure do |config|
2
+ config.include ValidAttribute::Method
3
+ end
@@ -1,3 +1,3 @@
1
1
  module ValidAttribute
2
- VERSION = '1.2.0'
2
+ VERSION = '1.3.0'
3
3
  end
@@ -4,7 +4,7 @@ require 'valid_attribute/minitest'
4
4
 
5
5
  describe 'MiniTest::Spec' do
6
6
  it '.have_valid' do
7
- MiniTest::Spec.have_valid(:name).should be_instance_of(ValidAttribute::Matcher)
7
+ have_valid(:name).should be_instance_of(ValidAttribute::Matcher)
8
8
  end
9
9
  end
10
10
 
@@ -1,14 +1,14 @@
1
1
  require 'rubygems'
2
2
  require 'bundler'
3
- Bundler.setup
3
+ Bundler.require
4
4
 
5
5
  $LOAD_PATH.unshift(File.dirname(__FILE__))
6
6
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
7
- require 'ruby-debug'
8
7
  require 'rspec'
9
8
  require 'rspec/autorun'
10
9
  require 'bourne'
11
10
  require 'valid_attribute'
11
+ require 'debugger'
12
12
 
13
13
  RSpec.configure do |config|
14
14
  config.mock_with :mocha
@@ -154,6 +154,26 @@ describe 'ValidAttribute' do
154
154
  end
155
155
  end
156
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
157
177
  end
158
178
 
159
179
  end
@@ -19,14 +19,10 @@ Gem::Specification.new do |s|
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  s.require_paths = ["lib"]
21
21
 
22
+ s.add_development_dependency 'rake'
22
23
  s.add_development_dependency 'rspec'
23
24
  s.add_development_dependency 'bourne'
25
+ s.add_development_dependency 'minitest'
24
26
  s.add_development_dependency 'minitest-matchers'
25
- if RUBY_VERSION >= '1.9'
26
- if RUBY_VERSION <= '1.9.2'
27
- s.add_development_dependency 'ruby-debug19'
28
- end
29
- else
30
- s.add_development_dependency 'ruby-debug'
31
- end
27
+ s.add_development_dependency 'debugger'
32
28
  end
metadata CHANGED
@@ -1,76 +1,124 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: valid_attribute
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.3.0
4
5
  prerelease:
5
- version: 1.2.0
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Brian Cardarella
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-09-05 00:00:00 -04:00
14
- default_executable:
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
17
- name: rspec
12
+ date: 2012-08-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
18
23
  prerelease: false
19
- requirement: &id001 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
20
33
  none: false
21
- requirements:
22
- - - ">="
23
- - !ruby/object:Gem::Version
24
- version: "0"
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
25
38
  type: :development
26
- version_requirements: *id001
27
- - !ruby/object:Gem::Dependency
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
28
47
  name: bourne
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
29
55
  prerelease: false
30
- requirement: &id002 !ruby/object:Gem::Requirement
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: minitest
64
+ requirement: !ruby/object:Gem::Requirement
31
65
  none: false
32
- requirements:
33
- - - ">="
34
- - !ruby/object:Gem::Version
35
- version: "0"
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
36
70
  type: :development
37
- version_requirements: *id002
38
- - !ruby/object:Gem::Dependency
39
- name: minitest-matchers
40
71
  prerelease: false
41
- requirement: &id003 !ruby/object:Gem::Requirement
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: minitest-matchers
80
+ requirement: !ruby/object:Gem::Requirement
42
81
  none: false
43
- requirements:
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- version: "0"
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
47
86
  type: :development
48
- version_requirements: *id003
49
- - !ruby/object:Gem::Dependency
50
- name: ruby-debug19
51
87
  prerelease: false
52
- requirement: &id004 !ruby/object:Gem::Requirement
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: debugger
96
+ requirement: !ruby/object:Gem::Requirement
53
97
  none: false
54
- requirements:
55
- - - ">="
56
- - !ruby/object:Gem::Version
57
- version: "0"
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
58
102
  type: :development
59
- version_requirements: *id004
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
60
110
  description: Minimalist validation matcher
61
- email:
111
+ email:
62
112
  - bcardarella@gmail.com
63
113
  executables: []
64
-
65
114
  extensions: []
66
-
67
115
  extra_rdoc_files: []
68
-
69
- files:
116
+ files:
70
117
  - .gitignore
71
118
  - .rspec
72
119
  - .rvmrc
73
120
  - .travis.yml
121
+ - .yardopts
74
122
  - Gemfile
75
123
  - HISTORY
76
124
  - README.markdown
@@ -80,6 +128,7 @@ files:
80
128
  - lib/valid_attribute/method.rb
81
129
  - lib/valid_attribute/minitest.rb
82
130
  - lib/valid_attribute/rspec.rb
131
+ - lib/valid_attribute/spec.rb
83
132
  - lib/valid_attribute/test_unit.rb
84
133
  - lib/valid_attribute/version.rb
85
134
  - spec/minitest_spec.rb
@@ -88,35 +137,37 @@ files:
88
137
  - spec/user.rb
89
138
  - spec/valid_attribute_spec.rb
90
139
  - valid_attribute.gemspec
91
- has_rdoc: true
92
140
  homepage: https://github.com/bcardarella/valid_attribute
93
141
  licenses: []
94
-
95
142
  post_install_message:
96
143
  rdoc_options: []
97
-
98
- require_paths:
144
+ require_paths:
99
145
  - lib
100
- required_ruby_version: !ruby/object:Gem::Requirement
146
+ required_ruby_version: !ruby/object:Gem::Requirement
101
147
  none: false
102
- requirements:
103
- - - ">="
104
- - !ruby/object:Gem::Version
105
- version: "0"
106
- required_rubygems_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ! '>='
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ segments:
153
+ - 0
154
+ hash: 2438991157879859276
155
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
156
  none: false
108
- requirements:
109
- - - ">="
110
- - !ruby/object:Gem::Version
111
- version: "0"
157
+ requirements:
158
+ - - ! '>='
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ segments:
162
+ - 0
163
+ hash: 2438991157879859276
112
164
  requirements: []
113
-
114
165
  rubyforge_project: valid_attribute
115
- rubygems_version: 1.3.9.2
166
+ rubygems_version: 1.8.23
116
167
  signing_key:
117
168
  specification_version: 3
118
169
  summary: Minimalist validation matcher
119
- test_files:
170
+ test_files:
120
171
  - spec/minitest_spec.rb
121
172
  - spec/spec_helper.rb
122
173
  - spec/test_unit_spec.rb