elabs_matchers 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -1
- data/Gemfile.lock +37 -26
- data/README.md +57 -47
- data/development.txt +26 -0
- data/doc/ElabsMatchers/Helpers/Fixtures.html +33 -23
- data/doc/ElabsMatchers/Helpers/NormalizeKeys.html +222 -0
- data/doc/ElabsMatchers/Helpers/ReloadRecord.html +302 -0
- data/doc/ElabsMatchers/Helpers/SelectYearAndMonth.html +251 -0
- data/doc/ElabsMatchers/Helpers.html +29 -22
- data/doc/ElabsMatchers/Matchers/Allow/AllowMatcher.html +707 -0
- data/doc/ElabsMatchers/Matchers/Allow.html +229 -0
- data/doc/ElabsMatchers/Matchers/ContainHash/ContainHashMatcher.html +506 -0
- data/doc/ElabsMatchers/Matchers/ContainHash.html +222 -0
- data/doc/ElabsMatchers/Matchers/HaveAttribute/HaveAttributeMatcher.html +656 -0
- data/doc/ElabsMatchers/Matchers/HaveAttribute.html +239 -0
- data/doc/ElabsMatchers/Matchers/HaveFields/HaveFieldsMatcher.html +572 -0
- data/doc/ElabsMatchers/Matchers/HaveFields.html +220 -0
- data/doc/ElabsMatchers/Matchers/HaveFlash/HaveFlashMatcher.html +654 -0
- data/doc/ElabsMatchers/Matchers/HaveFlash.html +306 -0
- data/doc/ElabsMatchers/Matchers/HaveFormErrorsOn/HaveFormErrorsOnMatcher.html +678 -0
- data/doc/ElabsMatchers/Matchers/HaveFormErrorsOn.html +236 -0
- data/doc/ElabsMatchers/Matchers/HaveHeader/HaveHeaderMatcher.html +568 -0
- data/doc/ElabsMatchers/Matchers/HaveHeader.html +219 -0
- data/doc/ElabsMatchers/Matchers/HaveImage/HaveImageMatcher.html +592 -0
- data/doc/ElabsMatchers/Matchers/HaveImage.html +219 -0
- data/doc/ElabsMatchers/Matchers/HaveTableRow/HaveTableRowMatcher.html +654 -0
- data/doc/ElabsMatchers/Matchers/HaveTableRow.html +236 -0
- data/doc/ElabsMatchers/Matchers/OnlyInclude/OnlyIncludeMatcher.html +494 -0
- data/doc/ElabsMatchers/Matchers/OnlyInclude.html +221 -0
- data/doc/ElabsMatchers/Matchers/Persist/PersistMatcher.html +586 -0
- data/doc/ElabsMatchers/Matchers/Persist.html +235 -0
- data/doc/ElabsMatchers/Matchers.html +29 -22
- data/doc/ElabsMatchers.html +1144 -21
- data/doc/_index.html +161 -79
- data/doc/class_list.html +12 -6
- data/doc/css/full_list.css +4 -2
- data/doc/css/style.css +50 -44
- data/doc/file.README.html +71 -73
- data/doc/file_list.html +12 -6
- data/doc/frames.html +20 -5
- data/doc/index.html +71 -73
- data/doc/js/app.js +52 -43
- data/doc/js/full_list.js +9 -9
- data/doc/js/jquery.js +4 -16
- data/doc/method_list.html +603 -77
- data/doc/top-level-namespace.html +24 -103
- data/elabs_matchers.gemspec +4 -3
- data/history.txt +15 -0
- data/lib/elabs_matchers/extensions/module.rb +24 -0
- data/lib/elabs_matchers/helpers/fixtures.rb +2 -2
- data/lib/elabs_matchers/helpers/{common.rb → normalize_keys.rb} +3 -4
- data/lib/elabs_matchers/helpers/{orm.rb → reload_record.rb} +9 -6
- data/lib/elabs_matchers/helpers/{capybara.rb → select_year_and_month.rb} +5 -3
- data/lib/elabs_matchers/matchers/allow.rb +130 -0
- data/lib/elabs_matchers/matchers/contain_hash.rb +58 -0
- data/lib/elabs_matchers/matchers/have_attribute.rb +62 -0
- data/lib/elabs_matchers/matchers/have_fields.rb +45 -0
- data/lib/elabs_matchers/matchers/have_flash.rb +65 -0
- data/lib/elabs_matchers/matchers/have_form_errors_on.rb +79 -0
- data/lib/elabs_matchers/matchers/have_header.rb +53 -0
- data/lib/elabs_matchers/matchers/have_image.rb +69 -0
- data/lib/elabs_matchers/matchers/have_table_row.rb +113 -0
- data/lib/elabs_matchers/matchers/only_include.rb +41 -0
- data/lib/elabs_matchers/matchers/persist.rb +42 -0
- data/lib/elabs_matchers/version.rb +1 -1
- data/lib/elabs_matchers.rb +90 -10
- data/spec/elabs_matchers/helpers/fixtures_spec.rb +1 -1
- data/spec/elabs_matchers/helpers/{common_spec.rb → normalize_keys_spec.rb} +2 -2
- data/spec/elabs_matchers/helpers/{orm_spec.rb → reload_record_spec.rb} +3 -2
- data/spec/elabs_matchers/helpers/select_year_and_month_spec.rb +32 -0
- data/spec/elabs_matchers/matchers/{rspec/allow_spec.rb → allow_spec.rb} +5 -4
- data/spec/elabs_matchers/matchers/contain_hash_spec.rb +86 -0
- data/spec/elabs_matchers/matchers/have_attribute_spec.rb +65 -0
- data/spec/elabs_matchers/matchers/have_fields_spec.rb +46 -0
- data/spec/elabs_matchers/matchers/have_flash_spec.rb +97 -0
- data/spec/elabs_matchers/matchers/have_form_errors_on_spec.rb +93 -0
- data/spec/elabs_matchers/matchers/have_header_spec.rb +54 -0
- data/spec/elabs_matchers/matchers/have_image_spec.rb +49 -0
- data/spec/elabs_matchers/matchers/have_table_row_spec.rb +119 -0
- data/spec/elabs_matchers/matchers/only_include_spec.rb +32 -0
- data/spec/elabs_matchers/matchers/persist_spec.rb +21 -0
- data/{lib/elabs_matchers/orm → spec/fixtures}/post.rb +0 -0
- data/spec/spec_helper.rb +19 -8
- data/todo.txt +6 -0
- metadata +104 -48
- data/lib/elabs_matchers/cucumber/common.rb +0 -57
- data/lib/elabs_matchers/helpers/session.rb +0 -81
- data/lib/elabs_matchers/matchers/capybara/common.rb +0 -245
- data/lib/elabs_matchers/matchers/rspec/allow.rb +0 -112
- data/lib/elabs_matchers/matchers/rspec/common.rb +0 -59
- data/lib/elabs_matchers/matchers/rspec/orm.rb +0 -29
- data/spec/elabs_matchers/cucumber/common_spec.rb +0 -49
- data/spec/elabs_matchers/helpers/capybara_spec.rb +0 -32
- data/spec/elabs_matchers/helpers/session_spec.rb +0 -35
- data/spec/elabs_matchers/matchers/capybara/common_spec.rb +0 -202
- data/spec/elabs_matchers/matchers/rspec/common_spec.rb +0 -74
- data/spec/elabs_matchers/matchers/rspec/orm_spec.rb +0 -16
@@ -6,7 +6,7 @@
|
|
6
6
|
<title>
|
7
7
|
Top Level Namespace
|
8
8
|
|
9
|
-
— Documentation by YARD 0.
|
9
|
+
— Documentation by YARD 0.8.2.1
|
10
10
|
|
11
11
|
</title>
|
12
12
|
|
@@ -15,10 +15,12 @@
|
|
15
15
|
<link rel="stylesheet" href="css/common.css" type="text/css" media="screen" charset="utf-8" />
|
16
16
|
|
17
17
|
<script type="text/javascript" charset="utf-8">
|
18
|
+
hasFrames = window.top.frames.main ? true : false;
|
18
19
|
relpath = '';
|
19
|
-
|
20
|
+
framesUrl = "frames.html#!" + escape(window.location.href);
|
20
21
|
</script>
|
21
22
|
|
23
|
+
|
22
24
|
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
23
25
|
|
24
26
|
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
@@ -26,36 +28,41 @@
|
|
26
28
|
|
27
29
|
</head>
|
28
30
|
<body>
|
29
|
-
<script type="text/javascript" charset="utf-8">
|
30
|
-
if (window.top.frames.main) document.body.className = 'frames';
|
31
|
-
</script>
|
32
|
-
|
33
31
|
<div id="header">
|
34
32
|
<div id="menu">
|
35
33
|
|
36
|
-
<a href="_index.html">Index</a> »
|
34
|
+
<a href="_index.html">Index</a> »
|
37
35
|
|
38
36
|
|
39
37
|
<span class="title">Top Level Namespace</span>
|
40
38
|
|
41
|
-
|
39
|
+
|
42
40
|
<div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
|
43
41
|
</div>
|
44
42
|
|
45
43
|
<div id="search">
|
46
44
|
|
47
|
-
<a
|
45
|
+
<a class="full_list_link" id="class_list_link"
|
46
|
+
href="class_list.html">
|
47
|
+
Class List
|
48
|
+
</a>
|
48
49
|
|
49
|
-
<a
|
50
|
+
<a class="full_list_link" id="method_list_link"
|
51
|
+
href="method_list.html">
|
52
|
+
Method List
|
53
|
+
</a>
|
50
54
|
|
51
|
-
<a
|
55
|
+
<a class="full_list_link" id="file_list_link"
|
56
|
+
href="file_list.html">
|
57
|
+
File List
|
58
|
+
</a>
|
52
59
|
|
53
60
|
</div>
|
54
61
|
<div class="clear"></div>
|
55
62
|
</div>
|
56
|
-
|
63
|
+
|
57
64
|
<iframe id="search_frame"></iframe>
|
58
|
-
|
65
|
+
|
59
66
|
<div id="content"><h1>Top Level Namespace
|
60
67
|
|
61
68
|
|
@@ -76,115 +83,29 @@
|
|
76
83
|
|
77
84
|
<h2>Defined Under Namespace</h2>
|
78
85
|
<p class="children">
|
79
|
-
|
80
|
-
|
81
|
-
<strong class="modules">Modules:</strong> <span class='object_link'><a href="Cucumber.html" title="Cucumber (module)">Cucumber</a></span>, <span class='object_link'><a href="ElabsMatchers.html" title="ElabsMatchers (module)">ElabsMatchers</a></span>
|
82
|
-
|
83
|
-
|
84
|
-
|
85
86
|
|
86
|
-
</p>
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
<h2>
|
96
|
-
Instance Method Summary
|
97
|
-
<small>(<a href="#" class="summary_toggle">collapse</a>)</small>
|
98
|
-
</h2>
|
99
|
-
|
100
|
-
<ul class="summary">
|
101
|
-
|
102
|
-
<li class="public ">
|
103
|
-
<span class="summary_signature">
|
104
87
|
|
105
|
-
<a href="
|
106
|
-
|
107
|
-
|
88
|
+
<strong class="modules">Modules:</strong> <span class='object_link'><a href="ElabsMatchers.html" title="ElabsMatchers (module)">ElabsMatchers</a></span>
|
108
89
|
|
109
|
-
</span>
|
110
90
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
<span class="summary_desc"><div class='inline'>
|
119
|
-
<p>Transforms a cucumber step so that the list it includes turns into an
|
120
|
-
array.</p>
|
121
|
-
</div></span>
|
122
|
-
|
123
|
-
</li>
|
124
|
-
|
125
|
-
|
126
|
-
</ul>
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
<div id="instance_method_details" class="method_details_list">
|
132
|
-
<h2>Instance Method Details</h2>
|
133
|
-
|
134
91
|
|
135
|
-
<div class="method_details first">
|
136
|
-
<p class="signature first" id="^-instance_method">
|
137
|
-
|
138
|
-
- (<tt>Object</tt>) <strong>^</strong>
|
139
92
|
|
93
|
+
</p>
|
140
94
|
|
141
|
-
|
142
|
-
</p><div class="docstring">
|
143
|
-
<div class="discussion">
|
144
|
-
|
145
|
-
<p>Transforms a cucumber step so that the list it includes turns into an array</p>
|
146
95
|
|
147
|
-
<p>Example: Step: Then I should see "Bart", "Lisa" and "Homer" Definition:</p>
|
148
96
|
|
149
|
-
<pre class="code ruby"><code><span class='const'>Then</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>^I should see (</span><span class='embexpr_beg'>#{</span><span class='const'>LIST_REGEXP</span><span class='rbrace'>}</span><span class='tstring_content'>)$</span><span class='regexp_end'>/</span></span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_names'>names</span><span class='op'>|</span>
|
150
|
-
<span class='comment'># names == ["Bart", "Lisa", "Homer"]
|
151
|
-
</span><span class='kw'>end</span></code></pre>
|
152
97
|
|
153
98
|
|
154
|
-
</div>
|
155
|
-
</div>
|
156
|
-
<div class="tags">
|
157
|
-
|
158
99
|
|
159
|
-
</div><table class="source_code">
|
160
|
-
<tr>
|
161
|
-
<td>
|
162
|
-
<pre class="lines">
|
163
100
|
|
164
101
|
|
165
|
-
52
|
166
|
-
53
|
167
|
-
54</pre>
|
168
|
-
</td>
|
169
|
-
<td>
|
170
|
-
<pre class="code"><span class="info file"># File 'lib/elabs_matchers/cucumber/common.rb', line 52</span>
|
171
102
|
|
172
|
-
<span class='const'>Transform</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>^</span><span class='embexpr_beg'>#{</span><span class='const'>LIST_REGEXP</span><span class='rbrace'>}</span><span class='tstring_content'>$</span><span class='regexp_end'>/</span></span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_list'>list</span><span class='op'>|</span>
|
173
|
-
<span class='const'>ElabsMatchers</span><span class='op'>::</span><span class='const'>Cucumber</span><span class='op'>::</span><span class='const'>Common</span><span class='op'>::</span><span class='id identifier rubyid_human_list_to_array'>human_list_to_array</span><span class='lparen'>(</span><span class='id identifier rubyid_list'>list</span><span class='rparen'>)</span>
|
174
|
-
<span class='kw'>end</span></pre>
|
175
|
-
</td>
|
176
|
-
</tr>
|
177
|
-
</table>
|
178
103
|
</div>
|
179
|
-
|
180
|
-
</div>
|
181
104
|
|
182
|
-
</div>
|
183
|
-
|
184
105
|
<div id="footer">
|
185
|
-
Generated on
|
106
|
+
Generated on Wed Sep 19 15:04:26 2012 by
|
186
107
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
187
|
-
0.
|
108
|
+
0.8.2.1 (ruby-1.9.3).
|
188
109
|
</div>
|
189
110
|
|
190
111
|
</body>
|
data/elabs_matchers.gemspec
CHANGED
@@ -6,9 +6,9 @@ Gem::Specification.new do |s|
|
|
6
6
|
s.name = "elabs_matchers"
|
7
7
|
s.version = ElabsMatchers::VERSION
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
|
-
s.authors = ["
|
10
|
-
s.email = ["dev
|
11
|
-
s.homepage = ""
|
9
|
+
s.authors = ["Everyone at Elabs"]
|
10
|
+
s.email = ["dev@elabs.se"]
|
11
|
+
s.homepage = "http://github.com/elabs/elabs_matchers"
|
12
12
|
s.summary = %q{Provides a set of usefull rspec matchers}
|
13
13
|
s.description = %q{Provides a set of usefull rspec matchers to be used with RSpec and/or Capybara}
|
14
14
|
|
@@ -26,4 +26,5 @@ Gem::Specification.new do |s|
|
|
26
26
|
s.add_development_dependency("activesupport")
|
27
27
|
s.add_development_dependency("activemodel")
|
28
28
|
s.add_development_dependency("redcarpet")
|
29
|
+
s.add_development_dependency("pry")
|
29
30
|
end
|
data/history.txt
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# Version 0.0.4
|
2
|
+
|
3
|
+
### Changed
|
4
|
+
* Elabs matchers is now using Module.rspec internaly to include modules.
|
5
|
+
* Major restructure of files, folders and module names.
|
6
|
+
|
7
|
+
### Removed
|
8
|
+
* All cucucmber helpers and matchers
|
9
|
+
* Session helpers (sign_in, login and current_user)
|
10
|
+
* have_options in favor of Capybara's built in have_select "Letters", :options => ["A", "B"]
|
11
|
+
|
12
|
+
### Added
|
13
|
+
* Module.rspec to help you include your helpers into your rspec test suite.
|
14
|
+
* Tests for failing assertions.
|
15
|
+
* Most matcher's selectors can be configured to match your markup.
|
@@ -0,0 +1,24 @@
|
|
1
|
+
Module.class_eval do
|
2
|
+
##
|
3
|
+
#
|
4
|
+
# Allows you to include a module to be available in your
|
5
|
+
# rspec tests from without the module it self.
|
6
|
+
#
|
7
|
+
# @param [Hash] rspec options A hash of options which instructs rspec on how (and where) to include the module.
|
8
|
+
#
|
9
|
+
# Example:
|
10
|
+
# module MyMatchers
|
11
|
+
# rspec :type => :request
|
12
|
+
#
|
13
|
+
# matcher :have_image do |alt|
|
14
|
+
# ...
|
15
|
+
# end
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
|
19
|
+
def rspec(options={})
|
20
|
+
RSpec.configure do |config|
|
21
|
+
config.include self, options
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -1,16 +1,16 @@
|
|
1
1
|
module ElabsMatchers
|
2
2
|
module Helpers
|
3
3
|
module Fixtures
|
4
|
+
rspec
|
4
5
|
|
5
6
|
##
|
6
7
|
#
|
7
8
|
# Opens a file from the fixtures directory.
|
8
9
|
#
|
9
|
-
# @param [String]
|
10
|
+
# @param [String] path A file name, relative to the fixtures folder.
|
10
11
|
#
|
11
12
|
# Example:
|
12
13
|
# fixture_file("file.txt")
|
13
|
-
#
|
14
14
|
|
15
15
|
def fixture_file(path)
|
16
16
|
root = if defined?(Rails) then Rails.root else "../../../spec/" end
|
@@ -1,22 +1,21 @@
|
|
1
1
|
module ElabsMatchers
|
2
2
|
module Helpers
|
3
|
-
module
|
3
|
+
module NormalizeKeys
|
4
|
+
rspec
|
4
5
|
|
5
6
|
##
|
6
7
|
#
|
7
8
|
# Normalizes a hash so that it can be described in a more
|
8
9
|
# human friendly manner.
|
9
10
|
#
|
10
|
-
# @param [Hash]
|
11
|
+
# @param [Hash] hash A hash of human-friendly key and value pairs.
|
11
12
|
#
|
12
13
|
# Examples:
|
13
|
-
# normalize_keys({ "First name" => "Adam" }) => HashWithIndifferentAccess.new({ "first_name" => "adam" })
|
14
14
|
#
|
15
15
|
# # Or in a Cucumber table:
|
16
16
|
# Given the following people:
|
17
17
|
# | First name | Last name |
|
18
18
|
# | Douglas | Adams |
|
19
|
-
#
|
20
19
|
|
21
20
|
def normalize_keys(hash)
|
22
21
|
hash.inject(HashWithIndifferentAccess.new) do |new_hash, (key, value)|
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module ElabsMatchers
|
2
2
|
module Helpers
|
3
|
-
module
|
3
|
+
module ReloadRecord
|
4
|
+
rspec :type => :model
|
5
|
+
|
4
6
|
##
|
5
7
|
#
|
6
8
|
# Finds the record from the database and return a new instance for that record.
|
@@ -10,8 +12,8 @@ module ElabsMatchers
|
|
10
12
|
# Example:
|
11
13
|
# reload(post)
|
12
14
|
|
13
|
-
def reload(
|
14
|
-
|
15
|
+
def reload(record)
|
16
|
+
record.class.find(record.id)
|
15
17
|
end
|
16
18
|
|
17
19
|
##
|
@@ -23,10 +25,11 @@ module ElabsMatchers
|
|
23
25
|
# Example:
|
24
26
|
# save_and_reload(post)
|
25
27
|
|
26
|
-
def save_and_reload(
|
27
|
-
|
28
|
-
reload(
|
28
|
+
def save_and_reload(record)
|
29
|
+
record.save!
|
30
|
+
reload(record)
|
29
31
|
end
|
30
32
|
end
|
31
33
|
end
|
32
34
|
end
|
35
|
+
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module ElabsMatchers
|
2
2
|
module Helpers
|
3
|
-
module
|
3
|
+
module SelectYearAndMonth
|
4
|
+
rspec :type => :request
|
5
|
+
|
4
6
|
##
|
5
7
|
#
|
6
8
|
# Selects a year and a month on a rails date select input field.
|
@@ -14,11 +16,11 @@ module ElabsMatchers
|
|
14
16
|
|
15
17
|
def select_year_and_month(year, month, options={})
|
16
18
|
year_field = find_field(options[:from])
|
17
|
-
month_field = find(:id, year_field[:id].sub(/_1i$/,
|
19
|
+
month_field = find(:id, year_field[:id].sub(/_1i$/, "_2i"))
|
18
20
|
|
19
21
|
year_field.select(year)
|
20
22
|
month_field.select(month)
|
21
23
|
end
|
22
24
|
end
|
23
25
|
end
|
24
|
-
end
|
26
|
+
end
|
@@ -0,0 +1,130 @@
|
|
1
|
+
module ElabsMatchers
|
2
|
+
module Matchers
|
3
|
+
module Allow
|
4
|
+
if defined?(ActiveModel)
|
5
|
+
rspec :type => :model
|
6
|
+
|
7
|
+
class AllowMatcher
|
8
|
+
attr_reader :record, :attributes
|
9
|
+
|
10
|
+
def initialize(values)
|
11
|
+
@values = values
|
12
|
+
end
|
13
|
+
|
14
|
+
def matches?(record)
|
15
|
+
@record = record
|
16
|
+
errors.none?
|
17
|
+
end
|
18
|
+
|
19
|
+
def does_not_match?(record)
|
20
|
+
@record = record
|
21
|
+
errors.all? and correct_number_of_errors?
|
22
|
+
end
|
23
|
+
|
24
|
+
##
|
25
|
+
#
|
26
|
+
# Tell the matcher which attributes to check
|
27
|
+
#
|
28
|
+
# @param [*Array] attributes The method name(s) that has the validation(s) attached to it
|
29
|
+
#
|
30
|
+
# Example:
|
31
|
+
# post.should allow("Elabs").as(:title)
|
32
|
+
|
33
|
+
def as(*attributes)
|
34
|
+
@attributes = [*attributes]
|
35
|
+
self
|
36
|
+
end
|
37
|
+
|
38
|
+
def failure_message_for_should
|
39
|
+
common_failure_message(:valid)
|
40
|
+
end
|
41
|
+
|
42
|
+
def failure_message_for_should_not
|
43
|
+
common_failure_message(:invalid)
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def correct_number_of_errors?
|
49
|
+
@num_errors = errors.length
|
50
|
+
|
51
|
+
if attributes?
|
52
|
+
if values?
|
53
|
+
matches_number_of_errors?(attributes, values)
|
54
|
+
else
|
55
|
+
matches_number_of_errors?(attributes)
|
56
|
+
end
|
57
|
+
else
|
58
|
+
if values?
|
59
|
+
matches_number_of_errors?(values)
|
60
|
+
else
|
61
|
+
matches_number_of_errors?(1)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def errors
|
67
|
+
values.map do |value|
|
68
|
+
errors_with(value)
|
69
|
+
end.flatten.compact
|
70
|
+
end
|
71
|
+
|
72
|
+
def errors_with(value)
|
73
|
+
attributes.each do |attribute|
|
74
|
+
record.send(:"#{attribute}=", value)
|
75
|
+
end
|
76
|
+
|
77
|
+
record.valid?
|
78
|
+
|
79
|
+
attributes.map do |attribute|
|
80
|
+
record.errors.keys.include?(attribute)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def matches_number_of_errors?(list1, list2 = [])
|
85
|
+
@num_errors == ([*list1] + list2).flatten.length
|
86
|
+
end
|
87
|
+
|
88
|
+
def attributes?; attributes.length > 1 ; end
|
89
|
+
def values? ; values.length > 1 ; end
|
90
|
+
def values ; [*@values] ; end
|
91
|
+
|
92
|
+
def common_failure_message(match_type)
|
93
|
+
"Expected #{expected_values_explain} to be #{match_type} on #{record.class.model_name.demodulize}'s #{attributes_values_explain} attributes but it wasn't."
|
94
|
+
end
|
95
|
+
|
96
|
+
def expected_values_explain
|
97
|
+
values.map(&:inspect).to_sentence
|
98
|
+
end
|
99
|
+
|
100
|
+
def attributes_values_explain
|
101
|
+
attributes.map(&:to_s).map(&:inspect).to_sentence
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
##
|
106
|
+
#
|
107
|
+
# Asserts if a sample value is valid on a given attribute
|
108
|
+
#
|
109
|
+
# @param [*Array] values Sample value(s) to check the validation against
|
110
|
+
#
|
111
|
+
# Example:
|
112
|
+
# post.should allow("Elabs").as(:title)
|
113
|
+
# post.should_not allow("").as(:title)
|
114
|
+
#
|
115
|
+
# post.should allow("Elabs").as(:title, :body)
|
116
|
+
# post.should_not allow("").as(:title, :body)
|
117
|
+
#
|
118
|
+
# post.should allow("Elabs", "Sweden").as(:title)
|
119
|
+
# post.should_not allow("", nil).as(:title)
|
120
|
+
#
|
121
|
+
# post.should allow("Elabs", "Sweden").as(:title, :body)
|
122
|
+
# post.should_not allow("", nil).as(:title, :body)
|
123
|
+
|
124
|
+
def allow(*values)
|
125
|
+
AllowMatcher.new(values)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|