remarkable 3.1.7 → 3.1.8
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/remarkable.rb +2 -1
- data/lib/remarkable/base.rb +21 -4
- data/lib/remarkable/dsl/assertions.rb +38 -14
- data/lib/remarkable/negative.rb +24 -0
- data/lib/remarkable/version.rb +1 -1
- data/spec/base_spec.rb +5 -0
- data/spec/matchers/contain_matcher.rb +1 -1
- metadata +3 -2
data/lib/remarkable.rb
CHANGED
@@ -8,7 +8,8 @@ require File.join(dir, 'remarkable', 'messages')
|
|
8
8
|
|
9
9
|
require File.join(dir, 'remarkable', 'base')
|
10
10
|
require File.join(dir, 'remarkable', 'macros')
|
11
|
-
require File.join(dir, 'remarkable', 'pending')
|
11
|
+
require File.join(dir, 'remarkable', 'pending')
|
12
|
+
require File.join(dir, 'remarkable', 'negative')
|
12
13
|
require File.join(dir, 'remarkable', 'core_ext', 'array')
|
13
14
|
|
14
15
|
if defined?(Spec)
|
data/lib/remarkable/base.rb
CHANGED
@@ -10,6 +10,14 @@ module Remarkable
|
|
10
10
|
@spec = binding
|
11
11
|
self
|
12
12
|
end
|
13
|
+
|
14
|
+
def positive?
|
15
|
+
!negative?
|
16
|
+
end
|
17
|
+
|
18
|
+
def negative?
|
19
|
+
false
|
20
|
+
end
|
13
21
|
|
14
22
|
protected
|
15
23
|
|
@@ -28,11 +36,20 @@ module Remarkable
|
|
28
36
|
|
29
37
|
# Iterates over the collection given yielding the block and return false
|
30
38
|
# if any of them also returns false.
|
31
|
-
def
|
32
|
-
collection.each do |item|
|
33
|
-
|
39
|
+
def assert_collection(key, collection, inspect=true) #:nodoc:
|
40
|
+
collection.each do |item|
|
41
|
+
value = yield(item)
|
42
|
+
|
43
|
+
if positive? == !value
|
44
|
+
if key
|
45
|
+
output = inspect ? item.inspect : item
|
46
|
+
return negative?, key => output
|
47
|
+
else
|
48
|
+
return negative?
|
49
|
+
end
|
50
|
+
end
|
34
51
|
end
|
35
|
-
|
52
|
+
positive?
|
36
53
|
end
|
37
54
|
|
38
55
|
# Asserts that the given collection contains item x. If x is a regular
|
@@ -280,15 +280,17 @@ module Remarkable
|
|
280
280
|
def matches?(subject)
|
281
281
|
@subject = subject
|
282
282
|
|
283
|
-
run_before_assert_callbacks
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
end
|
283
|
+
run_before_assert_callbacks
|
284
|
+
|
285
|
+
assertions = self.class.matcher_single_assertions
|
286
|
+
unless assertions.empty?
|
287
|
+
value = send_methods_and_generate_message(assertions)
|
288
|
+
return negative? if positive? == !value
|
289
|
+
end
|
290
|
+
|
291
|
+
matches_collection_assertions?
|
290
292
|
end
|
291
|
-
|
293
|
+
|
292
294
|
protected
|
293
295
|
|
294
296
|
# You can overwrite this instance method to provide default options on
|
@@ -368,20 +370,42 @@ module Remarkable
|
|
368
370
|
methods.each do |method|
|
369
371
|
bool, hash = send(method)
|
370
372
|
|
371
|
-
|
373
|
+
if positive? == !bool
|
372
374
|
parent_scope = matcher_i18n_scope.split('.')
|
373
|
-
matcher_name = parent_scope.pop
|
374
|
-
|
375
|
+
matcher_name = parent_scope.pop
|
376
|
+
method_name = method.to_s.gsub(/(\?|\!)$/, '')
|
377
|
+
|
378
|
+
lookup = []
|
379
|
+
lookup << :"#{matcher_name}.negative_expectations.#{method_name}" if negative?
|
380
|
+
lookup << :"#{matcher_name}.expectations.#{method_name}"
|
381
|
+
lookup << :"negative_expectations.#{method_name}" if negative?
|
382
|
+
lookup << :"expectations.#{method_name}"
|
375
383
|
|
376
384
|
hash = { :scope => parent_scope, :default => lookup }.merge(hash || {})
|
377
|
-
@expectation ||= Remarkable.t
|
385
|
+
@expectation ||= Remarkable.t lookup.shift, default_i18n_options.merge(hash)
|
378
386
|
|
379
|
-
return
|
387
|
+
return negative?
|
380
388
|
end
|
381
389
|
end
|
382
390
|
|
383
|
-
return
|
391
|
+
return positive?
|
384
392
|
end
|
393
|
+
|
394
|
+
def matches_single_assertions? #:nodoc:
|
395
|
+
assertions = self.class.matcher_single_assertions
|
396
|
+
send_methods_and_generate_message(assertions)
|
397
|
+
end
|
398
|
+
|
399
|
+
def matches_collection_assertions? #:nodoc:
|
400
|
+
arguments = self.class.matcher_arguments
|
401
|
+
assertions = self.class.matcher_collection_assertions
|
402
|
+
collection = instance_variable_get("@#{self.class.matcher_arguments[:collection]}") || []
|
403
|
+
|
404
|
+
assert_collection(nil, collection) do |value|
|
405
|
+
instance_variable_set("@#{arguments[:as]}", value)
|
406
|
+
send_methods_and_generate_message(assertions)
|
407
|
+
end
|
408
|
+
end
|
385
409
|
|
386
410
|
|
387
411
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Remarkable
|
2
|
+
# Allows Remarkable matchers to work on the negative way. Your matcher has to
|
3
|
+
# follow some conventions to allow this to work by default.
|
4
|
+
#
|
5
|
+
# In negative cases, expectations can also be found under negative_expectations
|
6
|
+
# keys, falling back to expectations. This allows to set customized failure
|
7
|
+
# messages.
|
8
|
+
#
|
9
|
+
module Negative
|
10
|
+
def matches?(subject)
|
11
|
+
@negative ||= false
|
12
|
+
super
|
13
|
+
end
|
14
|
+
|
15
|
+
def does_not_match?(subject)
|
16
|
+
@negative = true
|
17
|
+
!matches?(subject)
|
18
|
+
end
|
19
|
+
|
20
|
+
def negative?
|
21
|
+
@negative
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/remarkable/version.rb
CHANGED
data/spec/base_spec.rb
CHANGED
@@ -27,6 +27,11 @@ describe Remarkable::Base do
|
|
27
27
|
should matcher
|
28
28
|
matcher.instance_variable_get('@spec').class.ancestors.should include(Spec::Example::ExampleGroup)
|
29
29
|
end
|
30
|
+
|
31
|
+
it 'should be positive' do
|
32
|
+
contain(1).should be_positive
|
33
|
+
contain(1).should_not be_negative
|
34
|
+
end
|
30
35
|
|
31
36
|
it { should contain(1) }
|
32
37
|
it { should_not contain(10) }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: remarkable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.1.
|
4
|
+
version: 3.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carlos Brando
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2009-07-
|
13
|
+
date: 2009-07-16 00:00:00 +02:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -52,6 +52,7 @@ files:
|
|
52
52
|
- lib/remarkable/matchers.rb
|
53
53
|
- lib/remarkable/core_ext/array.rb
|
54
54
|
- lib/remarkable/messages.rb
|
55
|
+
- lib/remarkable/negative.rb
|
55
56
|
- lib/remarkable.rb
|
56
57
|
- locale/en.yml
|
57
58
|
has_rdoc: true
|