Removing the included testing gems; you must now install them yourself.

Everything passes, but autotest doesn't include color.

Signed-off-by: Luke Kanies <luke@madstop.com>
This commit is contained in:
Luke Kanies 2008-11-23 00:56:38 -06:00 коммит произвёл James Turnbull
Родитель b415848841
Коммит bbad983157
596 изменённых файлов: 59 добавлений и 34906 удалений

Просмотреть файл

@ -42,19 +42,9 @@ Autotest.add_hook :initialize do |at|
}
end
# a place for overrides when necessary.
class Autotest::PuppetRspec < Autotest::Rspec
# Autotest will look for spec commands in the following
# locations, in this order:
#
# * bin/spec
# * default spec bin/loader installed in Rubygems
# * our local vendor/gems/rspec/bin/spec
def spec_commands
[
File.join('vendor', 'gems', 'rspec', 'bin', 'spec') ,
File.join('bin', 'spec'),
File.join(Config::CONFIG['bindir'], 'spec')
]
ENV["PATH"].split(":").collect { |dir| File.join(dir, "spec") }
end
end

Просмотреть файл

@ -73,7 +73,9 @@ module Puppet::Network
rescue Timeout::Error => detail
Puppet.err "Connection timeout calling %s.%s: %s" %
[namespace, method, detail.to_s]
raise XMLRPCClientError.new("Connection Timeout").set_backtrace(detail.backtrace)
error = XMLRPCClientError.new("Connection Timeout")
error.set_backtrace(detail.backtrace)
raise error
rescue => detail
if detail.message =~ /^Wrong size\. Was \d+, should be \d+$/
Puppet.warning "XMLRPC returned wrong size. Retrying."

0
spec/unit/network/xmlrpc/client.rb Normal file → Executable file
Просмотреть файл

Просмотреть файл

@ -152,7 +152,7 @@ describe Puppet::Node::Catalog, " when extracting transobjects" do
end
describe Puppet::Node::Catalog, " when converting to a transobject catalog" do
class TestResource
class CatalogTestResource
attr_accessor :name, :virtual, :builtin
def initialize(name, options = {})
@name = name
@ -185,14 +185,14 @@ describe Puppet::Node::Catalog, " when converting to a transobject catalog" do
@original.tag(*%w{one two three})
@original.add_class *%w{four five six}
@top = TestResource.new 'top'
@topobject = TestResource.new 'topobject', :builtin => true
@virtual = TestResource.new 'virtual', :virtual => true
@virtualobject = TestResource.new 'virtualobject', :builtin => true, :virtual => true
@middle = TestResource.new 'middle'
@middleobject = TestResource.new 'middleobject', :builtin => true
@bottom = TestResource.new 'bottom'
@bottomobject = TestResource.new 'bottomobject', :builtin => true
@top = CatalogTestResource.new 'top'
@topobject = CatalogTestResource.new 'topobject', :builtin => true
@virtual = CatalogTestResource.new 'virtual', :virtual => true
@virtualobject = CatalogTestResource.new 'virtualobject', :builtin => true, :virtual => true
@middle = CatalogTestResource.new 'middle'
@middleobject = CatalogTestResource.new 'middleobject', :builtin => true
@bottom = CatalogTestResource.new 'bottom'
@bottomobject = CatalogTestResource.new 'bottomobject', :builtin => true
@resources = [@top, @topobject, @middle, @middleobject, @bottom, @bottomobject]

Просмотреть файл

@ -2,6 +2,34 @@
require File.dirname(__FILE__) + '/../../spec_helper'
class CompilerTestResource
attr_accessor :builtin, :virtual, :evaluated, :type, :title
def initialize(type, title)
@type = type
@title = title
end
def ref
"%s[%s]" % [type.to_s.capitalize, title]
end
def evaluated?
@evaluated
end
def builtin?
@builtin
end
def virtual?
@virtual
end
def evaluate
end
end
describe Puppet::Parser::Compiler do
before :each do
@node = Puppet::Node.new "testnode"
@ -164,11 +192,12 @@ describe Puppet::Parser::Compiler do
end
it "should evaluate unevaluated resources" do
resource = stub 'notevaluated', :ref => "File[testing]", :builtin? => false, :evaluated? => false, :virtual? => false
resource = CompilerTestResource.new(:file, "testing")
@compiler.add_resource(@scope, resource)
# We have to now mark the resource as evaluated
resource.expects(:evaluate).with { |*whatever| resource.stubs(:evaluated?).returns true }
resource.expects(:evaluate).with { |*whatever| resource.evaluated = true }
@compiler.compile
end
@ -182,14 +211,14 @@ describe Puppet::Parser::Compiler do
end
it "should evaluate unevaluated resources created by evaluating other resources" do
resource = stub 'notevaluated', :ref => "File[testing]", :builtin? => false, :evaluated? => false, :virtual? => false
resource = CompilerTestResource.new(:file, "testing")
@compiler.add_resource(@scope, resource)
resource2 = stub 'created', :ref => "File[other]", :builtin? => false, :evaluated? => false, :virtual? => false
resource2 = CompilerTestResource.new(:file, "other")
# We have to now mark the resource as evaluated
resource.expects(:evaluate).with { |*whatever| resource.stubs(:evaluated?).returns(true); @compiler.add_resource(@scope, resource2) }
resource2.expects(:evaluate).with { |*whatever| resource2.stubs(:evaluated?).returns(true) }
resource.expects(:evaluate).with { |*whatever| resource.evaluated = true; @compiler.add_resource(@scope, resource2) }
resource2.expects(:evaluate).with { |*whatever| resource2.evaluated = true }
@compiler.compile

Просмотреть файл

@ -486,6 +486,10 @@ describe Puppet::Util::Settings do
@settings.setdefaults :files, :myfile => {:default => "/myfile", :desc => "a", :mode => 0755}
end
after do
Puppet::Type.type(:file).clear
end
def stub_transaction
@bucket = mock 'bucket'
@config = mock 'config', :clear => nil

Просмотреть файл

@ -16,6 +16,10 @@ describe Puppet::Util::Storage do
Puppet::Util::Storage.clear()
end
after do
Puppet::Type.type(:file).clear
end
describe "when caching a symbol" do
it "should return an empty hash" do
Puppet::Util::Storage.cache(:yayness).should == {}

Двоичные данные
vendor/gems/mocha-0.5.6/._RELEASE поставляемый

Двоичный файл не отображается.

Двоичные данные
vendor/gems/mocha-0.5.6/._Rakefile поставляемый

Двоичный файл не отображается.

3
vendor/gems/mocha-0.5.6/COPYING поставляемый
Просмотреть файл

