mocha-on-bacon 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (C) 2011, Eloy Durán <eloy.de.enige@gmail.com>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
20
+
@@ -0,0 +1,75 @@
1
+ Mocha on Bacon
2
+ ==============
3
+
4
+ _Doesn’t that sound yummy?_
5
+
6
+ [Mocha][1] is a mocking and stubbing library for Ruby and [Bacon][2] is a small
7
+ RSpec clone.
8
+
9
+ Out of the box, Mocha only ships with adapters for the testing libraries that
10
+ come with the Ruby ‘standard library’, which are `Test::Unit` and `MiniTest`.
11
+
12
+ This is an adapter to make it play nicely with Bacon and its MacRuby specific
13
+ fork [MacBacon][3].
14
+
15
+
16
+ Installation
17
+ ------------
18
+
19
+ $ sudo gem install mocha-on-bacon
20
+
21
+
22
+ Usage
23
+ -----
24
+
25
+ $ cat readme_spec.rb
26
+ require "mocha-on-bacon" # automatically requires mocha
27
+
28
+ describe "A mock" do
29
+ before do
30
+ @mock = mock("A mock")
31
+ @mock.expects(:here_you_go).with("a method call!")
32
+ end
33
+
34
+ it "passes if an expectation is fulfilled" do
35
+ @mock.here_you_go("a method call!")
36
+ end
37
+
38
+ it "fails if an expectation is not fulfilled" do
39
+ # not much happening here
40
+ end
41
+ end
42
+
43
+ Running it results in:
44
+
45
+ $ bacon readme_spec.rb
46
+ A mock
47
+ - passes if an expectation is fulfilled
48
+ - fails if an expectation is not fulfilled [FAILED]
49
+
50
+ Bacon::Error: not all expectations were satisfied
51
+ unsatisfied expectations:
52
+ - expected exactly once, not yet invoked: #<Mock:A mock>.here_you_go('a method call!')
53
+
54
+ ./lib/mocha-on-bacon.rb:60:in `it': A mock - fails if an expectation is not fulfilled
55
+ ./lib/mocha-on-bacon.rb:54:in `it'
56
+ ./readme_spec.rb:13
57
+ ./readme_spec.rb:3
58
+
59
+ 2 specifications (2 requirements), 1 failures, 0 errors
60
+
61
+ For more information see the Mocha and Bacon websites.
62
+
63
+
64
+ License
65
+ -------
66
+
67
+ Copyright (C) 2011, Eloy Durán <eloy.de.enige@gmail.com>
68
+
69
+ Mocha-on-Bacon is available under the MIT license. See the LICENSE file or
70
+ http://www.opensource.org/licenses/mit-license.php
71
+
72
+
73
+ [1]: https://github.com/floehopper/mocha
74
+ [2]: https://github.com/chneukirchen/bacon
75
+ [3]: https://github.com/alloy/MacBacon
@@ -1,4 +1,3 @@
1
- require "bacon"
2
1
  require "mocha"
3
2
 
4
3
  module Bacon
@@ -7,24 +6,64 @@ module Bacon
7
6
  Counter[:requirements] += 1
8
7
  end
9
8
  end
10
-
9
+
11
10
  class Context
12
11
  include Mocha::API
13
-
14
- alias_method :it_before_mocha, :it
15
-
16
- def it(description, &block)
17
- it_before_mocha(description) do
18
- begin
19
- mocha_setup
20
- block.call
21
- mocha_verify(MochaRequirementsCounter)
22
- rescue Mocha::ExpectationError => e
23
- raise Error.new(:failed, e.message)
24
- ensure
25
- mocha_teardown
12
+ end
13
+
14
+ # For now let's assume only MacBacon has this class and upstream Bacon
15
+ # won't have it any time soon.
16
+ if defined?(Bacon::Specification)
17
+ class Specification
18
+ include Mocha::API
19
+
20
+ alias_method :run_before_mocha, :run
21
+ def run
22
+ @context.mocha_setup
23
+ run_before_mocha
24
+ end
25
+
26
+ alias_method :execute_block_before_mocha, :execute_block
27
+ def execute_block
28
+ execute_block_before_mocha do
29
+ begin
30
+ yield
31
+ rescue Mocha::ExpectationError => e
32
+ raise Error.new(:failed, e.message)
33
+ end
26
34
  end
27
35
  end
36
+
37
+ alias_method :finalize_before_mocha, :finalize
38
+ def finalize
39
+ # If an exception already occurred, we don't need to verify Mocha
40
+ # expectations anymore, as the test has already failed.
41
+ unless @exception_occurred
42
+ execute_block { @context.mocha_verify(MochaRequirementsCounter) }
43
+ end
44
+ @context.mocha_teardown
45
+ finalize_before_mocha
46
+ end
28
47
  end
