dm-rspec 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -2,8 +2,7 @@ GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
4
  addressable (2.2.6)
5
- archive-tar-minitar (0.5.2)
6
- columnize (0.3.4)
5
+ columnize (0.3.6)
7
6
  data_objects (0.10.6)
8
7
  addressable (~> 2.1)
9
8
  diff-lcs (1.1.3)
@@ -21,6 +20,7 @@ GEM
21
20
  dm-core (~> 1.1.0)
22
21
  do_sqlite3 (0.10.6)
23
22
  data_objects (= 0.10.6)
23
+ ffi (1.0.9)
24
24
  git (1.2.5)
25
25
  guard (0.6.3)
26
26
  thor (~> 0.14.6)
@@ -31,10 +31,12 @@ GEM
31
31
  git (>= 1.2.5)
32
32
  rake
33
33
  libnotify (0.5.7)
34
- linecache19 (0.5.12)
35
- ruby_core_source (>= 0.1.4)
36
- rake (0.9.2)
37
- rcov (0.9.10)
34
+ ffi (= 1.0.9)
35
+ linecache (0.46)
36
+ rbx-require-relative (> 0.0.4)
37
+ rake (0.9.2.2)
38
+ rbx-require-relative (0.0.5)
39
+ rcov (0.9.11)
38
40
  reek (1.2.8)
39
41
  ruby2ruby (~> 1.2)
40
42
  ruby_parser (~> 2.0)
@@ -47,22 +49,17 @@ GEM
47
49
  rspec-expectations (2.3.0)
48
50
  diff-lcs (~> 1.1.2)
49
51
  rspec-mocks (2.3.0)
50
- ruby-debug-base19 (0.11.25)
51
- columnize (>= 0.3.1)
52
- linecache19 (>= 0.5.11)
53
- ruby_core_source (>= 0.1.4)
54
- ruby-debug19 (0.11.6)
55
- columnize (>= 0.3.1)
56
- linecache19 (>= 0.5.11)
57
- ruby-debug-base19 (>= 0.11.19)
58
- ruby2ruby (1.3.0)
52
+ ruby-debug (0.10.4)
53
+ columnize (>= 0.1)
54
+ ruby-debug-base (~> 0.10.4.0)
55
+ ruby-debug-base (0.10.4)
56
+ linecache (>= 0.3)
57
+ ruby2ruby (1.3.1)
59
58
  ruby_parser (~> 2.0)
60
59
  sexp_processor (~> 3.0)
61
- ruby_core_source (0.1.5)
62
- archive-tar-minitar (>= 0.5.2)
63
- ruby_parser (2.3.0)
60
+ ruby_parser (2.3.1)
64
61
  sexp_processor (~> 3.0)
65
- sexp_processor (3.0.6)
62
+ sexp_processor (3.0.8)
66
63
  thor (0.14.6)
67
64
 
68
65
  PLATFORMS
@@ -80,4 +77,4 @@ DEPENDENCIES
80
77
  rcov
81
78
  reek (~> 1.2.8)
82
79
  rspec (~> 2.3.0)
83
- ruby-debug19
80
+ ruby-debug
data/README.markdown CHANGED
@@ -1,4 +1,4 @@
1
- # dm-rspec
1
+ # dm-rspec (RSpec matchers for DataMapper)
2
2
  by Potapov Sergey (aka Blake)
3
3
 
4
4
  A set of rspec matchers to test DataMapper models like you test ActiveRecord models with rspec-rails.
@@ -19,9 +19,10 @@ Add the next to your `spec_helper`:
19
19
  config.include(DataMapper::Matchers)
20
20
  end
21
21
 
22
- In your spec files you can use the next matchers:
22
+ In your spec files you can use the next matchers to test appropriate DataMapper's validations:
23
23
 
24
24
  * belong\_to
25
+ * have\_one
25
26
  * have\_many
26
27
  * have\_many\_and\_belong\_to
27
28
  * have\_property
@@ -34,7 +35,7 @@ In your spec files you can use the next matchers:
34
35
 
35
36
  ## Examples
36
37
 
37
- Assume you have the next models:
38
+ Assume you have the next data mapper models:
38
39
 
39
40
  class Book
40
41
  include DataMapper::Resource
