dm-rspec 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -24,8 +24,7 @@ In your spec files you can use the next matchers:
24
24
  * have\_many
25
25
  * have\_many\_and\_belong\_to
26
26
  * have\_property
27
- * have\_errors\_on
28
- * have\_error\_on
27
+ * have(n).errors_on(:property)
29
28
 
30
29
 
31
30
  ## Examples
@@ -63,16 +62,19 @@ You specs can contain the next:
63
62
  specify {Books.should have_many_and_belong_to :genres}
64
63
 
65
64
  it 'has errors' do
66
- book = Book.new
65
+ book = Book.new(:name => 'fails on two validations')
67
66
  book.valid?
68
- book.should have_errors_on(:name)
67
+ book.should have(2).errors_on(:name)
69
68
  end
70
69
 
71
70
 
72
71
  ## TODO
73
72
 
74
73
  Implement the next matchers:
75
- * have(n).errors\_on * have\_many(:models).through(:association)
74
+
75
+ * have\_many(:models).through(:association)
76
+
77
+ Implement matchers for validations.
76
78
 
77
79
 
78
80
  ## Contributing to dm-rspec
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
@@ -1,4 +1,5 @@
1
1
  module DataMapper
2
2
  end
3
3
 
4
+ require File.join(File.dirname(__FILE__), 'dm', 'resource')
4
5
  require 'dm/matchers'
@@ -26,9 +26,13 @@ module DataMapper
26
26
  end
27
27
 
28
28
  def have_errors_on(property)
29
+ puts "dm-rspec: `have_errors_on` is deprecated. Please use `have(n).errors_on` instead"
29
30
  HaveErrorsOn.new(property)
30
31
  end
31
32
 
32
- alias :have_error_on :have_errors_on
33
+ def have_error_on(property)
34
+ puts "dm-rspec: `have_error_on` is deprecated. Please use `have(1).error_on` instead"
35
+ HaveErrorsOn.new(property)
36
+ end
33
37
  end
34
38
  end
@@ -0,0 +1,11 @@
1
+ module DataMapper
2
+ module Resource
3
+
4
+ def errors_on(property)
5
+ self.valid?
6
+ errors.send(:errors)[property] or []
7
+ end
8
+
9
+ alias :error_on :errors_on
10
+ end
11
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ describe 'have errors_on' do
5
+ before(:all) do
6
+ @valid = Book.new(:name => 'War and Peace')
7
+ @one_err = Book.new(:name => 'too short')
8
+ @two_errs = Book.new
9
+ end
10
+
11
+
12
+ context '#should' do
13
+ it 'passes' do
14
+ lambda {@one_err.should have(1).error_on :name}.should_pass
15
+ lambda {@two_errs.should have(2).errors_on :name}.should_pass
16
+ lambda {@valid.should have(0).errors_on :name}.should_pass
17
+ end
18
+
19
+ it 'fails for valid mode' do
20
+ lambda {@valid.should have(1).errors_on :name}.should fail
21
+ end
22
+ end
23
+
24
+ context '#should_not' do
25
+ it 'fails for invalid model' do
26
+ lambda {@one_err.should_not have(1).error_on :name}.should fail
27
+ lambda {@two_errs.should_not have(2).errors_on :name}.should fail
28
+ end
29
+ end
30
+ end
@@ -43,6 +43,7 @@ class Book
43
43
  belongs_to :author
44
44
  has n, :genres, :through => Resource
45
45
  validates_presence_of :name
46
+ validates_length_of :name, :min => 10
46
47
  end
47
48
 
