sleepers 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sleepers/rspec/collection_matchers.rb +88 -0
- data/lib/sleepers/rspec/matchers.rb +2 -1
- data/lib/sleepers/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dd18fde840a70b466161fcef45890777f546d8f4
|
4
|
+
data.tar.gz: 9870ef102dc85bebfa6230e20eb473c4fd78175c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b29afeda0d84aef85cb6f20abe64aabbbc5eef7b43193e840d3500c53c60dbc9a2c9b8d404e855899a7419931727d27820359a357728b04b99a4b5a5d581cd0f
|
7
|
+
data.tar.gz: efbcf768ac656ae793e3e88102fab1146b64253c0520a83b6720ba1a0b28e35837dce80646c2c9349311889d15b410830864f231aa01c7b8dd0faa0123dbc7e2
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'rspec/expectations'
|
2
|
+
|
3
|
+
RSpec::Matchers.define :each_be do
|
4
|
+
match do |object|
|
5
|
+
@object = object
|
6
|
+
object.all?{|item| item.send("#{expected}?")}
|
7
|
+
end
|
8
|
+
|
9
|
+
failure_message do
|
10
|
+
"expected collection to all be '#{expected || "nil"}'"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
RSpec::Matchers.define :each_not_be do
|
15
|
+
match do |object|
|
16
|
+
object.none?{|item| item.send("#{expected}?")}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
RSpec::Matchers.define :each_eq do
|
21
|
+
match do |actual|
|
22
|
+
actual.all?{|item| item == expected}
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
RSpec::Matchers.define :each_be_kind_of do
|
27
|
+
match do |actual|
|
28
|
+
actual.all?{|item| item.kind_of?(expected)}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
RSpec::Matchers.define :each_respond_to do
|
33
|
+
match do |actual|
|
34
|
+
actual.all?{|item| item.respond_to? expected}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
RSpec::Matchers.define :each_match do
|
39
|
+
match do |actual|
|
40
|
+
actual.all?{|item| item.match(expected).nil?}
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
RSpec::Matchers.define :have_count_of do
|
45
|
+
match do |actual|
|
46
|
+
actual.count == expected
|
47
|
+
end
|
48
|
+
|
49
|
+
failure_message do
|
50
|
+
"expected collection to have count of #{expected}, got #{actual.count}"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
RSpec::Matchers.define :each_have_key do
|
55
|
+
match do |actual|
|
56
|
+
actual.all?{|item| item.keys.include? expected }
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
RSpec::Matchers.define :each_have_keys do
|
61
|
+
match do |actual|
|
62
|
+
@unmatched = actual.select{|item| item.keys.sort & expected.sort != expected.sort}
|
63
|
+
@missing_keys = @unmatched.map { |item| expected - (item.keys.sort & expected.sort) }.uniq.flatten
|
64
|
+
@unmatched.empty?
|
65
|
+
end
|
66
|
+
|
67
|
+
failure_message do
|
68
|
+
"Expected collection to each have keys #{expected.sort}. The following keys were missing from one or more items #{@missing_keys} "
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
RSpec::Matchers.define :each_only_have_keys do
|
73
|
+
match do |actual|
|
74
|
+
actual.all?{|item| item.keys.sort == expected.sort}
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
RSpec::Matchers.define :have_ids_matching do
|
79
|
+
match do |actual|
|
80
|
+
actual.collect{|item| (item['id'] || item[:id]) }.sort == expected.collect(&:id).sort
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
RSpec::Matchers.define :not_have_ids_matching do
|
85
|
+
match do |actual|
|
86
|
+
(actual.collect{|item| (item['id'] || item[:id]) } & expected.collect(&:id)).empty?
|
87
|
+
end
|
88
|
+
end
|
@@ -1 +1,2 @@
|
|
1
|
-
require_relative './hash_matchers'
|
1
|
+
require_relative './hash_matchers'
|
2
|
+
require_relative './collection_matchers'
|
data/lib/sleepers/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sleepers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tyrone Wilson
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hashie
|
@@ -155,6 +155,7 @@ files:
|
|
155
155
|
- bin/console
|
156
156
|
- bin/setup
|
157
157
|
- lib/sleepers.rb
|
158
|
+
- lib/sleepers/rspec/collection_matchers.rb
|
158
159
|
- lib/sleepers/rspec/hash_matchers.rb
|
159
160
|
- lib/sleepers/rspec/matchers.rb
|
160
161
|
- lib/sleepers/version.rb
|