@@ -66,7 +67,7 @@ You specs can contain the next:
66
67
  specify {Genre.should have_many_and_belong_to :books}
67
68
  specify {Books.should have_many_and_belong_to :genres}
68
69
 
69
- specify {Books.should validates_presence_of :name}
70
+ specify {Books.should validate_presence_of :name}
70
71
 
71
72
  it 'has errors' do
72
73
  book = Book.new(:name => 'fails on two validations')
@@ -78,7 +79,7 @@ You specs can contain the next:
78
79
 
79
80
  ## TODO
80
81
 
81
- Implement the next matchers:
82
+ Implement the next rspec matchers:
82
83
 
83
84
  * have timestamps
84
85
  * matchers to verify validations
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -0,0 +1,34 @@
1
+ module DataMapper
2
+ module Matchers
3
+ class HaveOne
4
+ def initialize(child)
5
+ @child = child
6
+ end
7
+
8
+ def matches?(parent)
9
+ @parent = parent
10
+ relation = @parent.relationships[@child.to_s]
11
+
12
+ relation and
13
+ relation.is_a?(DataMapper::Associations::OneToOne::Relationship) and
14
+ relation.parent_model == parent
15
+ end
16
+
17
+ def failure_message
18
+ "expected to have one #{@child}"
19
+ end
20
+
21
+ def negative_failure_message
22
+ "expected not to have one #{@child}"
23
+ end
24
+
25
+ def description
26
+ "has one #{@child}"
27
+ end
28
+ end
29
+
30
+ def have_one(name)
31
+ HaveOne.new(name)
32
+ end
33
+ end
34
+ end
@@ -6,21 +6,17 @@ module DataMapper
6
6
 
7
7
  class ValidatePresenceOf < ValidationMatcher
8
8
  set_validation_subject "presence"
9
- set_default_msg_reg /must not be blank$/
10
-
11
9
 
12
10
  def matches?(model)
13
- [nil, ''].each do |val|
14
- obj = model.new(@property => val)
15
- return false if obj.valid?
16
- if messages = obj.errors.send(:errors)[@property]
17
- return false unless messages.find{|msg| msg =~ @msg_reg}
18
- else
19
- return false
20
- end
11
+ validators = model.validators.contexts[:default]
12
+ presence_of = validators.find do |validator|
13
+ validator.is_a? DataMapper::Validations::PresenceValidator and validator.field_name == @property
21
14
  end
15
+ return false unless presence_of
16
+ return false if @msg and @msg != presence_of.options[:message]
22
17
  true
23
18
  end
19
+
24
20
  end
25
21
 
26
22
  end
@@ -6,16 +6,15 @@ module DataMapper
6
6
 
7
7
  class ValidateUniquenessOf < ValidationMatcher
8
8
  set_validation_subject "uniqueness"
9
- set_default_msg_reg /is already taken$/
10
9
 
11
- def matches?(klass)
12
- val = rand.to_s
13
- klass.create!(@property => val)
14
- model = klass.new(@property => val)
15
- model.valid?
16
- errors = model.errors.send(:errors)
17
- errors = errors[@property.to_sym]
18
- errors and errors.find {|msg| msg =~ @msg_reg}
10
+ def matches?(model)
11
+ validators = model.validators.contexts[:default]
12
+ uniqueness_of = validators.find do |validator|
13
+ validator.is_a? DataMapper::Validations::UniquenessValidator and validator.field_name == @property
14
+ end
15
+ return false unless uniqueness_of
16
+ return false if @msg and @msg != uniqueness_of.options[:message]
17
+ true
19
18
  end
20
19
  end
21
20
 
data/lib/dm/matchers.rb CHANGED
@@ -5,6 +5,7 @@ module DataMapper
5
5
  end
6
6
 
7
7
  require 'dm/matchers/belong_to'
8
+ require 'dm/matchers/have_one'
8
9
  require 'dm/matchers/have_many'
9
10
  require 'dm/matchers/have_many_and_belong_to'
