set_specs 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +9 -0
- data/lib/matchers.rb +64 -0
- metadata +76 -0
data/README
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
set_specs - A few useful RSpec matchers for making assertions about enumerables.
|
2
|
+
================================================================================
|
3
|
+
|
4
|
+
Consists of:
|
5
|
+
* intersects_with - asserts that one enumerable intersects with another
|
6
|
+
* be_a_subset_of - asserts that one enumerable is a subset of another
|
7
|
+
* be_a_proper_subset_of - asserts that one enumerable is a proper subset of another (ie, the two are not equivalent)
|
8
|
+
|
9
|
+
Enjoy!
|
data/lib/matchers.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
Spec::Matchers.define :intersect_with do |challenge_range|
|
2
|
+
|
3
|
+
#based on http://gist.github.com/247669, but using Enumerable#select rather than '&', for compatibility with all enumerables (Enumerable doesn't implement &lo).
|
4
|
+
|
5
|
+
match do |current_range|
|
6
|
+
!current_range.select {|element| challenge_range.include?(element)}.empty?
|
7
|
+
end
|
8
|
+
|
9
|
+
failure_message_for_should do |current_range|
|
10
|
+
"#{current_range.inspect} doesn't overlap with #{challenge_range.inspect}"
|
11
|
+
end
|
12
|
+
|
13
|
+
failure_message_for_should_not do |current_range|
|
14
|
+
"#{current_range.inspect} overlaps with #{challenge_range.inspect}"
|
15
|
+
end
|
16
|
+
|
17
|
+
description do
|
18
|
+
"intersection of an enumerable's elements"
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
Spec::Matchers.define :be_a_subset_of do |challenge_range|
|
24
|
+
|
25
|
+
|
26
|
+
match do |current_range|
|
27
|
+
current_range.map {|element| challenge_range.include?(element)}.inject(true) {|m,n| m && n}
|
28
|
+
end
|
29
|
+
|
30
|
+
failure_message_for_should do |current_range|
|
31
|
+
"#{current_range.inspect} is a subset of #{challenge_range.inspect}"
|
32
|
+
end
|
33
|
+
|
34
|
+
failure_message_for_should_not do |current_range|
|
35
|
+
"#{current_range.inspect} is not a subset of #{challenge_range.inspect}"
|
36
|
+
end
|
37
|
+
|
38
|
+
description do
|
39
|
+
"compare subsets"
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
Spec::Matchers.define :be_a_proper_subset_of do |challenge_range|
|
46
|
+
|
47
|
+
|
48
|
+
match do |current_range|
|
49
|
+
current_range.map {|element| challenge_range.include?(element)}.inject(true) {|m,n| m && n} && !challenge_range.map {|element| current_range.include?(element)}.inject(true) {|m,n| m && n}
|
50
|
+
end
|
51
|
+
|
52
|
+
failure_message_for_should do |current_range|
|
53
|
+
"#{current_range.inspect} is a proper subset of #{challenge_range.inspect}"
|
54
|
+
end
|
55
|
+
|
56
|
+
failure_message_for_should_not do |current_range|
|
57
|
+
"#{current_range.inspect} is not a proper subset of #{challenge_range.inspect}"
|
58
|
+
end
|
59
|
+
|
60
|
+
description do
|
61
|
+
"compare proper subsets"
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: set_specs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tim Cowlishaw
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-01-26 00:00:00 +00:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rspec
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
35
|
+
description:
|
36
|
+
email: tim@timcowlishaw.co.uk
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- README
|
43
|
+
files:
|
44
|
+
- README
|
45
|
+
- lib/matchers.rb
|
46
|
+
has_rdoc: true
|
47
|
+
homepage: http://github.com/timcowlishaw/set_specs/
|
48
|
+
licenses: []
|
49
|
+
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options:
|
52
|
+
- --main
|
53
|
+
- README
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: "0"
|
61
|
+
version:
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: "0"
|
67
|
+
version:
|
68
|
+
requirements: []
|
69
|
+
|
70
|
+
rubyforge_project: set_specs
|
71
|
+
rubygems_version: 1.3.5
|
72
|
+
signing_key:
|
73
|
+
specification_version: 3
|
74
|
+
summary: A few Rspec matchers for making assertions about set-like properties of Enumerables.
|
75
|
+
test_files: []
|
76
|
+
|