48
+
49
+ else
50
+
51
+ class Context
52
+ alias_method :it_before_mocha, :it
53
+ def it(description, &block)
54
+ it_before_mocha(description) do
55
+ begin
56
+ mocha_setup
57
+ block.call
58
+ mocha_verify(MochaRequirementsCounter)
59
+ rescue Mocha::ExpectationError => e
60
+ raise Error.new(:failed, e.message)
61
+ ensure
62
+ mocha_teardown
63
+ end
64
+ end
65
+ end
66
+ end
67
+
29
68
  end
30
- end
69
+ end
@@ -66,4 +66,4 @@ describe "Bacon specs using Mocha, with a stub" do
66
66
  stubbee = AStub.new
67
67
  lambda { stubbee.expects(:blah) }.should.be unsatisfied(stubbee, :blah)
68
68
  end
69
- end
69
+ end
@@ -1,28 +1,59 @@
1
1
  require "rubygems" rescue LoadError
2
- require "bacon"
3
- require "mocha"
4
-
5
2
  require File.expand_path('../../lib/mocha-on-bacon', __FILE__)
6
3
 
7
4
  class Should
8
5
  alias_method :have, :be
9
6
  end
10
7
 
8
+ class MochaTestContext < Bacon::Context
9
+ def initialize(name)
10
+ @name = name
11
+ @before, @after = [], []
12
+ @specifications = []
13
+ @current_specification_index = 0
14
+ end
15
+
16
+ def it(description, &block)
17
+ super
18
+ @specifications.pop
19
+ end
20
+
21
+ def specification_did_finish(spec)
22
+ # We don't care in this case
23
+ end
24
+ end
25
+
11
26
  module MochaBaconHelper
12
27
  module SilenceOutput
13
28
  attr_accessor :silence
14
-
15
- def handle_specification(name)
29
+
30
+ def handle_specification_begin(name)
16
31
  puts name unless silence
17
- yield
32
+ end
33
+
34
+ def handle_specification_end
18
35
  puts unless silence
19
36
  end
20
-
21
- def handle_requirement(description)
37
+
38
+ def handle_specification(name)
39
+ handle_specification_begin(name)
40
+ yield
41
+ handle_specification_end
42
+ end
43
+
44
+ def handle_requirement_begin(description)
22
45
  print "- #{description}" unless silence
23
- error = yield
46
+ end
47
+
48
+ def handle_requirement_end(error)
24
49
  puts(error.empty? ? "" : " [#{error}]") unless silence
25
50
  end
51
+
52
+ def handle_requirement(description)
53
+ handle_requirement_begin(description)
54
+ error = yield
55
+ handle_requirement_end(error)
56
+ end
26
57
 
27
58
  def handle_summary
28
59
  print Bacon::ErrorLog if Bacon::Backtraces && !silence
@@ -41,7 +72,7 @@ module MochaBaconHelper
41
72
  end
42
73
 
43
74
  def mocha_context
44
- @mocha_context ||= Bacon::Context.new("Mocha test context")
75
+ @mocha_context ||= MochaTestContext.new("Mocha test context") {}
45
76
  end
46
77
 
47
78
  def run_example(proc)
@@ -51,7 +82,8 @@ module MochaBaconHelper
51
82
  error_log_before = error_log.dup
52
83
  Bacon.silence = true
53
84
 
54
- mocha_context.it("Mocha example `#{@example_counter}'", &proc)
85
+ spec = mocha_context.it("Mocha example `#{@example_counter}'", &proc)
86
+ spec.run if spec.respond_to?(:run) # MacBacon
55
87
  [{ :failed => counter[:failed] - counter_before[:failed], :errors => counter_before[:errors] - counter_before[:errors] }, error_log.dup]
56
88
  ensure
57
89
  counter.replace(counter_before)
@@ -81,4 +113,4 @@ module MochaBaconHelper
81
113
  error_log.include?("unexpected invocation: #{mockee.mocha_inspect}.#{method}(#{params})")
82
114
  end
83
115
  end
84
- end
116
+ end
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mocha-on-bacon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ hash: 23
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
5
11
  platform: ruby
6
12
  authors:
7
13
  - Eloy Duran
@@ -9,47 +15,42 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2010-01-25 00:00:00 +01:00
18
+ date: 2011-01-17 00:00:00 +01:00
13
19
  default_executable:
14
20
  dependencies:
15
21
  - !ruby/object:Gem::Dependency
16
22
  name: mocha
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
20
26
  requirements:
21
27
  - - ">="
22
28
  - !ruby/object:Gem::Version
29
+ hash: 43
30
+ segments:
31
+ - 0
32
+ - 9
33
+ - 8
23
34
  version: 0.9.8
24
- version:
25
- - !ruby/object:Gem::Dependency
26
- name: bacon
27
35
  type: :runtime
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: 1.1.0
34
- version:
36
+ version_requirements: *id001
35
37
  description: A Mocha adapter for Bacon, because it's yummy!
