mocha 0.9.11 → 0.9.12

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,10 @@
1
- = 0.9.11 ()
1
+ = 0.9.12 ()
2
+ * Make Mocha's tests pass under Ruby 1.9.2 i.e. using MiniTest. One of the main issues was that we were not parsing stacktraces on MiniTest errors comprehensively enough.
3
+ * Avoid 'circular require considered harmful' warning when running Mocha's tests in Ruby 1.9.2
4
+ * Make performance tests work on Ruby 1.9.2 i.e. using MiniTest.
5
+ * Declare rake as a *development* dependency with newer versions of Rubygems since it's only needed to carry out developer-related tasks.
6
+
7
+ = 0.9.11 (1613ed2267fef5927ea06adfdbcf512b89eadaad)
2
8
  * Added explicit support for minitest v1.5.0 to v2.0.2.
3
9
  * Make testable by rubygems-test.
4
10
  * Update links to my blog and make other links consistent.
data/Rakefile CHANGED
@@ -3,7 +3,7 @@ require 'rake/gempackagetask'
3
3
  require 'rake/testtask'
4
4
 
5
5
  module Mocha
6
- VERSION = "0.9.11"
6
+ VERSION = "0.9.12"
7
7
  end
8
8
 
9
9
  desc "Run all tests"
@@ -58,16 +58,22 @@ end
58
58
 
59
59
  def benchmark_test_case(klass, iterations)
60
60
  require 'benchmark'
61
- load 'test/unit/ui/console/testrunner.rb' unless defined?(Test::Unit::UI::Console::TestRunner)
62
- unless $silent_option
63
- begin
64
- load 'test/unit/ui/console/outputlevel.rb' unless defined?(Test::Unit::UI::Console::OutputLevel::SILENT)
65
- $silent_option = { :output_level => Test::Unit::UI::Console::OutputLevel::SILENT }
66
- rescue LoadError
67
- $silent_option = Test::Unit::UI::SILENT
61
+
62
+ if defined?(MiniTest)
63
+ MiniTest::Unit.output = StringIO.new
64
+ Benchmark.realtime { iterations.times { |i| MiniTest::Unit.new.run(klass) } }
65
+ else
66
+ load 'test/unit/ui/console/testrunner.rb' unless defined?(Test::Unit::UI::Console::TestRunner)
67
+ unless $silent_option
68
+ begin
69
+ load 'test/unit/ui/console/outputlevel.rb' unless defined?(Test::Unit::UI::Console::OutputLevel::SILENT)
70
+ $silent_option = { :output_level => Test::Unit::UI::Console::OutputLevel::SILENT }
71
+ rescue LoadError
72
+ $silent_option = Test::Unit::UI::SILENT
73
+ end
68
74
  end
75
+ Benchmark.realtime { iterations.times { Test::Unit::UI::Console::TestRunner.run(klass, $silent_option) } }
69
76
  end
70
- time = Benchmark.realtime { iterations.times { Test::Unit::UI::Console::TestRunner.run(klass, $silent_option) } }
71
77
  end
72
78
 
73
79
  desc 'Generate RDoc'
@@ -152,7 +158,7 @@ def build_specification(version = Mocha::VERSION)
152
158
  s.summary = "Mocking and stubbing library"
153
159
  s.version = version
154
160
  s.platform = Gem::Platform::RUBY
155
- s.author = 'James Mead'
161
+ s.author = 'James Mead'
156
162
  s.description = <<-EOF
157
163
  Mocking and stubbing library with JMock/SchMock syntax, which allows mocking and stubbing of methods on real (non-mock) classes.
158
164
  EOF
@@ -164,7 +170,12 @@ def build_specification(version = Mocha::VERSION)
164
170
  s.extra_rdoc_files = ['README.rdoc', 'COPYING.rdoc']
165
171
  s.rdoc_options << '--title' << 'Mocha' << '--main' << 'README.rdoc' << '--line-numbers'
166
172
 
167
- s.add_dependency('rake')
173
+ if Gem::RubyGemsVersion < '1.2.0'
174
+ s.add_dependency('rake')
175
+ else
176
+ s.add_development_dependency('rake')
177
+ end
178
+
168
179
  s.files = FileList['{lib,test,examples}/**/*.rb', '[A-Z]*', '.gemtest'].exclude('TODO').to_a
169
180
  end
170
181
  end
@@ -6,7 +6,6 @@ require 'mocha/method_matcher'
6
6
  require 'mocha/parameters_matcher'
7
7
  require 'mocha/unexpected_invocation'
8
8
  require 'mocha/argument_iterator'
9
- require 'mocha/mockery'
10
9
 
11
10
  module Mocha # :nodoc:
12
11
 
@@ -160,6 +159,7 @@ module Mocha # :nodoc:
160
159
  if (matching_expectation = @expectations.match(symbol, *arguments)) || (!matching_expectation && !@everything_stubbed)
161
160
  matching_expectation.invoke(&block) if matching_expectation
162
161
  message = UnexpectedInvocation.new(self, symbol, *arguments).to_s
162
+ require 'mocha/mockery'
163
163
  message << Mockery.instance.mocha_inspect
164
164
  raise ExpectationError.new(message, caller)
165
165
  end
@@ -3,16 +3,21 @@ require 'test/unit/testcase'
3
3
  require 'minitest/unit'
4
4
 
5
5
  class MiniTestResult
