1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471
|
module RSpec
RSpec.describe Matchers, "aliases", :order => :defined do
matcher :be_aliased_to do |old_matcher|
chain :with_description do |desc|
@expected_desc = desc
end
match do |aliased_matcher|
@actual_desc = aliased_matcher.description
@actual_desc == @expected_desc &&
aliased_matcher.base_matcher.class == old_matcher.class
end
failure_message do |aliased_matcher|
"expected #{aliased_matcher} to be aliased to #{old_matcher} with " \
"description: #{@expected_desc.inspect}, but got #{@actual_desc.inspect}"
end
description do |_aliased_matcher|
"have an alias for #{old_matcher.description.inspect} with description: #{@expected_desc.inspect}"
end
end
specify do
expect(a_truthy_value).to be_aliased_to(be_truthy).with_description("a truthy value")
end
specify do
expect(a_falsey_value).to be_aliased_to(be_falsey).with_description("a falsey value")
end
specify do
expect(be_falsy).to be_aliased_to(be_falsey).with_description("be falsy")
end
specify do
expect(a_falsy_value).to be_aliased_to(be_falsey).with_description("a falsy value")
end
specify do
expect(a_nil_value).to be_aliased_to(be_nil).with_description("a nil value")
end
specify do
expect(a_value > 3).to be_aliased_to(be > 3).with_description("a value > 3")
end
specify do
expect(a_value < 3).to be_aliased_to(be < 3).with_description("a value < 3")
end
specify do
expect(a_value <= 3).to be_aliased_to(be <= 3).with_description("a value <= 3")
end
specify do
expect(a_value == 3).to be_aliased_to(be == 3).with_description("a value == 3")
end
specify do
expect(a_value === 3).to be_aliased_to(be === 3).with_description("a value === 3")
end
specify do
expect(
an_instance_of(Integer)
).to be_aliased_to(
be_an_instance_of(Integer)
).with_description("an instance of Integer")
end
specify do
expect(
a_kind_of(Integer)
).to be_aliased_to(
be_a_kind_of(Integer)
).with_description("a kind of Integer")
end
specify do
expect(
a_value_between(1, 10)
).to be_aliased_to(
be_between(1, 10)
).with_description("a value between 1 and 10 (inclusive)")
end
specify do
expect(
a_value_within(0.1).of(3)
).to be_aliased_to(
be_within(0.1).of(3)
).with_description("a value within 0.1 of 3")
end
specify do
expect(
within(0.1).of(3)
).to be_aliased_to(
be_within(0.1).of(3)
).with_description("within 0.1 of 3")
end
specify do
expect(a_block_changing).to be_aliased_to(change).with_description("a block changing result")
end
specify do
expect(changing).to be_aliased_to(change).with_description("changing result")
end
specify do
expect(
a_collection_containing_exactly(1, 2)
).to be_aliased_to(
contain_exactly(1, 2)
).with_description("a collection containing exactly 1 and 2")
end
specify do
expect(
containing_exactly(1, 2)
).to be_aliased_to(
contain_exactly(1, 2)
).with_description("containing exactly 1 and 2")
end
specify do
expect(
a_range_covering(1, 2)
).to be_aliased_to(
cover(1, 2)
).with_description("a range covering 1 and 2")
end
specify do
expect(
covering(1, 2)
).to be_aliased_to(
cover(1, 2)
).with_description("covering 1 and 2")
end
specify do
expect(
ending_with(23)
).to be_aliased_to(
end_with(23)
).with_description("ending with 23")
end
specify do
expect(
a_collection_ending_with(23)
).to be_aliased_to(
end_with(23)
).with_description("a collection ending with 23")
end
specify do
expect(
a_string_ending_with("z")
).to be_aliased_to(
end_with("z")
).with_description('a string ending with "z"')
end
specify do
expect(
an_object_eq_to(3)
).to be_aliased_to(eq 3).with_description("an object eq to 3")
end
specify do
expect(
eq_to(3)
).to be_aliased_to(eq 3).with_description("eq to 3")
end
specify do
expect(
an_object_eql_to(3)
).to be_aliased_to(eql 3).with_description("an object eql to 3")
end
specify do
expect(
eql_to(3)
).to be_aliased_to(eql 3).with_description("eql to 3")
end
specify do
expect(
an_object_equal_to(3)
).to be_aliased_to(equal 3).with_description("an object equal to 3")
end
specify do
expect(
equal_to(3)
).to be_aliased_to(equal 3).with_description("equal to 3")
end
specify do
expect(
an_object_existing
).to be_aliased_to(exist).with_description("an object existing")
end
specify do
expect(existing).to be_aliased_to(exist).with_description("existing")
end
specify do
expect(
an_object_having_attributes(:age => 32)
).to be_aliased_to(
have_attributes(:age => 32)
).with_description("an object having attributes {:age => 32}")
end
specify do
expect(
having_attributes(:age => 32)
).to be_aliased_to(
have_attributes(:age => 32)
).with_description("having attributes {:age => 32}")
end
specify do
expect(
a_string_including("a")
).to be_aliased_to(
include("a")
).with_description('a string including "a"')
end
specify do
expect(
a_collection_including("a")
).to be_aliased_to(
include("a")
).with_description('a collection including "a"')
end
specify do
expect(
a_hash_including(:a => 5)
).to be_aliased_to(
include(:a => 5)
).with_description('a hash including {:a => 5}')
end
specify do
expect(
including(3)
).to be_aliased_to(
include(3)
).with_description('including 3')
end
specify do
expect(
a_string_matching(/foo/)
).to be_aliased_to(
match(/foo/)
).with_description('a string matching /foo/')
end
specify do
expect(
an_object_matching(/foo/)
).to be_aliased_to(
match(/foo/)
).with_description('an object matching /foo/')
end
specify do
expect(
match_regex(/foo/)
).to be_aliased_to(
match(/foo/)
).with_description('match regex /foo/')
end
specify do
expect(
matching(/foo/)
).to be_aliased_to(
match(/foo/)
).with_description('matching /foo/')
end
specify do
expect(
an_array_matching([1, 2])
).to be_aliased_to(
match_array([1, 2])
).with_description('an array containing exactly 1 and 2')
end
specify do
expect(
a_block_outputting('foo').to_stdout
).to be_aliased_to(
output('foo').to_stdout
).with_description('a block outputting "foo" to stdout')
end
specify do
expect(
a_block_outputting('foo').to_stderr
).to be_aliased_to(
output('foo').to_stderr
).with_description('a block outputting "foo" to stderr')
end
specify do
expect(
a_block_raising(ArgumentError)
).to be_aliased_to(
raise_error(ArgumentError)
).with_description('a block raising ArgumentError')
end
specify do
expect(
raising(ArgumentError)
).to be_aliased_to(
raise_error(ArgumentError)
).with_description("raising ArgumentError")
end
specify do
expect(
an_object_responding_to(:foo)
).to be_aliased_to(
respond_to(:foo)
).with_description("an object responding to #foo")
end
specify do
expect(
responding_to(:foo)
).to be_aliased_to(
respond_to(:foo)
).with_description("responding to #foo")
end
specify do
expect(
an_object_satisfying {}
).to be_aliased_to(
satisfy {}
).with_description("an object satisfying block")
end
specify do
expect(
satisfying {}
).to be_aliased_to(
satisfy {}
).with_description("satisfying block")
end
specify do
expect(
a_collection_starting_with(23)
).to be_aliased_to(
start_with(23)
).with_description("a collection starting with 23")
end
specify do
expect(
a_string_starting_with("z")
).to be_aliased_to(
start_with("z")
).with_description('a string starting with "z"')
end
specify do
expect(
starting_with("d")
).to be_aliased_to(
start_with("d")
).with_description('starting with "d"')
end
specify do
expect(
a_block_throwing(:foo)
).to be_aliased_to(
throw_symbol(:foo)
).with_description("a block throwing :foo")
end
specify do
expect(
throwing(:foo)
).to be_aliased_to(
throw_symbol(:foo)
).with_description("throwing :foo")
end
specify do
expect(
a_block_yielding_control
).to be_aliased_to(
yield_control
).with_description("a block yielding control")
end
specify do
expect(
yielding_control
).to be_aliased_to(
yield_control
).with_description("yielding control")
end
specify do
expect(
a_block_yielding_with_no_args
).to be_aliased_to(
yield_with_no_args
).with_description("a block yielding with no args")
end
specify do
expect(
yielding_with_no_args
).to be_aliased_to(
yield_with_no_args
).with_description("yielding with no args")
end
specify do
expect(
a_block_yielding_with_args
).to be_aliased_to(
yield_with_args
).with_description("a block yielding with args")
end
specify do
expect(
yielding_with_args
).to be_aliased_to(
yield_with_args
).with_description("yielding with args")
end
specify do
expect(
a_block_yielding_successive_args
).to be_aliased_to(
yield_successive_args
).with_description("a block yielding successive args()")
end
specify do
expect(
yielding_successive_args
).to be_aliased_to(
yield_successive_args
).with_description("yielding successive args()")
end
end
end
|