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
@@ -1,245 +0,0 @@
|
|
1
|
-
module ElabsMatchers
|
2
|
-
module Matchers
|
3
|
-
module Capybara
|
4
|
-
module Common
|
5
|
-
##
|
6
|
-
#
|
7
|
-
# Asserts if the select input tag contains the given options.
|
8
|
-
#
|
9
|
-
# @param [Array] options One or serveral strings seperated by comma
|
10
|
-
#
|
11
|
-
# Example:
|
12
|
-
# find(:xpath, XPath::HTML.select("My input label")).should have_options(options)
|
13
|
-
|
14
|
-
RSpec::Matchers.define :have_options do |*options|
|
15
|
-
match do |select|
|
16
|
-
options.all? { |option| select.all("option").map(&:text).include?(option) }
|
17
|
-
end
|
18
|
-
|
19
|
-
failure_message_for_should do |select|
|
20
|
-
actual_options = select.all("option").map(&:text).inspect
|
21
|
-
"expected options to include '#{options.flatten.inspect}' but it had the options #{actual_options}."
|
22
|
-
end
|
23
|
-
failure_message_for_should_not { |select| "expected options not to include '#{options.flatten.inspect}' but it did." }
|
24
|
-
end
|
25
|
-
|
26
|
-
##
|
27
|
-
#
|
28
|
-
# Asserts if the supplied table row exists in the table
|
29
|
-
#
|
30
|
-
# @param [String] table name The tables's caption text.
|
31
|
-
# @param [Hash] column value A hash representing the column name and value in key-value form.
|
32
|
-
#
|
33
|
-
# Example:
|
34
|
-
# table.should have_table_row('Posts', "Title" => "First", :year => "2012")
|
35
|
-
|
36
|
-
RSpec::Matchers.define :have_table_row do |table_name, row|
|
37
|
-
match do |page|
|
38
|
-
table = page.find(:xpath, XPath::HTML.table(table_name))
|
39
|
-
|
40
|
-
if row.is_a? Hash
|
41
|
-
exps = row.map do |header, value|
|
42
|
-
col_index = table.all("thead th").index { |th| th.text.include?(header) }
|
43
|
-
col_index = if col_index then col_index + 1 else 0 end
|
44
|
-
XPath.child(:td, :th)[col_index.to_s.to_sym][XPath.contains(value)]
|
45
|
-
end
|
46
|
-
exps = exps.inject { |agg, exp| agg & exp }
|
47
|
-
table.has_xpath?(XPath.descendant['tr'][exps])
|
48
|
-
else
|
49
|
-
exps = []
|
50
|
-
row.each_with_index do |value, index|
|
51
|
-
exps << XPath.child(:td)[(index + 1).to_s.to_sym][XPath.contains(value)]
|
52
|
-
end
|
53
|
-
exps = exps.inject { |agg, exp| agg & exp }
|
54
|
-
|
55
|
-
table.has_xpath?(XPath.descendant['tr'][exps])
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
match_for_should_not do |page|
|
60
|
-
table = page.find(:xpath, XPath::HTML.table(table_name))
|
61
|
-
|
62
|
-
if row.is_a? Hash
|
63
|
-
exps = row.map do |header, value|
|
64
|
-
col_index = table.all("thead th").index { |th| th.text.include?(header) }
|
65
|
-
col_index = if col_index then col_index + 1 else 0 end
|
66
|
-
XPath.child(:td, :th)[col_index.to_s.to_sym][XPath.contains(value)]
|
67
|
-
end
|
68
|
-
exps = exps.inject { |agg, exp| agg & exp }
|
69
|
-
table.has_no_xpath?(XPath.descendant['tr'][exps])
|
70
|
-
else
|
71
|
-
exps = []
|
72
|
-
row.each_with_index do |value, index|
|
73
|
-
exps << XPath.child(:td)[(index + 1).to_s.to_sym][XPath.contains(value)]
|
74
|
-
end
|
75
|
-
exps = exps.inject { |agg, exp| agg & exp }
|
76
|
-
|
77
|
-
table.has_no_xpath?(XPath.descendant['tr'][exps])
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
failure_message_for_should do |page|
|
82
|
-
table = page.find(:xpath, XPath::HTML.table(table_name))
|
83
|
-
ascii_table = table.all('tr').map do |tr|
|
84
|
-
'| ' + tr.all('td,th').map { |td| td.text.strip.ljust(21) }.join(' | ') + ' |'
|
85
|
-
end.join("\n")
|
86
|
-
"expected #{row.inspect} to be included in the table #{table_name}, but it wasn't:\n\n#{ascii_table}"
|
87
|
-
end
|
88
|
-
failure_message_for_should_not { |page| "expected there to be no table #{table_name} with row #{row.inspect}, but there was." }
|
89
|
-
end
|
90
|
-
|
91
|
-
##
|
92
|
-
#
|
93
|
-
# Asserts if the supplied show_for* attribute exists or not
|
94
|
-
#
|
95
|
-
# @param [String] label The name of the attribute.
|
96
|
-
# @param [String] value The value of the attribute.
|
97
|
-
#
|
98
|
-
# Example:
|
99
|
-
# page.should have_attribute("Status", "Pending")
|
100
|
-
#
|
101
|
-
# * https://github.com/plataformatec/show_for
|
102
|
-
|
103
|
-
RSpec::Matchers.define :have_attribute do |label, value|
|
104
|
-
xpath = XPath.generate { |x| x.descendant(:p)[x.attr(:class).contains('wrapper')][x.child(:strong).contains(label)][x.contains(value)] }
|
105
|
-
|
106
|
-
match do |page|
|
107
|
-
page.has_xpath?(xpath)
|
108
|
-
end
|
109
|
-
|
110
|
-
match_for_should_not do |page|
|
111
|
-
page.has_no_xpath?(xpath)
|
112
|
-
end
|
113
|
-
|
114
|
-
failure_message_for_should do |page|
|
115
|
-
attributes = page.all(:css, 'li.wrapper').map(&:text).to_sentence
|
116
|
-
"expected there to be an attribute #{label}: #{value}, but the only attributes were: #{attributes}."
|
117
|
-
end
|
118
|
-
failure_message_for_should_not { |page| "expected there to be no attribute #{label}: #{value}, but there was." }
|
119
|
-
end
|
120
|
-
|
121
|
-
##
|
122
|
-
#
|
123
|
-
# Asserts if the supplied image exists or not
|
124
|
-
#
|
125
|
-
# @param [String] alt The alt attribute content of the image
|
126
|
-
#
|
127
|
-
# Example:
|
128
|
-
# page.should have_image("Logo")
|
129
|
-
|
130
|
-
RSpec::Matchers.define :have_image do |alt|
|
131
|
-
match { |page| page.has_css?("img[alt=\"#{alt}\"]") }
|
132
|
-
match_for_should_not { |page| page.has_no_css?("img[alt=\"#{alt}\"]") }
|
133
|
-
|
134
|
-
failure_message_for_should do |page|
|
135
|
-
alts = page.all('img').map { |img| "'#{img[:alt]}'" }.to_sentence
|
136
|
-
"expected image alt to be '#{alt}' but it had the image alts: #{alts}."
|
137
|
-
end
|
138
|
-
failure_message_for_should_not { |page| "expected image not to be '#{alt}' but it was" }
|
139
|
-
end
|
140
|
-
|
141
|
-
##
|
142
|
-
#
|
143
|
-
# Asserts if the supplied header exists or not
|
144
|
-
#
|
145
|
-
# @param [String] text The content of the header
|
146
|
-
#
|
147
|
-
# Example:
|
148
|
-
# page.should have_header("Elabs")
|
149
|
-
|
150
|
-
RSpec::Matchers.define :have_header do |text|
|
151
|
-
match { |page| page.has_css?('h1,h2', :text => text) }
|
152
|
-
match_for_should_not { |page| page.has_no_css?('h1,h2', :text => text) }
|
153
|
-
|
154
|
-
failure_message_for_should do |page|
|
155
|
-
headers = page.all('h1,h2').map { |h| "'#{h.text}'" }.to_sentence
|
156
|
-
"expected header to be '#{text}' but it had the headers #{headers}"
|
157
|
-
end
|
158
|
-
failure_message_for_should_not { |page| "expected header not to be '#{text}' but it was" }
|
159
|
-
end
|
160
|
-
|
161
|
-
##
|
162
|
-
#
|
163
|
-
# Asserts if the supplied flash notice exists or not
|
164
|
-
#
|
165
|
-
# @param [String] text The content of the flash notice
|
166
|
-
#
|
167
|
-
# Example:
|
168
|
-
# page.should have_flash_notice("Success")
|
169
|
-
|
170
|
-
RSpec::Matchers.define :have_flash_notice do |text|
|
171
|
-
match { |page| page.has_css?('#flash.notice, #flash .notice', :text => text) }
|
172
|
-
match_for_should_not { |page| page.has_no_css?('#flash.notice, #flash .notice', :text => text) }
|
173
|
-
failure_message_for_should { |page| "expected flash notice to be '#{text}' but was '#{page.find('#flash.notice').text}'" }
|
174
|
-
failure_message_for_should_not { |page| "expected flash notice not to be '#{text}' but it was" }
|
175
|
-
end
|
176
|
-
|
177
|
-
##
|
178
|
-
#
|
179
|
-
# Asserts if the supplied flash alert exists or not
|
180
|
-
#
|
181
|
-
# @param [String] text The content of the flash alert
|
182
|
-
#
|
183
|
-
# Example:
|
184
|
-
# page.should have_flash_alert("Error")
|
185
|
-
|
186
|
-
RSpec::Matchers.define :have_flash_alert do |text|
|
187
|
-
match { |page| page.has_css?('#flash.alert, #flash .alert', :text => text) }
|
188
|
-
match_for_should_not { |page| page.has_no_css?('#flash.alert, #flash .alert', :text => text) }
|
189
|
-
failure_message_for_should { |page| "expected flash alert to be '#{text}' but was '#{page.find('#flash.alert').text}'" }
|
190
|
-
failure_message_for_should_not { |page| "expected flash alert not to be '#{text}' but it was" }
|
191
|
-
end
|
192
|
-
|
193
|
-
##
|
194
|
-
#
|
195
|
-
# Asserts if the supplied flash alert exists or not
|
196
|
-
#
|
197
|
-
# @param [String] label The label content associated with the field.
|
198
|
-
# @param [String] message The error message expected.
|
199
|
-
#
|
200
|
-
# Example:
|
201
|
-
# page.should have_form_errors_on("Name", "Can't be blank")
|
202
|
-
|
203
|
-
RSpec::Matchers.define :have_form_errors_on do |field, message|
|
204
|
-
xpath = %Q{..//span[contains(@class,'error')]}
|
205
|
-
match { |page| page.has_field?(field) and page.find_field(field).has_xpath?(xpath, :text => message) }
|
206
|
-
match_for_should_not { |page| page.has_no_field?(field) or page.find_field(field).has_no_xpath?(xpath, :text => message) }
|
207
|
-
|
208
|
-
failure_message_for_should do |page|
|
209
|
-
error = page.find_field(field).all(:xpath, xpath).first
|
210
|
-
if not error
|
211
|
-
"expected field '#{field}' to have an error, but it didn't"
|
212
|
-
elsif error.text != message
|
213
|
-
"expected error message on #{field} to be '#{message}' but was '#{error.text}'"
|
214
|
-
else
|
215
|
-
raise "This should not happen"
|
216
|
-
end
|
217
|
-
end
|
218
|
-
failure_message_for_should_not { |page| "expected error message on '#{field}' not to be '#{text}' but it was" }
|
219
|
-
end
|
220
|
-
|
221
|
-
##
|
222
|
-
#
|
223
|
-
# Asserts if the supplied fields exists or not
|
224
|
-
#
|
225
|
-
# @param [Hash] field name, value A hash containing pairs of field name => value
|
226
|
-
#
|
227
|
-
# Example:
|
228
|
-
# page.should have_fields("Author" => "Adam", "Year" => "2011")
|
229
|
-
|
230
|
-
RSpec::Matchers.define :have_fields do |fields|
|
231
|
-
match do |page|
|
232
|
-
exps = fields.map { |label, value| XPath::HTML.field(label, :with => value) }
|
233
|
-
page.has_xpath?("(./html | ./self::*)[#{exps.join(' and ')}]")
|
234
|
-
end
|
235
|
-
match_for_should_not do |page|
|
236
|
-
exps = fields.map { |label, value| XPath::HTML.field(label, :with => value) }
|
237
|
-
page.has_no_xpath?("(./html | ./self::*)[#{exps.join(' and ')}]")
|
238
|
-
end
|
239
|
-
failure_message_for_should { |page| "expected page to have the fields #{fields.inspect}, but it didn't." }
|
240
|
-
failure_message_for_should_not { |page| "expected page not to have the fields #{fields.inspect}, but it did." }
|
241
|
-
end
|
242
|
-
end
|
243
|
-
end
|
244
|
-
end
|
245
|
-
end
|
@@ -1,112 +0,0 @@
|
|
1
|
-
module ElabsMatchers
|
2
|
-
module Matchers
|
3
|
-
module Rspec
|
4
|
-
module Allow
|
5
|
-
|
6
|
-
##
|
7
|
-
#
|
8
|
-
# Asserts if a sample value is valid on a given attribute
|
9
|
-
#
|
10
|
-
# @param [*Array] sample value(s) Sample value(s) to check the validation against
|
11
|
-
# @param [*Array] method name(s) The method name(s) that has the validation(s) attached to it
|
12
|
-
#
|
13
|
-
# Example:
|
14
|
-
# post.should allow("Elabs").as(:title)
|
15
|
-
# post.should_not allow("").as(:title)
|
16
|
-
#
|
17
|
-
# post.should allow("Elabs").as(:title, :body)
|
18
|
-
# post.should_not allow("").as(:title, :body)
|
19
|
-
#
|
20
|
-
# post.should allow("Elabs", "Sweden").as(:title)
|
21
|
-
# post.should_not allow("", nil).as(:title)
|
22
|
-
#
|
23
|
-
# post.should allow("Elabs", "Sweden").as(:title, :body)
|
24
|
-
# post.should_not allow("", nil).as(:title, :body)
|
25
|
-
|
26
|
-
if defined?(ActiveModel)
|
27
|
-
RSpec::Matchers.define :allow do |*values|
|
28
|
-
chain :as do |*attributes|
|
29
|
-
@attributes = [*attributes]
|
30
|
-
end
|
31
|
-
|
32
|
-
match_for_should do |actual|
|
33
|
-
@actual, @values = actual, values
|
34
|
-
errors.none?
|
35
|
-
end
|
36
|
-
|
37
|
-
match_for_should_not do |actual|
|
38
|
-
@actual, @values = actual, values
|
39
|
-
errors.all? and correct_number_of_errors?
|
40
|
-
end
|
41
|
-
|
42
|
-
def correct_number_of_errors?
|
43
|
-
@num_errors = errors.length
|
44
|
-
|
45
|
-
if attributes?
|
46
|
-
if values?
|
47
|
-
matches_number_of_errors?(attributes, values)
|
48
|
-
else
|
49
|
-
matches_number_of_errors?(attributes)
|
50
|
-
end
|
51
|
-
else
|
52
|
-
if values?
|
53
|
-
matches_number_of_errors?(values)
|
54
|
-
else
|
55
|
-
matches_number_of_errors?(1)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def errors
|
61
|
-
values.map do |value|
|
62
|
-
errors_with(value)
|
63
|
-
end.flatten.compact
|
64
|
-
end
|
65
|
-
|
66
|
-
def errors_with(value)
|
67
|
-
attributes.each do |attribute|
|
68
|
-
actual.send(:"#{attribute}=", value)
|
69
|
-
end
|
70
|
-
|
71
|
-
actual.valid?
|
72
|
-
|
73
|
-
attributes.map do |attribute|
|
74
|
-
actual.errors.has_key?(attribute)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
def matches_number_of_errors?(list1, list2 = [])
|
79
|
-
@num_errors == ([*list1] + list2).flatten.length
|
80
|
-
end
|
81
|
-
|
82
|
-
def attributes?; attributes.length > 1 ; end
|
83
|
-
def values? ; values.length > 1 ; end
|
84
|
-
def attributes ; @attributes ; end
|
85
|
-
def values ; [*@values] ; end
|
86
|
-
def actual ; @actual ; end
|
87
|
-
|
88
|
-
failure_message_for_should do |actual|
|
89
|
-
common_failure_message(:valid)
|
90
|
-
end
|
91
|
-
|
92
|
-
failure_message_for_should_not do |actual|
|
93
|
-
common_failure_message(:invalid)
|
94
|
-
end
|
95
|
-
|
96
|
-
def common_failure_message(match_type)
|
97
|
-
"Expected #{expected_values_explain} to be #{match_type} on #{actual.class.model_name.demodulize}'s #{attributes_values_explain} attributes but it wasn't."
|
98
|
-
end
|
99
|
-
|
100
|
-
def expected_values_explain
|
101
|
-
values.map(&:inspect).to_sentence(:two_words_connector => ' or ')
|
102
|
-
end
|
103
|
-
|
104
|
-
def attributes_values_explain
|
105
|
-
attributes.map(&:to_s).map(&:inspect).to_sentence
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
@@ -1,59 +0,0 @@
|
|
1
|
-
module ElabsMatchers
|
2
|
-
module Matchers
|
3
|
-
module Rspec
|
4
|
-
module Common
|
5
|
-
##
|
6
|
-
#
|
7
|
-
# Asserts if the hash contains the supplied hash.
|
8
|
-
# Works with nested hashes and array of hashes.
|
9
|
-
#
|
10
|
-
# @param [Hash] options Key => value pairs seperated by comma
|
11
|
-
#
|
12
|
-
# Example:
|
13
|
-
# { "foo" => ['quox', { 'bar' => 'baz'}]}.should contain_hash({ "foo" => [{ "bar" => "baz" }]})
|
14
|
-
# { "foo" => "bar", "baz" => "quox" }.should_not contain_hash({ "baz" => "bar" })
|
15
|
-
|
16
|
-
RSpec::Matchers.define :contain_hash do |expected|
|
17
|
-
match do |actual|
|
18
|
-
contains?(expected, actual)
|
19
|
-
end
|
20
|
-
|
21
|
-
def contains?(expected, actual)
|
22
|
-
return false unless actual.is_a?(expected.class)
|
23
|
-
|
24
|
-
if expected.is_a?(Array)
|
25
|
-
expected.all? do |expected_value|
|
26
|
-
actual.any? do |actual_value|
|
27
|
-
contains?(expected_value, actual_value)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
elsif expected.is_a?(Hash)
|
31
|
-
expected.all? do |key, value|
|
32
|
-
contains?(value, actual[key])
|
33
|
-
end
|
34
|
-
else
|
35
|
-
actual == expected
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
##
|
41
|
-
#
|
42
|
-
# Asserts if the array contains exactly the supplied elements.
|
43
|
-
# The order of the element do not have to match.
|
44
|
-
#
|
45
|
-
# @param argument list options comma seperated list of arguments
|
46
|
-
#
|
47
|
-
# Example:
|
48
|
-
# ["foo", "bar"].should only_include("bar", "foo")
|
49
|
-
# ["foo", "bar"].should_not only_include("foo")
|
50
|
-
|
51
|
-
RSpec::Matchers.define :only_include do |*collection|
|
52
|
-
match { |actual| actual.length == collection.length and collection.all? { |element| actual.include?(element) } }
|
53
|
-
failure_message_for_should { |actual| "Expected #{actual.inspect} to only include #{collection.inspect}." }
|
54
|
-
failure_message_for_should_not { |actual| "Expected #{actual.inspect} to not only include #{collection.inspect}, but it did." }
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
module ElabsMatchers
|
2
|
-
module Matchers
|
3
|
-
module Rspec
|
4
|
-
module Orm
|
5
|
-
##
|
6
|
-
#
|
7
|
-
# Asserts if an assigned value persistes in the database.
|
8
|
-
#
|
9
|
-
# @param [Symbol] attribute name The name of the attibute to check if it persisted or not
|
10
|
-
# @param [Object] value The value to persist to the attribute
|
11
|
-
#
|
12
|
-
# Example:
|
13
|
-
# post.should persist(:title, "Blog post")
|
14
|
-
|
15
|
-
RSpec::Matchers.define :persist do |attribute, value|
|
16
|
-
match do |actual|
|
17
|
-
actual.send(:"#{attribute}=", value)
|
18
|
-
actual.save!
|
19
|
-
actual = actual.class.find(actual.id)
|
20
|
-
@final_value = actual.send(attribute)
|
21
|
-
@final_value == value
|
22
|
-
end
|
23
|
-
failure_message_for_should { |actual| "Expected #{attribute} to be persisted and retain its value of #{value.inspect} but the value was #{@final_value.inspect}" }
|
24
|
-
failure_message_for_should_not { |actual| "Expected #{attribute} not to be persisted and retain its value of #{value.inspect} but it did." }
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|