fix 1.0.0.beta4 → 1.0.0.beta8
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 +4 -4
- data/LICENSE.md +1 -1
- data/README.md +71 -49
- data/lib/fix.rb +12 -15
- data/lib/fix/doc.rb +24 -0
- data/lib/fix/dsl.rb +113 -0
- data/lib/fix/matcher.rb +241 -0
- data/lib/fix/requirement.rb +162 -0
- data/lib/fix/run.rb +55 -0
- data/lib/fix/set.rb +92 -0
- data/lib/kernel.rb +29 -2
- metadata +82 -35
- data/lib/fix/context.rb +0 -160
- data/lib/fix/expectation_result_not_found_error.rb +0 -5
- data/lib/fix/it.rb +0 -31
- data/lib/fix/suspicious_success_error.rb +0 -5
data/lib/fix/context.rb
DELETED
@@ -1,160 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'aw'
|
4
|
-
require 'defi'
|
5
|
-
|
6
|
-
module Fix
|
7
|
-
# Wraps the target of challenge.
|
8
|
-
class Context
|
9
|
-
RESERVED_KEYWORDS = %i[
|
10
|
-
alias
|
11
|
-
and
|
12
|
-
begin
|
13
|
-
break
|
14
|
-
case
|
15
|
-
catch
|
16
|
-
class
|
17
|
-
def
|
18
|
-
defined?
|
19
|
-
do
|
20
|
-
else
|
21
|
-
elsif
|
22
|
-
end
|
23
|
-
ensure
|
24
|
-
fail
|
25
|
-
false
|
26
|
-
for
|
27
|
-
if
|
28
|
-
in
|
29
|
-
module
|
30
|
-
next
|
31
|
-
nil
|
32
|
-
not
|
33
|
-
or
|
34
|
-
raise
|
35
|
-
redo
|
36
|
-
rescue
|
37
|
-
retry
|
38
|
-
return
|
39
|
-
self
|
40
|
-
super
|
41
|
-
then
|
42
|
-
throw
|
43
|
-
true
|
44
|
-
undef
|
45
|
-
unless
|
46
|
-
until
|
47
|
-
when
|
48
|
-
while
|
49
|
-
yield
|
50
|
-
].freeze
|
51
|
-
|
52
|
-
attr_reader :callable
|
53
|
-
|
54
|
-
def initialize(subject, challenge, before_hooks_counter = 0, *hooks, **lets)
|
55
|
-
@subject = subject
|
56
|
-
@callable = challenge.to(subject)
|
57
|
-
@before_hooks = hooks[0, before_hooks_counter]
|
58
|
-
@after_hooks = hooks[before_hooks_counter..-1]
|
59
|
-
@lets = lets
|
60
|
-
end
|
61
|
-
|
62
|
-
def before(&block)
|
63
|
-
@before_hooks << block
|
64
|
-
end
|
65
|
-
|
66
|
-
def after(&block)
|
67
|
-
@after_hooks << block
|
68
|
-
end
|
69
|
-
|
70
|
-
def let(name, &block)
|
71
|
-
raise ::TypeError, "expected a Symbol, got #{name.class}" unless name.is_a?(::Symbol)
|
72
|
-
raise ::NameError, "wrong method name `#{name}'" unless name.match(/\A[a-z][a-z0-9_]+[?!]?\z/)
|
73
|
-
raise ::NameError, "reserved keyword name `#{name}'" if RESERVED_KEYWORDS.include?(name)
|
74
|
-
raise ::NameError, "reserved method name `#{name}'" if respond_to?(name, true) && !@lets.key?(name)
|
75
|
-
|
76
|
-
@lets.update(name => block.call)
|
77
|
-
rescue ::SystemExit => e
|
78
|
-
raise SuspiciousSuccessError, "attempt `#{name}' to bypass the tests" if e.success?
|
79
|
-
raise e
|
80
|
-
end
|
81
|
-
|
82
|
-
def let!(name, &block)
|
83
|
-
raise ::TypeError, "expected a Symbol, got #{name.class}" unless name.is_a?(::Symbol)
|
84
|
-
raise ::NameError, "wrong method name `#{name}'" unless name.match(/\A[a-z][a-z0-9_]+[?!]?\z/)
|
85
|
-
raise ::NameError, "reserved keyword name `#{name}'" if RESERVED_KEYWORDS.include?(name)
|
86
|
-
raise ::NameError, "reserved method name `#{name}'" if respond_to?(name, true) && !@lets.key?(name)
|
87
|
-
|
88
|
-
@lets.update(name => ::Aw.fork! { block.call })
|
89
|
-
rescue ::SystemExit => e
|
90
|
-
raise SuspiciousSuccessError, "attempt `#{name}' to bypass the tests" if e.success?
|
91
|
-
raise e
|
92
|
-
end
|
93
|
-
|
94
|
-
# Verify the expectation.
|
95
|
-
#
|
96
|
-
# @param block [Proc] A spec to compare against the computed actual value.
|
97
|
-
#
|
98
|
-
# @return [::Spectus::Result::Pass, ::Spectus::Result::Fail] Pass or fail.
|
99
|
-
def it(_message = nil, &block)
|
100
|
-
print "#{block.source_location.join(':')}: "
|
101
|
-
i = It.new(callable, **@lets)
|
102
|
-
@before_hooks.each { |hook| i.instance_eval(&hook) }
|
103
|
-
result = i.instance_eval(&block)
|
104
|
-
puts result.colored_string
|
105
|
-
rescue ::Spectus::Result::Fail => result
|
106
|
-
abort result.colored_string
|
107
|
-
ensure
|
108
|
-
@after_hooks.each { |hook| i.instance_eval(&hook) }
|
109
|
-
raise ExpectationResultNotFoundError, result.class.inspect unless result.is_a?(::Spectus::Result::Common)
|
110
|
-
end
|
111
|
-
|
112
|
-
def its(name, *args, **options, &block)
|
113
|
-
if callable.raised?
|
114
|
-
actual = callable
|
115
|
-
challenge = ::Defi.send(:call)
|
116
|
-
else
|
117
|
-
actual = callable.object
|
118
|
-
challenge = ::Defi.send(name, *args, **options)
|
119
|
-
end
|
120
|
-
|
121
|
-
o = Context.new(actual, challenge, @before_hooks.length, *@before_hooks + @after_hooks, **@lets)
|
122
|
-
o.it(&block)
|
123
|
-
end
|
124
|
-
|
125
|
-
def on(name, *args, **options, &block)
|
126
|
-
if callable.raised?
|
127
|
-
actual = callable
|
128
|
-
challenge = ::Defi.send(:call)
|
129
|
-
else
|
130
|
-
actual = callable.object
|
131
|
-
challenge = ::Defi.send(name, *args, **options)
|
132
|
-
end
|
133
|
-
|
134
|
-
o = Context.new(actual, challenge, @before_hooks.length, *@before_hooks + @after_hooks, **@lets)
|
135
|
-
o.instance_eval(&block)
|
136
|
-
end
|
137
|
-
|
138
|
-
def with(_message = nil, **new_lets, &block)
|
139
|
-
actual = callable.object
|
140
|
-
challenge = ::Defi.send(:itself)
|
141
|
-
|
142
|
-
c = Context.new(actual, challenge, @before_hooks.length, *@before_hooks + @after_hooks, **@lets.merge(new_lets))
|
143
|
-
c.instance_eval(&block)
|
144
|
-
end
|
145
|
-
|
146
|
-
private
|
147
|
-
|
148
|
-
def method_missing(name, *args, &block)
|
149
|
-
@lets.fetch(name) { super }
|
150
|
-
end
|
151
|
-
|
152
|
-
def respond_to_missing?(name, include_private = false)
|
153
|
-
@lets.key?(name) || super
|
154
|
-
end
|
155
|
-
end
|
156
|
-
end
|
157
|
-
|
158
|
-
require_relative 'it'
|
159
|
-
require_relative 'expectation_result_not_found_error'
|
160
|
-
require_relative 'suspicious_success_error'
|
data/lib/fix/it.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spectus/expectation_target'
|
4
|
-
require 'matchi/helper'
|
5
|
-
|
6
|
-
module Fix
|
7
|
-
# Wraps the target of an expectation.
|
8
|
-
class It < ::Spectus::ExpectationTarget
|
9
|
-
include ::Matchi::Helper
|
10
|
-
|
11
|
-
# Create a new expection target
|
12
|
-
#
|
13
|
-
# @param callable [#call] The object to test.
|
14
|
-
def initialize(callable, **lets)
|
15
|
-
raise unless callable.respond_to?(:call)
|
16
|
-
|
17
|
-
@callable = callable
|
18
|
-
@lets = lets
|
19
|
-
end
|
20
|
-
|
21
|
-
private
|
22
|
-
|
23
|
-
def method_missing(name, *args, &block)
|
24
|
-
@lets.fetch(name) { super }
|
25
|
-
end
|
26
|
-
|
27
|
-
def respond_to_missing?(name, include_private = false)
|
28
|
-
@lets.key?(name) || super
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|