10
11
  require 'dm/matchers/have_many_through'
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe DataMapper::Matchers::HaveOne do
4
+ context '#should' do
5
+ it 'passes if association exists' do
6
+ lambda { Book.should have_one :foreword}.should_pass
7
+ end
8
+
9
+ it 'fails if association does not exist' do
10
+ lambda { Author.should have_one :book}.should fail_with "expected to have one book"
11
+ end
12
+ end
13
+
14
+ context '#should_not' do
15
+ it 'fails if association exists' do
16
+ lambda { Book.should_not have_one :foreword}.should fail_with "expected not to have one foreword"
17
+ end
18
+ end
19
+ end
data/spec/spec_helper.rb CHANGED
@@ -48,6 +48,7 @@ class Book
48
48
  property :id, Serial
49
49
  property :name, String
50
50
  belongs_to :author
51
+ has 1, :foreword
51
52
  has n, :genres, :through => Resource
52
53
  has n, :taggings
53
54
  has n, :tags, :through => :taggings
@@ -90,6 +91,10 @@ class Tagging
90
91
  belongs_to :book
91
92
  end
92
93
 
94
+ class Foreword
95
+ include DataMapper::Resource
96
+ property :id, Serial
97
+ end
93
98
 
94
99
  DataMapper.finalize
95
100
  DataMapper.auto_migrate!
metadata CHANGED
@@ -1,156 +1,207 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: dm-rspec
3
- version: !ruby/object:Gem::Version
4
- version: 0.1.1
3
+ version: !ruby/object:Gem::Version
4
+ hash: 31
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 2
10
+ version: 0.1.2
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Potapov Sergey
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2011-09-12 00:00:00.000000000 +03:00
13
- default_executable:
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: dm-core
17
- requirement: &15883760 !ruby/object:Gem::Requirement
17
+
18
+ date: 2011-12-29 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ version_requirements: &id001 !ruby/object:Gem::Requirement
18
22
  none: false
19
- requirements:
20
- - - ! '>='
21
- - !ruby/object:Gem::Version
22
- version: '0'
23
- type: :runtime
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ hash: 3
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ name: dm-core
24
31
  prerelease: false
25
- version_requirements: *15883760
26
- - !ruby/object:Gem::Dependency
27
- name: dm-validations
28
- requirement: &15883280 !ruby/object:Gem::Requirement
29
- none: false
30
- requirements:
31
- - - ! '>='
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
32
  type: :runtime
33
+ requirement: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ version_requirements: &id002 !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ hash: 3
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ name: dm-validations
35
45
  prerelease: false
36
- version_requirements: *15883280
37
- - !ruby/object:Gem::Dependency
38
- name: rspec
39
- requirement: &15882800 !ruby/object:Gem::Requirement
46
+ type: :runtime
47
+ requirement: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ version_requirements: &id003 !ruby/object:Gem::Requirement
40
50
  none: false
41
- requirements:
51
+ requirements:
42
52
  - - ~>
43
- - !ruby/object:Gem::Version
53
+ - !ruby/object:Gem::Version
54
+ hash: 3
55
+ segments:
56
+ - 2
57
+ - 3
58
+ - 0
44
59
  version: 2.3.0
45
- type: :development
60
+ name: rspec
46
61
  prerelease: false
47
- version_requirements: *15882800
48
- - !ruby/object:Gem::Dependency
49
- name: bundler
50
- requirement: &15882320 !ruby/object:Gem::Requirement
62
+ type: :development
63
+ requirement: *id003
64
+ - !ruby/object:Gem::Dependency
65
+ version_requirements: &id004 !ruby/object:Gem::Requirement
51
66
  none: false
52
- requirements:
67
+ requirements:
53
68
  - - ~>
54
- - !ruby/object:Gem::Version
69
+ - !ruby/object:Gem::Version
70
+ hash: 23
71
+ segments:
72
+ - 1
73
+ - 0
74
+ - 0
55
75
  version: 1.0.0
56
- type: :development
76
+ name: bundler
57
77
  prerelease: false
58
- version_requirements: *15882320
59
- - !ruby/object:Gem::Dependency
60
- name: jeweler
61
- requirement: &15881840 !ruby/object:Gem::Requirement
78
+ type: :development
79
+ requirement: *id004
80
+ - !ruby/object:Gem::Dependency
81
+ version_requirements: &id005 !ruby/object:Gem::Requirement
62
82
  none: false