6
+
7
+ FAILURE_PATTERN = %r{(Failure)\:\n([^\(]+)\(([^\)]+)\) \[([^\]]+)\]\:\n(.*)\n}m
8
+ ERROR_PATTERN = %r{(Error)\:\n([^\(]+)\(([^\)]+)\)\:\n(.+?)\n}m
9
+
6
10
  def self.parse_failure(raw)
7
- matches = %r{(Failure)\:\n([^\(]+)\(([^\)]+)\) \[([^\]]+)\]\:\n(.*)\n}m.match(raw)
11
+ matches = FAILURE_PATTERN.match(raw)
8
12
  return nil unless matches
9
13
  Failure.new(matches[2], matches[3], [matches[4]], matches[5])
10
14
  end
11
15
 
12
16
  def self.parse_error(raw)
13
- matches = %r{(Error)\:\n([^\(]+)\(([^\)]+)\)\:\n(.+?)\n.+ (.*)\n}m.match(raw)
17
+ matches = ERROR_PATTERN.match(raw)
14
18
  return nil unless matches
15
- Error.new(matches[2], matches[3], matches[4], [matches[5]])
19
+ backtrace = raw.gsub(ERROR_PATTERN, '').split("\n").map(&:strip)
20
+ Error.new(matches[2], matches[3], matches[4], backtrace)
16
21
  end
17
22
 
18
23
  class Failure
@@ -68,6 +73,10 @@ class MiniTestResult
68
73
  failures.map(&:message)
69
74
  end
70
75
 
76
+ def failure_message_lines
77
+ failure_messages.map { |message| message.split("\n") }.flatten
78
+ end
79
+
71
80
  def error_messages
72
81
  errors.map { |e| e.exception.message }
73
82
  end
@@ -8,8 +8,11 @@ else
8
8
  end
9
9
 
10
10
  module TestRunner
11
- def run_test_case(test_class, test_result = nil)
12
- test = test_class.suite
11
+ def run_as_test(test_result = nil, &block)
12
+ test_class = Class.new(Test::Unit::TestCase) do
13
+ define_method(:test_me, &block)
14
+ end
15
+ test = test_class.new(:test_me)
13
16
 
14
17
  if defined?(Test::Unit::TestResult)
15
18
  test_result ||= Test::Unit::TestResult.new
@@ -35,13 +38,6 @@ module TestRunner
35
38
  test_result
36
39
  end
37
40
 
38
- def run_as_test(test_result = nil, &block)
39
- test_class = Class.new(Test::Unit::TestCase) do
40
- define_method(:test_me, &block)
41
- end
42
- run_test_case(test_class)
43
- end
44
-
45
41
  def assert_passed(test_result)
46
42
  flunk "Test failed unexpectedly with message: #{test_result.failures}" if test_result.failure_count > 0
47
43
  flunk "Test failed unexpectedly with message: #{test_result.errors}" if test_result.error_count > 0
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mocha
3
3
  version: !ruby/object:Gem::Version
4
- hash: 45
4
+ hash: 35
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 11
10
- version: 0.9.11
9
+ - 12
10
+ version: 0.9.12
11
11
  platform: ruby
12
12
  authors:
13
13
  - James Mead
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-03 00:00:00 +00:00
18
+ date: 2011-02-13 00:00:00 +00:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -30,7 +30,7 @@ dependencies:
30
30
  segments:
31
31
  - 0
32
32
  version: "0"
33
- type: :runtime
33
+ type: :development
34
34
  version_requirements: *id001
35
35
  description: " Mocking and stubbing library with JMock/SchMock syntax, which allows mocking and stubbing of methods on real (non-mock) classes.\n"
36
36
  email: mocha-developer@googlegroups.com
@@ -132,7 +132,6 @@ files:
132
132
  - test/acceptance/exception_rescue_test.rb
133
133
  - test/acceptance/expected_invocation_count_test.rb
134
134
  - test/acceptance/failure_messages_test.rb
135
- - test/acceptance/github_issue_20_test.rb
136
135
  - test/acceptance/minitest_test.rb
137
136
  - test/acceptance/mocha_example_test.rb
138
137
  - test/acceptance/mocha_test_result_test.rb
@@ -1,45 +0,0 @@
1
- require File.expand_path('../acceptance_test_helper', __FILE__)
2
- require 'mocha'
3
-
4
- class GithubIssue20Test < Test::Unit::TestCase
5
-
6
- include AcceptanceTest
7
-
8
- def setup
9
- setup_acceptance_test
10
- end
11
-
12
- def teardown
13
- teardown_acceptance_test
14
- end
15
-
16
- class MyClass
17
- def my_instance_method
18
- :original_value
19
- end
20
- # class << self
21
- # attr_accessor :my_instance
22
- # end
23
- end
24
-
25
- def test_me
26
- # MyClass.my_instance = MyClass.new
27
- test_case = Class.new(Test::Unit::TestCase) do
28
- def setup
29
- @my_instance = MyClass.new
30
- end
31
- def test_1
32
- @my_instance.stubs(:my_instance_method).returns(:first_value)
33
- assert_equal :first_value, @my_instance.my_instance_method
34
- end
35
- def test_2
36
- assert_equal :original_value, @my_instance.my_instance_method
37
- MyClass.any_instance.stubs(:my_instance_method).returns(:second_value)
38
- assert_equal :second_value, @my_instance.my_instance_method
39
- end
40
- end
41
- test_result = run_test_case(test_case)
42
- assert_passed(test_result)
43
- end
44
-
45
- end