muack 1.2.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.travis.yml +19 -9
- data/CHANGES.md +47 -0
- data/Gemfile +0 -4
- data/README.md +162 -65
- data/Rakefile +3 -4
- data/lib/muack.rb +43 -11
- data/lib/muack/block.rb +4 -15
- data/lib/muack/block_26.rb +16 -0
- data/lib/muack/block_27.rb +16 -0
- data/lib/muack/coat.rb +1 -1
- data/lib/muack/definition.rb +4 -3
- data/lib/muack/error.rb +6 -0
- data/lib/muack/failure.rb +5 -4
- data/lib/muack/mock.rb +134 -68
- data/lib/muack/satisfying.rb +195 -0
- data/lib/muack/spy.rb +18 -4
- data/lib/muack/stub.rb +7 -6
- data/lib/muack/test.rb +42 -11
- data/lib/muack/version.rb +1 -1
- data/muack.gemspec +65 -55
- data/task/README.md +8 -8
- data/task/gemgem.rb +34 -7
- data/test/test_any_instance_of.rb +16 -2
- data/test/test_from_readme.rb +6 -8
- data/test/test_keyargs.rb +111 -0
- data/test/test_modifier.rb +6 -6
- data/test/test_prepend.rb +121 -0
- data/test/test_proxy.rb +19 -4
- data/test/{test_satisfy.rb → test_satisfying.rb} +216 -80
- data/test/test_spy.rb +149 -0
- data/test/test_stub.rb +0 -95
- data/test/test_visibility.rb +120 -0
- metadata +20 -11
- data/lib/muack/satisfy.rb +0 -100
data/lib/muack/satisfy.rb
DELETED
@@ -1,100 +0,0 @@
|
|
1
|
-
|
2
|
-
module Muack
|
3
|
-
class Satisfy < Struct.new(:block, :api_args)
|
4
|
-
def match actual_arg
|
5
|
-
!!block.call(actual_arg)
|
6
|
-
end
|
7
|
-
|
8
|
-
def | rhs; Satisfy::Disj.new(self, rhs); end
|
9
|
-
def & rhs; Satisfy::Conj.new(self, rhs); end
|
10
|
-
|
11
|
-
class Disj < Satisfy
|
12
|
-
def initialize lhs, rhs
|
13
|
-
@lhs, @rhs = lhs, rhs
|
14
|
-
super(lambda{ |actual_arg| lhs.match(actual_arg) ||
|
15
|
-
rhs.match(actual_arg) })
|
16
|
-
end
|
17
|
-
|
18
|
-
def to_s; "#{@lhs} | #{@rhs}"; end
|
19
|
-
alias_method :inspect, :to_s
|
20
|
-
end
|
21
|
-
|
22
|
-
class Conj < Satisfy
|
23
|
-
def initialize lhs, rhs
|
24
|
-
@lhs, @rhs = lhs, rhs
|
25
|
-
super(lambda{ |actual_arg| lhs.match(actual_arg) &&
|
26
|
-
rhs.match(actual_arg) })
|
27
|
-
end
|
28
|
-
|
29
|
-
def to_s; "#{@lhs} & #{@rhs}"; end
|
30
|
-
alias_method :inspect, :to_s
|
31
|
-
end
|
32
|
-
|
33
|
-
def to_s
|
34
|
-
"Muack::API.#{api_name}(#{api_args.map(&:inspect).join(', ')})"
|
35
|
-
end
|
36
|
-
alias_method :inspect, :to_s
|
37
|
-
|
38
|
-
def api_name
|
39
|
-
(self.class.name || 'Unknown')[/(::)*(\w+)$/, 2].
|
40
|
-
gsub(/([A-Z][a-z]*)+?(?=[A-Z][a-z]*)/, '\\1_').downcase
|
41
|
-
end
|
42
|
-
|
43
|
-
def api_args
|
44
|
-
super || [block]
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
class IsA < Satisfy
|
49
|
-
def initialize klass
|
50
|
-
super lambda{ |actual_arg| actual_arg.kind_of?(klass) }, [klass]
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
class Anything < Satisfy
|
55
|
-
def initialize
|
56
|
-
super lambda{ |_| true }, []
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
class Match < Satisfy
|
61
|
-
def initialize regexp
|
62
|
-
super lambda{ |actual_arg| regexp.match(actual_arg) }, [regexp]
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
class HashIncluding < Satisfy
|
67
|
-
def initialize hash
|
68
|
-
super lambda{ |actual_arg|
|
69
|
-
actual_arg.values_at(*hash.keys).zip(hash.values).all? do |(av, ev)|
|
70
|
-
if ev.kind_of?(Satisfy)
|
71
|
-
ev.match(av)
|
72
|
-
else
|
73
|
-
ev == av
|
74
|
-
end
|
75
|
-
end
|
76
|
-
}, [hash]
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
class Including < Satisfy
|
81
|
-
def initialize element
|
82
|
-
super lambda{ |actual_arg|
|
83
|
-
actual_arg.include?(element) }, [element]
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
class Within < Satisfy
|
88
|
-
def initialize range_or_array
|
89
|
-
super lambda{ |actual_arg| range_or_array.include?(actual_arg) },
|
90
|
-
[range_or_array]
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
class RespondTo < Satisfy
|
95
|
-
def initialize *messages
|
96
|
-
super lambda{ |actual_arg|
|
97
|
-
messages.all?{ |msg| actual_arg.respond_to?(msg) } }, messages
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|