matahari 0.2.1 → 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.
data/README.rdoc CHANGED
@@ -75,7 +75,7 @@ influenced the creation of Matahari
75
75
  == KNOWN ISSUES/TODO:
76
76
 
77
77
  * Stubbing implementation is incredibly basic
78
- * Not very usable at all for test/unit users (but this is easily fixed with an assert_received method)
78
+ * Not very usable or test/unit users (it works, but you don't get a fancy DSL.)
79
79
  * No support for argument matchers - arguments must match exactly via == or not at all
80
80
  * We need to be able to remote-control BMWs.
81
81
 
data/lib/matahari.rb CHANGED
@@ -2,7 +2,7 @@ $:.unshift(File.dirname(__FILE__)) unless
2
2
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
3
 
4
4
  require 'matahari/spy'
5
- require 'matahari/debriefing'
5
+ require 'matahari/invocation_matcher'
6
6
  require 'matahari/adapters/matahari_methods'
7
7
  require 'matahari/adapters/rspec'
8
8
  require 'matahari/adapters/test_unit'
@@ -1,8 +1,8 @@
1
1
  module Matahari
2
2
  module Adapters
3
3
  module MatahariMethods
4
- def spy(name = nil)
5
- Spy.new(name)
4
+ def spy(name = nil, opts={})
5
+ Spy.new(name, opts)
6
6
  end
7
7
  end
8
8
  end
@@ -4,14 +4,7 @@ module Matahari
4
4
  include Matahari::Adapters::MatahariMethods
5
5
 
6
6
  def have_received(times = nil)
7
- if times
8
- @calls_expected = 0
9
- times.each { @calls_expected+= 1 }
10
-
11
- Debriefing.new(@calls_expected)
12
- else
13
- Debriefing.new
14
- end
7
+ InvocationMatcher.new(times)
15
8
  end
16
9
  end
17
10
  end
@@ -8,10 +8,10 @@ module Matahari
8
8
  assert result.matches?(subject), result.failure_message_for_should
9
9
  end
10
10
 
11
- def assert_not_received(subject, &block)
12
- result = block.call
13
- assert !result.matches?(subject), result.failure_message_for_should_not
14
- end
11
+ def assert_not_received(subject, &block)
12
+ result = block.call
13
+ assert !result.matches?(subject), result.failure_message_for_should_not
14
+ end
15
15
  end
16
16
  end
17
17
  end
@@ -1,4 +1,4 @@
1
- class Debriefing
1
+ class InvocationMatcher
2
2
 
3
3
  #TODO I can't work out how to disentangle the 2 responsibilities of this class:
4
4
  #1. Inspecting and acting on spy invocations
@@ -6,8 +6,8 @@ class Debriefing
6
6
  #
7
7
  #One to revisit later when my head is less befuddled.
8
8
 
9
- def initialize(expected_call_count = nil)
10
- @expected_call_count = expected_call_count
9
+ def initialize(iterator = nil)
10
+ @expected_call_count = iterator ? iterator.count : nil
11
11
  end
12
12
 
13
13
  def matches?(subject)
@@ -53,21 +53,21 @@ class Debriefing
53
53
  end
54
54
  private :prettify_times
55
55
 
56
- def matching_calls(verifying_args=true)
57
- @matching_calls ||= if verifying_args
58
- @invocations_of_method.select {|i| i[:args].flatten === @args_to_verify}.size
59
- else
60
- @invocations_of_method.size
61
- end
62
- end
63
- private :matching_calls
56
+ def matching_calls(verifying_args=true)
57
+ @matching_calls ||= if verifying_args
58
+ @invocations_of_method.select {|i| i[:args].flatten === @args_to_verify}.size
59
+ else
60
+ @invocations_of_method.size
61
+ end
62
+ end
63
+ private :matching_calls
64
64
 
65
- def match_passes?(verifying_args)
66
- if @expected_call_count
67
- matching_calls(verifying_args) == @expected_call_count
68
- else
69
- matching_calls(verifying_args) > 0
70
- end
71
- end
72
- private :match_passes?
65
+ def match_passes?(verifying_args)
66
+ if @expected_call_count
67
+ matching_calls(verifying_args) == @expected_call_count
68
+ else
69
+ matching_calls(verifying_args) > 0
70
+ end
71
+ end
72
+ private :match_passes?
73
73
  end
data/lib/matahari/spy.rb CHANGED
@@ -1,13 +1,15 @@
1
1
  class Spy
2
2
  attr_reader :name, :invocations
3
3
 
4
- def initialize(name = nil)
5
- @name = name if name
4
+ def initialize(name = nil, opts={})
5
+ @subject = opts[:subject]
6
+ @name = name
6
7
  @invocations = []
7
8
  @stubbed_calls = {}
8
9
  class << self
9
10
  instance_methods.each do |meth|
10
- next if [:name, :define_method, :stubs, :method_missing, :record_invocation, :invocations, :has_received?, :object_id, :respond_to?, :respond_to_missing?, :instance_eval, :instance_exec, :class_eval, :__send__, :send, :should, :should_not].include?(meth)
11
+ whitelist = [:name, :define_method, :stubs, :passes_on, :method_missing, :record_invocation, :invocations, :has_received?, :object_id, :respond_to?, :respond_to_missing?, :instance_eval, :instance_exec, :class_eval, :__send__, :send, :should, :should_not, :__id__, :__send__]
12
+ next if whitelist.include?(meth) || whitelist.include?(meth.to_sym)
11
13
  undef_method(meth)
12
14
  end
13
15
  end
@@ -18,14 +20,14 @@ class Spy
18
20
  @stubbed_calls[sym] = block
19
21
  end
20
22
 
23
+ def passes_on(sym)
24
+ @stubbed_calls[sym] = @subject.method(sym)
25
+ end
26
+
21
27
  #Captures the details of any method call and store for later inspection
22
28
  def method_missing(sym, *args, &block)
23
- if @verifying
24
- raise
25
- else
26
- record_invocation(sym, args)
27
- @stubbed_calls[sym].call if @stubbed_calls[sym]
28
- end
29
+ record_invocation(sym, args)
30
+ @stubbed_calls[sym].call if @stubbed_calls[sym]
29
31
  end
30
32
 
31
33
  #Pass an iterator to this method to specify the number of times the method should
@@ -33,14 +35,7 @@ class Spy
33
35
  #the idea is to allow this nice DSL-ish way of asserting on the number of calls, hence
34
36
  #the odd method signature.
35
37
  def has_received?(times=nil)
36
- if times
37
- calls_expected = 0
38
- times.each { calls_expected += 1 }
39
-
40
- Debriefing.new(calls_expected)
41
- else
42
- Debriefing.new
43
- end
38
+ InvocationMatcher.new(times)
44
39
  end
45
40
 
46
41
  private
@@ -1,3 +1,3 @@
1
1
  module Matahari
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3"
3
3
  end
metadata CHANGED
@@ -1,88 +1,125 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: matahari
3
- version: !ruby/object:Gem::Version
4
- version: 0.2.1
5
- prerelease:
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 3
8
+ version: "0.3"
6
9
  platform: ruby
7
- authors:
10
+ authors:
8
11
  - Tom Stuart
9
12
  autorequire:
10
13
  bindir: bin
11
14
  cert_chain: []
12
- date: 2011-06-10 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
15
+
16
+ date: 2011-06-28 00:00:00 +01:00
17
+ default_executable:
18
+ dependencies:
19
+ - !ruby/object:Gem::Dependency
15
20
  name: rspec
16
- requirement: &2156576720 !ruby/object:Gem::Requirement
21
+ prerelease: false
22
+ requirement: &id001 !ruby/object:Gem::Requirement
17
23
  none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
22
30
  type: :development
23
- prerelease: false
24
- version_requirements: *2156576720
25
- - !ruby/object:Gem::Dependency
31
+ version_requirements: *id001
32
+ - !ruby/object:Gem::Dependency
26
33
  name: cucumber
27
- requirement: &2156576300 !ruby/object:Gem::Requirement
34
+ prerelease: false
35
+ requirement: &id002 !ruby/object:Gem::Requirement
28
36
  none: false
29
- requirements:
30
- - - ! '>='
31
- - !ruby/object:Gem::Version
32
- version: '0'
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ segments:
41
+ - 0
42
+ version: "0"
33
43
  type: :development
34
- prerelease: false
35
- version_requirements: *2156576300
36
- - !ruby/object:Gem::Dependency
44
+ version_requirements: *id002
45
+ - !ruby/object:Gem::Dependency
37
46
  name: aruba
38
- requirement: &2156575780 !ruby/object:Gem::Requirement
47
+ prerelease: false
48
+ requirement: &id003 !ruby/object:Gem::Requirement
39
49
  none: false
40
- requirements:
41
- - - ! '>='
42
- - !ruby/object:Gem::Version
43
- version: '0'
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ segments:
54
+ - 0
55
+ version: "0"
44
56
  type: :development
57
+ version_requirements: *id003
58
+ - !ruby/object:Gem::Dependency
59
+ name: rake
45
60
  prerelease: false
46
- version_requirements: *2156575780
61
+ requirement: &id004 !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ segments:
67
+ - 0
68
+ version: "0"
69
+ type: :development
70
+ version_requirements: *id004
47
71
  description: Matahari provides test spies for Ruby
48
- email:
72
+ email:
49
73
  - tom@therye.org
50
74
  executables: []
75
+
51
76
  extensions: []
77
+
52
78
  extra_rdoc_files: []
53
- files:
79
+
80
+ files:
54
81
  - lib/matahari/adapters/matahari_methods.rb
55
82
  - lib/matahari/adapters/rspec.rb
56
83
  - lib/matahari/adapters/test_unit.rb
57
- - lib/matahari/debriefing.rb
84
+ - lib/matahari/invocation_matcher.rb
58
85
  - lib/matahari/spy.rb
59
86
  - lib/matahari/version.rb
60
87
  - lib/matahari.rb
61
88
  - README.rdoc
89
+ has_rdoc: true
62
90
  homepage: https://github.com/mortice/matahari
63
91
  licenses: []
92
+
64
93
  post_install_message:
65
- rdoc_options:
94
+ rdoc_options:
66
95
  - --main
67
96
  - README.rdoc
68
- require_paths:
97
+ require_paths:
69
98
  - lib
70
- required_ruby_version: !ruby/object:Gem::Requirement
99
+ required_ruby_version: !ruby/object:Gem::Requirement
71
100
  none: false
72
- requirements:
73
- - - ! '>='
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ segments:
105
+ - 0
106
+ version: "0"
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
108
  none: false
78
- requirements:
79
- - - ! '>='
80
- - !ruby/object:Gem::Version
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ segments:
113
+ - 1
114
+ - 3
115
+ - 6
81
116
  version: 1.3.6
82
117
  requirements: []
118
+
83
119
  rubyforge_project:
84
- rubygems_version: 1.8.5
120
+ rubygems_version: 1.3.7
85
121
  signing_key:
86
122
  specification_version: 3
87
123
  summary: Test spy library, inspired by Mockito and RR
88
124
  test_files: []
125
+