defekt 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +28 -2
- data/lib/defekt/assertions.rb +48 -0
- data/lib/defekt/base.rb +1 -1
- data/lib/defekt/object.rb +1 -1
- data/lib/defekt/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 275d792094526444f3788ba4ba64c6d7a843a189
|
4
|
+
data.tar.gz: 4c667631152f5acd1c02ff37cdc7d85546224656
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3bac76848cc8b80de750319fdd8ba2ac509a1c2fdfd0dfd9176c8f0c8e708db79a08d92d7438bfd7062eb7af913bd2d38ccd219b544885dfeae7a322ee94caff
|
7
|
+
data.tar.gz: ccb5b7deb6f7cfab73b65dee8c3ad21d0abf8cc8aacdaacde6dece222f1c8d58e654a1ec3050b9b9c30580d4d0357620b4f855f523d9f76b996b385ac2687e78
|
data/README.md
CHANGED
@@ -50,9 +50,9 @@ class PersonTest < Defekt::Base
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def test_age
|
53
|
-
|
53
|
+
not_respond_to! @person, :age
|
54
54
|
@person.stub(:age, 'unknown') do
|
55
|
-
|
55
|
+
respond_to! @person, :age
|
56
56
|
equal_to! 'unknown', @person.age
|
57
57
|
end
|
58
58
|
end
|
@@ -61,6 +61,32 @@ end
|
|
61
61
|
Defekt.run
|
62
62
|
```
|
63
63
|
|
64
|
+
## Assertions
|
65
|
+
|
66
|
+
All available assertions have negative counterparts prefixed with `not_`.
|
67
|
+
|
68
|
+
- true!
|
69
|
+
- equal_to!
|
70
|
+
- identical_to!
|
71
|
+
- included_in!
|
72
|
+
- instance_of!
|
73
|
+
- kind_of!
|
74
|
+
- respond_to!
|
75
|
+
|
76
|
+
You can add your own assertions by opening up the `Defekt::Assertions` module.
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
module Defekt
|
80
|
+
module Assertions
|
81
|
+
def awesome!(value)
|
82
|
+
unless value == 'awesome'
|
83
|
+
raise Errors::AwesomeError, "~#{value}~ is not awesome"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
```
|
89
|
+
|
64
90
|
## Development
|
65
91
|
|
66
92
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/defekt/assertions.rb
CHANGED
@@ -6,36 +6,84 @@ module Defekt
|
|
6
6
|
end
|
7
7
|
end
|
8
8
|
|
9
|
+
def not_true!(value)
|
10
|
+
if value
|
11
|
+
raise Errors::NotTrueError, message(value, 'is', true)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
9
15
|
def equal_to!(expected, actual)
|
10
16
|
unless actual == expected
|
11
17
|
raise Errors::EqualToError, message(actual, 'is not equal to', expected)
|
12
18
|
end
|
13
19
|
end
|
14
20
|
|
21
|
+
def not_equal_to!(expected, actual)
|
22
|
+
if actual == expected
|
23
|
+
raise Errors::NotEqualToError, message(actual, 'is equal to', expected)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
15
27
|
def identical_to!(expected, actual)
|
16
28
|
unless actual.equal?(expected)
|
17
29
|
raise Errors::IdenticalToError, message(actual, 'is not identical to', expected)
|
18
30
|
end
|
19
31
|
end
|
20
32
|
|
33
|
+
def not_identical_to!(expected, actual)
|
34
|
+
if actual.equal?(expected)
|
35
|
+
raise Errors::NotIdenticalToError, message(actual, 'is identical to', expected)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
21
39
|
def included_in!(collection, member)
|
22
40
|
unless collection.include?(member)
|
23
41
|
raise Errors::IncludedInError, message(member, 'is not included in', collection)
|
24
42
|
end
|
25
43
|
end
|
26
44
|
|
45
|
+
def not_included_in!(collection, member)
|
46
|
+
if collection.include?(member)
|
47
|
+
raise Errors::NotIncludedInError, message(member, 'is included in', collection)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
27
51
|
def instance_of!(klass, instance)
|
28
52
|
unless instance.instance_of?(klass)
|
29
53
|
raise Errors::InstanceOfError, message(instance, 'is not an instance of', klass)
|
30
54
|
end
|
31
55
|
end
|
32
56
|
|
57
|
+
def not_instance_of!(klass, instance)
|
58
|
+
if instance.instance_of?(klass)
|
59
|
+
raise Errors::NotInstanceOfError, message(instance, 'is an instance of', klass)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
33
63
|
def kind_of!(klass, instance)
|
34
64
|
unless instance.kind_of?(klass)
|
35
65
|
raise Errors::KindOfError, message(instance, 'is not a kind of', klass)
|
36
66
|
end
|
37
67
|
end
|
38
68
|
|
69
|
+
def not_kind_of!(klass, instance)
|
70
|
+
if instance.kind_of?(klass)
|
71
|
+
raise Errors::NotKindOfError, message(instance, 'is a kind of', klass)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def respond_to!(object, methot)
|
76
|
+
unless object.respond_to?(methot)
|
77
|
+
raise Errors::RespondToError, message(object, 'does not respond to', methot)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def not_respond_to!(object, methot)
|
82
|
+
if object.respond_to?(methot)
|
83
|
+
raise Errors::NotRespondToError, message(object, 'does respond to', methot)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
39
87
|
private
|
40
88
|
|
41
89
|
def message(object1, text, object2)
|
data/lib/defekt/base.rb
CHANGED
data/lib/defekt/object.rb
CHANGED
data/lib/defekt/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: defekt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Boot
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|