63
- requirements:
83
+ requirements:
64
84
  - - ~>
65
- - !ruby/object:Gem::Version
85
+ - !ruby/object:Gem::Version
86
+ hash: 7
87
+ segments:
88
+ - 1
89
+ - 6
90
+ - 4
66
91
  version: 1.6.4
67
- type: :development
92
+ name: jeweler
68
93
  prerelease: false
69
- version_requirements: *15881840
70
- - !ruby/object:Gem::Dependency
71
- name: rcov
72
- requirement: &15881360 !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
75
- - - ! '>='
76
- - !ruby/object:Gem::Version
77
- version: '0'
78
94
  type: :development
95
+ requirement: *id005
96
+ - !ruby/object:Gem::Dependency
97
+ version_requirements: &id006 !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ hash: 3
103
+ segments:
104
+ - 0
105
+ version: "0"
106
+ name: rcov
79
107
  prerelease: false
80
- version_requirements: *15881360
81
- - !ruby/object:Gem::Dependency
82
- name: reek
83
- requirement: &15880880 !ruby/object:Gem::Requirement
108
+ type: :development
109
+ requirement: *id006
110
+ - !ruby/object:Gem::Dependency
111
+ version_requirements: &id007 !ruby/object:Gem::Requirement
84
112
  none: false
85
- requirements:
113
+ requirements:
86
114
  - - ~>
87
- - !ruby/object:Gem::Version
115
+ - !ruby/object:Gem::Version
116
+ hash: 15
117
+ segments:
118
+ - 1
119
+ - 2
120
+ - 8
88
121
  version: 1.2.8
89
- type: :development
122
+ name: reek
90
123
  prerelease: false
91
- version_requirements: *15880880
92
- - !ruby/object:Gem::Dependency
93
- name: guard-rspec
94
- requirement: &15880400 !ruby/object:Gem::Requirement
95
- none: false
96
- requirements:
97
- - - ! '>='
98
- - !ruby/object:Gem::Version
99
- version: '0'
100
124
  type: :development
101
- prerelease: false
102
- version_requirements: *15880400
103
- - !ruby/object:Gem::Dependency
104
- name: libnotify
105
- requirement: &15879920 !ruby/object:Gem::Requirement
125
+ requirement: *id007
126
+ - !ruby/object:Gem::Dependency
127
+ version_requirements: &id008 !ruby/object:Gem::Requirement
106
128
  none: false
107
- requirements:
108
- - - ! '>='
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
- type: :development
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ hash: 3
133
+ segments:
134
+ - 0
135
+ version: "0"
136
+ name: guard-rspec
112
137
  prerelease: false
113
- version_requirements: *15879920
114
- - !ruby/object:Gem::Dependency
115
- name: ruby-debug19
116
- requirement: &15879440 !ruby/object:Gem::Requirement
117
- none: false
118
- requirements:
119
- - - ! '>='
120
- - !ruby/object:Gem::Version
121
- version: '0'
122
138
  type: :development
123
- prerelease: false
124
- version_requirements: *15879440
125
- - !ruby/object:Gem::Dependency
126
- name: dm-migrations
127
- requirement: &15878960 !ruby/object:Gem::Requirement
139
+ requirement: *id008
140
+ - !ruby/object:Gem::Dependency
141
+ version_requirements: &id009 !ruby/object:Gem::Requirement
128
142
  none: false
129
- requirements:
130
- - - ! '>='
131
- - !ruby/object:Gem::Version
132
- version: '0'
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ hash: 3
147
+ segments:
148
+ - 0
149
+ version: "0"
150
+ name: libnotify
151
+ prerelease: false
133
152
  type: :development
153
+ requirement: *id009
154
+ - !ruby/object:Gem::Dependency
155
+ version_requirements: &id010 !ruby/object:Gem::Requirement
156
+ none: false
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ hash: 3
161
+ segments:
162
+ - 0
163
+ version: "0"
164
+ name: ruby-debug
134
165
  prerelease: false
135
- version_requirements: *15878960
136
- - !ruby/object:Gem::Dependency
137
- name: dm-sqlite-adapter
138
- requirement: &15912980 !ruby/object:Gem::Requirement
166
+ type: :development
167
+ requirement: *id010
168
+ - !ruby/object:Gem::Dependency
169
+ version_requirements: &id011 !ruby/object:Gem::Requirement
139
170
  none: false