36
38
  email: eloy.de.enige@gmail.com
37
39
  executables: []
38
40
 
39
41
  extensions: []
40
42
 
41
- extra_rdoc_files: []
42
-
43
+ extra_rdoc_files:
44
+ - LICENSE
45
+ - README.md
43
46
  files:
44
- - .gitignore
45
- - Rakefile
46
- - VERSION
47
+ - LICENSE
48
+ - README.md
47
49
  - lib/mocha-on-bacon.rb
48
- - mocha-on-bacon.gemspec
49
50
  - spec/mocha-on-bacon_spec.rb
50
51
  - spec/spec_helper.rb
51
52
  has_rdoc: true
52
- homepage: http://github.com/alloy/mocha-on-bacon
53
+ homepage: https://github.com/alloy/mocha-on-bacon
53
54
  licenses: []
54
55
 
55
56
  post_install_message:
@@ -58,21 +59,27 @@ rdoc_options:
58
59
  require_paths:
59
60
  - lib
60
61
  required_ruby_version: !ruby/object:Gem::Requirement
62
+ none: false
61
63
  requirements:
62
64
  - - ">="
63
65
  - !ruby/object:Gem::Version
66
+ hash: 3
67
+ segments:
68
+ - 0
64
69
  version: "0"
65
- version:
66
70
  required_rubygems_version: !ruby/object:Gem::Requirement
71
+ none: false
67
72
  requirements:
68
73
  - - ">="
69
74
  - !ruby/object:Gem::Version
75
+ hash: 3
76
+ segments:
77
+ - 0
70
78
  version: "0"
71
- version:
72
79
  requirements: []
73
80
 
74
81
  rubyforge_project:
75
- rubygems_version: 1.3.5
82
+ rubygems_version: 1.3.7
76
83
  signing_key:
77
84
  specification_version: 3
78
85
  summary: A Mocha adapter for Bacon
data/.gitignore DELETED
@@ -1 +0,0 @@
1
- pkg
data/Rakefile DELETED
@@ -1,16 +0,0 @@
1
- begin
2
- require 'jeweler'
3
- Jeweler::Tasks.new do |gemspec|
4
- gemspec.name = "mocha-on-bacon"
5
- gemspec.summary = "A Mocha adapter for Bacon"
6
- gemspec.description = "A Mocha adapter for Bacon, because it's yummy!"
7
- gemspec.email = "eloy.de.enige@gmail.com"
8
- gemspec.homepage = "http://github.com/alloy/mocha-on-bacon"
9
- gemspec.authors = ["Eloy Duran"]
10
-
11
- gemspec.add_runtime_dependency("mocha", [">= 0.9.8"])
12
- gemspec.add_runtime_dependency("bacon", [">= 1.1.0"])
13
- end
14
- Jeweler::GemcutterTasks.new
15
- rescue LoadError
16
- end
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.1.1
@@ -1,50 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
- # -*- encoding: utf-8 -*-
5
-
6
- Gem::Specification.new do |s|
7
- s.name = %q{mocha-on-bacon}
8
- s.version = "0.1.1"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Eloy Duran"]
12
- s.date = %q{2010-01-25}
13
- s.description = %q{A Mocha adapter for Bacon, because it's yummy!}
14
- s.email = %q{eloy.de.enige@gmail.com}
15
- s.files = [
16
- ".gitignore",
17
- "Rakefile",
18
- "VERSION",
19
- "lib/mocha-on-bacon.rb",
20
- "mocha-on-bacon.gemspec",
21
- "spec/mocha-on-bacon_spec.rb",
22
- "spec/spec_helper.rb"
23
- ]
24
- s.homepage = %q{http://github.com/alloy/mocha-on-bacon}
25
- s.rdoc_options = ["--charset=UTF-8"]
26
- s.require_paths = ["lib"]
27
- s.rubygems_version = %q{1.3.5}
28
- s.summary = %q{A Mocha adapter for Bacon}
29
- s.test_files = [
30
- "spec/mocha-on-bacon_spec.rb",
31
- "spec/spec_helper.rb"
32
- ]
33
-
34
- if s.respond_to? :specification_version then
35
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
36
- s.specification_version = 3
37
-
38
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
39
- s.add_runtime_dependency(%q<mocha>, [">= 0.9.8"])
40
- s.add_runtime_dependency(%q<bacon>, [">= 1.1.0"])
41
- else
42
- s.add_dependency(%q<mocha>, [">= 0.9.8"])
43
- s.add_dependency(%q<bacon>, [">= 1.1.0"])
44
- end
45
- else
46
- s.add_dependency(%q<mocha>, [">= 0.9.8"])
47
- s.add_dependency(%q<bacon>, [">= 1.1.0"])
48
- end
49
- end
50
-