48
49
  class Author
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dm-rspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-04 00:00:00.000000000 +03:00
12
+ date: 2011-09-05 00:00:00.000000000 +03:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: dm-core
17
- requirement: &21244360 !ruby/object:Gem::Requirement
17
+ requirement: &13450840 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *21244360
25
+ version_requirements: *13450840
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: dm-validations
28
- requirement: &21243880 !ruby/object:Gem::Requirement
28
+ requirement: &13450360 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *21243880
36
+ version_requirements: *13450360
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: rspec
39
- requirement: &21243400 !ruby/object:Gem::Requirement
39
+ requirement: &13449880 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: 2.3.0
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *21243400
47
+ version_requirements: *13449880
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: bundler
50
- requirement: &21242920 !ruby/object:Gem::Requirement
50
+ requirement: &13449400 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ~>
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: 1.0.0
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *21242920
58
+ version_requirements: *13449400
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: jeweler
61
- requirement: &21242440 !ruby/object:Gem::Requirement
61
+ requirement: &13448920 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ~>
@@ -66,10 +66,10 @@ dependencies:
66
66
  version: 1.6.4
67
67
  type: :development
68
68
  prerelease: false
69
- version_requirements: *21242440
69
+ version_requirements: *13448920
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: rcov
72
- requirement: &21241960 !ruby/object:Gem::Requirement
72
+ requirement: &13448440 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ! '>='
@@ -77,10 +77,10 @@ dependencies:
77
77
  version: '0'
78
78
  type: :development
79
79
  prerelease: false
80
- version_requirements: *21241960
80
+ version_requirements: *13448440
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: reek
83
- requirement: &21241480 !ruby/object:Gem::Requirement
83
+ requirement: &13447960 !ruby/object:Gem::Requirement
84
84
  none: false
85
85
  requirements:
86
86
  - - ~>
@@ -88,10 +88,10 @@ dependencies:
88
88
  version: 1.2.8
89
89
  type: :development
90
90
  prerelease: false
91
- version_requirements: *21241480
91
+ version_requirements: *13447960
92
92
  - !ruby/object:Gem::Dependency
93
93
  name: guard-rspec
94
- requirement: &21241000 !ruby/object:Gem::Requirement
94
+ requirement: &13447480 !ruby/object:Gem::Requirement
95
95
  none: false
96
96
  requirements:
97
97
  - - ! '>='
@@ -99,10 +99,10 @@ dependencies:
99
99
  version: '0'
100
100
  type: :development
101
101
  prerelease: false
102
- version_requirements: *21241000
102
+ version_requirements: *13447480
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: libnotify
105
- requirement: &21240520 !ruby/object:Gem::Requirement
105
+ requirement: &13447000 !ruby/object:Gem::Requirement
106
106
  none: false
107
107
  requirements:
108
108
  - - ! '>='
@@ -110,10 +110,10 @@ dependencies:
110
110
  version: '0'
111
111
  type: :development
112
112
  prerelease: false
113
- version_requirements: *21240520
113
+ version_requirements: *13447000
114
114
  - !ruby/object:Gem::Dependency
115
115
  name: ruby-debug19
116
- requirement: &21240040 !ruby/object:Gem::Requirement
116
+ requirement: &13446520 !ruby/object:Gem::Requirement
117
117
  none: false
118
118
  requirements:
119
119
  - - ! '>='
@@ -121,7 +121,7 @@ dependencies:
121
121
  version: '0'
122
122
  type: :development
123
123
  prerelease: false
124
- version_requirements: *21240040
124
+ version_requirements: *13446520
125
125
  description: RSpec matchers for DataMapper
126
126
  email: blake131313@gmail.com
127
127
  executables: []
@@ -145,7 +145,9 @@ files:
145
145
  - lib/dm/matchers/have_many.rb
146
146
  - lib/dm/matchers/have_many_and_belong_to.rb
147
147
  - lib/dm/matchers/have_property.rb
148
+ - lib/dm/resource.rb
148
149
  - spec/dm/matchers/belong_to_spec.rb
150
+ - spec/dm/matchers/errors_on_spec.rb
149
151
  - spec/dm/matchers/have_errors_on_spec.rb
150
152
  - spec/dm/matchers/have_many_and_belong_to_spec.rb
151
153
  - spec/dm/matchers/have_many_spec.rb