@ -1,3 +0,0 @@
Copyright Revieworld Ltd. 2006
You may use, copy and redistribute this library under the same terms as Ruby itself (see http://www.ruby-lang.org/en/LICENSE.txt) or under the MIT license (see MIT-LICENSE file).

7
vendor/gems/mocha-0.5.6/MIT-LICENSE поставляемый
Просмотреть файл

@ -1,7 +0,0 @@
Copyright (c) 2006 Revieworld Ltd.
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.

35
vendor/gems/mocha-0.5.6/README поставляемый
Просмотреть файл

@ -1,35 +0,0 @@
= Mocha
Mocha is a library for mocking and stubbing using a syntax like that of JMock[http://www.jmock.org], and SchMock[http://rubyforge.org/projects/schmock]. Most commonly Mocha is used in conjunction with Test::Unit[http://www.ruby-doc.org/core/classes/Test/Unit.html], but it can be used in other contexts.
One of its main advantages is that it allows you to mock and stub methods on _real_ (non-mock) classes and instances. You can for example stub ActiveRecord[http://api.rubyonrails.com/classes/ActiveRecord/Base.html] instance methods like +create+, +save+, +destroy+ and even class methods like +find+ to avoid hitting the database in unit tests.
Mocha provides a unified, simple and readable syntax for both traditional mocking and for mocking with _real_ objects.
Mocha has been harvested from projects at Reevoo[http://www.reevoo.com] by me (James[http://blog.floehopper.org]) and my colleagues Ben[http://www.reevoo.com/blogs/bengriffiths], Chris[http://blog.seagul.co.uk] and Paul[http://po-ru.com]. Mocha is in use on real-world Rails[http://www.rubyonrails.org] projects.
== Download and Installation
Install the gem with the following command...
$ gem install mocha
Or install the Rails[http://www.rubyonrails.org] plugin...
$ script/plugin install svn://rubyforge.org/var/svn/mocha/trunk
Or download Mocha from here - http://rubyforge.org/projects/mocha
== Examples
* Quick Start - {Usage Examples}[link:examples/misc.html]
* Traditional mocking - {Star Trek Example}[link:examples/mocha.html]
* Setting expectations on real classes - {Order Example}[link:examples/stubba.html]
* More examples on {Floehopper's Blog}[http://blog.floehopper.org]
* {Mailing List Archives}[http://rubyforge.org/pipermail/mocha-developer/]
== License
Copyright Revieworld Ltd. 2006
You may use, copy and redistribute this library under the same terms as {Ruby itself}[http://www.ruby-lang.org/en/LICENSE.txt] or under the {MIT license}[http://mocha.rubyforge.org/files/MIT-LICENSE.html].

188
vendor/gems/mocha-0.5.6/RELEASE поставляемый
Просмотреть файл

@ -1,188 +0,0 @@
= 0.5.5 (r167)
- Renamed Matches parameter matcher to RegexpMatches for clarity.
- Added noframes tag to rdoc index to assist Google.
= 0.5.4 (r166)
- Added matches parameter matcher for matching regular expressions.
= 0.5.3 (r165)
- Attempt to fix packaging problems by switching to newer version (1.15.1) of gnutar and setting COPY_EXTENDED_ATTRIBUTES_DISABLE environment variable.
- Removed unused ExpectationSequenceError exception.
- Added instance_of and kind_of parameter matchers.
- Added Google Webmaster meta tag to rdoc template header.
- Put Google Webmaster meta tag in the right header i.e. the one for the index page.
= 0.5.2 (r159)
- Fix bug 11885 - "never doesn't work with stub_everything" submitted by Alexander Lang. In fixing this bug, also fixed undiscoverd bug where expected & actual invocation counts were being incorrectly reported which seems to have been introduced when fixes were added for invocation dispatch (see MockedMethodDispatchAcceptanceTest).
- Previously when an expectation did not allow more invocations, it was treated as not matching. Now we prefer matching expectations which allow more invocations, but still match expectations which cannot allow more invocations. I think this may be overcomplicating things, but let's see how it goes.
= 0.5.1 (r149)
- Fixed bug #11583 "Mocha 0.5.0 throwing unexpected warnings". Also switched on ruby warning for all rake test tasks. Fixed majority of warnings, but some left to fix.
= 0.5.0 (r147)
- Parameter Matchers - Ive added a few Hamcrest-style parameter matchers which are designed to be used inside Expectation#with. The following matchers are currently available: anything(), includes(), has_key(), has_value(), has_entry(), all_of() & any_of(). More to follow soon. The idea is eventually to get rid of the nasty parameter_block option on Expectation#with.
object = mock()
object.expects(:method).with(has_key('key_1'))
object.method('key_1' => 1, 'key_2' => 2)
# no verification error raised
object = mock()
object.expects(:method).with(has_key('key_1'))
object.method('key_2' => 2)
# verification error raised, because method was not called with Hash containing key: 'key_1'
- Values Returned and Exceptions Raised on Consecutive Invocations - Allow multiple calls to Expectation#returns and Expectation#raises to build up a sequence of responses to invocations on the mock. Added syntactic sugar method Expectation#then to allow more readable expectations.
object = mock()
object.stubs(:method).returns(1, 2).then.raises(Exception).then.returns(4)
object.method # => 1
object.method # => 2
object.method # => raises exception of class Exception
object.method # => 4
- Yields on Consecutive Invocations - Allow multiple calls to yields on single expectation to allow yield parameters to be specified for consecutive invocations.
object = mock()
object.stubs(:method).yields(1, 2).then.yields(3)
object.method { |*values| p values } # => [1, 2]
object.method { |*values| p values } # => [3]
- Multiple Yields on Single Invocation - Added Expectation#multiple_yields to allow a mocked or stubbed method to yield multiple times for a single invocation.
object = mock()
object.stubs(:method).multiple_yields([1, 2], [3])
object.method { |*values| p values } # => [1, 2] # => [3]
- Invocation Dispatch - Expectations were already being matched in reverse order i.e. the most recently defined one was being found first. This is still the case, but we now stop matching an expectation when its maximum number of expected invocations is reached. c.f. JMock v1. A stub will never stop matching by default. Hopefully this means we can soon get rid of the need to pass a Proc to Expectation#returns.
object = mock()
object.stubs(:method).returns(2)
object.expects(:method).once.returns(1)
object.method # => 1
object.method # => 2
object.method # => 2
# no verification error raised
# The following should still work...
Time.stubs(:now).returns(Time.parse('Mon Jan 01 00:00:00 UTC 2007'))
Time.now # => Mon Jan 01 00:00:00 UTC 2007
Time.stubs(:now).returns(Time.parse('Thu Feb 01 00:00:00 UTC 2007'))
Time.now # => Thu Feb 01 00:00:00 UTC 2007
- Deprecate passing an instance of Proc to Expectation#returns.
- Explicitly include all Rakefile dependencies in project.
- Fixed old Stubba example.
- Fix so that it is possible for a stubbed method to raise an Interrupt exception without a message in Ruby 1.8.6
- Added responds_like and quacks_like.
- Capture standard object methods before Mocha adds any.
- Added Expectation#once method to make interface less surprising.
- Use Rake::TestTask to run tests. Created three separate tasks to run unit, integration & acceptance tests. Split inspect_test into one file per TestCase. Deleted superfluous all_tests file.
- Fiddled with mocha_inspect and tests to give more sensible results on x86 platform.
- Fixed bug #7834 "infinite_range.rb makes incorrect assumption about to_f" logged by James Moore.
= 0.4.0 (r92)
- Allow naming of mocks (patch from Chris Roos).
- Specify multiple return values for consecutive calls.
- Improved consistency of expectation error messages.
- Allow mocking of Object instance methods e.g. kind_of?, type.
- Provide aliased versions of #expects and #stubs to allow mocking of these methods.
- Added at_least, at_most, at_most_once methods to expectation.
- Allow expects and stubs to take a hash of method and return values.
- Eliminate warning: "instance variable @yield not initialized" (patch from Xavier Shay).
- Restore instance methods on partial mocks (patch from Chris Roos).
- Allow stubbing of a method with non-word characters in its name (patch from Paul Battley).
- Removed coupling to Test::Unit.
- Allow specified exception instance to be raised (patch from Chris Roos).
- Make mock object_id appear in hex like normal Ruby inspect (patch from Paul Battley).
- Fix path to object.rb in rdoc rake task (patch from Tomas Pospisek).
- Reverse order in which expectations are matched, so that last expectation is matched first. This allows e.g. a call to #stubs to be effectively overridden by a call to #expects (patch from Tobias Lutke).
- Stubba & SmartTestCase modules incorporated into Mocha module so only need to require 'mocha' - no longer need to require 'stubba'.
- AutoMocha removed.
= 0.3.3
- Quick bug fix to restore instance methods on partial mocks (for Kevin Clark).
= 0.3.2
- Examples added.
= 0.3.1
- Dual licensing with MIT license added.
= 0.3.0
* Rails plugin.
* Auto-verify for expectations on concrete classes.
* Include each expectation verification in the test result assertion count.
* Filter out noise from assertion backtraces.
* Point assertion backtrace to line where failing expectation was created.
* New yields method for expectations.
* Create stubs which stub all method calls.
* Mocks now respond_to? expected methods.
= 0.2.1
* Rename MochaAcceptanceTest::Rover#move method to avoid conflict with Rake (in Ruby 1.8.4 only?)
= 0.2.0
* Small change to SetupAndTeardown#teardown_stubs suggested by Luke Redpath (http://www.lukeredpath.co.uk) to allow use of Stubba with RSpec (http://rspec.rubyforge.org).
* Reorganized directory structure and extracted addition of setup and teardown methods into SmartTestCase mini-library.
* Addition of auto-verify for Mocha (but not Stubba). This means there is more significance in the choice of expects or stubs in that any expects on a mock will automatically get verified.
So instead of...
wotsit = Mocha.new
wotsit.expects(:thingummy).with(5).returns(10)
doobrey = Doobrey.new(wotsit)
doobrey.hoojamaflip
wotsit.verify
you need to do...
wotsit = mock()
wotsit.expects(:thingummy).with(5).returns(10)
doobrey = Doobrey.new(wotsit)
doobrey.hoojamaflip
# no need to verify
There are also shortcuts as follows...
instead of...
wotsit = Mocha.new
wotsit.expects(:thingummy).returns(10)
wotsit.expects(:summat).returns(25)
you can have...
wotsit = mock(:thingummy => 5, :summat => 25)
and instead of...
wotsit = Mocha.new
wotsit.stubs(:thingummy).returns(10)
wotsit.stubs(:summat).returns(25)
you can have...
wotsit = stub(:thingummy => 5, :summat => 25)
= 0.1.2
* Minor tweaks
= 0.1.1
* Initial release.

149
vendor/gems/mocha-0.5.6/Rakefile поставляемый
Просмотреть файл

@ -1,149 +0,0 @@
require 'rubygems'
require 'rake/rdoctask'
require 'rake/gempackagetask'
require 'rake/testtask'
require 'rake/contrib/sshpublisher'
module Mocha
VERSION = "0.5.6"
end
desc "Run all tests"
task :default => :test_all
task :test_all => [:test_unit, :test_integration, :test_acceptance]
desc "Run unit tests"
Rake::TestTask.new(:test_unit) do |t|
t.libs << 'test'
t.test_files = FileList['test/unit/**/*_test.rb']
t.verbose = true
t.warning = true
end
desc "Run integration tests"
Rake::TestTask.new(:test_integration) do |t|
t.libs << 'test'
t.test_files = FileList['test/integration/*_test.rb']
t.verbose = true
t.warning = true
end
desc "Run acceptance tests"
Rake::TestTask.new(:test_acceptance) do |t|
t.libs << 'test'
t.test_files = FileList['test/acceptance/*_test.rb']
t.verbose = true
t.warning = true
end
desc 'Generate RDoc'
Rake::RDocTask.new do |task|
task.main = 'README'
task.title = "Mocha #{Mocha::VERSION}"
task.rdoc_dir = 'doc'
task.template = File.expand_path(File.join(File.dirname(__FILE__), "templates", "html_with_google_analytics"))
task.rdoc_files.include('README', 'RELEASE', 'COPYING', 'MIT-LICENSE', 'agiledox.txt', 'lib/mocha/auto_verify.rb', 'lib/mocha/mock.rb', 'lib/mocha/expectation.rb', 'lib/mocha/object.rb', 'lib/mocha/parameter_matchers.rb', 'lib/mocha/parameter_matchers')
end
task :rdoc => :examples
desc "Upload RDoc to RubyForge"
task :publish_rdoc => [:rdoc, :examples] do
Rake::SshDirPublisher.new("jamesmead@rubyforge.org", "/var/www/gforge-projects/mocha", "doc").upload
end
desc "Generate agiledox-like documentation for tests"
file 'agiledox.txt' do
File.open('agiledox.txt', 'w') do |output|
tests = FileList['test/**/*_test.rb']
tests.each do |file|
m = %r".*/([^/].*)_test.rb".match(file)
output << m[1]+" should:\n"
test_definitions = File::readlines(file).select {|line| line =~ /.*def test.*/}
test_definitions.sort.each do |definition|
m = %r"test_(should_)?(.*)".match(definition)
output << " - "+m[2].gsub(/_/," ") << "\n"
end
end
end
end
desc "Convert example ruby files to syntax-highlighted html"
task :examples do
$:.unshift File.expand_path(File.join(File.dirname(__FILE__), "vendor", "coderay-0.7.4.215", "lib"))
require 'coderay'
mkdir_p 'doc/examples'
File.open('doc/examples/coderay.css', 'w') do |output|
output << CodeRay::Encoders[:html]::CSS.new.stylesheet
end
['mocha', 'stubba', 'misc'].each do |filename|
File.open("doc/examples/#{filename}.html", 'w') do |file|
file << "<html>"
file << "<head>"
file << %q(<link rel="stylesheet" media="screen" href="coderay.css" type="text/css">)
file << "</head>"
file << "<body>"
file << CodeRay.scan_file("examples/#{filename}.rb").html.div
file << "</body>"
file << "</html>"
end
end
end
Gem::manage_gems
specification = Gem::Specification.new do |s|
s.name = "mocha"
s.summary = "Mocking and stubbing library"
s.version = Mocha::VERSION
s.platform = Gem::Platform::RUBY
s.author = 'James Mead'
s.description = <<-EOF
Mocking and stubbing library with JMock/SchMock syntax, which allows mocking and stubbing of methods on real (non-mock) classes.
EOF
s.email = 'mocha-developer@rubyforge.org'
s.homepage = 'http://mocha.rubyforge.org'
s.rubyforge_project = 'mocha'
s.has_rdoc = true
s.extra_rdoc_files = ['README', 'COPYING']
s.rdoc_options << '--title' << 'Mocha' << '--main' << 'README' << '--line-numbers'
s.autorequire = 'mocha'
s.add_dependency('rake')
s.files = FileList['{lib,test,examples}/**/*.rb', '[A-Z]*'].exclude('TODO').to_a
end
Rake::GemPackageTask.new(specification) do |package|
package.need_zip = true
package.need_tar = true
end
task :verify_user do
raise "RUBYFORGE_USER environment variable not set!" unless ENV['RUBYFORGE_USER']
end
task :verify_password do
raise "RUBYFORGE_PASSWORD environment variable not set!" unless ENV['RUBYFORGE_PASSWORD']
end
desc "Publish package files on RubyForge."
task :publish_packages => [:verify_user, :verify_password, :package] do
$:.unshift File.expand_path(File.join(File.dirname(__FILE__), "vendor", "meta_project-0.4.15", "lib"))
require 'meta_project'
require 'rake/contrib/xforge'
release_files = FileList[
"pkg/mocha-#{Mocha::VERSION}.gem",
"pkg/mocha-#{Mocha::VERSION}.tgz",
"pkg/mocha-#{Mocha::VERSION}.zip"
]
Rake::XForge::Release.new(MetaProject::Project::XForge::RubyForge.new('mocha')) do |release|
release.user_name = ENV['RUBYFORGE_USER']
release.password = ENV['RUBYFORGE_PASSWORD']
release.files = release_files.to_a
release.release_name = "Mocha #{Mocha::VERSION}"
release.release_changes = ''
release.release_notes = ''
end
end

Двоичные данные
vendor/gems/mocha-0.5.6/examples/._misc.rb поставляемый

Двоичный файл не отображается.

Двоичные данные
vendor/gems/mocha-0.5.6/examples/._mocha.rb поставляемый

Двоичный файл не отображается.

Двоичные данные
vendor/gems/mocha-0.5.6/examples/._stubba.rb поставляемый

Двоичный файл не отображается.

44
vendor/gems/mocha-0.5.6/examples/misc.rb поставляемый
Просмотреть файл

@ -1,44 +0,0 @@
require 'test/unit'
require 'rubygems'
require 'mocha'
class MiscExampleTest < Test::Unit::TestCase
def test_mocking_a_class_method
product = Product.new
Product.expects(:find).with(1).returns(product)
assert_equal product, Product.find(1)
end
def test_mocking_an_instance_method_on_a_real_object
product = Product.new
product.expects(:save).returns(true)
assert product.save
end
def test_stubbing_instance_methods_on_real_objects
prices = [stub(:pence => 1000), stub(:pence => 2000)]
product = Product.new
product.stubs(:prices).returns(prices)
assert_equal [1000, 2000], product.prices.collect {|p| p.pence}
end
def test_stubbing_an_instance_method_on_all_instances_of_a_class
Product.any_instance.stubs(:name).returns('stubbed_name')
product = Product.new
assert_equal 'stubbed_name', product.name
end
def test_traditional_mocking
object = mock()
object.expects(:expected_method).with(:p1, :p2).returns(:result)
assert_equal :result, object.expected_method(:p1, :p2)
end
def test_shortcuts
object = stub(:method1 => :result1, :method2 => :result2)
assert_equal :result1, object.method1
assert_equal :result2, object.method2
end
end

26
vendor/gems/mocha-0.5.6/examples/mocha.rb поставляемый
Просмотреть файл

@ -1,26 +0,0 @@
class Enterprise
def initialize(dilithium)
@dilithium = dilithium
end
def go(warp_factor)
warp_factor.times { @dilithium.nuke(:anti_matter) }
end
end
require 'test/unit'
require 'rubygems'
require 'mocha'
class EnterpriseTest < Test::Unit::TestCase
def test_should_boldly_go
dilithium = mock()
dilithium.expects(:nuke).with(:anti_matter).at_least_once # auto-verified at end of test
enterprise = Enterprise.new(dilithium)
enterprise.go(2)
end
end

65
vendor/gems/mocha-0.5.6/examples/stubba.rb поставляемый
Просмотреть файл

@ -1,65 +0,0 @@
class Order
attr_accessor :shipped_on
def total_cost
line_items.inject(0) { |total, line_item| total + line_item.price } + shipping_cost
end
def total_weight
line_items.inject(0) { |total, line_item| total + line_item.weight }
end
def shipping_cost
total_weight * 5 + 10
end
class << self
def find_all
# Database.connection.execute('select * from orders...
end
def number_shipped_since(date)
find_all.select { |order| order.shipped_on > date }.length
end
def unshipped_value
find_all.inject(0) { |total, order| order.shipped_on ? total : total + order.total_cost }
end
end
end
require 'test/unit'
require 'rubygems'
require 'mocha'
class OrderTest < Test::Unit::TestCase
# illustrates stubbing instance method
def test_should_calculate_shipping_cost_based_on_total_weight
order = Order.new
order.stubs(:total_weight).returns(10)
assert_equal 60, order.shipping_cost
end
# illustrates stubbing class method
def test_should_count_number_of_orders_shipped_after_specified_date
now = Time.now; week_in_secs = 7 * 24 * 60 * 60
order_1 = Order.new; order_1.shipped_on = now - 1 * week_in_secs
order_2 = Order.new; order_2.shipped_on = now - 3 * week_in_secs
Order.stubs(:find_all).returns([order_1, order_2])
assert_equal 1, Order.number_shipped_since(now - 2 * week_in_secs)
end
# illustrates stubbing instance method for all instances of a class
def test_should_calculate_value_of_unshipped_orders
Order.stubs(:find_all).returns([Order.new, Order.new, Order.new])
Order.any_instance.stubs(:shipped_on).returns(nil)
Order.any_instance.stubs(:total_cost).returns(10)
assert_equal 30, Order.unshipped_value
end
end

Двоичные данные
vendor/gems/mocha-0.5.6/lib/._mocha.rb поставляемый

Двоичный файл не отображается.

19
vendor/gems/mocha-0.5.6/lib/mocha.rb поставляемый
Просмотреть файл

@ -1,19 +0,0 @@
require 'mocha_standalone'
require 'mocha/test_case_adapter'
require 'test/unit/testcase'
module Test
module Unit
class TestCase
include Mocha::Standalone
include Mocha::TestCaseAdapter
end
end
end

Двоичные данные
vendor/gems/mocha-0.5.6/lib/mocha/._any_instance_method.rb поставляемый

Двоичный файл не отображается.

Двоичные данные
vendor/gems/mocha-0.5.6/lib/mocha/._auto_verify.rb поставляемый

Двоичный файл не отображается.

Двоичные данные
vendor/gems/mocha-0.5.6/lib/mocha/._central.rb поставляемый

Двоичный файл не отображается.

Двоичные данные
vendor/gems/mocha-0.5.6/lib/mocha/._class_method.rb поставляемый

Двоичный файл не отображается.

Двоичные данные
vendor/gems/mocha-0.5.6/lib/mocha/._deprecation.rb поставляемый

Двоичный файл не отображается.

Двоичные данные
vendor/gems/mocha-0.5.6/lib/mocha/._expectation.rb поставляемый

Двоичный файл не отображается.

Двоичные данные
vendor/gems/mocha-0.5.6/lib/mocha/._expectation_error.rb поставляемый

Двоичный файл не отображается.

Двоичные данные
vendor/gems/mocha-0.5.6/lib/mocha/._expectation_list.rb поставляемый

Двоичный файл не отображается.

Двоичные данные
vendor/gems/mocha-0.5.6/lib/mocha/._infinite_range.rb поставляемый

Двоичный файл не отображается.

Двоичные данные
vendor/gems/mocha-0.5.6/lib/mocha/._inspect.rb поставляемый

Двоичный файл не отображается.

Двоичные данные
vendor/gems/mocha-0.5.6/lib/mocha/._instance_method.rb поставляемый

Двоичный файл не отображается.

Двоичные данные
vendor/gems/mocha-0.5.6/lib/mocha/._metaclass.rb поставляемый

Двоичный файл не отображается.

Двоичные данные
vendor/gems/mocha-0.5.6/lib/mocha/._method_matcher.rb поставляемый

Двоичный файл не отображается.

Двоичные данные
vendor/gems/mocha-0.5.6/lib/mocha/._missing_expectation.rb поставляемый

Двоичный файл не отображается.

Двоичные данные
vendor/gems/mocha-0.5.6/lib/mocha/._mock.rb поставляемый

Двоичный файл не отображается.

Двоичные данные
vendor/gems/mocha-0.5.6/lib/mocha/._object.rb поставляемый

Двоичный файл не отображается.

Двоичные данные
vendor/gems/mocha-0.5.6/lib/mocha/._parameter_matchers.rb поставляемый

Двоичный файл не отображается.

Двоичные данные
vendor/gems/mocha-0.5.6/lib/mocha/._parameters_matcher.rb поставляемый

Двоичный файл не отображается.

Двоичные данные
vendor/gems/mocha-0.5.6/lib/mocha/._pretty_parameters.rb поставляемый

Двоичный файл не отображается.

Двоичные данные
vendor/gems/mocha-0.5.6/lib/mocha/._return_values.rb поставляемый

Двоичный файл не отображается.

Двоичные данные
vendor/gems/mocha-0.5.6/lib/mocha/._sequence.rb поставляемый

Двоичный файл не отображается.

Двоичные данные
vendor/gems/mocha-0.5.6/lib/mocha/._setup_and_teardown.rb поставляемый

Двоичный файл не отображается.

Двоичные данные
vendor/gems/mocha-0.5.6/lib/mocha/._single_return_value.rb поставляемый

Двоичный файл не отображается.

Двоичные данные
vendor/gems/mocha-0.5.6/lib/mocha/._standalone.rb поставляемый

Двоичный файл не отображается.

Двоичные данные
vendor/gems/mocha-0.5.6/lib/mocha/._test_case_adapter.rb поставляемый

Двоичный файл не отображается.

Двоичные данные
vendor/gems/mocha-0.5.6/lib/mocha/._yield_parameters.rb поставляемый

Двоичный файл не отображается.

Просмотреть файл

@ -1,35 +0,0 @@
require 'mocha/class_method'
module Mocha
class AnyInstanceMethod < ClassMethod
def unstub
remove_new_method
restore_original_method
stubbee.any_instance.reset_mocha
end
def mock
stubbee.any_instance.mocha
end
def hide_original_method
stubbee.class_eval "alias_method :#{hidden_method}, :#{method}" if stubbee.method_defined?(method)
end
def define_new_method
stubbee.class_eval "def #{method}(*args, &block); self.class.any_instance.mocha.method_missing(:#{method}, *args, &block); end"
end
def remove_new_method
stubbee.class_eval "remove_method :#{method}"
end
def restore_original_method
stubbee.class_eval "alias_method :#{method}, :#{hidden_method}; remove_method :#{hidden_method}" if stubbee.method_defined?(hidden_method)
end
end
end

Просмотреть файл

@ -1,118 +0,0 @@
require 'mocha/mock'
require 'mocha/sequence'
module Mocha # :nodoc:
# Methods added to TestCase allowing creation of traditional mock objects.
#
# Mocks created this way will have their expectations automatically verified at the end of the test.
#
# See Mock for methods on mock objects.
module AutoVerify
def mocks # :nodoc:
@mocks ||= []
end
def reset_mocks # :nodoc:
@mocks = nil
end
# :call-seq: mock(name, &block) -> mock object
# mock(expected_methods = {}, &block) -> mock object
# mock(name, expected_methods = {}, &block) -> mock object
#
# Creates a mock object.
#
# +name+ is a +String+ identifier for the mock object.
#
# +expected_methods+ is a +Hash+ with expected method name symbols as keys and corresponding return values as values.
#
# +block+ is a block to be evaluated against the mock object instance, giving an alernative way to set up expectations & stubs.
#
# Note that (contrary to expectations set up by #stub) these expectations <b>must</b> be fulfilled during the test.
# def test_product
# product = mock('ipod_product', :manufacturer => 'ipod', :price => 100)
# assert_equal 'ipod', product.manufacturer
# assert_equal 100, product.price
# # an error will be raised unless both Product#manufacturer and Product#price have been called
# end
def mock(*arguments, &block)
name = arguments.shift if arguments.first.is_a?(String)
expectations = arguments.shift || {}
mock = Mock.new(name, &block)
mock.expects(expectations)
mocks << mock
mock
end
# :call-seq: stub(name, &block) -> mock object
# stub(stubbed_methods = {}, &block) -> mock object
# stub(name, stubbed_methods = {}, &block) -> mock object
#
# Creates a mock object.
#
# +name+ is a +String+ identifier for the mock object.
#
# +stubbed_methods+ is a +Hash+ with stubbed method name symbols as keys and corresponding return values as values.
#
# +block+ is a block to be evaluated against the mock object instance, giving an alernative way to set up expectations & stubs.
#
# Note that (contrary to expectations set up by #mock) these expectations <b>need not</b> be fulfilled during the test.
# def test_product
# product = stub('ipod_product', :manufacturer => 'ipod', :price => 100)
# assert_equal 'ipod', product.manufacturer
# assert_equal 100, product.price
# # an error will not be raised even if Product#manufacturer and Product#price have not been called
# end
def stub(*arguments, &block)
name = arguments.shift if arguments.first.is_a?(String)
expectations = arguments.shift || {}
stub = Mock.new(name, &block)
stub.stubs(expectations)
mocks << stub
stub
end
# :call-seq: stub_everything(name, &block) -> mock object
# stub_everything(stubbed_methods = {}, &block) -> mock object
# stub_everything(name, stubbed_methods = {}, &block) -> mock object
#
# Creates a mock object that accepts calls to any method.
#
# By default it will return +nil+ for any method call.
#
# +block+ is a block to be evaluated against the mock object instance, giving an alernative way to set up expectations & stubs.
#
# +name+ and +stubbed_methods+ work in the same way as for #stub.
# def test_product
# product = stub_everything('ipod_product', :price => 100)
# assert_nil product.manufacturer
# assert_nil product.any_old_method
# assert_equal 100, product.price
# end
def stub_everything(*arguments, &block)
name = arguments.shift if arguments.first.is_a?(String)
expectations = arguments.shift || {}
stub = Mock.new(name, &block)
stub.stub_everything
stub.stubs(expectations)
mocks << stub
stub
end
def verify_mocks # :nodoc:
mocks.each { |mock| mock.verify { yield if block_given? } }
end
def teardown_mocks # :nodoc:
reset_mocks
end
def sequence(name) # :nodoc:
Sequence.new(name)
end
end
end

35
vendor/gems/mocha-0.5.6/lib/mocha/central.rb поставляемый
Просмотреть файл

@ -1,35 +0,0 @@
module Mocha
class Central
attr_accessor :stubba_methods
def initialize
self.stubba_methods = []
end
def stub(method)
unless stubba_methods.include?(method)
method.stub
stubba_methods.push method
end
end
def verify_all(&block)
unique_mocks.each { |mock| mock.verify(&block) }
end
def unique_mocks
stubba_methods.inject({}) { |mocks, method| mocks[method.mock.__id__] = method.mock; mocks }.values
end
def unstub_all
while stubba_methods.length > 0
method = stubba_methods.pop
method.unstub
end
end
end
end

Просмотреть файл

@ -1,66 +0,0 @@
require 'mocha/metaclass'
module Mocha
class ClassMethod
attr_reader :stubbee, :method
def initialize(stubbee, method)
@stubbee, @method = stubbee, method
end
def stub
hide_original_method
define_new_method
end
def unstub
remove_new_method
restore_original_method
stubbee.reset_mocha
end
def mock
stubbee.mocha
end
def hide_original_method
stubbee.__metaclass__.class_eval "alias_method :#{hidden_method}, :#{method}" if stubbee.__metaclass__.method_defined?(method)
end
def define_new_method
stubbee.__metaclass__.class_eval "def #{method}(*args, &block); mocha.method_missing(:#{method}, *args, &block); end"
end
def remove_new_method
stubbee.__metaclass__.class_eval "remove_method :#{method}"
end
def restore_original_method
stubbee.__metaclass__.class_eval "alias_method :#{method}, :#{hidden_method}; remove_method :#{hidden_method}" if stubbee.__metaclass__.method_defined?(hidden_method)
end
def hidden_method
if RUBY_VERSION < '1.9'
method_name = method.to_s.gsub(/\W/) { |s| "_substituted_character_#{s[0]}_" }
else
method_name = method.to_s.gsub(/\W/) { |s| "_substituted_character_#{s.ord}_" }
end
"__stubba__#{method_name}__stubba__"
end
def eql?(other)
return false unless (other.class == self.class)
(stubbee == other.stubbee) and (method == other.method)
end
alias_method :==, :eql?
def to_s
"#{stubbee}.#{method}"
end
end
end

Просмотреть файл

@ -1,22 +0,0 @@
module Mocha
class Deprecation
class << self
attr_accessor :mode, :messages
def warning(message)
@messages << message
$stderr.puts "Mocha deprecation warning: #{message}" unless mode == :disabled
$stderr.puts caller.join("\n ") if mode == :debug
end
end
self.mode = :enabled
self.messages = []
end
end

Просмотреть файл

@ -1,17 +0,0 @@
module Mocha # :nodoc:
class ExceptionRaiser # :nodoc:
def initialize(exception, message)
@exception, @message = exception, message
end
def evaluate
raise @exception, @exception.to_s if @exception == Interrupt
raise @exception, @message if @message
raise @exception
end
end
end

Просмотреть файл

@ -1,384 +0,0 @@
require 'mocha/infinite_range'
require 'mocha/method_matcher'
require 'mocha/parameters_matcher'
require 'mocha/expectation_error'
require 'mocha/return_values'
require 'mocha/exception_raiser'
require 'mocha/yield_parameters'
require 'mocha/is_a'
module Mocha # :nodoc:
# Methods on expectations returned from Mock#expects, Mock#stubs, Object#expects and Object#stubs.
class Expectation
# :call-seq: times(range) -> expectation
#
# Modifies expectation so that the number of calls to the expected method must be within a specific +range+.
#
# +range+ can be specified as an exact integer or as a range of integers
# object = mock()
# object.expects(:expected_method).times(3)
# 3.times { object.expected_method }
# # => verify succeeds
#
# object = mock()
# object.expects(:expected_method).times(3)
# 2.times { object.expected_method }
# # => verify fails
#
# object = mock()
# object.expects(:expected_method).times(2..4)
# 3.times { object.expected_method }
# # => verify succeeds
#
# object = mock()
# object.expects(:expected_method).times(2..4)
# object.expected_method
# # => verify fails
def times(range)
@expected_count = range
self
end
# :call-seq: once() -> expectation
#
# Modifies expectation so that the expected method must be called exactly once.
# Note that this is the default behaviour for an expectation, but you may wish to use it for clarity/emphasis.
# object = mock()
# object.expects(:expected_method).once
# object.expected_method
# # => verify succeeds
#
# object = mock()
# object.expects(:expected_method).once
# object.expected_method
# object.expected_method
# # => verify fails
#
# object = mock()
# object.expects(:expected_method).once
# # => verify fails
def once()
times(1)
self
end
# :call-seq: never() -> expectation
#
# Modifies expectation so that the expected method must never be called.
# object = mock()
# object.expects(:expected_method).never
# object.expected_method
# # => verify fails
#
# object = mock()
# object.expects(:expected_method).never
# object.expected_method
# # => verify succeeds
def never
times(0)
self
end
# :call-seq: at_least(minimum_number_of_times) -> expectation
#
# Modifies expectation so that the expected method must be called at least a +minimum_number_of_times+.
# object = mock()
# object.expects(:expected_method).at_least(2)
# 3.times { object.expected_method }
# # => verify succeeds
#
# object = mock()
# object.expects(:expected_method).at_least(2)
# object.expected_method
# # => verify fails
def at_least(minimum_number_of_times)
times(Range.at_least(minimum_number_of_times))
self
end
# :call-seq: at_least_once() -> expectation
#
# Modifies expectation so that the expected method must be called at least once.
# object = mock()
# object.expects(:expected_method).at_least_once
# object.expected_method
# # => verify succeeds
#
# object = mock()
# object.expects(:expected_method).at_least_once
# # => verify fails
def at_least_once()
at_least(1)
self
end
# :call-seq: at_most(maximum_number_of_times) -> expectation
#
# Modifies expectation so that the expected method must be called at most a +maximum_number_of_times+.
# object = mock()
# object.expects(:expected_method).at_most(2)
# 2.times { object.expected_method }
# # => verify succeeds
#
# object = mock()
# object.expects(:expected_method).at_most(2)
# 3.times { object.expected_method }
# # => verify fails
def at_most(maximum_number_of_times)
times(Range.at_most(maximum_number_of_times))
self
end
# :call-seq: at_most_once() -> expectation
#
# Modifies expectation so that the expected method must be called at most once.
# object = mock()
# object.expects(:expected_method).at_most_once
# object.expected_method
# # => verify succeeds
#
# object = mock()
# object.expects(:expected_method).at_most_once
# 2.times { object.expected_method }
# # => verify fails
def at_most_once()
at_most(1)
self
end
# :call-seq: with(*expected_parameters, &matching_block) -> expectation
#
# Modifies expectation so that the expected method must be called with +expected_parameters+.
# object = mock()
# object.expects(:expected_method).with(:param1, :param2)
# object.expected_method(:param1, :param2)
# # => verify succeeds
#
# object = mock()
# object.expects(:expected_method).with(:param1, :param2)
# object.expected_method(:param3)
# # => verify fails
# May be used with parameter matchers in Mocha::ParameterMatchers.
#
# If a +matching_block+ is given, the block is called with the parameters passed to the expected method.
# The expectation is matched if the block evaluates to +true+.
# object = mock()
# object.expects(:expected_method).with() { |value| value % 4 == 0 }
# object.expected_method(16)
# # => verify succeeds
#
# object = mock()
# object.expects(:expected_method).with() { |value| value % 4 == 0 }
# object.expected_method(17)
# # => verify fails
def with(*expected_parameters, &matching_block)
@parameters_matcher = ParametersMatcher.new(expected_parameters, &matching_block)
self
end
# :call-seq: yields(*parameters) -> expectation
#
# Modifies expectation so that when the expected method is called, it yields with the specified +parameters+.
# object = mock()
# object.expects(:expected_method).yields('result')
# yielded_value = nil
# object.expected_method { |value| yielded_value = value }
# yielded_value # => 'result'
# May be called multiple times on the same expectation for consecutive invocations. Also see Expectation#then.
# object = mock()
# object.stubs(:expected_method).yields(1).then.yields(2)
# yielded_values_from_first_invocation = []
# yielded_values_from_second_invocation = []
# object.expected_method { |value| yielded_values_from_first_invocation << value } # first invocation
# object.expected_method { |value| yielded_values_from_second_invocation << value } # second invocation
# yielded_values_from_first_invocation # => [1]
# yielded_values_from_second_invocation # => [2]
def yields(*parameters)
@yield_parameters.add(*parameters)
self
end
# :call-seq: multiple_yields(*parameter_groups) -> expectation
#
# Modifies expectation so that when the expected method is called, it yields multiple times per invocation with the specified +parameter_groups+.
# object = mock()
# object.expects(:expected_method).multiple_yields(['result_1', 'result_2'], ['result_3'])
# yielded_values = []
# object.expected_method { |*values| yielded_values << values }
# yielded_values # => [['result_1', 'result_2'], ['result_3]]
# May be called multiple times on the same expectation for consecutive invocations. Also see Expectation#then.
# object = mock()
# object.stubs(:expected_method).multiple_yields([1, 2], [3]).then.multiple_yields([4], [5, 6])
# yielded_values_from_first_invocation = []
# yielded_values_from_second_invocation = []
# object.expected_method { |*values| yielded_values_from_first_invocation << values } # first invocation
# object.expected_method { |*values| yielded_values_from_second_invocation << values } # second invocation
# yielded_values_from_first_invocation # => [[1, 2], [3]]
# yielded_values_from_second_invocation # => [[4], [5, 6]]
def multiple_yields(*parameter_groups)
@yield_parameters.multiple_add(*parameter_groups)
self
end
# :call-seq: returns(value) -> expectation
# returns(*values) -> expectation
#
# Modifies expectation so that when the expected method is called, it returns the specified +value+.
# object = mock()
# object.stubs(:stubbed_method).returns('result')
# object.stubbed_method # => 'result'
# object.stubbed_method # => 'result'
# If multiple +values+ are given, these are returned in turn on consecutive calls to the method.
# object = mock()
# object.stubs(:stubbed_method).returns(1, 2)
# object.stubbed_method # => 1
# object.stubbed_method # => 2
# May be called multiple times on the same expectation. Also see Expectation#then.
# object = mock()
# object.stubs(:expected_method).returns(1, 2).then.returns(3)
# object.expected_method # => 1
# object.expected_method # => 2
# object.expected_method # => 3
# May be called in conjunction with Expectation#raises on the same expectation.
# object = mock()
# object.stubs(:expected_method).returns(1, 2).then.raises(Exception)
# object.expected_method # => 1
# object.expected_method # => 2
# object.expected_method # => raises exception of class Exception1
# If +value+ is a +Proc+, then the expected method will return the result of calling <tt>Proc#call</tt>.
#
# This usage is _deprecated_.
# Use explicit multiple return values and/or multiple expectations instead.
#
# A +Proc+ instance will be treated the same as any other value in a future release.
# object = mock()
# object.stubs(:stubbed_method).returns(lambda { rand(100) })
# object.stubbed_method # => 41
# object.stubbed_method # => 77
def returns(*values)
@return_values += ReturnValues.build(*values)
self
end
# :call-seq: raises(exception = RuntimeError, message = nil) -> expectation
#
# Modifies expectation so that when the expected method is called, it raises the specified +exception+ with the specified +message+.
# object = mock()
# object.expects(:expected_method).raises(Exception, 'message')
# object.expected_method # => raises exception of class Exception and with message 'message'
# May be called multiple times on the same expectation. Also see Expectation#then.
# object = mock()
# object.stubs(:expected_method).raises(Exception1).then.raises(Exception2)
# object.expected_method # => raises exception of class Exception1
# object.expected_method # => raises exception of class Exception2
# May be called in conjunction with Expectation#returns on the same expectation.
# object = mock()
# object.stubs(:expected_method).raises(Exception).then.returns(2, 3)
# object.expected_method # => raises exception of class Exception1
# object.expected_method # => 2
# object.expected_method # => 3
def raises(exception = RuntimeError, message = nil)
@return_values += ReturnValues.new(ExceptionRaiser.new(exception, message))
self
end
# :call-seq: then() -> expectation
#
# Syntactic sugar to improve readability. Has no effect on state of the expectation.
# object = mock()
# object.stubs(:expected_method).returns(1, 2).then.raises(Exception).then.returns(4)
# object.expected_method # => 1
# object.expected_method # => 2
# object.expected_method # => raises exception of class Exception
# object.expected_method # => 4
def then
self
end
# :stopdoc:
def in_sequence(*sequences)
sequences.each { |sequence| sequence.constrain_as_next_in_sequence(self) }
self
end
attr_reader :backtrace
def initialize(mock, expected_method_name, backtrace = nil)
@mock = mock
@method_matcher = MethodMatcher.new(expected_method_name)
@parameters_matcher = ParametersMatcher.new
@ordering_constraints = []
@expected_count, @invoked_count = 1, 0
@return_values = ReturnValues.new
@yield_parameters = YieldParameters.new
@backtrace = backtrace || caller
end
def add_ordering_constraint(ordering_constraint)
@ordering_constraints << ordering_constraint
end
def in_correct_order?
@ordering_constraints.all? { |ordering_constraint| ordering_constraint.allows_invocation_now? }
end
def matches_method?(method_name)
@method_matcher.match?(method_name)
end
def match?(actual_method_name, *actual_parameters)
@method_matcher.match?(actual_method_name) && @parameters_matcher.match?(actual_parameters) && in_correct_order?
end
def invocations_allowed?
if @expected_count.is_a?(Range) then
@invoked_count < @expected_count.last
else
@invoked_count < @expected_count
end
end
def satisfied?
if @expected_count.is_a?(Range) then
@invoked_count >= @expected_count.first
else
@invoked_count >= @expected_count
end
end
def invoke
@invoked_count += 1
if block_given? then
@yield_parameters.next_invocation.each do |yield_parameters|
yield(*yield_parameters)
end
end
@return_values.next
end
def verify
yield(self) if block_given?
unless (@expected_count === @invoked_count) then
error = ExpectationError.new(error_message(@expected_count, @invoked_count), backtrace)
raise error
end
end
def method_signature
signature = "#{@mock.mocha_inspect}.#{@method_matcher.mocha_inspect}#{@parameters_matcher.mocha_inspect}"
signature << "; #{@ordering_constraints.map { |oc| oc.mocha_inspect }.join("; ")}" unless @ordering_constraints.empty?
signature
end
def error_message(expected_count, actual_count)
"#{method_signature} - expected calls: #{expected_count.mocha_inspect}, actual calls: #{actual_count}"
end
# :startdoc:
end
end

Просмотреть файл

@ -1,15 +0,0 @@
module Mocha
class ExpectationError < StandardError
LIB_DIRECTORY = File.expand_path(File.join(File.dirname(__FILE__), "..")) + File::SEPARATOR
def initialize(message = nil, backtrace = [], lib_directory = LIB_DIRECTORY)
super(message)
filtered_backtrace = backtrace.reject { |location| Regexp.new(lib_directory).match(File.expand_path(location)) }
set_backtrace(filtered_backtrace)
end
end
end

Просмотреть файл

@ -1,46 +0,0 @@
module Mocha # :nodoc:
class ExpectationList
def initialize
@expectations = []
end
def add(expectation)
@expectations << expectation
expectation
end
def matches_method?(method_name)
@expectations.any? { |expectation| expectation.matches_method?(method_name) }
end
def similar(method_name)
@expectations.select { |expectation| expectation.matches_method?(method_name) }
end
def detect(method_name, *arguments)
expectations = @expectations.reverse.select { |e| e.match?(method_name, *arguments) }
expectation = expectations.detect { |e| e.invocations_allowed? }
expectation || expectations.first
end
def verify(&block)
@expectations.each { |expectation| expectation.verify(&block) }
end
def to_a
@expectations
end
def to_set
@expectations.to_set
end
def length
@expectations.length
end
end
end

Просмотреть файл

@ -1,25 +0,0 @@
class Range
def self.at_least(minimum_value)
Range.new(minimum_value, infinite)
end
def self.at_most(maximum_value)
Range.new(-infinite, maximum_value, false)
end
def self.infinite
1/0.0
end
def mocha_inspect
if first.respond_to?(:to_f) and first.to_f.infinite? then
return "at most #{last}"
elsif last.respond_to?(:to_f) and last.to_f.infinite? then
return "at least #{first}"
else
to_s
end
end
end

39
vendor/gems/mocha-0.5.6/lib/mocha/inspect.rb поставляемый
Просмотреть файл

@ -1,39 +0,0 @@
require 'date'
class Object
def mocha_inspect
address = self.__id__ * 2
address += 0x100000000 if address < 0
inspect =~ /#</ ? "#<#{self.class}:0x#{'%x' % address}>" : inspect
end
end
class String
def mocha_inspect
inspect.gsub(/\"/, "'")
end
end
class Array
def mocha_inspect
"[#{collect { |member| member.mocha_inspect }.join(', ')}]"
end
end
class Hash
def mocha_inspect
"{#{collect { |key, value| "#{key.mocha_inspect} => #{value.mocha_inspect}" }.join(', ')}}"
end
end
class Time
def mocha_inspect
"#{inspect} (#{to_f} secs)"
end
end
class Date
def mocha_inspect
to_s
end
end

Просмотреть файл

@ -1,8 +0,0 @@
require 'mocha/class_method'
module Mocha
class InstanceMethod < ClassMethod
end
end

9
vendor/gems/mocha-0.5.6/lib/mocha/is_a.rb поставляемый
Просмотреть файл

@ -1,9 +0,0 @@
class Object
# :stopdoc:
alias_method :__is_a__, :is_a?
# :startdoc:
end

Просмотреть файл

@ -1,7 +0,0 @@
class Object
def __metaclass__
class << self; self; end
end
end

Просмотреть файл

@ -1,21 +0,0 @@
module Mocha
class MethodMatcher
attr_reader :expected_method_name
def initialize(expected_method_name)
@expected_method_name = expected_method_name
end
def match?(actual_method_name)
@expected_method_name == actual_method_name
end
def mocha_inspect
"#{@expected_method_name}"
end
end
end

Просмотреть файл

@ -1,17 +0,0 @@
require 'mocha/expectation'
module Mocha # :nodoc:
class MissingExpectation < Expectation # :nodoc:
def verify
message = error_message(0, 1)
similar_expectations = @mock.expectations.similar(@method_matcher.expected_method_name)
method_signatures = similar_expectations.map { |expectation| expectation.method_signature }
message << "\nSimilar expectations:\n#{method_signatures.join("\n")}" unless method_signatures.empty?
raise ExpectationError.new(message, backtrace)
end
end
end

202
vendor/gems/mocha-0.5.6/lib/mocha/mock.rb поставляемый
Просмотреть файл

@ -1,202 +0,0 @@
require 'mocha/expectation'
require 'mocha/expectation_list'
require 'mocha/stub'
require 'mocha/missing_expectation'
require 'mocha/metaclass'
module Mocha # :nodoc:
# Traditional mock object.
#
# Methods return an Expectation which can be further modified by methods on Expectation.
class Mock
# :call-seq: expects(method_name) -> expectation
# expects(method_names) -> last expectation
#
# Adds an expectation that a method identified by +method_name+ symbol must be called exactly once with any parameters.
# Returns the new expectation which can be further modified by methods on Expectation.
# object = mock()
# object.expects(:method1)
# object.method1
# # no error raised
#
# object = mock()
# object.expects(:method1)
# # error raised, because method1 not called exactly once
# If +method_names+ is a +Hash+, an expectation will be set up for each entry using the key as +method_name+ and value as +return_value+.
# object = mock()
# object.expects(:method1 => :result1, :method2 => :result2)
#
# # exactly equivalent to
#
# object = mock()
# object.expects(:method1).returns(:result1)
# object.expects(:method2).returns(:result2)
#
# Aliased by <tt>\_\_expects\_\_</tt>
def expects(method_name_or_hash, backtrace = nil)
if method_name_or_hash.is_a?(Hash) then
method_name_or_hash.each do |method_name, return_value|
ensure_method_not_already_defined(method_name)
@expectations.add(Expectation.new(self, method_name, backtrace).returns(return_value))
end
else
ensure_method_not_already_defined(method_name_or_hash)
@expectations.add(Expectation.new(self, method_name_or_hash, backtrace))
end
end
# :call-seq: stubs(method_name) -> expectation
# stubs(method_names) -> last expectation
#
# Adds an expectation that a method identified by +method_name+ symbol may be called any number of times with any parameters.
# Returns the new expectation which can be further modified by methods on Expectation.
# object = mock()
# object.stubs(:method1)
# object.method1
# object.method1
# # no error raised
# If +method_names+ is a +Hash+, an expectation will be set up for each entry using the key as +method_name+ and value as +return_value+.
# object = mock()
# object.stubs(:method1 => :result1, :method2 => :result2)
#
# # exactly equivalent to
#
# object = mock()
# object.stubs(:method1).returns(:result1)
# object.stubs(:method2).returns(:result2)
#
# Aliased by <tt>\_\_stubs\_\_</tt>
def stubs(method_name_or_hash, backtrace = nil)
if method_name_or_hash.is_a?(Hash) then
method_name_or_hash.each do |method_name, return_value|
ensure_method_not_already_defined(method_name)
@expectations.add(Stub.new(self, method_name, backtrace).returns(return_value))
end
else
ensure_method_not_already_defined(method_name_or_hash)
@expectations.add(Stub.new(self, method_name_or_hash, backtrace))
end
end
# :call-seq: responds_like(responder) -> mock
#
# Constrains the +mock+ so that it can only expect or stub methods to which +responder+ responds. The constraint is only applied at method invocation time.
#
# A +NoMethodError+ will be raised if the +responder+ does not <tt>respond_to?</tt> a method invocation (even if the method has been expected or stubbed).
#
# The +mock+ will delegate its <tt>respond_to?</tt> method to the +responder+.
# class Sheep
# def chew(grass); end
# def self.number_of_legs; end
# end
#
# sheep = mock('sheep')
# sheep.expects(:chew)
# sheep.expects(:foo)
# sheep.respond_to?(:chew) # => true
# sheep.respond_to?(:foo) # => true
# sheep.chew
# sheep.foo
# # no error raised
#
# sheep = mock('sheep')
# sheep.responds_like(Sheep.new)
# sheep.expects(:chew)
# sheep.expects(:foo)
# sheep.respond_to?(:chew) # => true
# sheep.respond_to?(:foo) # => false
# sheep.chew
# sheep.foo # => raises NoMethodError exception
#
# sheep_class = mock('sheep_class')
# sheep_class.responds_like(Sheep)
# sheep_class.stubs(:number_of_legs).returns(4)
# sheep_class.expects(:foo)
# sheep_class.respond_to?(:number_of_legs) # => true
# sheep_class.respond_to?(:foo) # => false
# assert_equal 4, sheep_class.number_of_legs
# sheep_class.foo # => raises NoMethodError exception
#
# Aliased by +quacks_like+
def responds_like(object)
@responder = object
self
end
# :stopdoc:
def initialize(name = nil, &block)
@mock_name = name
@expectations = ExpectationList.new
@everything_stubbed = false
@responder = nil
instance_eval(&block) if block
end
attr_reader :everything_stubbed, :expectations
alias_method :__expects__, :expects
alias_method :__stubs__, :stubs
alias_method :quacks_like, :responds_like
def add_expectation(expectation)
@expectations.add(expectation)
end
def stub_everything
@everything_stubbed = true
end
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}"
end
matching_expectation = @expectations.detect(symbol, *arguments)
if matching_expectation then
matching_expectation.invoke(&block)
elsif @everything_stubbed then
return
else
unexpected_method_called(symbol, *arguments)
end
end
def respond_to?(symbol)
if @responder then
@responder.respond_to?(symbol)
else
@expectations.matches_method?(symbol)
end
end
def unexpected_method_called(symbol, *arguments)
MissingExpectation.new(self, symbol).with(*arguments).verify
end
def verify(&block)
@expectations.verify(&block)
end
def mocha_inspect
address = self.__id__ * 2
address += 0x100000000 if address < 0
@mock_name ? "#<Mock:#{@mock_name}>" : "#<Mock:0x#{'%x' % address}>"
end
def inspect
mocha_inspect
end
def ensure_method_not_already_defined(method_name)
self.__metaclass__.send(:undef_method, method_name) if self.__metaclass__.method_defined?(method_name)
end
# :startdoc:
end
end

Просмотреть файл

@ -1,20 +0,0 @@
module Mocha # :nodoc:
class MultipleYields # :nodoc:
attr_reader :parameter_groups
def initialize(*parameter_groups)
@parameter_groups = parameter_groups
end
def each
@parameter_groups.each do |parameter_group|
yield(parameter_group)
end
end
end
end

Просмотреть файл

@ -1,11 +0,0 @@
module Mocha # :nodoc:
class NoYields # :nodoc:
def each
end
end
end

110
vendor/gems/mocha-0.5.6/lib/mocha/object.rb поставляемый
Просмотреть файл

@ -1,110 +0,0 @@
require 'mocha/mock'
require 'mocha/instance_method'
require 'mocha/class_method'
require 'mocha/any_instance_method'
# Methods added all objects to allow mocking and stubbing on real objects.
#
# Methods return a Mocha::Expectation which can be further modified by methods on Mocha::Expectation.
class Object
def mocha # :nodoc:
@mocha ||= Mocha::Mock.new
end
def reset_mocha # :nodoc:
@mocha = nil
end
def stubba_method # :nodoc:
Mocha::InstanceMethod
end
def stubba_object # :nodoc:
self
end
# :call-seq: expects(symbol) -> expectation
#
# Adds an expectation that a method identified by +symbol+ must be called exactly once with any parameters.
# Returns the new expectation which can be further modified by methods on Mocha::Expectation.
# product = Product.new
# product.expects(:save).returns(true)
# assert_equal false, product.save
#
# The original implementation of <tt>Product#save</tt> is replaced temporarily.
#
# The original implementation of <tt>Product#save</tt> is restored at the end of the test.
def expects(symbol)
method = stubba_method.new(stubba_object, symbol)
$stubba.stub(method)
mocha.expects(symbol, caller)
end
# :call-seq: stubs(symbol) -> expectation
#
# Adds an expectation that a method identified by +symbol+ may be called any number of times with any parameters.
# Returns the new expectation which can be further modified by methods on Mocha::Expectation.
# product = Product.new
# product.stubs(:save).returns(true)
# assert_equal false, product.save
#
# The original implementation of <tt>Product#save</tt> is replaced temporarily.
#
# The original implementation of <tt>Product#save</tt> is restored at the end of the test.
def stubs(symbol)
method = stubba_method.new(stubba_object, symbol)
$stubba.stub(method)
mocha.stubs(symbol, caller)
end
def verify # :nodoc:
mocha.verify
end
end
class Module # :nodoc:
def stubba_method
Mocha::ClassMethod
end
end
class Class
def stubba_method # :nodoc:
Mocha::ClassMethod
end
class AnyInstance # :nodoc:
def initialize(klass)
@stubba_object = klass
end
def stubba_method
Mocha::AnyInstanceMethod
end
def stubba_object
@stubba_object
end
end
# :call-seq: any_instance -> mock object
#
# Returns a mock object which will detect calls to any instance of this class.
# Product.any_instance.stubs(:save).returns(false)
# product_1 = Product.new
# assert_equal false, product_1.save
# product_2 = Product.new
# assert_equal false, product_2.save
def any_instance
@any_instance ||= AnyInstance.new(self)
end
end

Просмотреть файл

@ -1,25 +0,0 @@
module Mocha
# Used as parameters for Expectation#with to restrict the parameter values which will match the expectation.
module ParameterMatchers; end
end
require 'mocha/parameter_matchers/object'
require 'mocha/parameter_matchers/all_of'
require 'mocha/parameter_matchers/any_of'
require 'mocha/parameter_matchers/any_parameters'
require 'mocha/parameter_matchers/anything'
require 'mocha/parameter_matchers/equals'
require 'mocha/parameter_matchers/has_entry'
require 'mocha/parameter_matchers/has_entries'
require 'mocha/parameter_matchers/has_key'
require 'mocha/parameter_matchers/has_value'
require 'mocha/parameter_matchers/includes'
require 'mocha/parameter_matchers/instance_of'
require 'mocha/parameter_matchers/is_a'
require 'mocha/parameter_matchers/kind_of'
require 'mocha/parameter_matchers/not'
require 'mocha/parameter_matchers/optionally'
require 'mocha/parameter_matchers/regexp_matches'

Двоичные данные
vendor/gems/mocha-0.5.6/lib/mocha/parameter_matchers/._all_of.rb поставляемый

Двоичный файл не отображается.

Двоичные данные
vendor/gems/mocha-0.5.6/lib/mocha/parameter_matchers/._any_of.rb поставляемый

Двоичный файл не отображается.

Двоичные данные
vendor/gems/mocha-0.5.6/lib/mocha/parameter_matchers/._any_parameters.rb поставляемый

Двоичный файл не отображается.

Двоичные данные
vendor/gems/mocha-0.5.6/lib/mocha/parameter_matchers/._anything.rb поставляемый

Двоичный файл не отображается.

Двоичные данные
vendor/gems/mocha-0.5.6/lib/mocha/parameter_matchers/._base.rb поставляемый

Двоичный файл не отображается.

Двоичные данные
vendor/gems/mocha-0.5.6/lib/mocha/parameter_matchers/._equals.rb поставляемый

Двоичный файл не отображается.

Двоичные данные
vendor/gems/mocha-0.5.6/lib/mocha/parameter_matchers/._has_entries.rb поставляемый

Двоичный файл не отображается.

Двоичные данные
vendor/gems/mocha-0.5.6/lib/mocha/parameter_matchers/._has_entry.rb поставляемый

Двоичный файл не отображается.

Двоичные данные
vendor/gems/mocha-0.5.6/lib/mocha/parameter_matchers/._has_key.rb поставляемый

Двоичный файл не отображается.

Двоичные данные
vendor/gems/mocha-0.5.6/lib/mocha/parameter_matchers/._has_value.rb поставляемый

Двоичный файл не отображается.

Двоичные данные
vendor/gems/mocha-0.5.6/lib/mocha/parameter_matchers/._includes.rb поставляемый

Двоичный файл не отображается.

Двоичные данные
vendor/gems/mocha-0.5.6/lib/mocha/parameter_matchers/._instance_of.rb поставляемый

Двоичный файл не отображается.

Двоичные данные
vendor/gems/mocha-0.5.6/lib/mocha/parameter_matchers/._is_a.rb поставляемый

Двоичный файл не отображается.

Двоичные данные
vendor/gems/mocha-0.5.6/lib/mocha/parameter_matchers/._kind_of.rb поставляемый

Двоичный файл не отображается.

Двоичные данные
vendor/gems/mocha-0.5.6/lib/mocha/parameter_matchers/._not.rb поставляемый

Двоичный файл не отображается.

Двоичные данные
vendor/gems/mocha-0.5.6/lib/mocha/parameter_matchers/._object.rb поставляемый

Двоичный файл не отображается.

Двоичные данные
vendor/gems/mocha-0.5.6/lib/mocha/parameter_matchers/._optionally.rb поставляемый

Двоичный файл не отображается.

Двоичные данные
vendor/gems/mocha-0.5.6/lib/mocha/parameter_matchers/._regexp_matches.rb поставляемый

Двоичный файл не отображается.

Просмотреть файл

@ -1,42 +0,0 @@
require 'mocha/parameter_matchers/base'
module Mocha
module ParameterMatchers
# :call-seq: all_of -> parameter_matcher
#
# Matches if all +matchers+ match.
# object = mock()
# object.expects(:method_1).with(all_of(includes(1), includes(3)))
# object.method_1([1, 3])
# # no error raised
#
# object = mock()
# object.expects(:method_1).with(all_of(includes(1), includes(3)))
# object.method_1([1, 2])
# # error raised, because method_1 was not called with object including 1 and 3
def all_of(*matchers)
AllOf.new(*matchers)
end
class AllOf < Base # :nodoc:
def initialize(*matchers)
@matchers = matchers
end
def matches?(available_parameters)
parameter = available_parameters.shift
@matchers.all? { |matcher| matcher.matches?([parameter]) }
end
def mocha_inspect
"all_of(#{@matchers.map { |matcher| matcher.mocha_inspect }.join(", ") })"
end
end
end
end

Просмотреть файл

@ -1,47 +0,0 @@
require 'mocha/parameter_matchers/base'
module Mocha
module ParameterMatchers
# :call-seq: any_of -> parameter_matcher
#
# Matches if any +matchers+ match.
# object = mock()
# object.expects(:method_1).with(any_of(1, 3))
# object.method_1(1)
# # no error raised
#
# object = mock()
# object.expects(:method_1).with(any_of(1, 3))
# object.method_1(3)
# # no error raised
#
# object = mock()
# object.expects(:method_1).with(any_of(1, 3))
# object.method_1(2)
# # error raised, because method_1 was not called with 1 or 3
def any_of(*matchers)
AnyOf.new(*matchers)
end
class AnyOf < Base # :nodoc:
def initialize(*matchers)
@matchers = matchers
end
def matches?(available_parameters)
parameter = available_parameters.shift
@matchers.any? { |matcher| matcher.matches?([parameter]) }
end
def mocha_inspect
"any_of(#{@matchers.map { |matcher| matcher.mocha_inspect }.join(", ") })"
end
end
end
end

Просмотреть файл

@ -1,40 +0,0 @@
require 'mocha/parameter_matchers/base'
module Mocha
module ParameterMatchers
# :call-seq: any_parameters() -> parameter_matcher
#
# Matches any parameters.
# object = mock()
# object.expects(:method_1).with(any_parameters)
# object.method_1(1, 2, 3, 4)
# # no error raised
#
# object = mock()
# object.expects(:method_1).with(any_parameters)
# object.method_1(5, 6, 7, 8, 9, 0)
# # no error raised
def any_parameters
AnyParameters.new
end
class AnyParameters < Base # :nodoc:
def matches?(available_parameters)
while available_parameters.length > 0 do
available_parameters.shift
end
return true
end
def mocha_inspect
"any_parameters"
end
end
end
end

Просмотреть файл

@ -1,33 +0,0 @@
require 'mocha/parameter_matchers/base'
module Mocha
module ParameterMatchers
# :call-seq: anything -> parameter_matcher
#
# Matches any object.
# object = mock()
# object.expects(:method_1).with(anything)
# object.method_1('foo')
# # no error raised
def anything
Anything.new
end
class Anything < Base # :nodoc:
def matches?(available_parameters)
available_parameters.shift
return true
end
def mocha_inspect
"anything"
end
end
end
end

Просмотреть файл

@ -1,15 +0,0 @@
module Mocha
module ParameterMatchers
class Base # :nodoc:
def to_matcher
self
end
end
end
end

Просмотреть файл

@ -1,42 +0,0 @@
require 'mocha/parameter_matchers/base'
module Mocha
module ParameterMatchers
# :call-seq: equals(value) -> parameter_matcher
#
# Matches +Object+ equalling +value+.
# object = mock()
# object.expects(:method_1).with(equals(2))
# object.method_1(2)
# # no error raised
#
# object = mock()
# object.expects(:method_1).with(equals(2))
# object.method_1(3)
# # error raised, because method_1 was not called with Object equalling 3
def equals(value)
Equals.new(value)
end
class Equals < Base # :nodoc:
def initialize(value)
@value = value
end
def matches?(available_parameters)
parameter = available_parameters.shift
parameter == @value
end
def mocha_inspect
@value.mocha_inspect
end
end
end
end

Просмотреть файл

@ -1,42 +0,0 @@
require 'mocha/parameter_matchers/base'
module Mocha
module ParameterMatchers
# :call-seq: has_entries(entries) -> parameter_matcher
#
# Matches +Hash+ containing all +entries+.
# object = mock()
# object.expects(:method_1).with(has_entries('key_1' => 1, 'key_2' => 2))
# object.method_1('key_1' => 1, 'key_2' => 2, 'key_3' => 3)
# # no error raised
#
# object = mock()
# object.expects(:method_1).with(has_entries('key_1' => 1, 'key_2' => 2))
# object.method_1('key_1' => 1, 'key_2' => 99)
# # error raised, because method_1 was not called with Hash containing entries: 'key_1' => 1, 'key_2' => 2
def has_entries(entries)
HasEntries.new(entries)
end
class HasEntries < Base # :nodoc:
def initialize(entries)
@entries = entries
end
def matches?(available_parameters)
parameter = available_parameters.shift
@entries.all? { |key, value| parameter[key] == value }
end
def mocha_inspect
"has_entries(#{@entries.mocha_inspect})"
end
end
end
end

Просмотреть файл

@ -1,55 +0,0 @@
require 'mocha/parameter_matchers/base'
module Mocha
module ParameterMatchers
# :call-seq: has_entry(key, value) -> parameter_matcher
# has_entry(key => value) -> parameter_matcher
#
# Matches +Hash+ containing entry with +key+ and +value+.
# object = mock()
# object.expects(:method_1).with(has_entry('key_1', 1))
# object.method_1('key_1' => 1, 'key_2' => 2)
# # no error raised
#
# object = mock()
# object.expects(:method_1).with(has_entry('key_1' => 1))
# object.method_1('key_1' => 1, 'key_2' => 2)
# # no error raised
#
# object = mock()
# object.expects(:method_1).with(has_entry('key_1', 1))
# object.method_1('key_1' => 2, 'key_2' => 1)
# # error raised, because method_1 was not called with Hash containing entry: 'key_1' => 1
#
# object = mock()
# object.expects(:method_1).with(has_entry('key_1' => 1))
# object.method_1('key_1' => 2, 'key_2' => 1)
# # error raised, because method_1 was not called with Hash containing entry: 'key_1' => 1
def has_entry(*options)
key, value = options.shift, options.shift
key, value = key.to_a[0][0..1] if key.is_a?(Hash)
HasEntry.new(key, value)
end
class HasEntry < Base # :nodoc:
def initialize(key, value)
@key, @value = key, value
end
def matches?(available_parameters)
parameter = available_parameters.shift
parameter[@key] == @value
end
def mocha_inspect
"has_entry(#{@key.mocha_inspect}, #{@value.mocha_inspect})"
end
end
end
end

Просмотреть файл

@ -1,42 +0,0 @@
require 'mocha/parameter_matchers/base'
module Mocha
module ParameterMatchers
# :call-seq: has_key(key) -> parameter_matcher
#
# Matches +Hash+ containing +key+.
# object = mock()
# object.expects(:method_1).with(has_key('key_1'))
# object.method_1('key_1' => 1, 'key_2' => 2)
# # no error raised
#
# object = mock()
# object.expects(:method_1).with(has_key('key_1'))
# object.method_1('key_2' => 2)
# # error raised, because method_1 was not called with Hash containing key: 'key_1'
def has_key(key)
HasKey.new(key)
end
class HasKey < Base # :nodoc:
def initialize(key)
@key = key
end
def matches?(available_parameters)
parameter = available_parameters.shift
parameter.keys.include?(@key)
end
def mocha_inspect
"has_key(#{@key.mocha_inspect})"
end
end
end
end

Просмотреть файл

@ -1,42 +0,0 @@
require 'mocha/parameter_matchers/base'
module Mocha
module ParameterMatchers
# :call-seq: has_value(value) -> parameter_matcher
#
# Matches +Hash+ containing +value+.
# object = mock()
# object.expects(:method_1).with(has_value(1))
# object.method_1('key_1' => 1, 'key_2' => 2)
# # no error raised
#
# object = mock()
# object.expects(:method_1).with(has_value(1))
# object.method_1('key_2' => 2)
# # error raised, because method_1 was not called with Hash containing value: 1
def has_value(value)
HasValue.new(value)
end
class HasValue < Base # :nodoc:
def initialize(value)
@value = value
end
def matches?(available_parameters)
parameter = available_parameters.shift
parameter.values.include?(@value)
end
def mocha_inspect
"has_value(#{@value.mocha_inspect})"
end
end
end
end

Просмотреть файл

@ -1,40 +0,0 @@
require 'mocha/parameter_matchers/base'
module Mocha
module ParameterMatchers
# :call-seq: includes(item) -> parameter_matcher
#
# Matches any object that responds true to include?(item)
# object = mock()
# object.expects(:method_1).with(includes('foo'))
# object.method_1(['foo', 'bar'])
# # no error raised
#
# object.method_1(['baz'])
# # error raised, because ['baz'] does not include 'foo'.
def includes(item)
Includes.new(item)
end
class Includes < Base # :nodoc:
def initialize(item)
@item = item
end
def matches?(available_parameters)
parameter = available_parameters.shift
return parameter.include?(@item)
end
def mocha_inspect
"includes(#{@item.mocha_inspect})"
end
end
end
end

Просмотреть файл

@ -1,42 +0,0 @@
require 'mocha/parameter_matchers/base'
module Mocha
module ParameterMatchers
# :call-seq: instance_of(klass) -> parameter_matcher
#
# Matches any object that is an instance of +klass+
# object = mock()
# object.expects(:method_1).with(instance_of(String))
# object.method_1('string')
# # no error raised
#
# object = mock()
# object.expects(:method_1).with(instance_of(String))
# object.method_1(99)
# # error raised, because method_1 was not called with an instance of String
def instance_of(klass)
InstanceOf.new(klass)
end
class InstanceOf < Base # :nodoc:
def initialize(klass)
@klass = klass
end
def matches?(available_parameters)
parameter = available_parameters.shift
parameter.instance_of?(@klass)
end
def mocha_inspect
"instance_of(#{@klass.mocha_inspect})"
end
end
end
end

Просмотреть файл

@ -1,42 +0,0 @@
require 'mocha/parameter_matchers/base'
module Mocha
module ParameterMatchers
# :call-seq: is_a(klass) -> parameter_matcher
#
# Matches any object that is a +klass+
# object = mock()
# object.expects(:method_1).with(is_a(Integer))
# object.method_1(99)
# # no error raised
#
# object = mock()
# object.expects(:method_1).with(is_a(Integer))
# object.method_1('string')
# # error raised, because method_1 was not called with an Integer
def is_a(klass)
IsA.new(klass)
end
class IsA < Base # :nodoc:
def initialize(klass)
@klass = klass
end
def matches?(available_parameters)
parameter = available_parameters.shift
parameter.is_a?(@klass)
end
def mocha_inspect
"is_a(#{@klass.mocha_inspect})"
end
end
end
end

Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше