Browse files

Added a README, LICENSE, and gemspec

  • Loading branch information...
1 parent f61e789 commit 76cb53fd7c061a81a8c149e4a4775fb0d3f596b5 @jferris jferris committed Jun 9, 2010
Showing with 144 additions and 7 deletions.
  1. +2 −3 .gitignore
  2. +19 −0 LICENSE
  3. +59 −0 README
  4. +15 −0 Rakefile
  5. +33 −0 bourne.gemspec
  6. +3 −1 lib/bourne/expectation.rb
  7. +6 −2 lib/bourne/invocation.rb
  8. +3 −1 lib/bourne/mock.rb
  9. +4 −0 lib/bourne/mockery.rb
View
5 .gitignore
@@ -1,7 +1,6 @@
pkg
-doc
-templates
-agiledox.txt
*.swp
.swo
+*~
tags
+rdoc
View
19 LICENSE
@@ -0,0 +1,19 @@
+Copyright (c) 2010 Joe Ferris and thoughtbot, inc.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
View
59 README
@@ -0,0 +1,59 @@
+= Bourne
+
+Bourne extends mocha to allow detailed tracking and querying of stub and mock
+invocations. It allows test spies using the have_received rspec matcher and
+assert_received for Test::Unit. Bourne was extracted from jferris-mocha, a fork
+of mocha that adds test spies.
+
+== Test Spies
+
+Test spies are a form of test double that preserves the normal four-phase unit
+test order and allows separation of stubbing and verification.
+
+Using a test spy is like using a mocked expectation except that there are two steps:
+
+1. Stub out a method for which you want to verify invocations
+2. Use an assertion or matcher to verify that the stub was invoked correctly
+
+== Examples
+
+ # rspec
+
+ mock.should have_received(:to_s)
+ Radio.should have_received(:new).with(1041)
+ radio.should have_received(:volume).with(11).twice
+ radio.should have_received(:off).never
+
+ # Test::Unit
+
+ assert_received(mock, :to_s)
+ assert_received(Radio, :new) {|expect| expect.with(1041) }
+ assert_received(radio, :volume) {|expect| expect.with(11).twice }
+ assert_received(radio, :off) {|expect| expect.never }
+
+See Mocha::API for more information.
+
+== Download
+
+Rubygems:
+ gem install bourne
+
+Github: http://github.com/thoughtbot/bourne/tree/master
+
+== More Information
+
+* RDoc[http://rdoc.info/projects/thoughtbot/bourne]
+* Mocha mailing list[http://groups.google.com/group/mocha-developer?hl=en]
+* Issues[http://github.com/thoughtbot/bourne/issues]
+* GIANT ROBOTS SMASHING INTO OTHER GIANT ROBOTS[http://robots.thoughtbot.com]
+
+== Author
+
+Bourne was written by Joe Ferris. Mocha was written by James Mead. Several of
+the test examples and helpers used in the Bourne test suite were copied
+directly from Mocha.
+
+Thanks to thoughtbot for inspiration, ideas, and funding. Thanks to James for
+writing mocha.
+
+Copyright 2010 Joe Ferris and thoughtbot[http://www.thoughtbot.com], inc.
View
15 Rakefile
@@ -1,4 +1,5 @@
require 'rake/rdoctask'
+require 'rake/gempackagetask'
require 'rake/testtask'
desc "Run all tests"
@@ -44,3 +45,17 @@ def benchmark_test_case(klass, iterations)
time = Benchmark.realtime { iterations.times { Test::Unit::UI::Console::TestRunner.run(klass, silent_option) } }
end
+eval("$specification = #{IO.read('bourne.gemspec')}")
+Rake::GemPackageTask.new($specification) do |package|
+ package.need_zip = true
+ package.need_tar = true
+end
+
+desc 'Generate documentation.'
+Rake::RDocTask.new(:rdoc) do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = 'Bourne'
+ rdoc.options << '--line-numbers' << "--main" << "README"
+ rdoc.rdoc_files.include('README')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
View
33 bourne.gemspec
@@ -0,0 +1,33 @@
+Gem::Specification.new do |s|
+ s.name = %q{bourne}
+ s.version = "1.0"
+ s.authors = ["Joe Ferris"]
+ s.date = %q{2010-06-08}
+ s.description = %q{Extends mocha to allow detailed tracking and querying of
+ stub and mock invocations. Allows test spies using the have_received rspec
+ matcher and assert_received for Test::Unit. Extracted from the
+ jferris-mocha fork.}
+ s.email = %q{jferris@thoughtbot.com}
+ s.extra_rdoc_files = ["README", "LICENSE"]
+ s.files = %w(lib/bourne/api.rb lib/bourne/expectation.rb
+ lib/bourne/invocation.rb lib/bourne/mock.rb
+ lib/bourne/mockery.rb lib/bourne.rb
+ test/acceptance/acceptance_test_helper.rb
+ test/acceptance/mocha_example_test.rb
+ test/acceptance/spy_test.rb
+ test/acceptance/stubba_example_test.rb test/execution_point.rb
+ test/matcher_helpers.rb test/method_definer.rb
+ test/simple_counter.rb test/test_helper.rb test/test_runner.rb
+ test/unit/assert_received_test.rb test/unit/expectation_test.rb
+ test/unit/have_received_test.rb test/unit/invocation_test.rb
+ test/unit/mock_test.rb test/unit/mockery_test.rb LICENSE
+ Rakefile README)
+ s.homepage = %q{http://github.com/thoughtbot/bourne}
+ s.rdoc_options = ["--title", "Bourne", "--main", "README", "--line-numbers"]
+ s.require_paths = ["lib"]
+ s.rubygems_version = %q{1.3.4}
+ s.summary = %q{Adds test spies to mocha.}
+ s.specification_version = 3
+ s.add_runtime_dependency(%q<mocha>, ["= 0.9.8"])
+ s.add_development_dependency(%q<rake>, [">= 0"])
+end
View
4 lib/bourne/expectation.rb
@@ -1,7 +1,9 @@
require 'mocha/expectation'
module Mocha # :nodoc:
- class Expectation
+ # Extends Mocha::Expectation to record the full arguments and count whenver a
+ # stubbed or mocked method is invoked.
+ class Expectation # :nodoc:
attr_accessor :invocation_count
def invoke_with_args(args, &block)
View
8 lib/bourne/invocation.rb
@@ -1,5 +1,9 @@
-module Mocha
- class Invocation # :nodoc:
+module Mocha # :nodoc:
+ # Used internally by Bourne extensions to Mocha. Represents a single
+ # invocation of a stubbed or mocked method. The mock, method name, and
+ # arguments are recorded and can be used to determine how a method was
+ # invoked.
+ class Invocation
attr_reader :mock, :method_name, :arguments
def initialize(mock, method_name, arguments)
@mock = mock
View
4 lib/bourne/mock.rb
@@ -2,7 +2,9 @@
require 'bourne/expectation'
module Mocha # :nodoc:
- class Mock
+ # Overwrites #method_missing on Mocha::Mock so pass arguments to
+ # Mocha::Expectation#invoke so that an Invocation can be created.
+ class Mock # :nodoc:
def method_missing(symbol, *arguments, &block)
if @responder and not @responder.respond_to?(symbol)
raise NoMethodError, "undefined method `#{symbol}' for #{self.mocha_inspect} which responds like #{@responder.mocha_inspect}"
View
4 lib/bourne/mockery.rb
@@ -3,6 +3,10 @@
require 'bourne/invocation'
module Mocha
+ # Used internally by Bourne extensions to Mocha when recording invocations of
+ # stubbed and mocked methods. You shouldn't need to interact with this module
+ # through normal testing, but you can access the full list of invocations
+ # directly if necessary.
class Mockery
def invocation(mock, method_name, args)
invocations << Invocation.new(mock, method_name, args)

0 comments on commit 76cb53f

Please sign in to comment.