tiramisu 0.0.2 → 0.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6b275bd81b3a2fd180b1d094268b9bf5c6280309
4
- data.tar.gz: ba695c8ac455c1ff10e7a17e503c005f59006c73
3
+ metadata.gz: c2a209cd49ba2dcf6462a297a09c967f59c1edff
4
+ data.tar.gz: c76e48db62fee768e7307da6b14250fa10f706a4
5
5
  SHA512:
6
- metadata.gz: 906c88938fff1ad3556893cc19550c9806ad758f962dcb20889adaf7c17542bb70c7ad33851c3158afc63e2361e3282d94e93b99238f4bc149c4f69bc84c7984
7
- data.tar.gz: 39dcd11c0f4cec696030f47f08b79e27e0bc7998d2da856ace138ce77c19dd2c852be606cf3d794d7381cf91ab539edba21d910e4f99e98d2c908a46b594ba58
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
- proxify(@object = object)
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
- 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)
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
- 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
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 = name
6
- spec.version = version
7
- spec.authors = ['Slee Woo']
8
- spec.email = ['mail@sleewoo.com']
9
- spec.description = 'Super-simple testing library for Ruby'
10
- spec.summary = [name, version]*'-'
11
- spec.homepage = 'https://github.com/sleewoo/' + name
12
- spec.license = 'MIT'
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.2
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-25 00:00:00.000000000 Z
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.2
194
+ summary: tiramisu-0.0.3
195
195
  test_files: []