jferris-mocha 0.9.5.0.1241126838 → 0.9.7.0.1247796736
Sign up to get free protection for your applications and to get access to all the features.
- data/RELEASE +18 -0
- data/Rakefile +1 -1
- data/lib/mocha.rb +1 -67
- data/lib/mocha/any_instance_method.rb +5 -1
- data/lib/mocha/class_method.rb +5 -1
- data/lib/mocha/integration.rb +38 -0
- data/lib/mocha/integration/mini_test.rb +21 -1
- data/lib/mocha/integration/mini_test/version_131_and_above.rb +4 -3
- data/lib/mocha/integration/test_unit.rb +40 -4
- data/lib/mocha/standalone.rb +1 -0
- data/test/acceptance/minitest_test.rb +10 -3
- metadata +4 -7
- data/lib/mocha/integration/bacon.rb +0 -1
- data/lib/mocha/integration/bacon/assertion_counter.rb +0 -23
- data/lib/mocha/integration/bacon/version_11_and_above.rb +0 -34
- data/test/acceptance/bacon_spec.rb +0 -67
- data/test/acceptance/bacon_test.rb +0 -110
data/RELEASE
CHANGED
@@ -1,3 +1,21 @@
|
|
1
|
+
= 0.9.7 (80d816f250dc13aaf856f3f9cbd97ebe9c371839)
|
2
|
+
* Although I had provided a deprecation warning for people using Mocha::Standalone, I had assumed people wouldn't be explicitly loading the mocha/standalone.rb file. It turns out this assumption was incorrect at least in the case of Rspec. This is now fixed.
|
3
|
+
|
4
|
+
= 0.9.6 (57f8f77d715b7f1d9efee2e1a9438f7905c0006b)
|
5
|
+
* Version 2.0.1 of the test-unit gem introduced a private 'run_test' method on TestCase which clashed with the public TestRunner#run_test method. So this latter method has been renamed to 'run_as_test'.
|
6
|
+
* Stop requiring rubygems - this should be an environmental choice for the user. http://gist.github.com/54177 - describes why requiring rubygems in your library code is a bad idea.
|
7
|
+
* It seems like overkill to vendorize coderay and meta_project when they're only needed to generate the examples for documentation and for publishing files on RubyForge. So I'm removing them and installing them locally as gems when I need them.
|
8
|
+
* Added support for 'test-unit' gem (version >= 2.0). Note that as with other versions of Test::Unit I'm completely replacing the TestCase#run method. Unfortunately in version 2.0.0 this method differs slightly from the same method in version 2.0.1 & 2.0.2, so we have to provide different implementations to ensure that the internal working of Test::Unit are not compromised by Mocha. Note also that unless the 'test-unit' gem is loaded, requiring 'test/unit' leads to a mixture of stdlib and gem classes being loaded causing errors. To avoid a dependency on rubygems, the gem is loaded only if MOCHA_OPTIONS is set to 'use_test_unit_gem' - this option is only intended for use in running Mocha's own tests. It might be worthwhile to create a shim gem like minitest_tu_shim to allow the test-unit gem to completely replace the stdlib, but that's a job for another day. The changes in the Rakefile are to make the default task run with the 'test-unit' gem (version >= 2.0).
|
9
|
+
* Renamed Mocha::Standalone to Mocha::API to better reflect its purpose. Added a deprecation warning for those who are referencing Mocha::Standalone.
|
10
|
+
* Fix exception raised by HasEntry#matches? if first param is not a Hash (thanks to Taylor Barstow).
|
11
|
+
* Ken Collins reported [1] that Mocha is always loading MiniTest if it is available and loading it causes some Rails/ActionPack tests to break. I've removed the loading of MiniTest, but this now means the user has to ensure that if they want to use MiniTest in conjunction with Mocha, he must load MiniTest before loading Mocha. [1] http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/2060
|
12
|
+
* Implemented Bacon integration (thanks to Ubiratan Pires Alberton), but this was then removed after deciding only to maintain integration with Test::Unit and MiniTest which are both Ruby standard libraries. See mailing list for details.
|
13
|
+
* Don't monkey-patch MiniTest if it's already been monkey-patched by Mocha.
|
14
|
+
* Fixed bug: MiniTest integration was counting ExpectationErrors as errors not failures. http://floehopper.lighthouseapp.com/projects/22289-mocha/tickets/41.
|
15
|
+
* Fixed bug: Some Bacon tests were failing in Ruby 1.9.1. http://floehopper.lighthouseapp.com/projects/22289-mocha/tickets/43.
|
16
|
+
* Chad Humphries pointed out that in Ruby 1.9.1, if you are not using Test::Unit or MiniTest, Mocha will attempt to load and monkey-patch Test::Unit. Mocha will now only monkey-patch Test::Unit and/or MiniTest if they have already been loaded. MiniTest tests will now run in both Ruby 1.8.6 (with MiniTest gem) and in Ruby 1.9.1 (with MiniTest std lib). See Ligthouse ticket - http://floehopper.lighthouseapp.com/projects/22289/tickets/49.
|
17
|
+
* Made Mocha compatible with minitest 1.4.0 and above (thanks to Denis Defreyne).
|
18
|
+
|
1
19
|
= 0.9.5 (93cad010345ce5d68f31422cfc32ed9dd6de13ec)
|
2
20
|
* Fixed Lighthouse bug #32 - stub_everything should mean mock responds to anything.
|
3
21
|
* Added Expectation#twice to improve readability. Thanks to pull request from Celestino Gomes.
|
data/Rakefile
CHANGED
data/lib/mocha.rb
CHANGED
@@ -1,69 +1,3 @@
|
|
1
1
|
require 'mocha_standalone'
|
2
2
|
require 'mocha/configuration'
|
3
|
-
|
4
|
-
if defined?(MiniTest::Unit::TestCase) && !MiniTest::Unit::TestCase.ancestors.include?(Mocha::API)
|
5
|
-
require 'mocha/integration/mini_test'
|
6
|
-
|
7
|
-
module MiniTest
|
8
|
-
class Unit
|
9
|
-
class TestCase
|
10
|
-
|
11
|
-
include Mocha::API
|
12
|
-
|
13
|
-
alias_method :run_before_mocha, :run
|
14
|
-
remove_method :run
|
15
|
-
|
16
|
-
include Mocha::Integration::MiniTest::Version131AndAbove
|
17
|
-
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
if defined?(Bacon) && Bacon::VERSION >= "1.1" && defined?(Bacon::Context) && !Bacon::Context.ancestors.include?(Mocha::API)
|
24
|
-
|
25
|
-
require 'mocha/integration/bacon'
|
26
|
-
|
27
|
-
module Bacon
|
28
|
-
class Context
|
29
|
-
include Mocha::API
|
30
|
-
include Mocha::Integration::Bacon::Version11AndAbove
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
require 'test/unit/testcase'
|
37
|
-
require 'mocha/integration/test_unit'
|
38
|
-
|
39
|
-
unless Test::Unit::TestCase.ancestors.include?(Mocha::API)
|
40
|
-
module Test
|
41
|
-
module Unit
|
42
|
-
class TestCase
|
43
|
-
|
44
|
-
include Mocha::API
|
45
|
-
|
46
|
-
alias_method :run_before_mocha, :run
|
47
|
-
remove_method :run
|
48
|
-
|
49
|
-
test_unit_version = begin
|
50
|
-
require 'test/unit/version'
|
51
|
-
Test::Unit::VERSION
|
52
|
-
rescue LoadError
|
53
|
-
'1.x'
|
54
|
-
end
|
55
|
-
|
56
|
-
if test_unit_version == '2.0.0'
|
57
|
-
include Mocha::Integration::TestUnit::GemVersion200
|
58
|
-
elsif test_unit_version >= '2.0.1'
|
59
|
-
include Mocha::Integration::TestUnit::GemVersion201AndAbove
|
60
|
-
elsif RUBY_VERSION < '1.8.6'
|
61
|
-
include Mocha::Integration::TestUnit::RubyVersion185AndBelow
|
62
|
-
else
|
63
|
-
include Mocha::Integration::TestUnit::RubyVersion186AndAbove
|
64
|
-
end
|
65
|
-
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
3
|
+
require 'mocha/integration'
|
@@ -25,7 +25,11 @@ module Mocha
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def define_new_method
|
28
|
-
stubbee.class_eval(
|
28
|
+
stubbee.class_eval(%{
|
29
|
+
def #{method}(*args, &block)
|
30
|
+
self.class.any_instance.mocha.method_missing(:#{method}, *args, &block)
|
31
|
+
end
|
32
|
+
}, __FILE__, __LINE__)
|
29
33
|
end
|
30
34
|
|
31
35
|
def remove_new_method
|
data/lib/mocha/class_method.rb
CHANGED
@@ -37,7 +37,11 @@ module Mocha
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def define_new_method
|
40
|
-
stubbee.__metaclass__.class_eval(
|
40
|
+
stubbee.__metaclass__.class_eval(%{
|
41
|
+
def #{method}(*args, &block)
|
42
|
+
mocha.method_missing(:#{method}, *args, &block)
|
43
|
+
end
|
44
|
+
}, __FILE__, __LINE__)
|
41
45
|
end
|
42
46
|
|
43
47
|
def remove_new_method
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Mocha
|
2
|
+
|
3
|
+
module Integration
|
4
|
+
|
5
|
+
class << self
|
6
|
+
|
7
|
+
def monkey_patches
|
8
|
+
patches = []
|
9
|
+
if test_unit_testcase_defined? && !test_unit_testcase_inherits_from_miniunit_testcase?
|
10
|
+
patches << 'mocha/integration/test_unit'
|
11
|
+
end
|
12
|
+
if mini_unit_testcase_defined?
|
13
|
+
patches << 'mocha/integration/mini_test'
|
14
|
+
end
|
15
|
+
patches
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_unit_testcase_defined?
|
19
|
+
defined?(Test) && defined?(Test::Unit) && defined?(Test::Unit::TestCase)
|
20
|
+
end
|
21
|
+
|
22
|
+
def mini_unit_testcase_defined?
|
23
|
+
defined?(MiniTest) && defined?(MiniTest::Unit) && defined?(MiniTest::Unit::TestCase)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_unit_testcase_inherits_from_miniunit_testcase?
|
27
|
+
test_unit_testcase_defined? && mini_unit_testcase_defined? && Test::Unit::TestCase.ancestors.include?(MiniTest::Unit::TestCase)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
Mocha::Integration.monkey_patches.each do |patch|
|
37
|
+
require patch
|
38
|
+
end
|
@@ -1 +1,21 @@
|
|
1
|
-
require 'mocha/
|
1
|
+
require 'mocha/api'
|
2
|
+
|
3
|
+
if !MiniTest::Unit::TestCase.ancestors.include?(Mocha::API)
|
4
|
+
|
5
|
+
require 'mocha/integration/mini_test/version_131_and_above'
|
6
|
+
|
7
|
+
module MiniTest
|
8
|
+
class Unit
|
9
|
+
class TestCase
|
10
|
+
|
11
|
+
include Mocha::API
|
12
|
+
|
13
|
+
alias_method :run_before_mocha, :run
|
14
|
+
remove_method :run
|
15
|
+
|
16
|
+
include Mocha::Integration::MiniTest::Version131AndAbove
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -18,21 +18,22 @@ module Mocha
|
|
18
18
|
def run runner
|
19
19
|
assertion_counter = AssertionCounter.new(self)
|
20
20
|
result = '.'
|
21
|
+
name = (self.respond_to?(:name) ? self.name : self.__name__)
|
21
22
|
begin
|
22
23
|
begin
|
23
24
|
@passed = nil
|
24
25
|
self.setup
|
25
|
-
self.__send__
|
26
|
+
self.__send__ name
|
26
27
|
mocha_verify(assertion_counter)
|
27
28
|
@passed = true
|
28
29
|
rescue Exception => e
|
29
30
|
@passed = false
|
30
|
-
result = runner.puke(self.class,
|
31
|
+
result = runner.puke(self.class, name, Mocha::Integration::MiniTest.translate(e))
|
31
32
|
ensure
|
32
33
|
begin
|
33
34
|
self.teardown
|
34
35
|
rescue Exception => e
|
35
|
-
result = runner.puke(self.class,
|
36
|
+
result = runner.puke(self.class, name, Mocha::Integration::MiniTest.translate(e))
|
36
37
|
end
|
37
38
|
end
|
38
39
|
ensure
|
@@ -1,4 +1,40 @@
|
|
1
|
-
require 'mocha/
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
require 'mocha/api'
|
2
|
+
|
3
|
+
if !Test::Unit::TestCase.ancestors.include?(Mocha::API)
|
4
|
+
|
5
|
+
require 'mocha/integration/test_unit/gem_version_200'
|
6
|
+
require 'mocha/integration/test_unit/gem_version_201_and_above'
|
7
|
+
require 'mocha/integration/test_unit/ruby_version_185_and_below'
|
8
|
+
require 'mocha/integration/test_unit/ruby_version_186_and_above'
|
9
|
+
|
10
|
+
module Test
|
11
|
+
module Unit
|
12
|
+
class TestCase
|
13
|
+
|
14
|
+
include Mocha::API
|
15
|
+
|
16
|
+
alias_method :run_before_mocha, :run
|
17
|
+
remove_method :run
|
18
|
+
|
19
|
+
test_unit_version = begin
|
20
|
+
require 'test/unit/version'
|
21
|
+
Test::Unit::VERSION
|
22
|
+
rescue LoadError
|
23
|
+
'1.x'
|
24
|
+
end
|
25
|
+
|
26
|
+
if test_unit_version == '2.0.0'
|
27
|
+
include Mocha::Integration::TestUnit::GemVersion200
|
28
|
+
elsif test_unit_version >= '2.0.1'
|
29
|
+
include Mocha::Integration::TestUnit::GemVersion201AndAbove
|
30
|
+
elsif RUBY_VERSION < '1.8.6'
|
31
|
+
include Mocha::Integration::TestUnit::RubyVersion185AndBelow
|
32
|
+
else
|
33
|
+
include Mocha::Integration::TestUnit::RubyVersion186AndAbove
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'mocha/api'
|
@@ -1,15 +1,22 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), "acceptance_test_helper")
|
2
2
|
|
3
|
+
begin
|
4
|
+
require 'rubygems'
|
5
|
+
gem 'minitest'
|
6
|
+
rescue Gem::LoadError
|
7
|
+
# MiniTest gem not available
|
8
|
+
end
|
9
|
+
|
3
10
|
begin
|
4
11
|
require 'minitest/unit'
|
5
12
|
rescue LoadError
|
6
13
|
# MiniTest not available
|
7
14
|
end
|
8
15
|
|
9
|
-
# force load so that MiniTest is suitably monkey-patched
|
10
|
-
load 'mocha.rb'
|
11
|
-
|
12
16
|
if defined?(MiniTest)
|
17
|
+
|
18
|
+
# monkey-patch MiniTest now that it has hopefully been loaded
|
19
|
+
require 'mocha/integration/mini_test'
|
13
20
|
|
14
21
|
class MiniTestSampleTest < MiniTest::Unit::TestCase
|
15
22
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jferris-mocha
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.7.0.1247796736
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Mead
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-07-15 21:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -49,9 +49,6 @@ files:
|
|
49
49
|
- lib/mocha/in_state_ordering_constraint.rb
|
50
50
|
- lib/mocha/inspect.rb
|
51
51
|
- lib/mocha/instance_method.rb
|
52
|
-
- lib/mocha/integration/bacon/assertion_counter.rb
|
53
|
-
- lib/mocha/integration/bacon/version_11_and_above.rb
|
54
|
-
- lib/mocha/integration/bacon.rb
|
55
52
|
- lib/mocha/integration/mini_test/assertion_counter.rb
|
56
53
|
- lib/mocha/integration/mini_test/version_131_and_above.rb
|
57
54
|
- lib/mocha/integration/mini_test.rb
|
@@ -61,6 +58,7 @@ files:
|
|
61
58
|
- lib/mocha/integration/test_unit/ruby_version_185_and_below.rb
|
62
59
|
- lib/mocha/integration/test_unit/ruby_version_186_and_above.rb
|
63
60
|
- lib/mocha/integration/test_unit.rb
|
61
|
+
- lib/mocha/integration.rb
|
64
62
|
- lib/mocha/invocation.rb
|
65
63
|
- lib/mocha/is_a.rb
|
66
64
|
- lib/mocha/logger.rb
|
@@ -100,6 +98,7 @@ files:
|
|
100
98
|
- lib/mocha/sequence.rb
|
101
99
|
- lib/mocha/single_return_value.rb
|
102
100
|
- lib/mocha/single_yield.rb
|
101
|
+
- lib/mocha/standalone.rb
|
103
102
|
- lib/mocha/state_machine.rb
|
104
103
|
- lib/mocha/stubbing_error.rb
|
105
104
|
- lib/mocha/unexpected_invocation.rb
|
@@ -109,8 +108,6 @@ files:
|
|
109
108
|
- lib/stubba.rb
|
110
109
|
- test/acceptance/acceptance_test_helper.rb
|
111
110
|
- test/acceptance/api_test.rb
|
112
|
-
- test/acceptance/bacon_spec.rb
|
113
|
-
- test/acceptance/bacon_test.rb
|
114
111
|
- test/acceptance/bug_18914_test.rb
|
115
112
|
- test/acceptance/bug_21465_test.rb
|
116
113
|
- test/acceptance/bug_21563_test.rb
|
@@ -1 +0,0 @@
|
|
1
|
-
require 'mocha/integration/bacon/version_11_and_above.rb'
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module Mocha
|
2
|
-
|
3
|
-
module Integration
|
4
|
-
|
5
|
-
module Bacon
|
6
|
-
|
7
|
-
class AssertionCounter
|
8
|
-
|
9
|
-
def initialize(counter)
|
10
|
-
@counter = counter
|
11
|
-
end
|
12
|
-
|
13
|
-
def increment
|
14
|
-
@counter[:requirements] += 1
|
15
|
-
end
|
16
|
-
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'mocha/integration/bacon/assertion_counter'
|
2
|
-
|
3
|
-
module Mocha
|
4
|
-
|
5
|
-
module Integration
|
6
|
-
|
7
|
-
module Bacon
|
8
|
-
|
9
|
-
module Version11AndAbove
|
10
|
-
|
11
|
-
def self.included(base)
|
12
|
-
|
13
|
-
base.class_eval do
|
14
|
-
alias :it_before_bacon :it
|
15
|
-
def it(description)
|
16
|
-
it_before_bacon(description) do
|
17
|
-
assertion_counter = ::Mocha::Integration::Bacon::AssertionCounter.new(::Bacon::Counter)
|
18
|
-
mocha_setup
|
19
|
-
yield
|
20
|
-
mocha_verify(assertion_counter)
|
21
|
-
mocha_teardown
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
@@ -1,67 +0,0 @@
|
|
1
|
-
# This is not meant to be run by itself. It will be run by bacon_test.rb
|
2
|
-
$:.unshift File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "lib"))
|
3
|
-
require 'bacon'
|
4
|
-
require 'mocha'
|
5
|
-
|
6
|
-
module MetaTestOutput
|
7
|
-
def handle_specification(name)
|
8
|
-
yield
|
9
|
-
end
|
10
|
-
|
11
|
-
def handle_requirement(description)
|
12
|
-
yield
|
13
|
-
end
|
14
|
-
|
15
|
-
def handle_summary
|
16
|
-
puts
|
17
|
-
puts Bacon::ErrorLog if Bacon::Backtraces
|
18
|
-
puts "%d tests, %d assertions, %d failures, %d errors" %
|
19
|
-
Bacon::Counter.values_at(:specifications, :requirements, :failed, :errors)
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
Bacon.extend MetaTestOutput
|
25
|
-
Bacon.summary_on_exit
|
26
|
-
|
27
|
-
describe "Bacon specs using Mocha" do
|
28
|
-
should "pass when all expectations were fulfilled" do
|
29
|
-
mockee = mock()
|
30
|
-
mockee.expects(:blah)
|
31
|
-
mockee.blah
|
32
|
-
end
|
33
|
-
|
34
|
-
should "fail when not all expectations were fulfilled" do
|
35
|
-
mockee = mock()
|
36
|
-
mockee.expects(:blah)
|
37
|
-
end
|
38
|
-
|
39
|
-
should "fail when there is an unexpected invocation" do
|
40
|
-
mockee = mock()
|
41
|
-
mockee.blah
|
42
|
-
end
|
43
|
-
|
44
|
-
should "pass when they receive all expected parameters" do
|
45
|
-
mockee = mock()
|
46
|
-
mockee.expects(:blah).with(has_key(:wibble))
|
47
|
-
mockee.blah(:wibble => 1)
|
48
|
-
end
|
49
|
-
|
50
|
-
should "fail when they receive unexpected parameters" do
|
51
|
-
mockee = mock()
|
52
|
-
mockee.expects(:blah).with(has_key(:wibble))
|
53
|
-
mockee.blah(:wobble => 2)
|
54
|
-
end
|
55
|
-
|
56
|
-
should "pass when all Stubba expectations are fulfilled" do
|
57
|
-
stubbee = Class.new { define_method(:blah) {} }.new
|
58
|
-
stubbee.expects(:blah)
|
59
|
-
stubbee.blah
|
60
|
-
end
|
61
|
-
|
62
|
-
should "fail when not all Stubba expectations were fulfilled" do
|
63
|
-
stubbee = Class.new { define_method(:blah) {} }.new
|
64
|
-
stubbee.expects(:blah)
|
65
|
-
end
|
66
|
-
|
67
|
-
end
|
@@ -1,110 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), "acceptance_test_helper")
|
2
|
-
|
3
|
-
begin
|
4
|
-
require 'bacon'
|
5
|
-
rescue LoadError
|
6
|
-
# Bacon not available
|
7
|
-
end
|
8
|
-
|
9
|
-
if defined?(Bacon) && Bacon::VERSION >= "1.1"
|
10
|
-
|
11
|
-
class BaconRunner
|
12
|
-
|
13
|
-
attr_reader :output, :tests, :assertions, :failures, :errors
|
14
|
-
|
15
|
-
def initialize(*paths)
|
16
|
-
@paths = paths
|
17
|
-
end
|
18
|
-
|
19
|
-
def run(name)
|
20
|
-
@output = `bacon -n '#{name}' #{@paths.join(' ')}`
|
21
|
-
numbers = @output.scan(/(\d+) tests, (\d+) assertions, (\d+) failures, (\d+) errors/)
|
22
|
-
numbers.flatten!.map!{|e| e.to_i}
|
23
|
-
|
24
|
-
@tests = numbers[0]
|
25
|
-
@assertions = numbers[1]
|
26
|
-
@failures = numbers[2]
|
27
|
-
@errors = numbers[3]
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
class BaconTest < Test::Unit::TestCase
|
33
|
-
|
34
|
-
def setup
|
35
|
-
@runner = BaconRunner.new("#{File.dirname(__FILE__)}/bacon_spec.rb")
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_should_pass_mocha_test
|
39
|
-
|
40
|
-
@runner.run('should pass when all expectations were fulfilled')
|
41
|
-
|
42
|
-
assert_equal 0, @runner.errors
|
43
|
-
assert_equal 1, @runner.tests
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_should_fail_mocha_test_due_to_unfulfilled_expectation
|
47
|
-
|
48
|
-
@runner.run('should fail when not all expectations were fulfilled')
|
49
|
-
|
50
|
-
assert_equal 1, @runner.errors
|
51
|
-
assert_equal 1, @runner.tests
|
52
|
-
assert_not_all_expectation_were_satisfied(@runner.output)
|
53
|
-
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_should_fail_mocha_test_due_to_unexpected_invocation
|
57
|
-
@runner.run('should fail when there is an unexpected invocation')
|
58
|
-
|
59
|
-
assert_equal 1, @runner.errors
|
60
|
-
assert_equal 1, @runner.tests
|
61
|
-
assert_unexpected_invocation(@runner.output)
|
62
|
-
end
|
63
|
-
|
64
|
-
|
65
|
-
def test_should_pass_stubba_test
|
66
|
-
@runner.run('should pass when all Stubba expectations are fulfilled')
|
67
|
-
|
68
|
-
assert_equal 0, @runner.errors
|
69
|
-
assert_equal 1, @runner.tests
|
70
|
-
end
|
71
|
-
|
72
|
-
def test_should_fail_stubba_test_due_to_unfulfilled_expectation
|
73
|
-
@runner.run('should fail when not all Stubba expectations were fulfilled')
|
74
|
-
|
75
|
-
assert_equal 1, @runner.errors
|
76
|
-
assert_equal 1, @runner.tests
|
77
|
-
assert_not_all_expectation_were_satisfied(@runner.output)
|
78
|
-
end
|
79
|
-
|
80
|
-
def test_should_pass_mocha_test_with_matching_parameter
|
81
|
-
@runner.run('should pass when they receive all expected parameters')
|
82
|
-
|
83
|
-
assert_equal 0, @runner.errors
|
84
|
-
assert_equal 1, @runner.tests
|
85
|
-
end
|
86
|
-
|
87
|
-
def test_should_fail_mocha_test_with_non_matching_parameter
|
88
|
-
@runner.run('should fail when they receive unexpected parameters')
|
89
|
-
|
90
|
-
assert_equal 1, @runner.errors
|
91
|
-
assert_equal 1, @runner.tests
|
92
|
-
assert_unexpected_invocation(@runner.output)
|
93
|
-
end
|
94
|
-
|
95
|
-
private
|
96
|
-
|
97
|
-
def assert_unexpected_invocation(string)
|
98
|
-
assert_match Regexp.new('unexpected invocation'), string, "Bacon output:\n#{string}"
|
99
|
-
end
|
100
|
-
|
101
|
-
def assert_not_all_expectation_were_satisfied(string)
|
102
|
-
assert_match Regexp.new('not all expectations were satisfied'), string, "Bacon output:\n#{string}"
|
103
|
-
end
|
104
|
-
|
105
|
-
end
|
106
|
-
|
107
|
-
else
|
108
|
-
warn "Bacon is not available, so BaconTest has not been run."
|
109
|
-
end
|
110
|
-
|