remarkable 3.1.8 → 3.1.9

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,58 +1,58 @@
1
- # v3.1
2
-
3
- * Remarkable.include_matchers! require just one argument [#80]
4
-
5
- * Pending groups show proper backtrace and run by default in execute mode [#49]
6
-
7
- * Added support to blocks configuration. All Remarkable matcher and macros can
8
- now be configured using a block:
9
-
10
- should_accept_nested_attributes_for :tasks do |m|
11
- m.allow_destroy
12
- m.accept(:name => 'cool')
13
- m.reject(:name => '')
14
- end
15
-
16
- * Added support to {{sentence}} as interpolation option in optionals.
17
- Previously we had:
18
-
19
- validate_uniqueness_of :id, :scope => [:project_id, :company_id]
20
- # Description: "should require unique attributes for id scoped to [:project_id, :company_id]"
21
-
22
- Now with the new sentence option, we can have:
23
-
24
- validate_uniqueness_of :id, :scope => [:project_id, :company_id]
25
- # Description: "should require unique attributes for id scoped to project_id and company_id"
26
-
27
- * Added support to splat and block to optionals
28
-
29
- * Added namespace lookup to optionals and expectations. For example, in ActiveRecord
30
- several matchers have :allow_nil and :allow_blank as options. So you can store
31
- the translation at:
32
-
33
- remarkable:
34
- activerecord:
35
- optionals:
36
- allow_nil:
37
- # ...
38
- allow_blank:
39
- # ...
40
-
41
- * Added a repository to hold I18n files
42
-
43
- # v3.0
44
-
45
- * Added Remarkable::Matchers. Now you can include your Remarkable matchers and
46
- macros in test unit as well.
47
-
48
- class Test::Unit::TestCase
49
- include Spec::Matchers
50
- include Remarkable::Matchers
51
- extend Remarkable::Macros
52
- end
53
-
54
- * Added pending and disabled macros
55
- * Added I18n
56
- * Added DSL core structure
57
- * Added macros core structure
58
- * Added matchers core structure
1
+ # v3.1
2
+
3
+ * Remarkable.include_matchers! require just one argument [#80]
4
+
5
+ * Pending groups show proper backtrace and run by default in execute mode [#49]
6
+
7
+ * Added support to blocks configuration. All Remarkable matcher and macros can
8
+ now be configured using a block:
9
+
10
+ should_accept_nested_attributes_for :tasks do |m|
11
+ m.allow_destroy
12
+ m.accept(:name => 'cool')
13
+ m.reject(:name => '')
14
+ end
15
+
16
+ * Added support to {{sentence}} as interpolation option in optionals.
17
+ Previously we had:
18
+
19
+ validate_uniqueness_of :id, :scope => [:project_id, :company_id]
20
+ # Description: "should require unique attributes for id scoped to [:project_id, :company_id]"
21
+
22
+ Now with the new sentence option, we can have:
23
+
24
+ validate_uniqueness_of :id, :scope => [:project_id, :company_id]
25
+ # Description: "should require unique attributes for id scoped to project_id and company_id"
26
+
27
+ * Added support to splat and block to optionals
28
+
29
+ * Added namespace lookup to optionals and expectations. For example, in ActiveRecord
30
+ several matchers have :allow_nil and :allow_blank as options. So you can store
31
+ the translation at:
32
+
33
+ remarkable:
34
+ activerecord:
35
+ optionals:
36
+ allow_nil:
37
+ # ...
38
+ allow_blank:
39
+ # ...
40
+
41
+ * Added a repository to hold I18n files
42
+
43
+ # v3.0
44
+
45
+ * Added Remarkable::Matchers. Now you can include your Remarkable matchers and
46
+ macros in test unit as well.
47
+
48
+ class Test::Unit::TestCase
49
+ include Spec::Matchers
50
+ include Remarkable::Matchers
51
+ extend Remarkable::Macros
52
+ end
53
+
54
+ * Added pending and disabled macros
55
+ * Added I18n
56
+ * Added DSL core structure
57
+ * Added macros core structure
58
+ * Added matchers core structure
data/LICENSE CHANGED
@@ -1,20 +1,20 @@
1
- Copyright (c) 2009 Carlos Brando
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ Copyright (c) 2009 Carlos Brando
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README CHANGED
@@ -1,18 +1,18 @@
1
- = Remarkable
2
-
3
- This is the core package of Remarkable. It provides a DSL for creating matchers
1
+ = Remarkable
2
+
3
+ This is the core package of Remarkable. It provides a DSL for creating matchers
4
4
  with I18n support, decouples messages from matchers logic, add rspec extra features,
5
- create macros automatically and allow those macros to be configurable wth blocks.
6
-
7
- == Macros
8
-
9
- Each matcher in Remarkable is also available as a macro. So this matcher:
5
+ create macros automatically and allow those macros to be configurable wth blocks.
6
+
7
+ == Macros
8
+
9
+ Each matcher in Remarkable is also available as a macro. So this matcher:
10
10
 
11
11
  it { should validate_numericality_of(:age, :greater_than => 18, :only_integer => true) }
12
- it { should validate_numericality_of(:age).greater_than(18).only_integer }
13
-
14
- Can also be written as:
15
-
12
+ it { should validate_numericality_of(:age).greater_than(18).only_integer }
13
+
14
+ Can also be written as:
15
+
16
16
  should_validate_numericality_of :age, :greater_than => 18, :only_integer => true
17
17
 
18
18
  Which can be also written as:
@@ -21,192 +21,192 @@ Which can be also written as:
21
21
  m.only_integer
22
22
  m.greater_than 18
23
23
  # Or: m.greater_than = 18
24
- end
24
+ end
25
25
 
26
26
  Choose your style!
27
27
 
28
28
  == Disabled Macros
29
-
30
- Remarkable adds the possibility to disable macros. So as you could do:
31
-
32
- xit { should validate_presence_of(:name) }
33
-
34
- You can also do:
35
-
36
- xshould_validate_presence_of :name
37
-
38
- And it will show in your specs output:
39
-
40
- "Example disabled: require name to be set"
41
-
42
- == Pending macros
43
-
44
- In Rspec you can mark some examples as pending:
45
-
46
- it "should have one manager" do
47
- pending("create managers resource")
48
- end
49
-
50
- it "should validate associated manager" do
51
- pending("create managers resource")
52
- end
53
-
54
- To allow this to work with macros, we created the pending group:
55
-
56
- pending "create managers resource" do
57
- should_have_one :manager
58
- should_validate_associated :manager
59
- end
60
-
61
- This outputs the same as above.
62
-
63
- == I18n
64
-
65
- All matchers come with I18n support. You can find an example locale file under
66
- the locale folder of each project.
67
-
68
- To change the locale, you have first to add your locale file:
69
-
70
- Remarkable.add_locale 'path/to/my_locale.yml'
71
-
72
- And then:
73
-
74
- Remarkable.locale = :my_locale
75
-
76
- Internationalization is powered by the I18n gem. If you are using it with Rails,
77
- it will use the built in gem, otherwise you will have to install the gem by hand:
78
-
79
- gem sources -a http://gems.github.com
80
- sudo gem install svenfuchs-i18n
81
-
82
- == Creating you own matcher
83
-
84
- Create a new matcher is easy. Let's create validate_inclusion_of matcher for
85
- ActiveRecord as an example. A first matcher version would be:
86
-
87
- module Remarkable
88
- module ActiveRecord
89
- module Matchers
90
- class ValidateInclusionOfMatcher < Remarkable::ActiveRecord::Base
91
- arguments :attribute
92
- assertion :is_valid?
93
-
94
- optional :in
95
- optional :allow_blank, :allow_nil, :default => true
96
-
97
- protected
98
-
99
- def is_valid?
100
- @options[:in].each do |value|
101
- @subject.send(:"#{@attribute}=", value)
102
- return false, :value => value unless @subject.valid?
103
- end
104
- true
105
- end
106
- end
107
-
108
- def validate_inclusion_of(*args)
109
- ValidateInclusionOfMatcher.new(*args).spec(self)
110
- end
111
- end
112
- end
113
- end
114
-
115
- This creates a matcher which requires one attribute and has :in, :allow_blank
116
- and :allow_nil as options. So you can call the matcher in the following way:
117
-
118
- should_validate_inclusion_of :size, :in => %w(S M L XL)
119
- should_validate_inclusion_of :size, :in => %w(S M L XL), :allow_blank => true
120
-
121
- it { should validate_inclusion_of(:size, :in => %w(S M L XL)).allow_nil(true) }
122
- it { should validate_inclusion_of(:size, :in => %w(S M L XL)).allow_nil }
123
-
124
- it { should validate_inclusion_of(:size, :in => %w(S M L XL)) }
125
- it { should validate_inclusion_of(:size, :in => %w(S M L XL), :allow_nil => true) }
126
-
127
- The assertions methods (in this case, :is_valid?) makes the matcher pass when
128
- it returns true and fail when returns false.
129
-
130
- As you noticed, the matcher doesn't have any message on it. You add them on I18n
131
- file. A file for this example would be:
132
-
133
- remarkable:
134
- active_record:
135
- validate_inclusion_of:
136
- description: "validate inclusion of {{attribute}}"
137
- expectations:
138
- is_valid: "to be valid when {{attribute}} is {{value}}"
139
- optionals:
140
- in:
141
- positive: "in {{inspect}}"
142
- allow_nil:
143
- positive: "allowing nil values"
144
- negative: "not allowing nil values"
145
- allow_blank:
146
- positive: "allowing blank values"
147
- negative: "allowing blank values"
148
-
149
- The optionals are just added to the description message when they are supplied.
150
- Look some description messages examples:
151
-
152
- should_validate_inclusion_of :size, :in => %w(S M L XL)
153
- #=> should validate inclusion of size in ["S", "M", "L", "XL"]
154
-
155
- should_validate_inclusion_of :size, :in => %w(S M L XL), :allow_nil => true
156
- #=> should validate inclusion of size in ["S", "M", "L", "XL"] and allowing nil values
157
-
158
- should_validate_inclusion_of :size, :in => %w(S M L XL), :allow_nil => false
159
- #=> should validate inclusion of size in ["S", "M", "L", "XL"] and not allowing nil values
160
-
161
- Please notice that the arguments are available as interpolation option, as well
162
- as the optionals.
163
-
164
- The expectations message are set whenever one of the assertions returns false.
165
- In this case, whenever the assertion fails, we are also returning a hash, with
166
- the value that failed:
167
-
168
- return false, :value => value
169
-
170
- This will tell remarkable to make value as interpolation option too.
171
-
172
- Whenever you create all your matchers, you tell remarkable to add them to the
173
- desired rspec example group:
174
-
175
- Remarkable.include_matchers!(Remarkable::ActiveRecord, Spec::Example::ExampleGroup)
176
-
177
- == Working with collections
178
-
179
- Finally, Remarkable also makes easy to deal with collections. The same matcher
180
- could be easily extended to accept a collection of attributes instead of just one:
181
-
182
- should_validate_inclusion_of :first_size, :second_size, :in => %w(S M L XL)
183
-
184
- For this we have just those two lines:
185
-
186
- arguments :attribute
187
- assertion :is_valid?
188
-
189
- For:
190
-
191
- arguments :collection => :attributes, :as => :attribute
192
- collection_assertion :is_valid?
193
-
194
- This means that the collection will be kept in the @attributes instance variable
195
- and for each value in the collection, it will run the :is_valid? assertion.
196
-
197
- Whenever running the assertion, it will also set the @attribute (in singular)
198
- variable. In your I18n files, you just need to change your description:
199
-
200
- validate_inclusion_of:
201
- description: "validate inclusion of {{attributes}}"
202
-
203
- And this will output:
204
-
205
- should_validate_inclusion_of :first_size, :second_size, :in => %w(S M L XL)
206
- #=> should validate inclusion of first size and second size in ["S", "M", "L", "XL"]
207
-
208
- == More
209
-
210
- This is just an overview of the API. You can add extra options to interpolation
211
- by overwriting the interpolation_options methods, you can add callbacks after
212
- initialize your matcher or before asserting and much more!
29
+
30
+ Remarkable adds the possibility to disable macros. So as you could do:
31
+
32
+ xit { should validate_presence_of(:name) }
33
+
34
+ You can also do:
35
+
36
+ xshould_validate_presence_of :name
37
+
38
+ And it will show in your specs output:
39
+
40
+ "Example disabled: require name to be set"
41
+
42
+ == Pending macros
43
+
44
+ In Rspec you can mark some examples as pending:
45
+
46
+ it "should have one manager" do
47
+ pending("create managers resource")
48
+ end
49
+
50
+ it "should validate associated manager" do
51
+ pending("create managers resource")
52
+ end
53
+
54
+ To allow this to work with macros, we created the pending group:
55
+
56
+ pending "create managers resource" do
57
+ should_have_one :manager
58
+ should_validate_associated :manager
59
+ end
60
+
61
+ This outputs the same as above.
62
+
63
+ == I18n
64
+
65
+ All matchers come with I18n support. You can find an example locale file under
66
+ the locale folder of each project.
67
+
68
+ To change the locale, you have first to add your locale file:
69
+
70
+ Remarkable.add_locale 'path/to/my_locale.yml'
71
+
72
+ And then:
73
+
74
+ Remarkable.locale = :my_locale
75
+
76
+ Internationalization is powered by the I18n gem. If you are using it with Rails,
77
+ it will use the built in gem, otherwise you will have to install the gem by hand:
78
+
79
+ gem sources -a http://gems.github.com
80
+ sudo gem install svenfuchs-i18n
81
+
82
+ == Creating you own matcher
83
+
84
+ Create a new matcher is easy. Let's create validate_inclusion_of matcher for
85
+ ActiveRecord as an example. A first matcher version would be:
86
+
87
+ module Remarkable
88
+ module ActiveRecord
89
+ module Matchers
90
+ class ValidateInclusionOfMatcher < Remarkable::ActiveRecord::Base
91
+ arguments :attribute
92
+ assertion :is_valid?
93
+
94
+ optional :in
95
+ optional :allow_blank, :allow_nil, :default => true
96
+
97
+ protected
98
+
99
+ def is_valid?
100
+ @options[:in].each do |value|
101
+ @subject.send(:"#{@attribute}=", value)
102
+ return false, :value => value unless @subject.valid?
103
+ end
104
+ true
105
+ end
106
+ end
107
+
108
+ def validate_inclusion_of(*args)
109
+ ValidateInclusionOfMatcher.new(*args).spec(self)
110
+ end
111
+ end
112
+ end
113
+ end
114
+
115
+ This creates a matcher which requires one attribute and has :in, :allow_blank
116
+ and :allow_nil as options. So you can call the matcher in the following way:
117
+
118
+ should_validate_inclusion_of :size, :in => %w(S M L XL)
119
+ should_validate_inclusion_of :size, :in => %w(S M L XL), :allow_blank => true
120
+
121
+ it { should validate_inclusion_of(:size, :in => %w(S M L XL)).allow_nil(true) }
122
+ it { should validate_inclusion_of(:size, :in => %w(S M L XL)).allow_nil }
123
+
124
+ it { should validate_inclusion_of(:size, :in => %w(S M L XL)) }
125
+ it { should validate_inclusion_of(:size, :in => %w(S M L XL), :allow_nil => true) }
126
+
127
+ The assertions methods (in this case, :is_valid?) makes the matcher pass when
128
+ it returns true and fail when returns false.
129
+
130
+ As you noticed, the matcher doesn't have any message on it. You add them on I18n
131
+ file. A file for this example would be:
132
+
133
+ remarkable:
134
+ active_record:
135
+ validate_inclusion_of:
136
+ description: "validate inclusion of {{attribute}}"
137
+ expectations:
138
+ is_valid: "to be valid when {{attribute}} is {{value}}"
139
+ optionals:
140
+ in:
141
+ positive: "in {{inspect}}"
142
+ allow_nil:
143
+ positive: "allowing nil values"
144
+ negative: "not allowing nil values"
145
+ allow_blank:
146
+ positive: "allowing blank values"
147
+ negative: "allowing blank values"
148
+
149
+ The optionals are just added to the description message when they are supplied.
150
+ Look some description messages examples:
151
+
152
+ should_validate_inclusion_of :size, :in => %w(S M L XL)
153
+ #=> should validate inclusion of size in ["S", "M", "L", "XL"]
154
+
155
+ should_validate_inclusion_of :size, :in => %w(S M L XL), :allow_nil => true
156
+ #=> should validate inclusion of size in ["S", "M", "L", "XL"] and allowing nil values
157
+
158
+ should_validate_inclusion_of :size, :in => %w(S M L XL), :allow_nil => false
159
+ #=> should validate inclusion of size in ["S", "M", "L", "XL"] and not allowing nil values
160
+
161
+ Please notice that the arguments are available as interpolation option, as well
162
+ as the optionals.
163
+
164
+ The expectations message are set whenever one of the assertions returns false.
165
+ In this case, whenever the assertion fails, we are also returning a hash, with
166
+ the value that failed:
167
+
168
+ return false, :value => value
169
+
170
+ This will tell remarkable to make value as interpolation option too.
171
+
172
+ Whenever you create all your matchers, you tell remarkable to add them to the
173
+ desired rspec example group:
174
+
175
+ Remarkable.include_matchers!(Remarkable::ActiveRecord, Spec::Example::ExampleGroup)
176
+
177
+ == Working with collections
178
+
179
+ Finally, Remarkable also makes easy to deal with collections. The same matcher
180
+ could be easily extended to accept a collection of attributes instead of just one:
181
+
182
+ should_validate_inclusion_of :first_size, :second_size, :in => %w(S M L XL)
183
+
184
+ For this we have just those two lines:
185
+
186
+ arguments :attribute
187
+ assertion :is_valid?
188
+
189
+ For:
190
+
191
+ arguments :collection => :attributes, :as => :attribute
192
+ collection_assertion :is_valid?
193
+
194
+ This means that the collection will be kept in the @attributes instance variable
195
+ and for each value in the collection, it will run the :is_valid? assertion.
196
+
197
+ Whenever running the assertion, it will also set the @attribute (in singular)
198
+ variable. In your I18n files, you just need to change your description:
199
+
200
+ validate_inclusion_of:
201
+ description: "validate inclusion of {{attributes}}"
202
+
203
+ And this will output:
204
+
205
+ should_validate_inclusion_of :first_size, :second_size, :in => %w(S M L XL)
206
+ #=> should validate inclusion of first size and second size in ["S", "M", "L", "XL"]
207
+
208
+ == More
209
+
210
+ This is just an overview of the API. You can add extra options to interpolation
211
+ by overwriting the interpolation_options methods, you can add callbacks after
212
+ initialize your matcher or before asserting and much more!