tiramisu 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/tiramisu/assert.rb +8 -3
- data/lib/tiramisu/core_ext.rb +2 -1
- data/lib/tiramisu/expectations/raise.rb +32 -0
- data/lib/tiramisu/expectations/return.rb +32 -0
- data/lib/tiramisu/expectations/throw.rb +24 -0
- data/lib/tiramisu/expectations/with.rb +36 -0
- data/lib/tiramisu/expectations.rb +82 -0
- data/lib/tiramisu/run.rb +32 -15
- data/lib/tiramisu/unit.rb +10 -15
- data/lib/tiramisu/util.rb +3 -3
- data/lib/tiramisu.rb +2 -1
- data/test/receive_and_raise_test.rb +8 -16
- data/test/receive_and_return_test.rb +7 -35
- data/test/receive_and_throw_test.rb +6 -6
- data/test/receive_test.rb +4 -8
- data/test/receive_with_test.rb +8 -13
- data/test/skip_test.rb +2 -7
- data/tiramisu.gemspec +2 -3
- metadata +22 -10
- data/README.md.html +0 -348
- data/lib/tiramisu/mock/expectation/raise.rb +0 -34
- data/lib/tiramisu/mock/expectation/return.rb +0 -34
- data/lib/tiramisu/mock/expectation/throw.rb +0 -26
- data/lib/tiramisu/mock/expectation/with.rb +0 -38
- data/lib/tiramisu/mock/expectation.rb +0 -44
- data/lib/tiramisu/mock.rb +0 -48
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b275bd81b3a2fd180b1d094268b9bf5c6280309
|
4
|
+
data.tar.gz: ba695c8ac455c1ff10e7a17e503c005f59006c73
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 906c88938fff1ad3556893cc19550c9806ad758f962dcb20889adaf7c17542bb70c7ad33851c3158afc63e2361e3282d94e93b99238f4bc149c4f69bc84c7984
|
7
|
+
data.tar.gz: 39dcd11c0f4cec696030f47f08b79e27e0bc7998d2da856ace138ce77c19dd2c852be606cf3d794d7381cf91ab539edba21d910e4f99e98d2c908a46b594ba58
|
data/README.md
CHANGED
data/lib/tiramisu/assert.rb
CHANGED
@@ -116,14 +116,19 @@ module Tiramisu
|
|
116
116
|
# end
|
117
117
|
#
|
118
118
|
# @param Symbol expected message
|
119
|
-
# @return [
|
119
|
+
# @return [Expectation]
|
120
120
|
#
|
121
121
|
def receive expected_message
|
122
|
-
@object[:
|
123
|
-
@object[:returned]
|
122
|
+
Kernel.throw(:__tiramisu_status__, @object[:raised]) if @object[:raised]
|
123
|
+
@__expectation__ = Expectation.new(@object[:returned], expected_message.to_sym, @assert, caller[0])
|
124
124
|
end
|
125
125
|
alias to_receive receive
|
126
126
|
|
127
|
+
def __validate_expectations__
|
128
|
+
return unless @__expectation__
|
129
|
+
@__expectation__.validate
|
130
|
+
end
|
131
|
+
|
127
132
|
private
|
128
133
|
def __assert__ message, arguments, block
|
129
134
|
Kernel.throw(:__tiramisu_status__, @object[:raised]) if @object[:raised]
|
data/lib/tiramisu/core_ext.rb
CHANGED
@@ -0,0 +1,32 @@
|
|
1
|
+
module Tiramisu
|
2
|
+
class Expectation
|
3
|
+
|
4
|
+
# ensure received message raises as expected
|
5
|
+
#
|
6
|
+
# @note if block given it will have precedence over arguments
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
# x = mock(X.new)
|
10
|
+
# expect(x).to_receive(:y).and_raise(NoMethodError)
|
11
|
+
# # call `x.y` for test to pass
|
12
|
+
#
|
13
|
+
def and_raise type = nil, message = nil, &block
|
14
|
+
@raise = block || [type, message]
|
15
|
+
end
|
16
|
+
|
17
|
+
def assert_message_raised_as_expected
|
18
|
+
return unless @raise
|
19
|
+
if @raise.is_a?(Proc)
|
20
|
+
received_messages.find {|log| @raise.call(log[:raised])} || Tiramisu.fail([
|
21
|
+
'Looks like :%s message never raised as expected' % expected_message,
|
22
|
+
'See validation block'
|
23
|
+
], @caller)
|
24
|
+
else
|
25
|
+
received_messages.each do |log|
|
26
|
+
next unless f = Tiramisu.assert_raised_as_expected(log, *@raise)
|
27
|
+
Tiramisu.fail(f, log[:caller])
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Tiramisu
|
2
|
+
class Expectation
|
3
|
+
|
4
|
+
# ensure received message returns expected value
|
5
|
+
#
|
6
|
+
# @note if block given it will have precedence over arguments
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
# n = mock(1)
|
10
|
+
# expect(n).to_receive(:+).with(1).and_return(2)
|
11
|
+
#
|
12
|
+
def and_return value = nil, &block
|
13
|
+
@return = block || value
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
def assert_message_returned_correct_value
|
18
|
+
return unless @return
|
19
|
+
if @return.is_a?(Proc)
|
20
|
+
received_messages.find {|log| @return.call(log[:returned])} || Tiramisu.fail([
|
21
|
+
'Looks like :%s message never returned expected value' % expected_message,
|
22
|
+
'See validation block'
|
23
|
+
], @caller)
|
24
|
+
else
|
25
|
+
received_messages.find {|log| log[:returned] == @return} || Tiramisu.fail([
|
26
|
+
'Looks like :%s message never returned expected value:' % expected_message,
|
27
|
+
Array(@return).map {|x| Tiramisu.pp(x)}.join(', ')
|
28
|
+
], @caller)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Tiramisu
|
2
|
+
class Expectation
|
3
|
+
|
4
|
+
# ensure received message throws as expected
|
5
|
+
#
|
6
|
+
# @note if block given it will have precedence over arguments
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
# x = mock(X.new)
|
10
|
+
# expect(x).to_receive(:y).and_throw(:z)
|
11
|
+
#
|
12
|
+
def and_throw symbol = nil, &block
|
13
|
+
@throw = [symbol, block]
|
14
|
+
end
|
15
|
+
|
16
|
+
def assert_message_thrown_as_expected
|
17
|
+
return unless @throw
|
18
|
+
received_messages.each do |log|
|
19
|
+
next unless f = Tiramisu.assert_thrown_as_expected(log, *@throw)
|
20
|
+
Tiramisu.fail(f, log[:caller])
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Tiramisu
|
2
|
+
class Expectation
|
3
|
+
|
4
|
+
# ensure expected message received with correct arguments
|
5
|
+
#
|
6
|
+
# @note if block given it will have precedence over arguments
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
# test :some_test do
|
10
|
+
# some_object = mock(SomeObject.new)
|
11
|
+
# expect(some_object).to_receive(:some_method).with(:some, :args)
|
12
|
+
# # call `some_object.some_method(:some, :args)` for test to pass
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
def with *args, &block
|
16
|
+
@with = block || args
|
17
|
+
self
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
def assert_message_received_with_correct_arguments
|
22
|
+
return unless @with
|
23
|
+
if @with.is_a?(Proc)
|
24
|
+
received_messages.find {|log| @with.call(log[:arguments])} || Tiramisu.fail([
|
25
|
+
'Looks like :%s message never was called with expected arguments' % expected_message,
|
26
|
+
'See validation block'
|
27
|
+
], @caller)
|
28
|
+
else
|
29
|
+
received_messages.find {|log| log[:arguments] == @with} || Tiramisu.fail([
|
30
|
+
'Looks like :%s message never was called with expected arguments:' % expected_message,
|
31
|
+
Array(@with).map {|x| Tiramisu.pp(x)}.join(', ')
|
32
|
+
], @caller)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
module Tiramisu
|
2
|
+
class Expectation
|
3
|
+
|
4
|
+
def self.restore_object_status obj
|
5
|
+
return unless obj.instance_variable_get(:@__tiramisu__original_methods__)
|
6
|
+
|
7
|
+
obj.instance_variable_get(:@__tiramisu__original_methods__).each_pair do |n,m|
|
8
|
+
obj.define_singleton_method(n, &m)
|
9
|
+
end
|
10
|
+
|
11
|
+
obj.instance_variable_set(:@__tiramisu__original_methods__, {})
|
12
|
+
obj.instance_variable_set(:@__tiramisu__received_messages__, {})
|
13
|
+
end
|
14
|
+
|
15
|
+
attr_reader :expected_message, :received_messages
|
16
|
+
|
17
|
+
def initialize object, expected_message, assert, caller
|
18
|
+
proxify(@object = object)
|
19
|
+
@expected_message = expected_message.to_sym
|
20
|
+
@assert = assert
|
21
|
+
@caller = caller
|
22
|
+
end
|
23
|
+
|
24
|
+
def validate
|
25
|
+
@received_messages = @object.__tiramisu__received_messages__[expected_message] || []
|
26
|
+
return refute_message_received unless @assert
|
27
|
+
assert_message_received
|
28
|
+
assert_message_received_with_correct_arguments
|
29
|
+
assert_message_returned_correct_value
|
30
|
+
assert_message_raised_as_expected
|
31
|
+
assert_message_thrown_as_expected
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
def proxify object
|
36
|
+
return if object.respond_to?(:__tiramisu__original_methods__)
|
37
|
+
def object.__tiramisu__original_methods__; @__tiramisu__original_methods__ ||= {} end
|
38
|
+
def object.__tiramisu__received_messages__; @__tiramisu__received_messages__ ||= {} end
|
39
|
+
object.methods.each do |m|
|
40
|
+
next if m == :__tiramisu__original_methods__ || m == :__tiramisu__received_messages__
|
41
|
+
object.__tiramisu__original_methods__[m] = object.method(m)
|
42
|
+
object.define_singleton_method m do |*a,&b|
|
43
|
+
log = {arguments: a, block: b, caller: Tiramisu.relative_location(caller[0])}
|
44
|
+
(__tiramisu__received_messages__[m] ||= []).push(log)
|
45
|
+
begin
|
46
|
+
log[:returned] = __tiramisu__original_methods__[m].call(*a, &b)
|
47
|
+
rescue UncaughtThrowError => e
|
48
|
+
log[:thrown] = Tiramisu.extract_thrown_symbol(e)
|
49
|
+
rescue Exception => e
|
50
|
+
log[:raised] = e
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
object.define_singleton_method :method_missing do |m,*a,&b|
|
55
|
+
log = {arguments: a, block: b, caller: Tiramisu.relative_location(caller[0])}
|
56
|
+
(__tiramisu__received_messages__[:method_missing] ||= []).push(log.merge(arguments: [m] + a))
|
57
|
+
(__tiramisu__received_messages__[m] ||= []).push(log.merge({
|
58
|
+
raised: NoMethodError.new("undefined method `%s' for %s:%s" % [m, object.inspect, object.class])
|
59
|
+
}))
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def assert_message_received
|
64
|
+
Tiramisu.fail('Expected %s to receive %s message' % [
|
65
|
+
Tiramisu.pp(@object),
|
66
|
+
Tiramisu.pp(expected_message)
|
67
|
+
], @caller) if received_messages.empty?
|
68
|
+
end
|
69
|
+
|
70
|
+
def refute_message_received
|
71
|
+
Tiramisu.fail('Not Expected %s to receive %s message' % [
|
72
|
+
Tiramisu.pp(@object),
|
73
|
+
Tiramisu.pp(expected_message)
|
74
|
+
], @caller) if received_messages.any?
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
require 'tiramisu/expectations/with'
|
80
|
+
require 'tiramisu/expectations/return'
|
81
|
+
require 'tiramisu/expectations/raise'
|
82
|
+
require 'tiramisu/expectations/throw'
|
data/lib/tiramisu/run.rb
CHANGED
@@ -9,22 +9,38 @@ module Tiramisu
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def run pattern_or_files = DEFAULT_PATTERN
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
12
|
+
find_files(pattern_or_files).shuffle.each do |file|
|
13
|
+
r, w = IO.pipe
|
14
|
+
pid = Kernel.fork do
|
15
|
+
r.close
|
16
|
+
load_file(file)
|
17
|
+
progress.log ''
|
18
|
+
progress.log blue(relative_location(file))
|
19
|
+
units.shuffle.each do |unit|
|
20
|
+
# exceptions raised inside unit#__run__ will be treated as failures and pretty printed.
|
21
|
+
# any other exceptions will be treated as implementation errors and ugly printed.
|
22
|
+
unit.tests.keys.shuffle.each do |test|
|
23
|
+
status = unit.run(test)
|
24
|
+
if status.is_a?(Skip)
|
25
|
+
w.puts({reason: status.reason, caller: status.caller}.to_json)
|
26
|
+
else
|
27
|
+
unless status == :__tiramisu_passed__
|
28
|
+
render_failure(unit, unit.tests[test], status)
|
29
|
+
Kernel.exit(1)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
progress.advance
|
33
|
+
end
|
22
34
|
end
|
23
|
-
|
35
|
+
end
|
36
|
+
_, status = Process.waitpid2(pid)
|
37
|
+
Kernel.exit(1) unless status.success?
|
38
|
+
w.close
|
39
|
+
while skip = r.gets
|
40
|
+
skips << JSON.parse(skip)
|
24
41
|
end
|
25
42
|
end
|
26
43
|
render_skips
|
27
|
-
progress.log ''
|
28
44
|
end
|
29
45
|
|
30
46
|
def render_failure unit, test_uuid, failure
|
@@ -68,10 +84,11 @@ module Tiramisu
|
|
68
84
|
|
69
85
|
def render_skips
|
70
86
|
return if skips.empty?
|
71
|
-
|
72
|
-
|
87
|
+
puts
|
88
|
+
puts bold.magenta('Skips:')
|
73
89
|
skips.each do |skip|
|
74
|
-
|
90
|
+
puts ' %s (%s)' % [blue(skip['reason'] || 'skip'), relative_location(skip['caller'])]
|
75
91
|
end
|
92
|
+
puts
|
76
93
|
end
|
77
94
|
end
|
data/lib/tiramisu/unit.rb
CHANGED
@@ -12,23 +12,13 @@ module Tiramisu
|
|
12
12
|
:refute
|
13
13
|
].each do |meth|
|
14
14
|
define_method meth do |obj = nil, &block|
|
15
|
-
obj = block ? Tiramisu.call_block(block) : {returned: obj}.freeze
|
16
|
-
Tiramisu::Assert.new(obj, meth, caller[0])
|
15
|
+
__objects__[obj = block ? Tiramisu.call_block(block) : {returned: obj}.freeze] = true
|
16
|
+
__assertions__.push(Tiramisu::Assert.new(obj, meth, caller[0])).last
|
17
17
|
end
|
18
18
|
end
|
19
19
|
alias expect assert
|
20
20
|
alias fail_if refute
|
21
21
|
|
22
|
-
# wrap given object into a proxy that will register and pass all messages
|
23
|
-
#
|
24
|
-
# @example
|
25
|
-
# user = mock(User.new)
|
26
|
-
# expect(user).to_receive(:some_method)
|
27
|
-
#
|
28
|
-
def mock obj
|
29
|
-
__mocks__.push(Mock.new(obj)).last
|
30
|
-
end
|
31
|
-
|
32
22
|
# stop executing current test and mark it as skipped
|
33
23
|
#
|
34
24
|
# @example
|
@@ -49,15 +39,20 @@ module Tiramisu
|
|
49
39
|
__send__(test)
|
50
40
|
end
|
51
41
|
__send__(after) if after
|
52
|
-
|
42
|
+
__assertions__.each(&:__validate_expectations__)
|
43
|
+
__objects__.each_key {|o| Tiramisu::Expectation.restore_object_status(o[:returned])}
|
53
44
|
:__tiramisu_passed__
|
54
45
|
rescue Exception => e
|
55
46
|
throw(:__tiramisu_status__, e)
|
56
47
|
end
|
57
48
|
|
58
49
|
private
|
59
|
-
def
|
60
|
-
@
|
50
|
+
def __objects__
|
51
|
+
@__objects__ ||= {}
|
52
|
+
end
|
53
|
+
|
54
|
+
def __assertions__
|
55
|
+
@__assertions__ ||= []
|
61
56
|
end
|
62
57
|
end
|
63
58
|
|
data/lib/tiramisu/util.rb
CHANGED
@@ -55,9 +55,9 @@ module Tiramisu
|
|
55
55
|
[relative_location(file), line]
|
56
56
|
end
|
57
57
|
|
58
|
-
def
|
59
|
-
|
60
|
-
|
58
|
+
def find_files pattern_or_files
|
59
|
+
return pattern_or_files if pattern_or_files.is_a?(Array)
|
60
|
+
Dir[pwd(pattern_or_files)]
|
61
61
|
end
|
62
62
|
|
63
63
|
def load_file file
|
data/lib/tiramisu.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'tty-progressbar'
|
2
2
|
require 'tty-screen'
|
3
3
|
require 'pastel'
|
4
|
+
require 'json'
|
4
5
|
|
5
6
|
module Tiramisu
|
6
7
|
extend self
|
@@ -113,7 +114,7 @@ end
|
|
113
114
|
|
114
115
|
require 'tiramisu/core_ext'
|
115
116
|
require 'tiramisu/pretty_print'
|
116
|
-
require 'tiramisu/
|
117
|
+
require 'tiramisu/expectations'
|
117
118
|
require 'tiramisu/util'
|
118
119
|
require 'tiramisu/unit'
|
119
120
|
require 'tiramisu/assert'
|
@@ -4,8 +4,7 @@ describe :receive_and_raise do
|
|
4
4
|
this = self
|
5
5
|
spec rand do
|
6
6
|
test :test do
|
7
|
-
x =
|
8
|
-
expect(x).to_receive(:y).and_raise(NoMethodError)
|
7
|
+
expect(x = 'x').to_receive(:y).and_raise(NoMethodError)
|
9
8
|
x.y
|
10
9
|
end
|
11
10
|
this.assert_equal :__tiramisu_passed__, run(:test)
|
@@ -16,8 +15,7 @@ describe :receive_and_raise do
|
|
16
15
|
this = self
|
17
16
|
spec rand do
|
18
17
|
test :test do
|
19
|
-
x =
|
20
|
-
expect(x).to_receive(:y).and_raise
|
18
|
+
expect(x = 'x').to_receive(:y).and_raise
|
21
19
|
x.y
|
22
20
|
end
|
23
21
|
this.assert_equal :__tiramisu_passed__, run(:test)
|
@@ -28,8 +26,7 @@ describe :receive_and_raise do
|
|
28
26
|
this = self
|
29
27
|
spec rand do
|
30
28
|
test :test do
|
31
|
-
x =
|
32
|
-
expect(x).to_receive(:to_s).and_raise
|
29
|
+
expect(x = 'x').to_receive(:to_s).and_raise
|
33
30
|
x.to_s
|
34
31
|
end
|
35
32
|
this.assert_match /Expected a exception to be raised/, run(:test).reason*' '
|
@@ -40,8 +37,7 @@ describe :receive_and_raise do
|
|
40
37
|
this = self
|
41
38
|
spec rand do
|
42
39
|
test :test do
|
43
|
-
x =
|
44
|
-
expect(x).to_receive(:y).and_raise(NameError)
|
40
|
+
expect(x = 'x').to_receive(:y).and_raise(NameError)
|
45
41
|
x.y
|
46
42
|
end
|
47
43
|
this.assert_match /Expected a NameError to be raised/, run(:test).reason*' '
|
@@ -52,8 +48,7 @@ describe :receive_and_raise do
|
|
52
48
|
this = self
|
53
49
|
spec rand do
|
54
50
|
test :test do
|
55
|
-
x =
|
56
|
-
expect(x).to_receive(:y).and_raise(NoMethodError, /blah/)
|
51
|
+
expect(x = 'x').to_receive(:y).and_raise(NoMethodError, /blah/)
|
57
52
|
x.y
|
58
53
|
end
|
59
54
|
this.assert_match /to match "blah"/, run(:test).reason*' '
|
@@ -64,8 +59,7 @@ describe :receive_and_raise do
|
|
64
59
|
this = self
|
65
60
|
spec rand do
|
66
61
|
test :test do
|
67
|
-
x =
|
68
|
-
expect(x).to_receive(:y).and_raise(NoMethodError, /undefined method `y' for :x:Symbol/)
|
62
|
+
expect(x = 'x').to_receive(:y).and_raise(NoMethodError, /undefined method `y' for "x":String/)
|
69
63
|
x.y
|
70
64
|
end
|
71
65
|
this.assert_equal :__tiramisu_passed__, run(:test)
|
@@ -76,16 +70,14 @@ describe :receive_and_raise do
|
|
76
70
|
this, t, m = self, nil, nil
|
77
71
|
spec rand do
|
78
72
|
test :test do
|
79
|
-
x =
|
80
|
-
expect(x).to_receive(:y).and_raise {|e|
|
73
|
+
expect(x = 'x').to_receive(:y).and_raise {|e|
|
81
74
|
t, m = e.class, e.message
|
82
|
-
this.assert_match /undefined method .y. for :x:Symbol/, e.message
|
83
75
|
}
|
84
76
|
x.y
|
85
77
|
end
|
86
78
|
run(:test)
|
87
79
|
this.assert_equal NoMethodError, t
|
88
|
-
this.assert_match /undefined method .y. for
|
80
|
+
this.assert_match /undefined method .y. for "x":String/, m
|
89
81
|
end
|
90
82
|
end
|
91
83
|
end
|
@@ -4,9 +4,8 @@ describe :receive_and_return do
|
|
4
4
|
this = self
|
5
5
|
spec rand do
|
6
6
|
test :test do
|
7
|
-
x =
|
8
|
-
|
9
|
-
x + 1
|
7
|
+
expect(x = 'x').to_receive(:+).with('y').and_return('xy')
|
8
|
+
x + 'y'
|
10
9
|
end
|
11
10
|
this.assert_equal :__tiramisu_passed__, run(:test)
|
12
11
|
end
|
@@ -16,8 +15,7 @@ describe :receive_and_return do
|
|
16
15
|
this = self
|
17
16
|
spec rand do
|
18
17
|
test :test do
|
19
|
-
x =
|
20
|
-
expect(x).to_receive(:to_s).and_return(:y)
|
18
|
+
expect(x = 'x').to_receive(:to_s).and_return(:y)
|
21
19
|
x.to_s
|
22
20
|
end
|
23
21
|
this.assert_match /Looks like :to_s message never returned expected value/, run(:test).reason*' '
|
@@ -28,9 +26,8 @@ describe :receive_and_return do
|
|
28
26
|
this = self
|
29
27
|
spec rand do
|
30
28
|
test :test do
|
31
|
-
x =
|
32
|
-
|
33
|
-
x + 1
|
29
|
+
expect(x = 'x').to_receive(:+).with('y').and_return {|v| v == 'xy'}
|
30
|
+
x + 'y'
|
34
31
|
end
|
35
32
|
this.assert_equal :__tiramisu_passed__, run(:test)
|
36
33
|
end
|
@@ -40,33 +37,8 @@ describe :receive_and_return do
|
|
40
37
|
this = self
|
41
38
|
spec rand do
|
42
39
|
test :test do
|
43
|
-
x =
|
44
|
-
|
45
|
-
x + 1
|
46
|
-
end
|
47
|
-
this.assert_match /Looks like :\+ message never returned expected value/, run(:test).reason*' '
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'should pass when block validates all returned value' do
|
52
|
-
this = self
|
53
|
-
spec rand do
|
54
|
-
test :test do
|
55
|
-
x = mock(1)
|
56
|
-
expect(x).to_receive(:+).with(1).and_return {|v| v == 2}
|
57
|
-
x + 1
|
58
|
-
end
|
59
|
-
this.assert_equal :__tiramisu_passed__, run(:test)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
it 'should fail when block does not validate returned value' do
|
64
|
-
this = self
|
65
|
-
spec rand do
|
66
|
-
test :test do
|
67
|
-
x = mock(1)
|
68
|
-
expect(x).to_receive(:+).with(1).and_return {false}
|
69
|
-
x + 1
|
40
|
+
expect(x = 'x').to_receive(:+).with('y').and_return {false}
|
41
|
+
x + 'y'
|
70
42
|
end
|
71
43
|
this.assert_match /Looks like :\+ message never returned expected value/, run(:test).reason*' '
|
72
44
|
end
|
@@ -4,7 +4,7 @@ describe :receive_and_throw do
|
|
4
4
|
this = self
|
5
5
|
spec rand do
|
6
6
|
test :test do
|
7
|
-
x =
|
7
|
+
x = Class.new {define_singleton_method(:y) {throw :z}}
|
8
8
|
expect(x).to_receive(:y).and_throw
|
9
9
|
x.y
|
10
10
|
end
|
@@ -16,7 +16,7 @@ describe :receive_and_throw do
|
|
16
16
|
this = self
|
17
17
|
spec rand do
|
18
18
|
test :test do
|
19
|
-
x =
|
19
|
+
x = Class.new {define_singleton_method(:y) {throw :z}}
|
20
20
|
expect(x).to_receive(:y).and_throw(:z)
|
21
21
|
x.y
|
22
22
|
end
|
@@ -28,7 +28,7 @@ describe :receive_and_throw do
|
|
28
28
|
this = self
|
29
29
|
spec rand do
|
30
30
|
test :test do
|
31
|
-
x =
|
31
|
+
x = Class.new {define_singleton_method(:y) {}}
|
32
32
|
expect(x).to_receive(:y).and_throw
|
33
33
|
x.y
|
34
34
|
end
|
@@ -40,7 +40,7 @@ describe :receive_and_throw do
|
|
40
40
|
this = self
|
41
41
|
spec rand do
|
42
42
|
test :test do
|
43
|
-
x =
|
43
|
+
x = Class.new {define_singleton_method(:y) {throw :z}}
|
44
44
|
expect(x).to_receive(:y).and_throw(:a)
|
45
45
|
x.y
|
46
46
|
end
|
@@ -52,7 +52,7 @@ describe :receive_and_throw do
|
|
52
52
|
this = self
|
53
53
|
spec rand do
|
54
54
|
test :test do
|
55
|
-
x =
|
55
|
+
x = Class.new {define_singleton_method(:y) {throw :z}}
|
56
56
|
expect(x).to_receive(:y).and_throw {|s| s == :z}
|
57
57
|
x.y
|
58
58
|
end
|
@@ -64,7 +64,7 @@ describe :receive_and_throw do
|
|
64
64
|
this = self
|
65
65
|
spec rand do
|
66
66
|
test :test do
|
67
|
-
x =
|
67
|
+
x = Class.new {define_singleton_method(:y) {throw :z}}
|
68
68
|
expect(x).to_receive(:y).and_throw {false}
|
69
69
|
x.y
|
70
70
|
end
|
data/test/receive_test.rb
CHANGED
@@ -4,8 +4,7 @@ describe :receive do
|
|
4
4
|
this = self
|
5
5
|
spec rand do
|
6
6
|
test :test do
|
7
|
-
x =
|
8
|
-
expect(x).to_receive(:class)
|
7
|
+
expect(x = 'x').to_receive(:class)
|
9
8
|
x.class
|
10
9
|
end
|
11
10
|
this.assert_equal :__tiramisu_passed__, run(:test)
|
@@ -16,8 +15,7 @@ describe :receive do
|
|
16
15
|
this = self
|
17
16
|
spec rand do
|
18
17
|
test :test do
|
19
|
-
x =
|
20
|
-
expect(x).to_receive(:class)
|
18
|
+
expect(x = 'x').to_receive(:class)
|
21
19
|
end
|
22
20
|
this.assert_equal Tiramisu::GenericFailure, run(:test).class
|
23
21
|
end
|
@@ -27,8 +25,7 @@ describe :receive do
|
|
27
25
|
this = self
|
28
26
|
spec rand do
|
29
27
|
test :test do
|
30
|
-
x =
|
31
|
-
fail_if(x).receive(:class)
|
28
|
+
fail_if(x = 'x').receive(:class)
|
32
29
|
end
|
33
30
|
this.assert_equal :__tiramisu_passed__, run(:test)
|
34
31
|
end
|
@@ -38,8 +35,7 @@ describe :receive do
|
|
38
35
|
this = self
|
39
36
|
spec rand do
|
40
37
|
test :test do
|
41
|
-
x =
|
42
|
-
fail_if(x).receive(:class)
|
38
|
+
fail_if(x = 'x').receive(:class)
|
43
39
|
x.class
|
44
40
|
end
|
45
41
|
this.assert_equal Tiramisu::GenericFailure, run(:test).class
|