rspec-given 2.3.0.beta.1 → 2.3.0.beta.2
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.
- data/Gemfile +1 -0
- data/Gemfile.lock +4 -0
- data/README.md +6 -6
- data/lib/rspec/given/extensions.rb +56 -36
- data/lib/rspec/given/version.rb +1 -1
- metadata +2 -2
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -3,6 +3,9 @@ GEM
|
|
3
3
|
specs:
|
4
4
|
bluecloth (2.2.0)
|
5
5
|
diff-lcs (1.1.3)
|
6
|
+
flay (2.0.1)
|
7
|
+
ruby_parser (~> 3.0)
|
8
|
+
sexp_processor (~> 4.0)
|
6
9
|
flog (3.2.1)
|
7
10
|
ruby_parser (~> 3.1, > 3.1.0)
|
8
11
|
sexp_processor (~> 4.0)
|
@@ -32,6 +35,7 @@ PLATFORMS
|
|
32
35
|
|
33
36
|
DEPENDENCIES
|
34
37
|
bluecloth
|
38
|
+
flay
|
35
39
|
flog
|
36
40
|
ghpreview
|
37
41
|
rake (>= 0.9.2.2)
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# rspec-given
|
2
2
|
|
3
|
-
Covering rspec-given, version 3.0.
|
3
|
+
Covering rspec-given, version 2.3.0.beta.2.
|
4
4
|
|
5
5
|
rspec-given is an RSpec extension to allow Given/When/Then notation in
|
6
6
|
RSpec specifications. It is a natural extension of the experimental
|
@@ -392,11 +392,11 @@ comparison operators (==, !=, <, <=, >, >=) or matching operators (=~,
|
|
392
392
|
|
393
393
|
Keep the following in mind when using Natural Assertions.
|
394
394
|
|
395
|
-
* Only a single assertion per _Then_.
|
396
|
-
_Then_ block will be considered when determining pass/fail
|
397
|
-
assertion. If you _want_ to express a complex condition for
|
398
|
-
_Then_, you need to use ||, && or some other logical operation
|
399
|
-
join the conditions into a single expression (and the failure
|
395
|
+
* Only a single expression/assertion per _Then_. The single expression
|
396
|
+
of the _Then_ block will be considered when determining pass/fail
|
397
|
+
for the assertion. If you _want_ to express a complex condition for
|
398
|
+
the _Then_, you need to use ||, && or some other logical operation
|
399
|
+
to join the conditions into a single expression (and the failure
|
400
400
|
message will breakdown the values for each part).
|
401
401
|
|
402
402
|
* Natural assertions must be **idempotent** (that means they don't
|
@@ -14,7 +14,7 @@ module RSpec
|
|
14
14
|
# outermost.
|
15
15
|
def _rg_inner_contexts # :nodoc:
|
16
16
|
self.class.ancestors.select { |context|
|
17
|
-
context.respond_to?(:
|
17
|
+
context.respond_to?(:_rgc_givens)
|
18
18
|
}
|
19
19
|
end
|
20
20
|
|
@@ -24,9 +24,11 @@ module RSpec
|
|
24
24
|
_rg_inner_contexts.reverse
|
25
25
|
end
|
26
26
|
|
27
|
-
|
27
|
+
# Return the context information for keyword from the innermost
|
28
|
+
# defining context.
|
29
|
+
def _rg_info(keyword) # :nodoc:
|
28
30
|
_rg_inner_contexts.each do |context|
|
29
|
-
h = context.
|
31
|
+
h = context._rgc_context_info
|
30
32
|
if h.has_key?(keyword)
|
31
33
|
return h[keyword]
|
32
34
|
end
|
@@ -34,10 +36,28 @@ module RSpec
|
|
34
36
|
nil
|
35
37
|
end
|
36
38
|
|
37
|
-
|
39
|
+
# Should a natural assertion failure message be generated?
|
40
|
+
#
|
41
|
+
# A natural assertion failure message is generated if the
|
42
|
+
# assertion has non-empty content that doesn't use rspec
|
43
|
+
# assertions. The configuration options for natural assertions
|
44
|
+
# are checked and applied accordingly.
|
45
|
+
#
|
46
|
+
def _rg_need_na_message?(nassert) # :nodoc:
|
47
|
+
return false unless nassert.has_content?
|
48
|
+
use_na = _rg_na_configured?
|
49
|
+
return true if use_na == :always
|
50
|
+
return false if nassert.using_rspec_assertion?
|
51
|
+
use_na
|
52
|
+
end
|
53
|
+
|
54
|
+
# Return the configuration value for natural assertions.
|
55
|
+
#
|
56
|
+
# If natural assertions are not configured in the contexts, use
|
57
|
+
# the global configuration value.
|
58
|
+
def _rg_na_configured? # :nodoc:
|
38
59
|
info_value = _rg_info(:natural_assertions_enabled)
|
39
|
-
|
40
|
-
(! nassert.using_rspec_assertion? && use_na) || (use_na == :always)
|
60
|
+
info_value.nil? ? RSpec::Given.natural_assertions_enabled? : info_value
|
41
61
|
end
|
42
62
|
|
43
63
|
# Establish all the Given preconditions the current and
|
@@ -47,7 +67,7 @@ module RSpec
|
|
47
67
|
return if defined?(@_rg_ran) && @_rg_ran
|
48
68
|
@_rg_ran = true
|
49
69
|
_rg_contexts.each do |context|
|
50
|
-
context.
|
70
|
+
context._rgc_givens.each do |block|
|
51
71
|
instance_eval(&block)
|
52
72
|
end
|
53
73
|
end
|
@@ -57,18 +77,18 @@ module RSpec
|
|
57
77
|
# describe/context blocks, starting with the outermost context.
|
58
78
|
def _rg_check_invariants # :nodoc:
|
59
79
|
_rg_contexts.each do |context|
|
60
|
-
context.
|
80
|
+
context._rgc_invariants.each do |block|
|
61
81
|
_rg_evaluate(block)
|
62
82
|
end
|
63
83
|
end
|
64
84
|
end
|
65
85
|
|
66
86
|
def _rg_check_ands # :nodoc:
|
67
|
-
return if self.class.
|
68
|
-
self.class.
|
87
|
+
return if self.class._rgc_context_info[:and_ran]
|
88
|
+
self.class._rgc_and_blocks.each do |block|
|
69
89
|
_rg_evaluate(block)
|
70
90
|
end
|
71
|
-
self.class.
|
91
|
+
self.class._rgc_context_info[:and_ran] = true
|
72
92
|
end
|
73
93
|
|
74
94
|
# Implement the run-time semantics of the Then clause.
|
@@ -79,12 +99,12 @@ module RSpec
|
|
79
99
|
_rg_check_ands
|
80
100
|
end
|
81
101
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
102
|
+
# Evaluate a Then, And, or Invariant assertion.
|
103
|
+
def _rg_evaluate(block) # :nodoc:
|
104
|
+
passed = instance_eval(&block)
|
105
|
+
if ! passed && _rg_na_configured?
|
106
|
+
nassert = NaturalAssertion.new(block, binding, self.class._rgc_lines)
|
107
|
+
::RSpec::Expectations.fail_with nassert.message if _rg_need_na_message?(nassert)
|
88
108
|
end
|
89
109
|
end
|
90
110
|
end
|
@@ -93,31 +113,31 @@ module RSpec
|
|
93
113
|
|
94
114
|
# List of all givens directly in the current describe/context
|
95
115
|
# block.
|
96
|
-
def
|
97
|
-
@
|
116
|
+
def _rgc_givens # :nodoc:
|
117
|
+
@_rgc_givens ||= []
|
98
118
|
end
|
99
119
|
|
100
120
|
# List of all invariants directly in the current
|
101
121
|
# describe/context block.
|
102
|
-
def
|
103
|
-
@
|
122
|
+
def _rgc_invariants # :nodoc:
|
123
|
+
@_rgc_invariants ||= []
|
104
124
|
end
|
105
125
|
|
106
|
-
def
|
107
|
-
@
|
126
|
+
def _rgc_and_blocks
|
127
|
+
@_rgc_and_blocks ||= []
|
108
128
|
end
|
109
129
|
|
110
|
-
def
|
111
|
-
@
|
130
|
+
def _rgc_context_info
|
131
|
+
@_rgc_context_info ||= {}
|
112
132
|
end
|
113
133
|
|
114
|
-
def
|
115
|
-
@
|
134
|
+
def _rgc_lines
|
135
|
+
@_rgc_lines ||= LineExtractor.new
|
116
136
|
end
|
117
137
|
|
118
138
|
# Trigger the evaluation of a Given! block by referencing its
|
119
139
|
# name.
|
120
|
-
def
|
140
|
+
def _rgc_trigger_given(name) # :nodoc:
|
121
141
|
Proc.new { send(name) }
|
122
142
|
end
|
123
143
|
|
@@ -157,7 +177,7 @@ module RSpec
|
|
157
177
|
if args.first.is_a?(Symbol)
|
158
178
|
let(args.first, &block)
|
159
179
|
else
|
160
|
-
|
180
|
+
_rgc_givens << block
|
161
181
|
end
|
162
182
|
end
|
163
183
|
|
@@ -170,7 +190,7 @@ module RSpec
|
|
170
190
|
#
|
171
191
|
def Given!(name, &block)
|
172
192
|
let!(name, &block)
|
173
|
-
|
193
|
+
_rgc_givens << _rgc_trigger_given(name)
|
174
194
|
end
|
175
195
|
|
176
196
|
# Declare the code that is under test.
|
@@ -209,29 +229,29 @@ module RSpec
|
|
209
229
|
def Then(&block)
|
210
230
|
env = block.binding
|
211
231
|
file, line = eval "[__FILE__, __LINE__]", env
|
212
|
-
description =
|
232
|
+
description = _rgc_lines.line(file, line) unless RSpec::Given.source_caching_disabled
|
213
233
|
if description
|
214
234
|
cmd = "it(description)"
|
215
235
|
else
|
216
236
|
cmd = "specify"
|
217
237
|
end
|
218
238
|
eval %{#{cmd} do _rg_then(&block) end}, binding, file, line
|
219
|
-
|
239
|
+
_rgc_context_info[:then_defined] = true
|
220
240
|
end
|
221
241
|
|
222
242
|
# Establish an invariant that must be true for all Then blocks
|
223
243
|
# in the current (and nested) scopes.
|
224
244
|
def Invariant(&block)
|
225
|
-
|
245
|
+
_rgc_invariants << block
|
226
246
|
end
|
227
247
|
|
228
248
|
def And(&block)
|
229
|
-
fail "And defined without a Then" unless
|
230
|
-
|
249
|
+
fail "And defined without a Then" unless _rgc_context_info[:then_defined]
|
250
|
+
_rgc_and_blocks << block
|
231
251
|
end
|
232
252
|
|
233
253
|
def use_natural_assertions(enabled=true)
|
234
|
-
|
254
|
+
_rgc_context_info[:natural_assertions_enabled] = enabled
|
235
255
|
end
|
236
256
|
end
|
237
257
|
end
|
data/lib/rspec/given/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-given
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.3.0.beta.
|
4
|
+
version: 2.3.0.beta.2
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|