140
- requirements:
141
- - - ! '>='
142
- - !ruby/object:Gem::Version
143
- version: '0'
171
+ requirements:
172
+ - - ">="
173
+ - !ruby/object:Gem::Version
174
+ hash: 3
175
+ segments:
176
+ - 0
177
+ version: "0"
178
+ name: dm-migrations
179
+ prerelease: false
144
180
  type: :development
181
+ requirement: *id011
182
+ - !ruby/object:Gem::Dependency
183
+ version_requirements: &id012 !ruby/object:Gem::Requirement
184
+ none: false
185
+ requirements:
186
+ - - ">="
187
+ - !ruby/object:Gem::Version
188
+ hash: 3
189
+ segments:
190
+ - 0
191
+ version: "0"
192
+ name: dm-sqlite-adapter
145
193
  prerelease: false
146
- version_requirements: *15912980
194
+ type: :development
195
+ requirement: *id012
147
196
  description: RSpec matchers for DataMapper
148
197
  email: blake131313@gmail.com
149
198
  executables: []
199
+
150
200
  extensions: []
151
- extra_rdoc_files:
201
+
202
+ extra_rdoc_files:
152
203
  - README.markdown
153
- files:
204
+ files:
154
205
  - .document
155
206
  - .rspec
156
207
  - CHANGELOG.markdown
@@ -167,6 +218,7 @@ files:
167
218
  - lib/dm/matchers/have_many.rb
168
219
  - lib/dm/matchers/have_many_and_belong_to.rb
169
220
  - lib/dm/matchers/have_many_through.rb
221
+ - lib/dm/matchers/have_one.rb
170
222
  - lib/dm/matchers/have_property.rb
171
223
  - lib/dm/matchers/validate_format_of.rb
172
224
  - lib/dm/matchers/validate_presence_of.rb
@@ -178,35 +230,44 @@ files:
178
230
  - spec/dm/matchers/have_many_and_belong_to_spec.rb
179
231
  - spec/dm/matchers/have_many_spec.rb
180
232
  - spec/dm/matchers/have_many_through_spec.rb
233
+ - spec/dm/matchers/have_one_spec.rb
181
234
  - spec/dm/matchers/have_property_spec.rb
182
235
  - spec/dm/matchers/validate_format_of_spec.rb
183
236
  - spec/dm/matchers/validate_presence_of_spec.rb
184
237
  - spec/dm/matchers/validate_uniquness_of_spec.rb
185
238
  - spec/spec_helper.rb
186
- has_rdoc: true
187
239
  homepage: http://github.com/greyblake/dm-rspec
188
- licenses:
240
+ licenses:
189
241
  - MIT
190
242
  post_install_message:
191
243
  rdoc_options: []
192
- require_paths:
244
+
245
+ require_paths:
193
246
  - lib
194
- required_ruby_version: !ruby/object:Gem::Requirement
247
+ required_ruby_version: !ruby/object:Gem::Requirement
195
248
  none: false
196
- requirements:
197
- - - ! '>='
198
- - !ruby/object:Gem::Version
199
- version: '0'
200
- required_rubygems_version: !ruby/object:Gem::Requirement
249
+ requirements:
250
+ - - ">="
251
+ - !ruby/object:Gem::Version
252
+ hash: 3
253
+ segments:
254
+ - 0
255
+ version: "0"
256
+ required_rubygems_version: !ruby/object:Gem::Requirement
201
257
  none: false
202
- requirements:
203
- - - ! '>='
204
- - !ruby/object:Gem::Version
205
- version: '0'
258
+ requirements:
259
+ - - ">="
260
+ - !ruby/object:Gem::Version
261
+ hash: 3
262
+ segments:
263
+ - 0
264
+ version: "0"
206
265
  requirements: []
266
+
207
267
  rubyforge_project:
208
- rubygems_version: 1.6.2
268
+ rubygems_version: 1.8.10
209
269
  signing_key:
210
270
  specification_version: 3
211
271
  summary: It's a set of matchers for DataMapper. Something similar to rspec-rails gem.
212
272
  test_files: []
273
+