mocha-on-bacon 0.1.0

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/.gitignore ADDED
@@ -0,0 +1 @@
1
+ pkg
data/Rakefile ADDED
@@ -0,0 +1,16 @@
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 ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,30 @@
1
+ require "bacon"
2
+ require "mocha"
3
+
4
+ module Bacon
5
+ module MochaRequirementsCounter
6
+ def self.increment
7
+ Counter[:requirements] += 1
8
+ end
9
+ end
10
+
11
+ class Context
12
+ include Mocha::API
13
+
14
+ alias_method :it_before_mocha, :it
15
+
16
+ def it(description)
17
+ it_before_mocha(description) do
18
+ begin
19
+ mocha_setup
20
+ yield
21
+ mocha_verify(MochaRequirementsCounter)
22
+ rescue Mocha::ExpectationError => e
23
+ raise Error.new(:failed, e.message)
24
+ ensure
25
+ mocha_teardown
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,50 @@
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.0"
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
+
@@ -0,0 +1,69 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ describe "Bacon specs using Mocha, with a mock" do
4
+ extend MochaBaconHelper
5
+
6
+ it "passes when all expectations were fulfilled" do
7
+ mockee = mock()
8
+ lambda do
9
+ mockee.expects(:blah)
10
+ mockee.blah
11
+ end.should.be satisfied
12
+ end
13
+
14
+ it "fails when not all expectations were fulfilled" do
15
+ mockee = mock()
16
+ lambda { mockee.expects(:blah) }.should.be unsatisfied(mockee, :blah)
17
+ end
18
+
19
+ it "fails when there is an unexpected invocation" do
20
+ mockee = mock()
21
+ lambda { mockee.blah }.should.have received_unexpected_invocation(mockee, :blah)
22
+ end
23
+
24
+ it "passes when the mockee receives all expected parameters" do
25
+ mockee = mock()
26
+ lambda do
27
+ mockee.expects(:blah).with(:wibble => 1)
28
+ mockee.blah(:wibble => 1)
29
+ end.should.be satisfied
30
+ end
31
+
32
+ it "fails when the mockee receives unexpected parameters and complains about not being satisfied" do
33
+ mockee = mock()
34
+ lambda do
35
+ mockee.expects(:blah).with(:wobble => 1)
36
+ mockee.blah(:wobble => 2)
37
+ end.should.be unsatisfied(mockee, :blah, ':wobble => 1')
38
+ end
39
+
40
+ it "fails when the mockee receives unexpected parameters and complains about the unexpected parameters" do
41
+ mockee = mock()
42
+ lambda do
43
+ mockee.expects(:blah).with(:wabble => 1)
44
+ mockee.blah(:wabble => 2)
45
+ end.should.have received_unexpected_invocation(mockee, :blah, ':wabble => 2')
46
+ end
47
+ end
48
+
49
+ class AStub
50
+ def blah
51
+ end
52
+ end
53
+
54
+ describe "Bacon specs using Mocha, with a stub" do
55
+ extend MochaBaconHelper
56
+
57
+ it "passes when all Stubba expectations are fulfilled" do
58
+ stubbee = AStub.new
59
+ lambda do
60
+ stubbee.expects(:blah)
61
+ stubbee.blah
62
+ end.should.be satisfied
63
+ end
64
+
65
+ it "fails when not all Stubba expectations were fulfilled" do
66
+ stubbee = AStub.new
67
+ lambda { stubbee.expects(:blah) }.should.be unsatisfied(stubbee, :blah)
68
+ end
69
+ end
@@ -0,0 +1,84 @@
1
+ require "rubygems" rescue LoadError
2
+ require "bacon"
3
+ require "mocha"
4
+
5
+ require File.expand_path('../../lib/mocha-on-bacon', __FILE__)
6
+
7
+ class Should
8
+ alias_method :have, :be
9
+ end
10
+
11
+ module MochaBaconHelper
12
+ module SilenceOutput
13
+ attr_accessor :silence
14
+
15
+ def handle_specification(name)
16
+ puts name unless silence
17
+ yield
18
+ puts unless silence
19
+ end
20
+
21
+ def handle_requirement(description)
22
+ print "- #{description}" unless silence
23
+ error = yield
24
+ puts(error.empty? ? "" : " [#{error}]") unless silence
25
+ end
26
+
27
+ def handle_summary
28
+ print Bacon::ErrorLog if Bacon::Backtraces && !silence
29
+ puts "%d specifications (%d requirements), %d failures, %d errors" %
30
+ Bacon::Counter.values_at(:specifications, :requirements, :failed, :errors) unless silence
31
+ end
32
+ end
33
+ Bacon.extend SilenceOutput
34
+
35
+ def counter
36
+ Bacon::Counter
37
+ end
38
+
39
+ def error_log
40
+ Bacon::ErrorLog
41
+ end
42
+
43
+ def mocha_context
44
+ @mocha_context ||= Bacon::Context.new("Mocha test context")
45
+ end
46
+
47
+ def run_example(proc)
48
+ @example_counter ||= 0; @example_counter += 1
49
+
50
+ counter_before = counter.dup
51
+ error_log_before = error_log.dup
52
+ Bacon.silence = true
53
+
54
+ mocha_context.it("Mocha example `#{@example_counter}'", &proc)
55
+ [{ :failed => counter[:failed] - counter_before[:failed], :errors => counter_before[:errors] - counter_before[:errors] }, error_log.dup]
56
+ ensure
57
+ counter.replace(counter_before)
58
+ error_log.replace(error_log_before)
59
+ Bacon.silence = false
60
+ end
61
+
62
+ def satisfied
63
+ lambda do |proc|
64
+ difference, _ = run_example(proc)
65
+ difference[:errors] == 0 && difference[:failed] == 0
66
+ end
67
+ end
68
+
69
+ def unsatisfied(mockee, method, params = 'any_parameters')
70
+ lambda do |proc|
71
+ difference, error_log = run_example(proc)
72
+ difference[:errors] == 0 && difference[:failed] == 1 &&
73
+ error_log.include?("- expected exactly once, not yet invoked: #{mockee.mocha_inspect}.#{method}(#{params})")
74
+ end
75
+ end
76
+
77
+ def received_unexpected_invocation(mockee, method, params = '')
78
+ lambda do |proc|
79
+ difference, error_log = run_example(proc)
80
+ difference[:errors] == 0 && difference[:failed] == 1 &&
81
+ error_log.include?("unexpected invocation: #{mockee.mocha_inspect}.#{method}(#{params})")
82
+ end
83
+ end
84
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mocha-on-bacon
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Eloy Duran
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-01-25 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: mocha
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.9.8
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: bacon
27
+ 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:
35
+ description: A Mocha adapter for Bacon, because it's yummy!
36
+ email: eloy.de.enige@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files: []
42
+
43
+ files:
44
+ - .gitignore
45
+ - Rakefile
46
+ - VERSION
47
+ - lib/mocha-on-bacon.rb
48
+ - mocha-on-bacon.gemspec
49
+ - spec/mocha-on-bacon_spec.rb
50
+ - spec/spec_helper.rb
51
+ has_rdoc: true
52
+ homepage: http://github.com/alloy/mocha-on-bacon
53
+ licenses: []
54
+
55
+ post_install_message:
56
+ rdoc_options:
57
+ - --charset=UTF-8
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: "0"
65
+ version:
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: "0"
71
+ version:
72
+ requirements: []
73
+
74
+ rubyforge_project:
75
+ rubygems_version: 1.3.5
76
+ signing_key:
77
+ specification_version: 3
78
+ summary: A Mocha adapter for Bacon
79
+ test_files:
80
+ - spec/mocha-on-bacon_spec.rb
81
+ - spec/spec_helper.rb