tiramisu 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tiramisu/expectations.rb +41 -20
- data/test/receive_test.rb +27 -0
- data/tiramisu.gemspec +12 -13
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2a209cd49ba2dcf6462a297a09c967f59c1edff
|
4
|
+
data.tar.gz: c76e48db62fee768e7307da6b14250fa10f706a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 434656cd75baf8224f27ff707b9022d71b5d1ca5d5e16a244b9c86b6804e90a92c0ab9a23a9c9a43a4675ea40ee2451a30d27fb9c683496019d07a77fe09b571
|
7
|
+
data.tar.gz: 7be65f54d0f46526c3835b5abe5efe355bd55557cc1524350148333d0039cbbd2ad0b2c0f9354d213cc0cf3a48240345f8b523a15532228a8984ae596c13c9c1
|
@@ -15,10 +15,11 @@ module Tiramisu
|
|
15
15
|
attr_reader :expected_message, :received_messages
|
16
16
|
|
17
17
|
def initialize object, expected_message, assert, caller
|
18
|
-
|
18
|
+
@object = object
|
19
19
|
@expected_message = expected_message.to_sym
|
20
20
|
@assert = assert
|
21
21
|
@caller = caller
|
22
|
+
proxify(@object, @expected_message)
|
22
23
|
end
|
23
24
|
|
24
25
|
def validate
|
@@ -32,32 +33,52 @@ module Tiramisu
|
|
32
33
|
end
|
33
34
|
|
34
35
|
private
|
35
|
-
def proxify object
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
begin
|
46
|
-
log[:returned] = __tiramisu__original_methods__[
|
36
|
+
def proxify object, method
|
37
|
+
mount_original_methods_depot(object)
|
38
|
+
mount_received_messages_depot(object)
|
39
|
+
store_original_method(object, method)
|
40
|
+
|
41
|
+
object.define_singleton_method method do |*a,&b|
|
42
|
+
log = {arguments: a, block: b, caller: Tiramisu.relative_location(caller[0])}
|
43
|
+
(__tiramisu__received_messages__[method] ||= []).push(log)
|
44
|
+
|
45
|
+
if __tiramisu__original_methods__[method]
|
46
|
+
return begin
|
47
|
+
log[:returned] = __tiramisu__original_methods__[method].call(*a, &b)
|
47
48
|
rescue UncaughtThrowError => e
|
48
49
|
log[:thrown] = Tiramisu.extract_thrown_symbol(e)
|
49
50
|
rescue Exception => e
|
50
51
|
log[:raised] = e
|
51
52
|
end
|
52
53
|
end
|
54
|
+
|
55
|
+
if respond_to?(:method_missing)
|
56
|
+
return begin
|
57
|
+
log[:returned] = __send__(:method_missing, method, *a, &b)
|
58
|
+
rescue UncaughtThrowError => e
|
59
|
+
log[:thrown] = Tiramisu.extract_thrown_symbol(e)
|
60
|
+
rescue Exception => e
|
61
|
+
log[:raised] = e
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
log[:raised] = NoMethodError.new("undefined method `%s' for %s:%s" % [method, self.inspect, self.class])
|
53
66
|
end
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
67
|
+
end
|
68
|
+
|
69
|
+
def mount_original_methods_depot object
|
70
|
+
return if object.respond_to?(:__tiramisu__original_methods__)
|
71
|
+
def object.__tiramisu__original_methods__; @__tiramisu__original_methods__ ||= {} end
|
72
|
+
end
|
73
|
+
|
74
|
+
def mount_received_messages_depot object
|
75
|
+
return if object.respond_to?(:__tiramisu__received_messages__)
|
76
|
+
def object.__tiramisu__received_messages__; @__tiramisu__received_messages__ ||= {} end
|
77
|
+
end
|
78
|
+
|
79
|
+
def store_original_method object, method
|
80
|
+
return unless object.respond_to?(method)
|
81
|
+
object.__tiramisu__original_methods__[method] ||= object.method(method)
|
61
82
|
end
|
62
83
|
|
63
84
|
def assert_message_received
|
data/test/receive_test.rb
CHANGED
@@ -41,4 +41,31 @@ describe :receive do
|
|
41
41
|
this.assert_equal Tiramisu::GenericFailure, run(:test).class
|
42
42
|
end
|
43
43
|
end
|
44
|
+
|
45
|
+
describe 'missing methods' do
|
46
|
+
|
47
|
+
it 'should call method_missing if defined' do
|
48
|
+
this = self
|
49
|
+
x = Class.new {def self.method_missing(m); 'x' + m.to_s; end}
|
50
|
+
spec rand do
|
51
|
+
test :test do
|
52
|
+
assert(x).receive(:y)
|
53
|
+
x.y
|
54
|
+
end
|
55
|
+
this.assert_equal 'xy', x.y
|
56
|
+
this.assert_equal :__tiramisu_passed__, run(:test)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'should raise NoMethodError if no method_missing defined' do
|
61
|
+
this = self
|
62
|
+
spec rand do
|
63
|
+
test :test do
|
64
|
+
assert(x = 'x').receive(:y).and_raise(NoMethodError)
|
65
|
+
x.y
|
66
|
+
end
|
67
|
+
this.assert_equal :__tiramisu_passed__, run(:test)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
44
71
|
end
|
data/tiramisu.gemspec
CHANGED
@@ -1,27 +1,26 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
name, version = 'tiramisu 0.0.2'.split
|
4
1
|
Gem::Specification.new do |spec|
|
5
|
-
spec.name
|
6
|
-
spec.version
|
7
|
-
spec.authors
|
8
|
-
spec.email
|
9
|
-
spec.description
|
10
|
-
spec.summary
|
11
|
-
spec.homepage
|
12
|
-
spec.license
|
2
|
+
spec.name = 'tiramisu'
|
3
|
+
spec.version = '0.0.3'
|
4
|
+
spec.authors = ['Slee Woo']
|
5
|
+
spec.email = ['mail@sleewoo.com']
|
6
|
+
spec.description = 'Super-simple testing library for Ruby'
|
7
|
+
spec.summary = [spec.name, spec.version]*'-'
|
8
|
+
spec.homepage = 'https://github.com/sleewoo/' + spec.name
|
9
|
+
spec.license = 'MIT'
|
13
10
|
|
14
|
-
spec.files = Dir['**/{*,.[a-z]*}'].reject {|e| e =~ /\.(gem|lock)\Z/}
|
11
|
+
spec.files = Dir['**/{*,.[a-z]*}'].reject {|e| e =~ /\.(gem|lock|html)\Z/}
|
15
12
|
spec.require_paths = ['lib']
|
16
13
|
|
17
|
-
spec.executables = Dir['bin/*'].map{ |f| File.basename(f)}
|
14
|
+
spec.executables = Dir['bin/*'].map { |f| File.basename(f)}
|
18
15
|
|
19
16
|
spec.required_ruby_version = '>= 2'
|
17
|
+
|
20
18
|
spec.add_runtime_dependency 'tty-progressbar', '~> 0.5'
|
21
19
|
spec.add_runtime_dependency 'tty-screen', '~> 0.1'
|
22
20
|
spec.add_runtime_dependency 'pastel', '~> 0.4'
|
23
21
|
spec.add_runtime_dependency 'coderay', '~> 1'
|
24
22
|
spec.add_runtime_dependency 'json', '~> 1.8'
|
23
|
+
|
25
24
|
spec.add_development_dependency 'minitest', '~> 5.5'
|
26
25
|
spec.add_development_dependency 'bundler', '~> 1.8'
|
27
26
|
spec.add_development_dependency 'rake', '~> 10.4'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tiramisu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Slee Woo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tty-progressbar
|
@@ -191,5 +191,5 @@ rubyforge_project:
|
|
191
191
|
rubygems_version: 2.4.5
|
192
192
|
signing_key:
|
193
193
|
specification_version: 4
|
194
|
-
summary: tiramisu-0.0.
|
194
|
+
summary: tiramisu-0.0.3
|
195
195
|
test_files: []
|