dm-rspec 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.markdown +15 -0
- data/README.markdown +4 -3
- data/VERSION +1 -1
- data/lib/dm/matchers.rb +1 -1
- data/lib/dm/matchers/have_many.rb +6 -0
- data/lib/dm/matchers/have_many_through.rb +31 -0
- data/spec/dm/matchers/have_many_through_spec.rb +21 -0
- data/spec/spec_helper.rb +15 -0
- metadata +25 -24
- data/lib/dm/matchers/have_errors_on.rb +0 -38
- data/spec/dm/matchers/have_errors_on_spec.rb +0 -29
data/CHANGELOG.markdown
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
### version 0.1.0 / 2011-09-04
|
2
|
+
|
3
|
+
* New matcher: have many through
|
4
|
+
* have\_errors\_on is removed
|
5
|
+
|
6
|
+
|
7
|
+
### version 0.0.2 / 2011-09-04
|
8
|
+
|
9
|
+
* New matcher have(n).errors_on(:property)
|
10
|
+
* have\_errors\_on is deprecated
|
11
|
+
|
12
|
+
|
13
|
+
### version 0.0.1 / 2011-09-03
|
14
|
+
|
15
|
+
* Initial release
|
data/README.markdown
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# dm-rspec
|
2
|
+
by Potapov Sergey (aka Blake)
|
2
3
|
|
3
4
|
A set of rspec matchers to test DataMapper models like you test ActiveRecord models with rspec-rails.
|
4
5
|
|
@@ -25,6 +26,7 @@ In your spec files you can use the next matchers:
|
|
25
26
|
* have\_many\_and\_belong\_to
|
26
27
|
* have\_property
|
27
28
|
* have(n).errors_on(:property)
|
29
|
+
* have_many(:association).trough(:another_association)
|
28
30
|
|
29
31
|
|
30
32
|
## Examples
|
@@ -72,9 +74,8 @@ You specs can contain the next:
|
|
72
74
|
|
73
75
|
Implement the next matchers:
|
74
76
|
|
75
|
-
* have
|
76
|
-
|
77
|
-
Implement matchers for validations.
|
77
|
+
* have timestamps
|
78
|
+
* matchers to verify validations
|
78
79
|
|
79
80
|
|
80
81
|
## Contributing to dm-rspec
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
data/lib/dm/matchers.rb
CHANGED
@@ -15,6 +15,12 @@ module DataMapper
|
|
15
15
|
relation.parent_model == parent
|
16
16
|
end
|
17
17
|
|
18
|
+
# called only when the next syntax is used:
|
19
|
+
# Book.should have_many(:tags).trough(:tagging)
|
20
|
+
def through(broker)
|
21
|
+
HaveManyThrough.new(@children, broker)
|
22
|
+
end
|
23
|
+
|
18
24
|
def failure_message
|
19
25
|
"expected to have many #{@children}"
|
20
26
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module DataMapper
|
2
|
+
module Matchers
|
3
|
+
|
4
|
+
class HaveManyThrough
|
5
|
+
def initialize(children, broker)
|
6
|
+
@children, @broker = children, broker
|
7
|
+
end
|
8
|
+
|
9
|
+
def matches?(parent)
|
10
|
+
relation = parent.relationships[@children.to_s]
|
11
|
+
|
12
|
+
relation.parent_model == parent and
|
13
|
+
relation.name == @children.to_sym and
|
14
|
+
relation.options[:through] == @broker.to_sym
|
15
|
+
end
|
16
|
+
|
17
|
+
def failure_message
|
18
|
+
"expected to have many #{@children} through #{@broker}"
|
19
|
+
end
|
20
|
+
|
21
|
+
def negative_failure_message
|
22
|
+
"expected to not have many #{@children} through #{@broker}"
|
23
|
+
end
|
24
|
+
|
25
|
+
def description
|
26
|
+
"has many #{@children} through #{@broker}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
describe DataMapper::Matchers::HaveManyThrough do
|
5
|
+
context '#should' do
|
6
|
+
it 'passes if association exists' do
|
7
|
+
lambda { Book.should have_many(:tags).through(:taggings) }.should_pass
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'fails if association does not exist' do
|
11
|
+
lambda { Author.should have_many(:books).through(:something) }.should fail_with "expected to have many books through something"
|
12
|
+
lambda { Book.should have_many(:tags).through(:author) }.should fail_with "expected to have many tags through author"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context '#should_not' do
|
17
|
+
it 'fails if association exists' do
|
18
|
+
lambda { Book.should_not have_many(:tags).through(:taggings) }.should fail_with "expected to not have many tags through taggings"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -42,6 +42,8 @@ class Book
|
|
42
42
|
property :name, String
|
43
43
|
belongs_to :author
|
44
44
|
has n, :genres, :through => Resource
|
45
|
+
has n, :taggings
|
46
|
+
has n, :tags, :through => :taggings
|
45
47
|
validates_presence_of :name
|
46
48
|
validates_length_of :name, :min => 10
|
47
49
|
end
|
@@ -58,3 +60,16 @@ class Genre
|
|
58
60
|
property :name, String
|
59
61
|
has n, :books, :through => Resource
|
60
62
|
end
|
63
|
+
|
64
|
+
class Tag
|
65
|
+
include DataMapper::Resource
|
66
|
+
property :id, Serial
|
67
|
+
has n, :taggings
|
68
|
+
has n, :books, :through => :taggings
|
69
|
+
end
|
70
|
+
|
71
|
+
class Tagging
|
72
|
+
include DataMapper::Resource
|
73
|
+
belongs_to :tag
|
74
|
+
belongs_to :book
|
75
|
+
end
|
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
|
4
|
+
version: 0.1.0
|
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-
|
12
|
+
date: 2011-09-06 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: &
|
17
|
+
requirement: &18252280 !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: *
|
25
|
+
version_requirements: *18252280
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: dm-validations
|
28
|
-
requirement: &
|
28
|
+
requirement: &18251800 !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: *
|
36
|
+
version_requirements: *18251800
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: rspec
|
39
|
-
requirement: &
|
39
|
+
requirement: &18251320 !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: *
|
47
|
+
version_requirements: *18251320
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: bundler
|
50
|
-
requirement: &
|
50
|
+
requirement: &18250840 !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: *
|
58
|
+
version_requirements: *18250840
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: jeweler
|
61
|
-
requirement: &
|
61
|
+
requirement: &18250360 !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: *
|
69
|
+
version_requirements: *18250360
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: rcov
|
72
|
-
requirement: &
|
72
|
+
requirement: &18249880 !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: *
|
80
|
+
version_requirements: *18249880
|
81
81
|
- !ruby/object:Gem::Dependency
|
82
82
|
name: reek
|
83
|
-
requirement: &
|
83
|
+
requirement: &18249400 !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: *
|
91
|
+
version_requirements: *18249400
|
92
92
|
- !ruby/object:Gem::Dependency
|
93
93
|
name: guard-rspec
|
94
|
-
requirement: &
|
94
|
+
requirement: &18248920 !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: *
|
102
|
+
version_requirements: *18248920
|
103
103
|
- !ruby/object:Gem::Dependency
|
104
104
|
name: libnotify
|
105
|
-
requirement: &
|
105
|
+
requirement: &18248440 !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: *
|
113
|
+
version_requirements: *18248440
|
114
114
|
- !ruby/object:Gem::Dependency
|
115
115
|
name: ruby-debug19
|
116
|
-
requirement: &
|
116
|
+
requirement: &18247960 !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: *
|
124
|
+
version_requirements: *18247960
|
125
125
|
description: RSpec matchers for DataMapper
|
126
126
|
email: blake131313@gmail.com
|
127
127
|
executables: []
|
@@ -131,6 +131,7 @@ extra_rdoc_files:
|
|
131
131
|
files:
|
132
132
|
- .document
|
133
133
|
- .rspec
|
134
|
+
- CHANGELOG.markdown
|
134
135
|
- GPL-LICENSE.txt
|
135
136
|
- Gemfile
|
136
137
|
- Gemfile.lock
|
@@ -141,16 +142,16 @@ files:
|
|
141
142
|
- lib/dm-rspec.rb
|
142
143
|
- lib/dm/matchers.rb
|
143
144
|
- lib/dm/matchers/belong_to.rb
|
144
|
-
- lib/dm/matchers/have_errors_on.rb
|
145
145
|
- lib/dm/matchers/have_many.rb
|
146
146
|
- lib/dm/matchers/have_many_and_belong_to.rb
|
147
|
+
- lib/dm/matchers/have_many_through.rb
|
147
148
|
- lib/dm/matchers/have_property.rb
|
148
149
|
- lib/dm/resource.rb
|
149
150
|
- spec/dm/matchers/belong_to_spec.rb
|
150
151
|
- spec/dm/matchers/errors_on_spec.rb
|
151
|
-
- spec/dm/matchers/have_errors_on_spec.rb
|
152
152
|
- spec/dm/matchers/have_many_and_belong_to_spec.rb
|
153
153
|
- spec/dm/matchers/have_many_spec.rb
|
154
|
+
- spec/dm/matchers/have_many_through_spec.rb
|
154
155
|
- spec/dm/matchers/have_property_spec.rb
|
155
156
|
- spec/spec_helper.rb
|
156
157
|
has_rdoc: true
|
@@ -1,38 +0,0 @@
|
|
1
|
-
module DataMapper
|
2
|
-
module Matchers
|
3
|
-
|
4
|
-
class HaveErrorsOn
|
5
|
-
def initialize(property)
|
6
|
-
@property = property.to_sym
|
7
|
-
end
|
8
|
-
|
9
|
-
def matches?(model)
|
10
|
-
@model = model
|
11
|
-
@model.valid?
|
12
|
-
!@model.errors[@property].empty?
|
13
|
-
end
|
14
|
-
|
15
|
-
def failure_message
|
16
|
-
"expected to have errors on #{@property}"
|
17
|
-
end
|
18
|
-
|
19
|
-
def negative_failure_message
|
20
|
-
"expected to not have errors on #{@property}"
|
21
|
-
end
|
22
|
-
|
23
|
-
def description
|
24
|
-
"has errors on #{@property}"
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def have_errors_on(property)
|
29
|
-
puts "dm-rspec: `have_errors_on` is deprecated. Please use `have(n).errors_on` instead"
|
30
|
-
HaveErrorsOn.new(property)
|
31
|
-
end
|
32
|
-
|
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
|
37
|
-
end
|
38
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
|
4
|
-
describe DataMapper::Matchers::HaveErrorsOn do
|
5
|
-
before(:all) do
|
6
|
-
@invalid = Book.new
|
7
|
-
@valid = Book.new(:name => 'War and Peace')
|
8
|
-
end
|
9
|
-
|
10
|
-
|
11
|
-
context '#should' do
|
12
|
-
it 'passes for invalid model' do
|
13
|
-
lambda {@invalid.should have_errors_on :name}.should_pass
|
14
|
-
lambda {@invalid.should have_error_on :name}.should_pass
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'fails for valid model' do
|
18
|
-
lambda {@valid.should have_errors_on :name}.should fail_with "expected to have errors on name"
|
19
|
-
lambda {@valid.should have_error_on :name}.should fail_with "expected to have errors on name"
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
context '#should_not' do
|
24
|
-
it 'fails for invalid model' do
|
25
|
-
lambda {@invalid.should_not have_errors_on :name}.should fail_with "expected to not have errors on name"
|
26
|
-
lambda {@invalid.should_not have_error_on :name}.should fail_with "expected to not have errors on name"
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|