diff --git a/test/system_timer_test.rb b/test/system_timer_test.rb index f52b7ea..e948ff0 100644 --- a/test/system_timer_test.rb +++ b/test/system_timer_test.rb @@ -1,7 +1,7 @@ $: << File.dirname(__FILE__) + '/../lib' $: << File.dirname(__FILE__) + '/../ext/system_timer' - $: << File.dirname(__FILE__) + "/../../../vendor/gems/dust-0.1.4/lib" - $: << File.dirname(__FILE__) + "/../../../vendor/gems/mocha-0.5.3/lib" + $: << File.dirname(__FILE__) + "/../vendor/gems/dust-0.1.6/lib" + $: << File.dirname(__FILE__) + "/../vendor/gems/mocha-0.9.1/lib" require 'test/unit' require 'system_timer' require 'dust' diff --git a/vendor/gems/dust-0.1.6/README b/vendor/gems/dust-0.1.6/README new file mode 100644 index 0000000..17c9365 --- /dev/null +++ b/vendor/gems/dust-0.1.6/README @@ -0,0 +1,35 @@ += Dust + +Dust adds descriptive block syntax test definition. + +by Jay[http://blog.jayfields.com] Fields[http://blog.jayfields.com] + +== Download and Installation + +You can download Dust from here[http://rubyforge.org/projects/dust] or install it with the following command. + + $ gem install dust + +== License + +You may use, copy and redistribute this library under the same terms as Ruby itself (see http://www.ruby-lang.org/en/LICENSE.txt). + +== Examples + + unit_tests do + + test "assert true" do + assert_equal true, true + end + + end + +See the tests for more examples + +== IDE specific files + +You can download TextMate and JEdit Run Focused Test Commands from http://rubyforge.org/projects/dust/ (in Files) + +== Contributors + +Dan Manges, David Vollbracht, Shane Harvie \ No newline at end of file diff --git a/vendor/gems/dust-0.1.6/lib/array_extension.rb b/vendor/gems/dust-0.1.6/lib/array_extension.rb new file mode 100644 index 0000000..3f60304 --- /dev/null +++ b/vendor/gems/dust-0.1.6/lib/array_extension.rb @@ -0,0 +1,5 @@ +class Array #:nodoc: + def arrayize + self + end +end \ No newline at end of file diff --git a/vendor/gems/dust-0.1.6/lib/definition_error.rb b/vendor/gems/dust-0.1.6/lib/definition_error.rb new file mode 100644 index 0000000..cea0715 --- /dev/null +++ b/vendor/gems/dust-0.1.6/lib/definition_error.rb @@ -0,0 +1,20 @@ +module Dust #:nodoc: + # Dust::DefinitionError is raised when you attempt to define a disallowed method within a test file. + # + # Test::Unit::TestCase.disallow_setup! + # + # unit_tests do + # def setup + # ... + # end + # + # test "name" do + # ... + # end + # end + # + # The above code will generate the following error + # Dust::DefinitionError: setup is not allowed on class Units::[TestClassName] + class DefinitionError < StandardError + end +end \ No newline at end of file diff --git a/vendor/gems/dust-0.1.6/lib/dust.rb b/vendor/gems/dust-0.1.6/lib/dust.rb new file mode 100644 index 0000000..94e6863 --- /dev/null +++ b/vendor/gems/dust-0.1.6/lib/dust.rb @@ -0,0 +1,8 @@ +require 'test/unit' +require File.expand_path(File.dirname(__FILE__) + '/object_extension') +require File.expand_path(File.dirname(__FILE__) + '/array_extension') +require File.expand_path(File.dirname(__FILE__) + '/nil_extension') +require File.expand_path(File.dirname(__FILE__) + '/string_extension') +require File.expand_path(File.dirname(__FILE__) + '/symbol_extension') +require File.expand_path(File.dirname(__FILE__) + '/test_case_extension') +require File.expand_path(File.dirname(__FILE__) + '/definition_error') \ No newline at end of file diff --git a/vendor/gems/dust-0.1.6/lib/nil_extension.rb b/vendor/gems/dust-0.1.6/lib/nil_extension.rb new file mode 100644 index 0000000..11b519b --- /dev/null +++ b/vendor/gems/dust-0.1.6/lib/nil_extension.rb @@ -0,0 +1,5 @@ +class NilClass #:nodoc: + def arrayize + [] + end +end \ No newline at end of file diff --git a/vendor/gems/dust-0.1.6/lib/object_extension.rb b/vendor/gems/dust-0.1.6/lib/object_extension.rb new file mode 100644 index 0000000..de1d587 --- /dev/null +++ b/vendor/gems/dust-0.1.6/lib/object_extension.rb @@ -0,0 +1,62 @@ +class Object + # call-seq: unit_tests(options={}, &block) + # + # Used to define a block of unit tests. + # + # unit_tests do + # test "verify something" do + # ... + # end + # end + # + # Configuration Options: + # * allow - Allows you to specify the methods that are allowed despite being disallowed. + # See Test::Unit::TestCase.disallow_helpers! or Test::Unit::TestCase.disallow_setup! for more info + def unit_tests(options={}, &block) + do_tests("Units", options, &block) + end + + # call-seq: functional_tests(options={}, &block) + # + # Used to define a block of functional tests. + # + # functional_tests do + # test "verify something" do + # ... + # end + # end + # + # Configuration Options: + # * allow - Allows you to specify the methods that are allowed despite being disallowed. + # See Test::Unit::TestCase.disallow_helpers! or Test::Unit::TestCase.disallow_setup! for more info + def functional_tests(options={}, &block) + do_tests("Functionals", options, &block) + end + + protected + def do_tests(type, options, &block) #:nodoc: + options[:allow] = options[:allow].arrayize + full_path_file_name = eval "__FILE__", block.binding + test_name = File.basename(full_path_file_name, ".rb") + test_class = eval "module #{type}; class #{test_name.to_class_name} < Test::Unit::TestCase; self; end; end" + test_class.class_eval &block + check_for_setup(test_class, options) + check_for_helpers(test_class, options) + end + + def check_for_setup(test_class, options) #:nodoc: + if test_class.instance_methods(false).include?("setup") && Test::Unit::TestCase.disallow_setup? && + !options[:allow].include?(:setup) + raise Dust::DefinitionError.new("setup is not allowed on class #{test_class.name}") + end + end + + def check_for_helpers(test_class, options) #:nodoc: + test_class.instance_methods(false).each do |method_name| + if method_name !~ /^test_/ && Test::Unit::TestCase.disallow_helpers? && !options[:allow].include?(method_name.to_sym) + p method_name.to_sym + raise Dust::DefinitionError.new("helper methods are not allowed on class #{test_class.name}") + end + end + end +end \ No newline at end of file diff --git a/vendor/gems/dust-0.1.6/lib/string_extension.rb b/vendor/gems/dust-0.1.6/lib/string_extension.rb new file mode 100644 index 0000000..8756ec0 --- /dev/null +++ b/vendor/gems/dust-0.1.6/lib/string_extension.rb @@ -0,0 +1,5 @@ +class String #:nodoc: + def to_class_name + gsub(/(^|_)(.)/) { $2.upcase } + end +end diff --git a/vendor/gems/dust-0.1.6/lib/symbol_extension.rb b/vendor/gems/dust-0.1.6/lib/symbol_extension.rb new file mode 100644 index 0000000..1ff9448 --- /dev/null +++ b/vendor/gems/dust-0.1.6/lib/symbol_extension.rb @@ -0,0 +1,5 @@ +class Symbol #:nodoc: + def arrayize + [self] + end +end \ No newline at end of file diff --git a/vendor/gems/dust-0.1.6/lib/test_case_extension.rb b/vendor/gems/dust-0.1.6/lib/test_case_extension.rb new file mode 100644 index 0000000..9c6f4b3 --- /dev/null +++ b/vendor/gems/dust-0.1.6/lib/test_case_extension.rb @@ -0,0 +1,76 @@ +module Test #:nodoc: + module Unit #:nodoc: + class TestCase + # call-seq: disallow_setup! + # + # Used to disallow setup methods in test specifications. + # + # Test::Unit::TestCase.disallow_setup! + # + # A test specification can override this behavior by passing :setup in the :allow options. + # + # unit_tests :allow => :setup do + # def setup + # ... + # end + # + # test "verify something" do + # ... + # end + # end + def self.disallow_setup! + @disallow_setup = true + end + + def self.disallow_setup? #:nodoc: + @disallow_setup + end + + # call-seq: disallow_helpers! + # + # Used to disallow helper methods in test specifications. + # + # Test::Unit::TestCase.disallow_helper! + # + # A test specification can override this behavior by passing the helper name (as a symbol) in the :allow options. + # + # unit_tests :allow => [:create_something, :destroy_something] do + # test "verify something" do + # ... + # end + # + # def create_something + # ... + # end + # + # def destroy_something + # ... + # end + # end + def self.disallow_helpers! + @disallow_helpers = true + end + + def self.disallow_helpers? #:nodoc: + @disallow_helpers + end + + # call-seq: test(name, &block) + # + # Used to define a test and assign it a descriptive name. + # + # unit_tests do + # test "verify something" do + # ... + # end + # end + def self.test(name, &block) + test_name = "test_#{name.gsub(/[\s]/,'_')}".to_sym + raise "#{test_name} is already defined in #{self}" if self.instance_methods.include? test_name.to_s + define_method test_name do + instance_eval &block + end + end + end + end +end \ No newline at end of file diff --git a/vendor/gems/dust-0.1.6/rakefile.rb b/vendor/gems/dust-0.1.6/rakefile.rb new file mode 100644 index 0000000..81cd5f3 --- /dev/null +++ b/vendor/gems/dust-0.1.6/rakefile.rb @@ -0,0 +1,50 @@ +require 'rubygems' +require 'rake/gempackagetask' +require 'rake/rdoctask' +require 'rake/contrib/sshpublisher' + +task :default => :test + +task :test do + require File.dirname(__FILE__) + '/test/all_tests.rb' +end + +desc 'Generate RDoc' +Rake::RDocTask.new do |task| + task.main = 'README' + task.title = 'Dust' + task.rdoc_dir = 'doc' + task.options << "--line-numbers" << "--inline-source" + task.rdoc_files.include('README', 'lib/**/*.rb') +end + +desc "Upload RDoc to RubyForge" +task :publish_rdoc => [:rdoc] do + Rake::SshDirPublisher.new("jaycfields@rubyforge.org", "/var/www/gforge-projects/dust", "doc").upload +end + +Gem::manage_gems + +specification = Gem::Specification.new do |s| + s.name = "dust" + s.summary = "Dust is an add on for Test::Unit that allows an alternative test definintion syntax." + s.version = "0.1.6" + s.author = 'Jay Fields' + s.description = "Dust is an add on for Test::Unit that allows an alternative test definintion syntax." + s.email = 'dust-developer@rubyforge.org' + s.homepage = 'http://dust.rubyforge.org' + s.rubyforge_project = 'dust' + + s.has_rdoc = true + s.extra_rdoc_files = ['README'] + s.rdoc_options << '--title' << 'Dust' << '--main' << 'README' << '--line-numbers' + + s.autorequire = 'dust' + s.files = FileList['{lib,test}/**/*.rb', '[A-Z]*$', 'rakefile.rb'].to_a + s.test_file = "test/all_tests.rb" +end + +Rake::GemPackageTask.new(specification) do |package| + package.need_zip = false + package.need_tar = false +end \ No newline at end of file diff --git a/vendor/gems/dust-0.1.6/test/all_tests.rb b/vendor/gems/dust-0.1.6/test/all_tests.rb new file mode 100644 index 0000000..3697ba5 --- /dev/null +++ b/vendor/gems/dust-0.1.6/test/all_tests.rb @@ -0,0 +1 @@ +Dir['**/*_test.rb'].each { |test_case| require test_case } \ No newline at end of file diff --git a/vendor/gems/dust-0.1.6/test/failing_with_helper_unit_test.rb b/vendor/gems/dust-0.1.6/test/failing_with_helper_unit_test.rb new file mode 100644 index 0000000..f8363e9 --- /dev/null +++ b/vendor/gems/dust-0.1.6/test/failing_with_helper_unit_test.rb @@ -0,0 +1,16 @@ +require File.expand_path(File.dirname(__FILE__) + "/test_helper") + +begin + unit_tests do + Test::Unit::TestCase.disallow_helpers! + def helper_method + end + + test("true"){} + end + raise "shouldn't be here" +rescue Dust::DefinitionError => ex + raise unless ex.message == "helper methods are not allowed on class Units::FailingWithHelperUnitTest" +ensure + Test::Unit::TestCase.class_eval { @disallow_helpers = nil } +end \ No newline at end of file diff --git a/vendor/gems/dust-0.1.6/test/failing_with_setup_unit_test.rb b/vendor/gems/dust-0.1.6/test/failing_with_setup_unit_test.rb new file mode 100644 index 0000000..1935856 --- /dev/null +++ b/vendor/gems/dust-0.1.6/test/failing_with_setup_unit_test.rb @@ -0,0 +1,16 @@ +require File.expand_path(File.dirname(__FILE__) + "/test_helper") + +begin + unit_tests do + Test::Unit::TestCase.disallow_setup! + def setup + end + + test("true"){} + end + raise "shouldn't be here" +rescue Dust::DefinitionError => ex + raise unless ex.message == "setup is not allowed on class Units::FailingWithSetupUnitTest" +ensure + Test::Unit::TestCase.class_eval { @disallow_setup = nil } +end \ No newline at end of file diff --git a/vendor/gems/dust-0.1.6/test/functional_test.rb b/vendor/gems/dust-0.1.6/test/functional_test.rb new file mode 100644 index 0000000..64fedd2 --- /dev/null +++ b/vendor/gems/dust-0.1.6/test/functional_test.rb @@ -0,0 +1,12 @@ +require File.expand_path(File.dirname(__FILE__) + "/test_helper") + +functional_tests do + test "assert true" do + assert_equal true, true + end + + test "class name is Functionals::FunctionalTest" do + assert_equal "Functionals::FunctionalTest", self.class.name + end + +end \ No newline at end of file diff --git a/vendor/gems/dust-0.1.6/test/passing_unit_test.rb b/vendor/gems/dust-0.1.6/test/passing_unit_test.rb new file mode 100644 index 0000000..7362bb7 --- /dev/null +++ b/vendor/gems/dust-0.1.6/test/passing_unit_test.rb @@ -0,0 +1,11 @@ +require File.expand_path(File.dirname(__FILE__) + "/test_helper") + +unit_tests do + test "assert true" do + assert_equal true, true + end + + test "class name is Units::PassingUnitTest" do + assert_equal "Units::PassingUnitTest", self.class.name + end +end \ No newline at end of file diff --git a/vendor/gems/dust-0.1.6/test/passing_with_helper_unit_test.rb b/vendor/gems/dust-0.1.6/test/passing_with_helper_unit_test.rb new file mode 100644 index 0000000..d6208df --- /dev/null +++ b/vendor/gems/dust-0.1.6/test/passing_with_helper_unit_test.rb @@ -0,0 +1,10 @@ +require File.expand_path(File.dirname(__FILE__) + "/test_helper") + +Test::Unit::TestCase.disallow_helpers! +unit_tests :allow => :helper do + def helper + end + + test("true"){} +end +Test::Unit::TestCase.class_eval { @disallow_helpers = nil } \ No newline at end of file diff --git a/vendor/gems/dust-0.1.6/test/passing_with_helpers_unit_test.rb b/vendor/gems/dust-0.1.6/test/passing_with_helpers_unit_test.rb new file mode 100644 index 0000000..eaaafb1 --- /dev/null +++ b/vendor/gems/dust-0.1.6/test/passing_with_helpers_unit_test.rb @@ -0,0 +1,13 @@ +require File.expand_path(File.dirname(__FILE__) + "/test_helper") + +Test::Unit::TestCase.disallow_helpers! +unit_tests :allow => [:helper, :helper2] do + def helper + end + + def helper2 + end + + test("true"){} +end +Test::Unit::TestCase.class_eval { @disallow_helpers = nil } \ No newline at end of file diff --git a/vendor/gems/dust-0.1.6/test/passing_with_setup_unit_test.rb b/vendor/gems/dust-0.1.6/test/passing_with_setup_unit_test.rb new file mode 100644 index 0000000..5f2de9c --- /dev/null +++ b/vendor/gems/dust-0.1.6/test/passing_with_setup_unit_test.rb @@ -0,0 +1,10 @@ +require File.expand_path(File.dirname(__FILE__) + "/test_helper") + +Test::Unit::TestCase.disallow_setup! +unit_tests :allow => :setup do + def setup + end + + test("true"){} +end +Test::Unit::TestCase.class_eval { @disallow_setup = nil } \ No newline at end of file diff --git a/vendor/gems/dust-0.1.6/test/test_helper.rb b/vendor/gems/dust-0.1.6/test/test_helper.rb new file mode 100644 index 0000000..30b300c --- /dev/null +++ b/vendor/gems/dust-0.1.6/test/test_helper.rb @@ -0,0 +1 @@ +require File.dirname(__FILE__) + '/../lib/dust' diff --git a/vendor/gems/mocha-0.9.1/COPYING b/vendor/gems/mocha-0.9.1/COPYING new file mode 100644 index 0000000..8f74d71 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/COPYING @@ -0,0 +1,3 @@ +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). diff --git a/vendor/gems/mocha-0.9.1/MIT-LICENSE b/vendor/gems/mocha-0.9.1/MIT-LICENSE new file mode 100644 index 0000000..fa4efe7 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/MIT-LICENSE @@ -0,0 +1,7 @@ +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. \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/README b/vendor/gems/mocha-0.9.1/README new file mode 100644 index 0000000..1d0ca28 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/README @@ -0,0 +1,35 @@ += Mocha + +Mocha is a library for mocking and stubbing using a syntax like that of JMock[http://www.jmock.org]. + +It can be used with many testing frameworks e.g. Test::Unit[http://www.ruby-doc.org/core/classes/Test/Unit.html], RSpec[http://rspec.info/], test/spec[http://chneukirchen.org/repos/testspec/README], expectations[http://expectations.rubyforge.org/], Dust[http://dust.rubyforge.org/] and even JtestR[http://jtestr.codehaus.org/]. + +Mocha provides a unified, simple and readable syntax for both traditional mocking and partial mocking. + +Mocha was harvested from projects at Reevoo[http://www.reevoo.com] by me (James[http://blog.floehopper.org]) and my colleagues Ben[http://www.techbelly.com/], Chris[http://blog.seagul.co.uk] and Paul[http://po-ru.com]. + +== 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]. \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/RELEASE b/vendor/gems/mocha-0.9.1/RELEASE new file mode 100644 index 0000000..5d23d9c --- /dev/null +++ b/vendor/gems/mocha-0.9.1/RELEASE @@ -0,0 +1,246 @@ += 0.9.1 (r349) + +* Fixed bug #21465 - expects & stubs should support method names as strings (as well as symbols) or fail fast. Convert all expectation method names to a symbol in case they were supplied as a string. +* By removing Mock#unexpected_method_called we reduce the number of methods vulnerable to the problem that surfaced in bug #21563. +* Fix bug #21563 - stubbing 'verified?' method is unsafe. Instance method names on the Mock class should be more obscure. +* Performance improvement. StubbaExampleTest goes twice as fast on my local machine. +* Added primitive performance test to default rake task. +* Fix format of case statements which don't work in Ruby 1.9 and make others consistent. +* There is no point in running (potentially expensive) checks if configuration is set to allow such checks to fail. This is a relatively quick fix in response to Chris McGrath's performance problems. +* Fix for bug #21161 - 'uninitialized constant Deprecation in stubba.rb'. +* It's more readable to talk about 'once' and 'twice' rather than '1 time' and '2 times'. +* Fix bug #20883 - never should raise when called to prevent follow up errors. Fail fast when there are no matching invokable expectations and handle the stub_everything case sensibly. This might not be entirely backwards compatible, but I think the benefits outweigh the risks. The most likely change is that a test that was already failing will now fail faster, which doesn't seem so awful. + += 0.9.0 (r316) + +* Configurable warnings or errors + * when a method on a non-public method is stubbed + * when a method on a non-existent method is stubbed + * when a method on a non-mock object is stubbed + * when a method is stubbed unnecessarily (i.e. the stubbed method is not called during the test) + +* Improved error messages + * User-friendly list of unsatisfied expectations, satisfied expectations and state machines. + * Improved readability of cardinality description. + * Display sensible failure message for any_instance expectations e.g. "#.bar - expected calls: 1, actual calls: 0" + +* Parameter matchers + * New to this release + * optionally (allows matching of optional parameters if available) + * yaml_equivalent (allows matching of YAML that represents the specified object) + * responds_with (tests the quack not the duck) + * Nesting of parameter matchers is now supported. + +* Optional block passed into mock initializer is evaluated in the context of the new mock instance and can be used as a shortcut to set up expectations. + +* Added JMock-style sequences for constraining the order of expected invocations. See Standalone#sequence and Expectation#in_sequence. + +* Added JMock-style states for constraining the order of expected invocations. See Standalone#states, Expectation#then, Expectation#when and StateMachine. + +* Compatibility with versions of Ruby + * Compatibility with Ruby v1.9. All test errors and warnings fixed. + * Nasty fix so that TestCaseAdaptor works consistently with earlier versions of Test::Unit as well as more recent versions. + * Added platform to gem specification to avoid bug in rubygems 0.9.5 - see http://www.dcmanges.com/blog/rubygems-0-9-5-platform-bug and http://rubygems.org/read/chapter/20#platform. + * Make ExpectationRaiser deal with subclasses of Interrupt which seem to need a message supplied in the raise statement in Ruby 1.8.6 (but not 1.8.4 or 1.9). Not sure this is really Mocha's responsibility. + +* Added deprecation warning in stubba.rb which is no longer needed and will be removed. + +* Supply positioning information to evals to improve any error messages. See http://ola-bini.blogspot.com/2008/01/ruby-antipattern-using-eval-without.html + +* Bug fixes + * 18914 in revision 296 - http://rubyforge.org/tracker/index.php?func=detail&aid=18914&group_id=1917&atid=7477 + * 18917 in revision 295 - http://rubyforge.org/tracker/index.php?func=detail&aid=18917&group_id=1917&atid=7477 + * 18336 in revision 287 - http://rubyforge.org/tracker/index.php?func=detail&aid=18336&group_id=1917&atid=7477 + * 17835 in revision 255 - http://rubyforge.org/tracker/index.php?func=detail&aid=17835&group_id=1917&atid=7477 + * 17412 in revision 242 - http://rubyforge.org/tracker/index.php?func=detail&aid=17412&group_id=1917&atid=7477 + * 15977 in revision 198 - http://rubyforge.org/tracker/index.php?func=detail&aid=15977&group_id=1917&atid=7477 + * 11885 in revision 156 - http://rubyforge.org/tracker/index.php?func=detail&aid=11885&group_id=1917&atid=7477 + += 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 - I’ve 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. diff --git a/vendor/gems/mocha-0.9.1/Rakefile b/vendor/gems/mocha-0.9.1/Rakefile new file mode 100644 index 0000000..6855db7 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/Rakefile @@ -0,0 +1,188 @@ +require 'rubygems' +require 'rake/rdoctask' +require 'rake/gempackagetask' +require 'rake/testtask' +require 'rake/contrib/sshpublisher' + +module Mocha + VERSION = "0.9.1" +end + +desc "Run all tests" +task 'default' => ['test:units', 'test:acceptance', 'test:performance'] + +namespace 'test' do + + unit_tests = FileList['test/unit/**/*_test.rb'] + acceptance_tests = FileList['test/acceptance/*_test.rb'] + + desc "Run unit tests" + Rake::TestTask.new('units') do |t| + t.libs << 'test' + t.test_files = unit_tests + t.verbose = true + t.warning = true + end + + desc "Run acceptance tests" + Rake::TestTask.new('acceptance') do |t| + t.libs << 'test' + t.test_files = acceptance_tests + t.verbose = true + t.warning = true + end + + # require 'rcov/rcovtask' + # Rcov::RcovTask.new('coverage') do |t| + # t.libs << 'test' + # t.test_files = unit_tests + acceptance_tests + # t.verbose = true + # t.warning = true + # t.rcov_opts << '--sort coverage' + # t.rcov_opts << '--xref' + # end + + desc "Run performance tests" + task 'performance' do + require 'test/acceptance/stubba_example_test' + require 'test/acceptance/mocha_example_test' + iterations = 1000 + puts "\nBenchmarking with #{iterations} iterations..." + [MochaExampleTest, StubbaExampleTest].each do |test_case| + puts "#{test_case}: #{benchmark_test_case(test_case, iterations)} seconds." + end + end + +end + +def benchmark_test_case(klass, iterations) + require 'test/unit/ui/console/testrunner' + require 'benchmark' + time = Benchmark.realtime { iterations.times { Test::Unit::UI::Console::TestRunner.run(klass, Test::Unit::UI::SILENT) } } +end + +desc 'Generate RDoc' +Rake::RDocTask.new('rdoc') 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/standalone.rb', + 'lib/mocha/mock.rb', + 'lib/mocha/expectation.rb', + 'lib/mocha/object.rb', + 'lib/mocha/parameter_matchers.rb', + 'lib/mocha/parameter_matchers', + 'lib/mocha/state_machine.rb', + 'lib/mocha/configuration.rb', + 'lib/mocha/stubbing_error.rb' + ) +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 << "" + file << "" + file << %q() + file << "" + file << "" + file << CodeRay.scan_file("examples/#{filename}.rb").html.div + file << "" + file << "" + 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 diff --git a/vendor/gems/mocha-0.9.1/examples/misc.rb b/vendor/gems/mocha-0.9.1/examples/misc.rb new file mode 100644 index 0000000..1cb8b55 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/examples/misc.rb @@ -0,0 +1,44 @@ +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 \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/examples/mocha.rb b/vendor/gems/mocha-0.9.1/examples/mocha.rb new file mode 100644 index 0000000..863270d --- /dev/null +++ b/vendor/gems/mocha-0.9.1/examples/mocha.rb @@ -0,0 +1,26 @@ +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 diff --git a/vendor/gems/mocha-0.9.1/examples/stubba.rb b/vendor/gems/mocha-0.9.1/examples/stubba.rb new file mode 100644 index 0000000..2788d1b --- /dev/null +++ b/vendor/gems/mocha-0.9.1/examples/stubba.rb @@ -0,0 +1,65 @@ +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 diff --git a/vendor/gems/mocha-0.9.1/lib/mocha.rb b/vendor/gems/mocha-0.9.1/lib/mocha.rb new file mode 100644 index 0000000..5088d56 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha.rb @@ -0,0 +1,20 @@ +require 'mocha_standalone' +require 'mocha/test_case_adapter' +require 'mocha/configuration' + +require 'test/unit/testcase' + +module Test + + module Unit + + class TestCase + + include Mocha::Standalone + include Mocha::TestCaseAdapter + + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/lib/mocha/any_instance_method.rb b/vendor/gems/mocha-0.9.1/lib/mocha/any_instance_method.rb new file mode 100644 index 0000000..42d8901 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha/any_instance_method.rb @@ -0,0 +1,54 @@ +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 + if method_exists?(method) + begin + stubbee.class_eval("alias_method :#{hidden_method}, :#{method}", __FILE__, __LINE__) + rescue NameError + # deal with nasties like ActiveRecord::Associations::AssociationProxy + end + end + end + + def define_new_method + stubbee.class_eval("def #{method}(*args, &block); self.class.any_instance.mocha.method_missing(:#{method}, *args, &block); end", __FILE__, __LINE__) + end + + def remove_new_method + stubbee.class_eval("remove_method :#{method}", __FILE__, __LINE__) + end + + def restore_original_method + if method_exists?(hidden_method) + begin + stubbee.class_eval("alias_method :#{method}, :#{hidden_method}; remove_method :#{hidden_method}", __FILE__, __LINE__) + rescue NameError + # deal with nasties like ActiveRecord::Associations::AssociationProxy + end + end + end + + def method_exists?(method) + return true if stubbee.public_instance_methods(false).include?(method) + return true if stubbee.protected_instance_methods(false).include?(method) + return true if stubbee.private_instance_methods(false).include?(method) + return false + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/lib/mocha/backtrace_filter.rb b/vendor/gems/mocha-0.9.1/lib/mocha/backtrace_filter.rb new file mode 100644 index 0000000..69215e7 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha/backtrace_filter.rb @@ -0,0 +1,17 @@ +module Mocha + + class BacktraceFilter + + LIB_DIRECTORY = File.expand_path(File.join(File.dirname(__FILE__), "..")) + File::SEPARATOR + + def initialize(lib_directory = LIB_DIRECTORY) + @lib_directory = lib_directory + end + + def filtered(backtrace) + backtrace.reject { |location| Regexp.new(@lib_directory).match(File.expand_path(location)) } + end + + end + +end diff --git a/vendor/gems/mocha-0.9.1/lib/mocha/cardinality.rb b/vendor/gems/mocha-0.9.1/lib/mocha/cardinality.rb new file mode 100644 index 0000000..b0c0ddf --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha/cardinality.rb @@ -0,0 +1,95 @@ +module Mocha + + class Cardinality + + INFINITY = 1 / 0.0 + + class << self + + def exactly(count) + new(count, count) + end + + def at_least(count) + new(count, INFINITY) + end + + def at_most(count) + new(0, count) + end + + def times(range_or_count) + case range_or_count + when Range then new(range_or_count.first, range_or_count.last) + else new(range_or_count, range_or_count) + end + end + + end + + def initialize(required, maximum) + @required, @maximum = required, maximum + end + + def invocations_allowed?(invocation_count) + invocation_count < maximum + end + + def satisfied?(invocations_so_far) + invocations_so_far >= required + end + + def needs_verifying? + !allowed_any_number_of_times? + end + + def verified?(invocation_count) + (invocation_count >= required) && (invocation_count <= maximum) + end + + def allowed_any_number_of_times? + required == 0 && infinite?(maximum) + end + + def used?(invocation_count) + (invocation_count > 0) || (maximum == 0) + end + + def mocha_inspect + if allowed_any_number_of_times? + "allowed any number of times" + else + if required == 0 && maximum == 0 + "expected never" + elsif required == maximum + "expected exactly #{times(required)}" + elsif infinite?(maximum) + "expected at least #{times(required)}" + elsif required == 0 + "expected at most #{times(maximum)}" + else + "expected between #{required} and #{times(maximum)}" + end + end + end + + protected + + attr_reader :required, :maximum + + def times(number) + case number + when 0 then "no times" + when 1 then "once" + when 2 then "twice" + else "#{number} times" + end + end + + def infinite?(number) + number.respond_to?(:infinite?) && number.infinite? + end + + end + +end diff --git a/vendor/gems/mocha-0.9.1/lib/mocha/central.rb b/vendor/gems/mocha-0.9.1/lib/mocha/central.rb new file mode 100644 index 0000000..7bb287a --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha/central.rb @@ -0,0 +1,27 @@ +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 unstub_all + while stubba_methods.length > 0 + method = stubba_methods.pop + method.unstub + end + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/lib/mocha/change_state_side_effect.rb b/vendor/gems/mocha-0.9.1/lib/mocha/change_state_side_effect.rb new file mode 100644 index 0000000..fe85d6e --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha/change_state_side_effect.rb @@ -0,0 +1,19 @@ +module Mocha + + class ChangeStateSideEffect + + def initialize(state) + @state = state + end + + def perform + @state.activate + end + + def mocha_inspect + "then #{@state.mocha_inspect}" + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/lib/mocha/class_method.rb b/vendor/gems/mocha-0.9.1/lib/mocha/class_method.rb new file mode 100644 index 0000000..19a1827 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha/class_method.rb @@ -0,0 +1,86 @@ +require 'mocha/metaclass' + +module Mocha + + class ClassMethod + + attr_reader :stubbee, :method + + def initialize(stubbee, method) + @stubbee = stubbee + @method = RUBY_VERSION < '1.9' ? method.to_s : method.to_sym + 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 + if method_exists?(method) + begin + stubbee.__metaclass__.class_eval("alias_method :#{hidden_method}, :#{method}", __FILE__, __LINE__) + rescue NameError + # deal with nasties like ActiveRecord::Associations::AssociationProxy + end + end + end + + def define_new_method + stubbee.__metaclass__.class_eval("def #{method}(*args, &block); mocha.method_missing(:#{method}, *args, &block); end", __FILE__, __LINE__) + end + + def remove_new_method + stubbee.__metaclass__.class_eval("remove_method :#{method}", __FILE__, __LINE__) + end + + def restore_original_method + if method_exists?(hidden_method) + begin + stubbee.__metaclass__.class_eval("alias_method :#{method}, :#{hidden_method}; remove_method :#{hidden_method}", __FILE__, __LINE__) + rescue NameError + # deal with nasties like ActiveRecord::Associations::AssociationProxy + end + end + 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 + hidden_method = "__stubba__#{method_name}__stubba__" + RUBY_VERSION < '1.9' ? hidden_method.to_s : hidden_method.to_sym + end + + def eql?(other) + return false unless (other.class == self.class) + (stubbee.object_id == other.stubbee.object_id) and (method == other.method) + end + + alias_method :==, :eql? + + def to_s + "#{stubbee}.#{method}" + end + + def method_exists?(method) + symbol = method.to_sym + metaclass = stubbee.__metaclass__ + metaclass.public_method_defined?(symbol) || metaclass.protected_method_defined?(symbol) || metaclass.private_method_defined?(symbol) + end + + end + +end diff --git a/vendor/gems/mocha-0.9.1/lib/mocha/configuration.rb b/vendor/gems/mocha-0.9.1/lib/mocha/configuration.rb new file mode 100644 index 0000000..fb1ab6f --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha/configuration.rb @@ -0,0 +1,60 @@ +module Mocha # :nodoc: + + # Configuration settings + class Configuration + + DEFAULTS = { :stubbing_method_unnecessarily => :allow, :stubbing_method_on_non_mock_object => :allow, :stubbing_non_existent_method => :allow, :stubbing_non_public_method => :allow } + + class << self + + # :call-seq: allow(action) + # + # Allow the specified action (as a symbol). + # The actions currently available are :stubbing_method_unnecessarily, :stubbing_method_on_non_mock_object, :stubbing_non_existent_method, :stubbing_non_public_method. + def allow(action) + configuration[action] = :allow + end + + def allow?(action) # :nodoc: + configuration[action] == :allow + end + + # :call-seq: warn_when(action) + # + # Warn if the specified action (as a symbol) is attempted. + # The actions currently available are :stubbing_method_unnecessarily, :stubbing_method_on_non_mock_object, :stubbing_non_existent_method, :stubbing_non_public_method. + def warn_when(action) + configuration[action] = :warn + end + + def warn_when?(action) # :nodoc: + configuration[action] == :warn + end + + # :call-seq: prevent(action) + # + # Raise a StubbingError if the specified action (as a symbol) is attempted. + # The actions currently available are :stubbing_method_unnecessarily, :stubbing_method_on_non_mock_object, :stubbing_non_existent_method, :stubbing_non_public_method. + def prevent(action) + configuration[action] = :prevent + end + + def prevent?(action) # :nodoc: + configuration[action] == :prevent + end + + def reset_configuration # :nodoc: + @configuration = nil + end + + private + + def configuration # :nodoc: + @configuration ||= DEFAULTS.dup + end + + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/lib/mocha/deprecation.rb b/vendor/gems/mocha-0.9.1/lib/mocha/deprecation.rb new file mode 100644 index 0000000..7448510 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha/deprecation.rb @@ -0,0 +1,22 @@ +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 \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/lib/mocha/exception_raiser.rb b/vendor/gems/mocha-0.9.1/lib/mocha/exception_raiser.rb new file mode 100644 index 0000000..9e009cb --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha/exception_raiser.rb @@ -0,0 +1,17 @@ +module Mocha # :nodoc: + + class ExceptionRaiser # :nodoc: + + def initialize(exception, message) + @exception, @message = exception, message + end + + def evaluate + raise @exception, @exception.to_s if @exception.is_a?(Module) && @exception.ancestors.include?(Interrupt) + raise @exception, @message if @message + raise @exception + end + + end + +end diff --git a/vendor/gems/mocha-0.9.1/lib/mocha/expectation.rb b/vendor/gems/mocha-0.9.1/lib/mocha/expectation.rb new file mode 100644 index 0000000..abd949b --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha/expectation.rb @@ -0,0 +1,445 @@ +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' +require 'mocha/in_state_ordering_constraint' +require 'mocha/change_state_side_effect' +require 'mocha/cardinality' + +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) + @cardinality = Cardinality.times(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 + @cardinality = Cardinality.exactly(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 + @cardinality = Cardinality.exactly(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) + @cardinality = Cardinality.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) + @cardinality = Cardinality.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 + 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 + # then(state_machine.is(state)) -> expectation + # + # then() is used as syntactic sugar to improve readability. It 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 + # + # then(state_machine.is(state)) is used to change the +state_machine+ to the specified +state+ when the invocation occurs. + # + # See also Standalone#states, StateMachine and Expectation#when. + # power = states('power').starts_as('off') + # + # radio = mock('radio') + # radio.expects(:switch_on).then(power.is('on')) + # radio.expects(:select_channel).with('BBC Radio 4').when(power.is('on')) + # radio.expects(:adjust_volume).with(+5).when(power.is('on')) + # radio.expects(:select_channel).with('BBC World Service').when(power.is('on')) + # radio.expects(:adjust_volume).with(-5).when(power.is('on')) + # radio.expects(:switch_off).then(power.is('off')) + def then(*parameters) + if parameters.length == 1 + state = parameters.first + add_side_effect(ChangeStateSideEffect.new(state)) + end + self + end + + # :call-seq: when(state_machine.is(state)) -> exception + # + # Constrains the expectation to occur only when the +state_machine+ is in the named +state+. + # + # See also Standalone#states, StateMachine#starts_as and Expectation#then. + # power = states('power').starts_as('off') + # + # radio = mock('radio') + # radio.expects(:switch_on).then(power.is('on')) + # radio.expects(:select_channel).with('BBC Radio 4').when(power.is('on')) + # radio.expects(:adjust_volume).with(+5).when(power.is('on')) + # radio.expects(:select_channel).with('BBC World Service').when(power.is('on')) + # radio.expects(:adjust_volume).with(-5).when(power.is('on')) + # radio.expects(:switch_off).then(power.is('off')) + def when(state_predicate) + add_ordering_constraint(InStateOrderingConstraint.new(state_predicate)) + self + end + + # :call-seq: in_sequence(*sequences) -> expectation + # + # Constrains this expectation so that it must be invoked at the current point in the sequence. + # + # To expect a sequence of invocations, write the expectations in order and add the in_sequence(sequence) clause to each one. + # + # Expectations in a sequence can have any invocation count. + # + # If an expectation in a sequence is stubbed, rather than expected, it can be skipped in the sequence. + # + # See also Standalone#sequence. + # breakfast = sequence('breakfast') + # + # egg = mock('egg') + # egg.expects(:crack).in_sequence(breakfast) + # egg.expects(:fry).in_sequence(breakfast) + # egg.expects(:eat).in_sequence(breakfast) + def in_sequence(*sequences) + sequences.each { |sequence| add_in_sequence_ordering_constraint(sequence) } + self + end + + # :stopdoc: + + attr_reader :backtrace + + def initialize(mock, expected_method_name, backtrace = nil) + @mock = mock + @method_matcher = MethodMatcher.new(expected_method_name.to_sym) + @parameters_matcher = ParametersMatcher.new + @ordering_constraints = [] + @side_effects = [] + @cardinality, @invocation_count = Cardinality.exactly(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 add_in_sequence_ordering_constraint(sequence) + sequence.constrain_as_next_in_sequence(self) + end + + def add_side_effect(side_effect) + @side_effects << side_effect + end + + def perform_side_effects + @side_effects.each { |side_effect| side_effect.perform } + 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? + @cardinality.invocations_allowed?(@invocation_count) + end + + def satisfied? + @cardinality.satisfied?(@invocation_count) + end + + def invoke + @invocation_count += 1 + perform_side_effects() + if block_given? then + @yield_parameters.next_invocation.each do |yield_parameters| + yield(*yield_parameters) + end + end + @return_values.next + end + + def verified?(assertion_counter = nil) + assertion_counter.increment if assertion_counter && @cardinality.needs_verifying? + @cardinality.verified?(@invocation_count) + end + + def used? + @cardinality.used?(@invocation_count) + end + + def mocha_inspect + message = "#{@cardinality.mocha_inspect}, " + message << case @invocation_count + when 0 then "not yet invoked" + when 1 then "already invoked once" + when 2 then "already invoked twice" + else "already invoked #{@invocation_count} times" + end + message << ": " + message << method_signature + message << "; #{@ordering_constraints.map { |oc| oc.mocha_inspect }.join("; ")}" unless @ordering_constraints.empty? + message + end + + def method_signature + "#{@mock.mocha_inspect}.#{@method_matcher.mocha_inspect}#{@parameters_matcher.mocha_inspect}" + end + + # :startdoc: + + end + +end diff --git a/vendor/gems/mocha-0.9.1/lib/mocha/expectation_error.rb b/vendor/gems/mocha-0.9.1/lib/mocha/expectation_error.rb new file mode 100644 index 0000000..ffa9835 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha/expectation_error.rb @@ -0,0 +1,15 @@ +require 'mocha/backtrace_filter' + +module Mocha + + class ExpectationError < StandardError + + def initialize(message = nil, backtrace = []) + super(message) + filter = BacktraceFilter.new + set_backtrace(filter.filtered(backtrace)) + end + + end + +end diff --git a/vendor/gems/mocha-0.9.1/lib/mocha/expectation_list.rb b/vendor/gems/mocha-0.9.1/lib/mocha/expectation_list.rb new file mode 100644 index 0000000..788d07c --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha/expectation_list.rb @@ -0,0 +1,50 @@ +module Mocha # :nodoc: + + class ExpectationList + + def initialize + @expectations = [] + end + + def add(expectation) + @expectations.unshift(expectation) + expectation + end + + def matches_method?(method_name) + @expectations.any? { |expectation| expectation.matches_method?(method_name) } + end + + def match(method_name, *arguments) + matching_expectations(method_name, *arguments).first + end + + def match_allowing_invocation(method_name, *arguments) + matching_expectations(method_name, *arguments).detect { |e| e.invocations_allowed? } + end + + def verified?(assertion_counter = nil) + @expectations.all? { |expectation| expectation.verified?(assertion_counter) } + end + + def to_a + @expectations + end + + def to_set + @expectations.to_set + end + + def length + @expectations.length + end + + private + + def matching_expectations(method_name, *arguments) + @expectations.select { |e| e.match?(method_name, *arguments) } + end + + end + +end diff --git a/vendor/gems/mocha-0.9.1/lib/mocha/in_state_ordering_constraint.rb b/vendor/gems/mocha-0.9.1/lib/mocha/in_state_ordering_constraint.rb new file mode 100644 index 0000000..1ff0898 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha/in_state_ordering_constraint.rb @@ -0,0 +1,19 @@ +module Mocha + + class InStateOrderingConstraint + + def initialize(state_predicate) + @state_predicate = state_predicate + end + + def allows_invocation_now? + @state_predicate.active? + end + + def mocha_inspect + "when #{@state_predicate.mocha_inspect}" + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/lib/mocha/inspect.rb b/vendor/gems/mocha-0.9.1/lib/mocha/inspect.rb new file mode 100644 index 0000000..ad82ef7 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha/inspect.rb @@ -0,0 +1,39 @@ +require 'date' + +class Object + def mocha_inspect + address = self.__id__ * 2 + address += 0x100000000 if address < 0 + inspect =~ /#" : 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 \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/lib/mocha/instance_method.rb b/vendor/gems/mocha-0.9.1/lib/mocha/instance_method.rb new file mode 100644 index 0000000..49669ae --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha/instance_method.rb @@ -0,0 +1,16 @@ +require 'mocha/class_method' + +module Mocha + + class InstanceMethod < ClassMethod + + def method_exists?(method) + return true if stubbee.public_methods(false).include?(method) + return true if stubbee.protected_methods(false).include?(method) + return true if stubbee.private_methods(false).include?(method) + return false + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/lib/mocha/is_a.rb b/vendor/gems/mocha-0.9.1/lib/mocha/is_a.rb new file mode 100644 index 0000000..ee23c86 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha/is_a.rb @@ -0,0 +1,9 @@ +class Object + + # :stopdoc: + + alias_method :__is_a__, :is_a? + + # :startdoc: + +end diff --git a/vendor/gems/mocha-0.9.1/lib/mocha/logger.rb b/vendor/gems/mocha-0.9.1/lib/mocha/logger.rb new file mode 100644 index 0000000..9f09300 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha/logger.rb @@ -0,0 +1,15 @@ +module Mocha + + class Logger + + def initialize(io) + @io = io + end + + def warn(message) + @io.puts "WARNING: #{message}" + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/lib/mocha/metaclass.rb b/vendor/gems/mocha-0.9.1/lib/mocha/metaclass.rb new file mode 100644 index 0000000..f78fb89 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha/metaclass.rb @@ -0,0 +1,7 @@ +class Object + + def __metaclass__ + class << self; self; end + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/lib/mocha/method_matcher.rb b/vendor/gems/mocha-0.9.1/lib/mocha/method_matcher.rb new file mode 100644 index 0000000..6ce5f6d --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha/method_matcher.rb @@ -0,0 +1,21 @@ +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 \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/lib/mocha/mock.rb b/vendor/gems/mocha-0.9.1/lib/mocha/mock.rb new file mode 100644 index 0000000..d8a6f7c --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha/mock.rb @@ -0,0 +1,196 @@ +require 'mocha/expectation' +require 'mocha/expectation_list' +require 'mocha/metaclass' +require 'mocha/names' +require 'mocha/mockery' +require 'mocha/method_matcher' +require 'mocha/parameters_matcher' +require 'mocha/unexpected_invocation' + +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 \_\_expects\_\_ + 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 \_\_stubs\_\_ + 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(Expectation.new(self, method_name, backtrace).at_least(0).returns(return_value)) + end + else + ensure_method_not_already_defined(method_name_or_hash) + @expectations.add(Expectation.new(self, method_name_or_hash, backtrace).at_least(0)) + 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 respond_to? a method invocation (even if the method has been expected or stubbed). + # + # The +mock+ will delegate its respond_to? 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) + @name = name || DefaultName.new(self) + @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 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 + if matching_expectation_allowing_invocation = @expectations.match_allowing_invocation(symbol, *arguments) + matching_expectation_allowing_invocation.invoke(&block) + else + if (matching_expectation = @expectations.match(symbol, *arguments)) || (!matching_expectation && !@everything_stubbed) + message = UnexpectedInvocation.new(self, symbol, *arguments).to_s + message << Mockery.instance.mocha_inspect + raise ExpectationError.new(message, caller) + end + end + end + + def respond_to?(symbol) + if @responder then + @responder.respond_to?(symbol) + else + @expectations.matches_method?(symbol) + end + end + + def __verified__?(assertion_counter = nil) + @expectations.verified?(assertion_counter) + end + + def mocha_inspect + @name.mocha_inspect + 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 diff --git a/vendor/gems/mocha-0.9.1/lib/mocha/mockery.rb b/vendor/gems/mocha-0.9.1/lib/mocha/mockery.rb new file mode 100644 index 0000000..6fd5e5a --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha/mockery.rb @@ -0,0 +1,181 @@ +require 'mocha/central' +require 'mocha/mock' +require 'mocha/names' +require 'mocha/state_machine' +require 'mocha/logger' +require 'mocha/configuration' +require 'mocha/stubbing_error' + +module Mocha + + class Mockery + + class << self + + def instance + @instance ||= new + end + + def reset_instance + @instance = nil + end + + end + + def named_mock(name, &block) + add_mock(Mock.new(Name.new(name), &block)) + end + + def unnamed_mock(&block) + add_mock(Mock.new(&block)) + end + + def mock_impersonating(object, &block) + add_mock(Mock.new(ImpersonatingName.new(object), &block)) + end + + def mock_impersonating_any_instance_of(klass, &block) + add_mock(Mock.new(ImpersonatingAnyInstanceName.new(klass), &block)) + end + + def new_state_machine(name) + add_state_machine(StateMachine.new(name)) + end + + def verify(assertion_counter = nil) + unless mocks.all? { |mock| mock.__verified__?(assertion_counter) } + message = "not all expectations were satisfied\n#{mocha_inspect}" + if unsatisfied_expectations.empty? + backtrace = caller + else + backtrace = unsatisfied_expectations[0].backtrace + end + raise ExpectationError.new(message, backtrace) + end + expectations.each do |e| + unless Mocha::Configuration.allow?(:stubbing_method_unnecessarily) + unless e.used? + on_stubbing_method_unnecessarily(e) + end + end + end + end + + def teardown + stubba.unstub_all + reset + end + + def stubba + @stubba ||= Central.new + end + + def mocks + @mocks ||= [] + end + + def state_machines + @state_machines ||= [] + end + + def mocha_inspect + message = "" + message << "unsatisfied expectations:\n- #{unsatisfied_expectations.map { |e| e.mocha_inspect }.join("\n- ")}\n" unless unsatisfied_expectations.empty? + message << "satisfied expectations:\n- #{satisfied_expectations.map { |e| e.mocha_inspect }.join("\n- ")}\n" unless satisfied_expectations.empty? + message << "states:\n- #{state_machines.map { |sm| sm.mocha_inspect }.join("\n- ")}" unless state_machines.empty? + message + end + + def on_stubbing(object, method) + method = RUBY_VERSION < '1.9' ? method.to_s : method.to_sym + unless Mocha::Configuration.allow?(:stubbing_non_existent_method) + unless object.method_exists?(method, include_public_methods = true) + on_stubbing_non_existent_method(object, method) + end + end + unless Mocha::Configuration.allow?(:stubbing_non_public_method) + if object.method_exists?(method, include_public_methods = false) + on_stubbing_non_public_method(object, method) + end + end + unless Mocha::Configuration.allow?(:stubbing_method_on_non_mock_object) + on_stubbing_method_on_non_mock_object(object, method) + end + end + + def on_stubbing_non_existent_method(object, method) + if Mocha::Configuration.prevent?(:stubbing_non_existent_method) + raise StubbingError.new("stubbing non-existent method: #{object.mocha_inspect}.#{method}", caller) + end + if Mocha::Configuration.warn_when?(:stubbing_non_existent_method) + logger.warn "stubbing non-existent method: #{object.mocha_inspect}.#{method}" + end + end + + def on_stubbing_non_public_method(object, method) + if Mocha::Configuration.prevent?(:stubbing_non_public_method) + raise StubbingError.new("stubbing non-public method: #{object.mocha_inspect}.#{method}", caller) + end + if Mocha::Configuration.warn_when?(:stubbing_non_public_method) + logger.warn "stubbing non-public method: #{object.mocha_inspect}.#{method}" + end + end + + def on_stubbing_method_on_non_mock_object(object, method) + if Mocha::Configuration.prevent?(:stubbing_method_on_non_mock_object) + raise StubbingError.new("stubbing method on non-mock object: #{object.mocha_inspect}.#{method}", caller) + end + if Mocha::Configuration.warn_when?(:stubbing_method_on_non_mock_object) + logger.warn "stubbing method on non-mock object: #{object.mocha_inspect}.#{method}" + end + end + + def on_stubbing_method_unnecessarily(expectation) + if Mocha::Configuration.prevent?(:stubbing_method_unnecessarily) + raise StubbingError.new("stubbing method unnecessarily: #{expectation.method_signature}", expectation.backtrace) + end + if Mocha::Configuration.warn_when?(:stubbing_method_unnecessarily) + logger.warn "stubbing method unnecessarily: #{expectation.method_signature}" + end + end + + attr_writer :logger + + def logger + @logger ||= Logger.new($stderr) + end + + + private + + def expectations + mocks.map { |mock| mock.expectations.to_a }.flatten + end + + def unsatisfied_expectations + expectations.reject { |e| e.verified? } + end + + def satisfied_expectations + expectations.select { |e| e.verified? } + end + + def add_mock(mock) + mocks << mock + mock + end + + def add_state_machine(state_machine) + state_machines << state_machine + state_machine + end + + def reset + @stubba = nil + @mocks = nil + @state_machines = nil + end + + end + +end diff --git a/vendor/gems/mocha-0.9.1/lib/mocha/module_method.rb b/vendor/gems/mocha-0.9.1/lib/mocha/module_method.rb new file mode 100644 index 0000000..0c3b180 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha/module_method.rb @@ -0,0 +1,16 @@ +require 'mocha/module_method' + +module Mocha + + class ModuleMethod < ClassMethod + + def method_exists?(method) + return true if stubbee.public_methods(false).include?(method) + return true if stubbee.protected_methods(false).include?(method) + return true if stubbee.private_methods(false).include?(method) + return false + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/lib/mocha/multiple_yields.rb b/vendor/gems/mocha-0.9.1/lib/mocha/multiple_yields.rb new file mode 100644 index 0000000..8186c30 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha/multiple_yields.rb @@ -0,0 +1,20 @@ +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 + diff --git a/vendor/gems/mocha-0.9.1/lib/mocha/names.rb b/vendor/gems/mocha-0.9.1/lib/mocha/names.rb new file mode 100644 index 0000000..f59ebed --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha/names.rb @@ -0,0 +1,53 @@ +module Mocha + + class ImpersonatingName + + def initialize(object) + @object = object + end + + def mocha_inspect + @object.mocha_inspect + end + + end + + class ImpersonatingAnyInstanceName + + def initialize(klass) + @klass = klass + end + + def mocha_inspect + "#" + end + + end + + class Name + + def initialize(name) + @name = name + end + + def mocha_inspect + "#" + end + + end + + class DefaultName + + def initialize(mock) + @mock = mock + end + + def mocha_inspect + address = @mock.__id__ * 2 + address += 0x100000000 if address < 0 + "#" + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/lib/mocha/no_yields.rb b/vendor/gems/mocha-0.9.1/lib/mocha/no_yields.rb new file mode 100644 index 0000000..b0fba41 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha/no_yields.rb @@ -0,0 +1,11 @@ +module Mocha # :nodoc: + + class NoYields # :nodoc: + + def each + end + + end + +end + diff --git a/vendor/gems/mocha-0.9.1/lib/mocha/object.rb b/vendor/gems/mocha-0.9.1/lib/mocha/object.rb new file mode 100644 index 0000000..40f25e2 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha/object.rb @@ -0,0 +1,134 @@ +require 'mocha/mockery' +require 'mocha/instance_method' +require 'mocha/class_method' +require 'mocha/module_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::Mockery.instance.mock_impersonating(self) + 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 Product#save is replaced temporarily. + # + # The original implementation of Product#save is restored at the end of the test. + def expects(symbol) + mockery = Mocha::Mockery.instance + mockery.on_stubbing(self, symbol) + method = stubba_method.new(stubba_object, symbol) + mockery.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 Product#save is replaced temporarily. + # + # The original implementation of Product#save is restored at the end of the test. + def stubs(symbol) + mockery = Mocha::Mockery.instance + mockery.on_stubbing(self, symbol) + method = stubba_method.new(stubba_object, symbol) + mockery.stubba.stub(method) + mocha.stubs(symbol, caller) + end + + def method_exists?(method, include_public_methods = true) + if include_public_methods + return true if public_methods(include_superclass_methods = true).include?(method) + return true if respond_to?(method) + end + return true if protected_methods(include_superclass_methods = true).include?(method) + return true if private_methods(include_superclass_methods = true).include?(method) + return false + end + +end + +class Module # :nodoc: + + def stubba_method + Mocha::ModuleMethod + end + +end + +class Class + + def stubba_method # :nodoc: + Mocha::ClassMethod + end + + class AnyInstance # :nodoc: + + def initialize(klass) + @stubba_object = klass + end + + def mocha + @mocha ||= Mocha::Mockery.instance.mock_impersonating_any_instance_of(@stubba_object) + end + + def stubba_method + Mocha::AnyInstanceMethod + end + + def stubba_object + @stubba_object + end + + def method_exists?(method, include_public_methods = true) + if include_public_methods + return true if @stubba_object.public_instance_methods(include_superclass_methods = true).include?(method) + end + return true if @stubba_object.protected_instance_methods(include_superclass_methods = true).include?(method) + return true if @stubba_object.private_instance_methods(include_superclass_methods = true).include?(method) + return false + 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 + diff --git a/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers.rb b/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers.rb new file mode 100644 index 0000000..561fd55 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers.rb @@ -0,0 +1,26 @@ +module Mocha + + # Used as parameters for Expectation#with to restrict the parameter values which will match the expectation. Can be nested. + 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' +require 'mocha/parameter_matchers/yaml_equivalent' diff --git a/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/all_of.rb b/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/all_of.rb new file mode 100644 index 0000000..50bf05b --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/all_of.rb @@ -0,0 +1,42 @@ +require 'mocha/parameter_matchers/base' + +module Mocha + + module ParameterMatchers + + # :call-seq: all_of(*parameter_matchers) -> parameter_matcher + # + # Matches if all +parameter_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.to_matcher.matches?([parameter]) } + end + + def mocha_inspect + "all_of(#{@matchers.map { |matcher| matcher.mocha_inspect }.join(", ") })" + end + + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/any_of.rb b/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/any_of.rb new file mode 100644 index 0000000..b391ff3 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/any_of.rb @@ -0,0 +1,47 @@ +require 'mocha/parameter_matchers/base' + +module Mocha + + module ParameterMatchers + + # :call-seq: any_of(*parameter_matchers) -> parameter_matcher + # + # Matches if any +parameter_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.to_matcher.matches?([parameter]) } + end + + def mocha_inspect + "any_of(#{@matchers.map { |matcher| matcher.mocha_inspect }.join(", ") })" + end + + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/any_parameters.rb b/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/any_parameters.rb new file mode 100644 index 0000000..11dae83 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/any_parameters.rb @@ -0,0 +1,40 @@ +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 \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/anything.rb b/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/anything.rb new file mode 100644 index 0000000..90510e2 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/anything.rb @@ -0,0 +1,33 @@ +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 \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/base.rb b/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/base.rb new file mode 100644 index 0000000..6aaec51 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/base.rb @@ -0,0 +1,15 @@ +module Mocha + + module ParameterMatchers + + class Base # :nodoc: + + def to_matcher + self + end + + end + + end + +end diff --git a/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/equals.rb b/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/equals.rb new file mode 100644 index 0000000..bdc61a0 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/equals.rb @@ -0,0 +1,42 @@ +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 \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/has_entries.rb b/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/has_entries.rb new file mode 100644 index 0000000..03e968f --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/has_entries.rb @@ -0,0 +1,45 @@ +require 'mocha/parameter_matchers/base' +require 'mocha/parameter_matchers/all_of' +require 'mocha/parameter_matchers/has_entry' + +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 + has_entry_matchers = @entries.map { |key, value| HasEntry.new(key, value) } + AllOf.new(*has_entry_matchers).matches?([parameter]) + end + + def mocha_inspect + "has_entries(#{@entries.mocha_inspect})" + end + + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/has_entry.rb b/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/has_entry.rb new file mode 100644 index 0000000..303f1e0 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/has_entry.rb @@ -0,0 +1,56 @@ +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 + matching_keys = parameter.keys.select { |key| @key.to_matcher.matches?([key]) } + matching_keys.any? { |key| @value.to_matcher.matches?([parameter[key]]) } + end + + def mocha_inspect + "has_entry(#{@key.mocha_inspect} => #{@value.mocha_inspect})" + end + + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/has_key.rb b/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/has_key.rb new file mode 100644 index 0000000..a4c2668 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/has_key.rb @@ -0,0 +1,42 @@ +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.any? { |key| @key.to_matcher.matches?([key]) } + end + + def mocha_inspect + "has_key(#{@key.mocha_inspect})" + end + + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/has_value.rb b/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/has_value.rb new file mode 100644 index 0000000..6671237 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/has_value.rb @@ -0,0 +1,42 @@ +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.any? { |value| @value.to_matcher.matches?([value]) } + end + + def mocha_inspect + "has_value(#{@value.mocha_inspect})" + end + + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/includes.rb b/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/includes.rb new file mode 100644 index 0000000..4539a5c --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/includes.rb @@ -0,0 +1,40 @@ +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 diff --git a/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/instance_of.rb b/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/instance_of.rb new file mode 100644 index 0000000..49b4a47 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/instance_of.rb @@ -0,0 +1,42 @@ +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 \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/is_a.rb b/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/is_a.rb new file mode 100644 index 0000000..a721db5 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/is_a.rb @@ -0,0 +1,42 @@ +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 \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/kind_of.rb b/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/kind_of.rb new file mode 100644 index 0000000..710d709 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/kind_of.rb @@ -0,0 +1,42 @@ +require 'mocha/parameter_matchers/base' + +module Mocha + + module ParameterMatchers + + # :call-seq: kind_of(klass) -> parameter_matcher + # + # Matches any object that is a kind of +klass+ + # object = mock() + # object.expects(:method_1).with(kind_of(Integer)) + # object.method_1(99) + # # no error raised + # + # object = mock() + # object.expects(:method_1).with(kind_of(Integer)) + # object.method_1('string') + # # error raised, because method_1 was not called with a kind of Integer + def kind_of(klass) + KindOf.new(klass) + end + + class KindOf < Base # :nodoc: + + def initialize(klass) + @klass = klass + end + + def matches?(available_parameters) + parameter = available_parameters.shift + parameter.kind_of?(@klass) + end + + def mocha_inspect + "kind_of(#{@klass.mocha_inspect})" + end + + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/not.rb b/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/not.rb new file mode 100644 index 0000000..7a9cf27 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/not.rb @@ -0,0 +1,42 @@ +require 'mocha/parameter_matchers/base' + +module Mocha + + module ParameterMatchers + + # :call-seq: Not(parameter_matcher) -> parameter_matcher + # + # Matches if +parameter_matcher+ does not match. + # object = mock() + # object.expects(:method_1).with(Not(includes(1))) + # object.method_1([0, 2, 3]) + # # no error raised + # + # object = mock() + # object.expects(:method_1).with(Not(includes(1))) + # object.method_1([0, 1, 2, 3]) + # # error raised, because method_1 was not called with object not including 1 + def Not(matcher) + Not.new(matcher) + end + + class Not < Base # :nodoc: + + def initialize(matcher) + @matcher = matcher + end + + def matches?(available_parameters) + parameter = available_parameters.shift + !@matcher.matches?([parameter]) + end + + def mocha_inspect + "Not(#{@matcher.mocha_inspect})" + end + + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/object.rb b/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/object.rb new file mode 100644 index 0000000..96f32f0 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/object.rb @@ -0,0 +1,9 @@ +require 'mocha/parameter_matchers/equals' + +class Object + + def to_matcher # :nodoc: + Mocha::ParameterMatchers::Equals.new(self) + end + +end diff --git a/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/optionally.rb b/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/optionally.rb new file mode 100644 index 0000000..fc2c3a9 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/optionally.rb @@ -0,0 +1,55 @@ +module Mocha + + module ParameterMatchers + + # :call-seq: optionally(*parameter_matchers) -> parameter_matcher + # + # Matches optional parameters if available. + # object = mock() + # object.expects(:method_1).with(1, 2, optionally(3, 4)) + # object.method_1(1, 2) + # # no error raised + # + # object = mock() + # object.expects(:method_1).with(1, 2, optionally(3, 4)) + # object.method_1(1, 2, 3) + # # no error raised + # + # object = mock() + # object.expects(:method_1).with(1, 2, optionally(3, 4)) + # object.method_1(1, 2, 3, 4) + # # no error raised + # + # object = mock() + # object.expects(:method_1).with(1, 2, optionally(3, 4)) + # object.method_1(1, 2, 3, 5) + # # error raised, because optional parameters did not match + def optionally(*matchers) + Optionally.new(*matchers) + end + + class Optionally < Base # :nodoc: + + def initialize(*parameters) + @matchers = parameters.map { |parameter| parameter.to_matcher } + end + + def matches?(available_parameters) + index = 0 + while (available_parameters.length > 0) && (index < @matchers.length) do + matcher = @matchers[index] + return false unless matcher.matches?(available_parameters) + index += 1 + end + return true + end + + def mocha_inspect + "optionally(#{@matchers.map { |matcher| matcher.mocha_inspect }.join(", ") })" + end + + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/regexp_matches.rb b/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/regexp_matches.rb new file mode 100644 index 0000000..a807d8b --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/regexp_matches.rb @@ -0,0 +1,43 @@ +require 'mocha/parameter_matchers/base' + +module Mocha + + module ParameterMatchers + + # :call-seq: regexp_matches(regular_expression) -> parameter_matcher + # + # Matches any object that matches +regular_expression+. + # object = mock() + # object.expects(:method_1).with(regexp_matches(/e/)) + # object.method_1('hello') + # # no error raised + # + # object = mock() + # object.expects(:method_1).with(regexp_matches(/a/)) + # object.method_1('hello') + # # error raised, because method_1 was not called with a parameter that matched the + # # regular expression + def regexp_matches(regexp) + RegexpMatches.new(regexp) + end + + class RegexpMatches < Base # :nodoc: + + def initialize(regexp) + @regexp = regexp + end + + def matches?(available_parameters) + parameter = available_parameters.shift + parameter =~ @regexp + end + + def mocha_inspect + "regexp_matches(#{@regexp.mocha_inspect})" + end + + end + + end + +end diff --git a/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/responds_with.rb b/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/responds_with.rb new file mode 100644 index 0000000..4355796 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/responds_with.rb @@ -0,0 +1,43 @@ +require 'mocha/parameter_matchers/base' +require 'yaml' + +module Mocha + + module ParameterMatchers + + # :call-seq: responds_with(message, result) -> parameter_matcher + # + # Matches any object that responds to +message+ with +result+. To put it another way, it tests the quack, not the duck. + # object = mock() + # object.expects(:method_1).with(responds_with(:upcase, "FOO")) + # object.method_1("foo") + # # no error raised, because "foo".upcase == "FOO" + # + # object = mock() + # object.expects(:method_1).with(responds_with(:upcase, "BAR")) + # object.method_1("foo") + # # error raised, because "foo".upcase != "BAR" + def responds_with(message, result) + RespondsWith.new(message, result) + end + + class RespondsWith < Base # :nodoc: + + def initialize(message, result) + @message, @result = message, result + end + + def matches?(available_parameters) + parameter = available_parameters.shift + parameter.__send__(@message) == @result + end + + def mocha_inspect + "responds_with(#{@message.mocha_inspect}, #{@result.mocha_inspect})" + end + + end + + end + +end diff --git a/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/yaml_equivalent.rb b/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/yaml_equivalent.rb new file mode 100644 index 0000000..6449717 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/yaml_equivalent.rb @@ -0,0 +1,43 @@ +require 'mocha/parameter_matchers/base' +require 'yaml' + +module Mocha + + module ParameterMatchers + + # :call-seq: yaml_equivalent(object) -> parameter_matcher + # + # Matches any YAML that represents the specified +object+ + # object = mock() + # object.expects(:method_1).with(yaml_equivalent(1, 2, 3)) + # object.method_1("--- \n- 1\n- 2\n- 3\n") + # # no error raised + # + # object = mock() + # object.expects(:method_1).with(yaml_equivalent(1, 2, 3)) + # object.method_1("--- \n- 1\n- 2\n") + # # error raised, because method_1 was not called with YAML representing the specified Array + def yaml_equivalent(object) + YamlEquivalent.new(object) + end + + class YamlEquivalent < Base # :nodoc: + + def initialize(object) + @object = object + end + + def matches?(available_parameters) + parameter = available_parameters.shift + @object == YAML.load(parameter) + end + + def mocha_inspect + "yaml_equivalent(#{@object.mocha_inspect})" + end + + end + + end + +end diff --git a/vendor/gems/mocha-0.9.1/lib/mocha/parameters_matcher.rb b/vendor/gems/mocha-0.9.1/lib/mocha/parameters_matcher.rb new file mode 100644 index 0000000..d43ae43 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha/parameters_matcher.rb @@ -0,0 +1,37 @@ +require 'mocha/inspect' +require 'mocha/parameter_matchers' + +module Mocha + + class ParametersMatcher + + def initialize(expected_parameters = [ParameterMatchers::AnyParameters.new], &matching_block) + @expected_parameters, @matching_block = expected_parameters, matching_block + end + + def match?(actual_parameters = []) + if @matching_block + return @matching_block.call(*actual_parameters) + else + return parameters_match?(actual_parameters) + end + end + + def parameters_match?(actual_parameters) + matchers.all? { |matcher| matcher.matches?(actual_parameters) } && (actual_parameters.length == 0) + end + + def mocha_inspect + signature = matchers.mocha_inspect + signature = signature.gsub(/^\[|\]$/, '') + signature = signature.gsub(/^\{|\}$/, '') if matchers.length == 1 + "(#{signature})" + end + + def matchers + @expected_parameters.map { |parameter| parameter.to_matcher } + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/lib/mocha/pretty_parameters.rb b/vendor/gems/mocha-0.9.1/lib/mocha/pretty_parameters.rb new file mode 100644 index 0000000..59ed636 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha/pretty_parameters.rb @@ -0,0 +1,28 @@ +require 'mocha/inspect' + +module Mocha + + class PrettyParameters + + def initialize(params) + @params = params + @params_string = params.mocha_inspect + end + + def pretty + remove_outer_array_braces! + remove_outer_hash_braces! + @params_string + end + + def remove_outer_array_braces! + @params_string = @params_string.gsub(/^\[|\]$/, '') + end + + def remove_outer_hash_braces! + @params_string = @params_string.gsub(/^\{|\}$/, '') if @params.length == 1 + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/lib/mocha/return_values.rb b/vendor/gems/mocha-0.9.1/lib/mocha/return_values.rb new file mode 100644 index 0000000..d93fb1a --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha/return_values.rb @@ -0,0 +1,31 @@ +require 'mocha/single_return_value' + +module Mocha # :nodoc: + + class ReturnValues # :nodoc: + + def self.build(*values) + new(*values.map { |value| SingleReturnValue.new(value) }) + end + + attr_accessor :values + + def initialize(*values) + @values = values + end + + def next + case @values.length + when 0 then nil + when 1 then @values.first.evaluate + else @values.shift.evaluate + end + end + + def +(other) + self.class.new(*(@values + other.values)) + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/lib/mocha/sequence.rb b/vendor/gems/mocha-0.9.1/lib/mocha/sequence.rb new file mode 100644 index 0000000..ed9852e --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha/sequence.rb @@ -0,0 +1,42 @@ +module Mocha # :nodoc: + + class Sequence + + class InSequenceOrderingConstraint + + def initialize(sequence, index) + @sequence, @index = sequence, index + end + + def allows_invocation_now? + @sequence.satisfied_to_index?(@index) + end + + def mocha_inspect + "in sequence #{@sequence.mocha_inspect}" + end + + end + + def initialize(name) + @name = name + @expectations = [] + end + + def constrain_as_next_in_sequence(expectation) + index = @expectations.length + @expectations << expectation + expectation.add_ordering_constraint(InSequenceOrderingConstraint.new(self, index)) + end + + def satisfied_to_index?(index) + @expectations[0...index].all? { |expectation| expectation.satisfied? } + end + + def mocha_inspect + "#{@name.mocha_inspect}" + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/lib/mocha/single_return_value.rb b/vendor/gems/mocha-0.9.1/lib/mocha/single_return_value.rb new file mode 100644 index 0000000..98bc4be --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha/single_return_value.rb @@ -0,0 +1,17 @@ +require 'mocha/is_a' + +module Mocha # :nodoc: + + class SingleReturnValue # :nodoc: + + def initialize(value) + @value = value + end + + def evaluate + @value + end + + end + +end diff --git a/vendor/gems/mocha-0.9.1/lib/mocha/single_yield.rb b/vendor/gems/mocha-0.9.1/lib/mocha/single_yield.rb new file mode 100644 index 0000000..5af5716 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha/single_yield.rb @@ -0,0 +1,18 @@ +module Mocha # :nodoc: + + class SingleYield # :nodoc: + + attr_reader :parameters + + def initialize(*parameters) + @parameters = parameters + end + + def each + yield(@parameters) + end + + end + +end + diff --git a/vendor/gems/mocha-0.9.1/lib/mocha/standalone.rb b/vendor/gems/mocha-0.9.1/lib/mocha/standalone.rb new file mode 100644 index 0000000..2628296 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha/standalone.rb @@ -0,0 +1,166 @@ +require 'mocha/parameter_matchers' +require 'mocha/mockery' +require 'mocha/sequence' + +module Mocha # :nodoc: + + # Methods added to Test::Unit::TestCase or equivalent. + module Standalone + + include ParameterMatchers + + # :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. + # + # Note that (contrary to expectations set up by #stub) these expectations must 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 + # + # +block+ is an optional block to be evaluated against the mock object instance, giving an alernative way to set up expectations & stubs. + # def test_product + # product = mock('ipod_product') do + # expects(:manufacturer).returns('ipod') + # expects(:price).returns(100) + # end + # 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 = name ? Mockery.instance.named_mock(name, &block) : Mockery.instance.unnamed_mock(&block) + mock.expects(expectations) + 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. + # Note that (contrary to expectations set up by #mock) these expectations need not 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 + # + # +block+ is an optional block to be evaluated against the mock object instance, giving an alernative way to set up expectations & stubs. + # def test_product + # product = stub('ipod_product') do + # stubs(:manufacturer).returns('ipod') + # stubs(:price).returns(100) + # end + # 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 = name ? Mockery.instance.named_mock(name, &block) : Mockery.instance.unnamed_mock(&block) + stub.stubs(expectations) + 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 = name ? Mockery.instance.named_mock(name, &block) : Mockery.instance.unnamed_mock(&block) + stub.stub_everything + stub.stubs(expectations) + stub + end + + # :call-seq: sequence(name) -> sequence + # + # Returns a new sequence that is used to constrain the order in which expectations can occur. + # + # Specify that an expected invocation must occur in within a named +sequence+ by using Expectation#in_sequence. + # + # See also Expectation#in_sequence. + # breakfast = sequence('breakfast') + # + # egg = mock('egg') + # egg.expects(:crack).in_sequence(breakfast) + # egg.expects(:fry).in_sequence(breakfast) + # egg.expects(:eat).in_sequence(breakfast) + def sequence(name) + Sequence.new(name) + end + + # :call-seq: states(name) -> state_machine + # + # Returns a new +state_machine+ that is used to constrain the order in which expectations can occur. + # + # Specify the initial +state+ of the +state_machine+ by using StateMachine#starts_as. + # + # Specify that an expected invocation should change the +state+ of the +state_machine+ by using Expectation#then. + # + # Specify that an expected invocation should be constrained to occur within a particular +state+ by using Expectation#when. + # + # A test can contain multiple +state_machines+. + # + # See also Expectation#then, Expectation#when and StateMachine. + # power = states('power').starts_as('off') + # + # radio = mock('radio') + # radio.expects(:switch_on).then(power.is('on')) + # radio.expects(:select_channel).with('BBC Radio 4').when(power.is('on')) + # radio.expects(:adjust_volume).with(+5).when(power.is('on')) + # radio.expects(:select_channel).with('BBC World Service').when(power.is('on')) + # radio.expects(:adjust_volume).with(-5).when(power.is('on')) + # radio.expects(:switch_off).then(power.is('off')) + def states(name) + Mockery.instance.new_state_machine(name) + end + + def mocha_setup # :nodoc: + end + + def mocha_verify(assertion_counter = nil) # :nodoc: + Mockery.instance.verify(assertion_counter) + end + + def mocha_teardown # :nodoc: + Mockery.instance.teardown + Mockery.reset_instance + end + + end + +end diff --git a/vendor/gems/mocha-0.9.1/lib/mocha/state_machine.rb b/vendor/gems/mocha-0.9.1/lib/mocha/state_machine.rb new file mode 100644 index 0000000..1b9781a --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha/state_machine.rb @@ -0,0 +1,91 @@ +module Mocha # :nodoc: + + # A state machine that is used to constrain the order of invocations. + # An invocation can be constrained to occur when a state is, or is_not, active. + class StateMachine + + class State # :nodoc: + + def initialize(state_machine, state) + @state_machine, @state = state_machine, state + end + + def activate + @state_machine.current_state = @state + end + + def active? + @state_machine.current_state == @state + end + + def mocha_inspect + "#{@state_machine.name} is #{@state.mocha_inspect}" + end + + end + + class StatePredicate # :nodoc: + + def initialize(state_machine, state) + @state_machine, @state = state_machine, state + end + + def active? + @state_machine.current_state != @state + end + + def mocha_inspect + "#{@state_machine.name} is not #{@state.mocha_inspect}" + end + + end + + attr_reader :name # :nodoc: + + attr_accessor :current_state # :nodoc: + + def initialize(name) # :nodoc: + @name = name + @current_state = nil + end + + # :call-seq: starts_as(initial_state) -> state_machine + # + # Put the +state_machine+ into the +initial_state+. + def starts_as(initial_state) + become(initial_state) + self + end + + # :call-seq: become(next_state) + # + # Put the +state_machine+ into the +next_state+. + def become(next_state) + @current_state = next_state + end + + # :call-seq: is(state) + # + # Determines whether the +state_machine+ is in the specified +state+. + def is(state) + State.new(self, state) + end + + # :call-seq: is_not(state) + # + # Determines whether the +state_machine+ is not in the specified +state+. + def is_not(state) + StatePredicate.new(self, state) + end + + def mocha_inspect # :nodoc: + if @current_state + "#{@name} is #{@current_state.mocha_inspect}" + else + "#{@name} has no current state" + end + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/lib/mocha/stubbing_error.rb b/vendor/gems/mocha-0.9.1/lib/mocha/stubbing_error.rb new file mode 100644 index 0000000..34be289 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha/stubbing_error.rb @@ -0,0 +1,16 @@ +require 'mocha/backtrace_filter' + +module Mocha # :nodoc: + + # Exception raised when an action prevented by Configuration#prevent is attempted. + class StubbingError < StandardError + + def initialize(message = nil, backtrace = []) # :nodoc: + super(message) + filter = BacktraceFilter.new + set_backtrace(filter.filtered(backtrace)) + end + + end + +end diff --git a/vendor/gems/mocha-0.9.1/lib/mocha/test_case_adapter.rb b/vendor/gems/mocha-0.9.1/lib/mocha/test_case_adapter.rb new file mode 100644 index 0000000..5b33c4a --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha/test_case_adapter.rb @@ -0,0 +1,103 @@ +require 'mocha/expectation_error' + +module Mocha + + module TestCaseAdapter + + class AssertionCounter + + def initialize(test_result) + @test_result = test_result + end + + def increment + @test_result.add_assertion + end + + end + + def self.included(base) + if RUBY_VERSION < '1.8.6' + base.class_eval do + + alias_method :run_before_mocha_test_case_adapter, :run + + def run(result) + assertion_counter = AssertionCounter.new(result) + yield(Test::Unit::TestCase::STARTED, name) + @_result = result + begin + begin + setup + __send__(@method_name) + mocha_verify(assertion_counter) + rescue Mocha::ExpectationError => e + add_failure(e.message, e.backtrace) + rescue Test::Unit::AssertionFailedError => e + add_failure(e.message, e.backtrace) + rescue StandardError, ScriptError + add_error($!) + ensure + begin + teardown + rescue Test::Unit::AssertionFailedError => e + add_failure(e.message, e.backtrace) + rescue StandardError, ScriptError + add_error($!) + end + end + ensure + mocha_teardown + end + result.add_run + yield(Test::Unit::TestCase::FINISHED, name) + end + + end + else + base.class_eval do + + alias_method :run_before_mocha_test_case_adapter, :run + + def run(result) + assertion_counter = AssertionCounter.new(result) + yield(Test::Unit::TestCase::STARTED, name) + @_result = result + begin + begin + setup + __send__(@method_name) + mocha_verify(assertion_counter) + rescue Mocha::ExpectationError => e + add_failure(e.message, e.backtrace) + rescue Test::Unit::AssertionFailedError => e + add_failure(e.message, e.backtrace) + rescue Exception + raise if Test::Unit::TestCase::PASSTHROUGH_EXCEPTIONS.include? $!.class + add_error($!) + ensure + begin + teardown + rescue Test::Unit::AssertionFailedError => e + add_failure(e.message, e.backtrace) + rescue Exception + raise if Test::Unit::TestCase::PASSTHROUGH_EXCEPTIONS.include? $!.class + add_error($!) + end + end + ensure + mocha_teardown + end + result.add_run + yield(Test::Unit::TestCase::FINISHED, name) + end + + end + + end + + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/lib/mocha/unexpected_invocation.rb b/vendor/gems/mocha-0.9.1/lib/mocha/unexpected_invocation.rb new file mode 100644 index 0000000..2eabb6a --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha/unexpected_invocation.rb @@ -0,0 +1,18 @@ +module Mocha # :nodoc: + + class UnexpectedInvocation + + def initialize(mock, symbol, *arguments) + @mock = mock + @method_matcher = MethodMatcher.new(symbol) + @parameters_matcher = ParametersMatcher.new(arguments) + end + + def to_s + method_signature = "#{@mock.mocha_inspect}.#{@method_matcher.mocha_inspect}#{@parameters_matcher.mocha_inspect}" + "unexpected invocation: #{method_signature}\n" + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/lib/mocha/yield_parameters.rb b/vendor/gems/mocha-0.9.1/lib/mocha/yield_parameters.rb new file mode 100644 index 0000000..7d6ad12 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha/yield_parameters.rb @@ -0,0 +1,31 @@ +require 'mocha/no_yields' +require 'mocha/single_yield' +require 'mocha/multiple_yields' + +module Mocha # :nodoc: + + class YieldParameters # :nodoc: + + def initialize + @parameter_groups = [] + end + + def next_invocation + case @parameter_groups.length + when 0 then NoYields.new + when 1 then @parameter_groups.first + else @parameter_groups.shift + end + end + + def add(*parameters) + @parameter_groups << SingleYield.new(*parameters) + end + + def multiple_add(*parameter_groups) + @parameter_groups << MultipleYields.new(*parameter_groups) + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/lib/mocha_standalone.rb b/vendor/gems/mocha-0.9.1/lib/mocha_standalone.rb new file mode 100644 index 0000000..ce60581 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/mocha_standalone.rb @@ -0,0 +1,2 @@ +require 'mocha/standalone' +require 'mocha/object' diff --git a/vendor/gems/mocha-0.9.1/lib/stubba.rb b/vendor/gems/mocha-0.9.1/lib/stubba.rb new file mode 100644 index 0000000..ba4d93f --- /dev/null +++ b/vendor/gems/mocha-0.9.1/lib/stubba.rb @@ -0,0 +1,4 @@ +# for backwards compatibility +require 'mocha' +require 'mocha/deprecation' +Mocha::Deprecation.warning "require 'stubba' is no longer needed and stubba.rb will soon be removed" diff --git a/vendor/gems/mocha-0.9.1/test/acceptance/acceptance_test_helper.rb b/vendor/gems/mocha-0.9.1/test/acceptance/acceptance_test_helper.rb new file mode 100644 index 0000000..2341338 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/acceptance/acceptance_test_helper.rb @@ -0,0 +1,38 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") +require 'test_runner' +require 'mocha/configuration' + +module AcceptanceTest + + class FakeLogger + + attr_reader :warnings + + def initialize + @warnings = [] + end + + def warn(message) + @warnings << message + end + + end + + attr_reader :logger + + include TestRunner + + def setup_acceptance_test + Mocha::Configuration.reset_configuration + @logger = FakeLogger.new + mockery = Mocha::Mockery.instance + @original_logger = mockery.logger + mockery.logger = @logger + end + + def teardown_acceptance_test + Mocha::Configuration.reset_configuration + Mocha::Mockery.instance.logger = @original_logger + end + +end diff --git a/vendor/gems/mocha-0.9.1/test/acceptance/bug_18914_test.rb b/vendor/gems/mocha-0.9.1/test/acceptance/bug_18914_test.rb new file mode 100644 index 0000000..852a5f8 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/acceptance/bug_18914_test.rb @@ -0,0 +1,43 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' + +class Bug18914Test < Test::Unit::TestCase + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + class AlwaysEql + + def my_method + true + end + + def ==(o) + true + end + + def eql?(o) + true + end + + end + + def test_should_not_allow_stubbing_of_non_mock_instance_disrupted_by_legitimate_overriding_of_eql_method + + always_eql_1 = AlwaysEql.new + always_eql_1.stubs(:my_method).returns(false) + + always_eql_2 = AlwaysEql.new + always_eql_2.stubs(:my_method).returns(false) + + assert_equal false, always_eql_2.my_method + end + +end diff --git a/vendor/gems/mocha-0.9.1/test/acceptance/bug_21465_test.rb b/vendor/gems/mocha-0.9.1/test/acceptance/bug_21465_test.rb new file mode 100644 index 0000000..f60cc5d --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/acceptance/bug_21465_test.rb @@ -0,0 +1,34 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' + +class Bug21563Test < Test::Unit::TestCase + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_allow_expected_method_name_to_be_a_string + test_result = run_test do + mock = mock() + mock.expects('wibble') + mock.wibble + end + assert_passed(test_result) + end + + def test_should_allow_stubbed_method_name_to_be_a_string + test_result = run_test do + mock = mock() + mock.stubs('wibble') + mock.wibble + end + assert_passed(test_result) + end + +end diff --git a/vendor/gems/mocha-0.9.1/test/acceptance/bug_21563_test.rb b/vendor/gems/mocha-0.9.1/test/acceptance/bug_21563_test.rb new file mode 100644 index 0000000..6c78368 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/acceptance/bug_21563_test.rb @@ -0,0 +1,25 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' + +class Bug21563Test < Test::Unit::TestCase + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_allow_stubbing_of_verified_method + test_result = run_test do + object = Object.new + object.stubs(:verified?).returns(false) + assert !object.verified? + end + assert_passed(test_result) + end + +end diff --git a/vendor/gems/mocha-0.9.1/test/acceptance/expected_invocation_count_test.rb b/vendor/gems/mocha-0.9.1/test/acceptance/expected_invocation_count_test.rb new file mode 100644 index 0000000..de1282d --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/acceptance/expected_invocation_count_test.rb @@ -0,0 +1,196 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' + +class ExpectedInvocationCountTest < Test::Unit::TestCase + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_pass_if_method_is_never_expected_and_is_never_called + test_result = run_test do + mock = mock('mock') + mock.expects(:method).never + 0.times { mock.method } + end + assert_passed(test_result) + end + + def test_should_fail_fast_if_method_is_never_expected_but_is_called_once + test_result = run_test do + mock = mock('mock') + mock.expects(:method).never + 1.times { mock.method } + end + assert_failed(test_result) + assert_equal ["unexpected invocation: #.method()\nsatisfied expectations:\n- expected never, not yet invoked: #.method(any_parameters)\n"], test_result.failure_messages + end + + def test_should_pass_if_method_is_expected_twice_and_is_called_twice + test_result = run_test do + mock = mock('mock') + mock.expects(:method).times(2) + 2.times { mock.method } + end + assert_passed(test_result) + end + + def test_should_fail_if_method_is_expected_twice_but_is_called_once + test_result = run_test do + mock = mock('mock') + mock.expects(:method).times(2) + 1.times { mock.method } + end + assert_failed(test_result) + assert_equal ["not all expectations were satisfied\nunsatisfied expectations:\n- expected exactly twice, already invoked once: #.method(any_parameters)\n"], test_result.failure_messages + end + + def test_should_fail_fast_if_method_is_expected_twice_but_is_called_three_times + test_result = run_test do + mock = mock('mock') + mock.expects(:method).times(2) + 3.times { mock.method } + end + assert_failed(test_result) + assert_equal ["unexpected invocation: #.method()\nsatisfied expectations:\n- expected exactly twice, already invoked twice: #.method(any_parameters)\n"], test_result.failure_messages + end + + def test_should_pass_if_method_is_expected_between_two_and_four_times_and_is_called_twice + test_result = run_test do + mock = mock('mock') + mock.expects(:method).times(2..4) + 2.times { mock.method } + end + assert_passed(test_result) + end + + def test_should_pass_if_method_is_expected_between_two_and_four_times_and_is_called_three_times + test_result = run_test do + mock = mock('mock') + mock.expects(:method).times(2..4) + 3.times { mock.method } + end + assert_passed(test_result) + end + + def test_should_pass_if_method_is_expected_between_two_and_four_times_and_is_called_four_times + test_result = run_test do + mock = mock('mock') + mock.expects(:method).times(2..4) + 4.times { mock.method } + end + assert_passed(test_result) + end + + def test_should_fail_if_method_is_expected_between_two_and_four_times_and_is_called_once + test_result = run_test do + mock = mock('mock') + mock.expects(:method).times(2..4) + 1.times { mock.method } + end + assert_failed(test_result) + assert_equal ["not all expectations were satisfied\nunsatisfied expectations:\n- expected between 2 and 4 times, already invoked once: #.method(any_parameters)\n"], test_result.failure_messages + end + + def test_should_fail_fast_if_method_is_expected_between_two_and_four_times_and_is_called_five_times + test_result = run_test do + mock = mock('mock') + mock.expects(:method).times(2..4) + 5.times { mock.method } + end + assert_failed(test_result) + assert_equal ["unexpected invocation: #.method()\nsatisfied expectations:\n- expected between 2 and 4 times, already invoked 4 times: #.method(any_parameters)\n"], test_result.failure_messages + end + + def test_should_pass_if_method_is_expected_at_least_once_and_is_called_once + test_result = run_test do + mock = mock('mock') + mock.expects(:method).at_least_once + 1.times { mock.method } + end + assert_passed(test_result) + end + + def test_should_pass_if_method_is_expected_at_least_once_and_is_called_twice + test_result = run_test do + mock = mock('mock') + mock.expects(:method).at_least_once + 2.times { mock.method } + end + assert_passed(test_result) + end + + def test_should_fail_if_method_is_expected_at_least_once_but_is_never_called + test_result = run_test do + mock = mock('mock') + mock.expects(:method).at_least_once + 0.times { mock.method } + end + assert_failed(test_result) + assert_equal ["not all expectations were satisfied\nunsatisfied expectations:\n- expected at least once, not yet invoked: #.method(any_parameters)\n"], test_result.failure_messages + end + + def test_should_pass_if_method_is_expected_at_most_once_and_is_never_called + test_result = run_test do + mock = mock('mock') + mock.expects(:method).at_most_once + 0.times { mock.method } + end + assert_passed(test_result) + end + + def test_should_pass_if_method_is_expected_at_most_once_and_called_once + test_result = run_test do + mock = mock('mock') + mock.expects(:method).at_most_once + 1.times { mock.method } + end + assert_passed(test_result) + end + + def test_should_fail_fast_if_method_is_expected_at_most_once_but_is_called_twice + test_result = run_test do + mock = mock('mock') + mock.expects(:method).at_most_once + 2.times { mock.method } + end + assert_failed(test_result) + assert_equal ["unexpected invocation: #.method()\nsatisfied expectations:\n- expected at most once, already invoked once: #.method(any_parameters)\n"], test_result.failure_messages + end + + def test_should_pass_if_method_is_never_expected_and_is_never_called_even_if_everything_is_stubbed + test_result = run_test do + stub = stub_everything('stub') + stub.expects(:method).never + 0.times { stub.method } + end + assert_passed(test_result) + end + + def test_should_fail_fast_if_method_is_never_expected_but_is_called_once_even_if_everything_is_stubbed + test_result = run_test do + stub = stub_everything('stub') + stub.expects(:method).never + 1.times { stub.method } + end + assert_failed(test_result) + assert_equal ["unexpected invocation: #.method()\nsatisfied expectations:\n- expected never, not yet invoked: #.method(any_parameters)\n"], test_result.failure_messages + end + + def test_should_fail_fast_if_there_is_no_matching_expectation + test_result = run_test do + mock = mock('mock') + mock.expects(:method).with(1) + 1.times { mock.method } + end + assert_failed(test_result) + assert_equal ["unexpected invocation: #.method()\nunsatisfied expectations:\n- expected exactly once, not yet invoked: #.method(1)\n"], test_result.failure_messages + end + +end diff --git a/vendor/gems/mocha-0.9.1/test/acceptance/failure_messages_test.rb b/vendor/gems/mocha-0.9.1/test/acceptance/failure_messages_test.rb new file mode 100644 index 0000000..678c04a --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/acceptance/failure_messages_test.rb @@ -0,0 +1,64 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' + +class FailureMessagesTest < Test::Unit::TestCase + + OBJECT_ADDRESS_PATTERN = '0x[0-9A-Fa-f]{1,12}' + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + class Foo; end + + def test_should_display_class_name_when_expectation_was_on_class + test_result = run_test do + Foo.expects(:bar) + end + assert_match Regexp.new('FailureMessagesTest::Foo'), test_result.failures[0].message + end + + def test_should_display_class_name_and_address_when_expectation_was_on_instance + test_result = run_test do + Foo.new.expects(:bar) + end + assert_match Regexp.new("#"), test_result.failures[0].message + end + + def test_should_display_class_name_and_any_instance_prefix_when_expectation_was_on_any_instance + test_result = run_test do + Foo.any_instance.expects(:bar) + end + assert_match Regexp.new('#'), test_result.failures[0].message + end + + def test_should_display_mock_name_when_expectation_was_on_named_mock + test_result = run_test do + foo = mock('foo') + foo.expects(:bar) + end + assert_match Regexp.new('#'), test_result.failures[0].message + end + + def test_should_display_mock_address_when_expectation_was_on_unnamed_mock + test_result = run_test do + foo = mock() + foo.expects(:bar) + end + assert_match Regexp.new("#"), test_result.failures[0].message + end + + def test_should_display_string_when_expectation_was_on_string + test_result = run_test do + 'Foo'.expects(:bar) + end + assert_match Regexp.new("'Foo'"), test_result.failures[0].message + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/test/acceptance/mocha_example_test.rb b/vendor/gems/mocha-0.9.1/test/acceptance/mocha_example_test.rb new file mode 100644 index 0000000..34009c4 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/acceptance/mocha_example_test.rb @@ -0,0 +1,98 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") +require 'mocha' + +class MochaExampleTest < Test::Unit::TestCase + + class Rover + + def initialize(left_track, right_track, steps_per_metre, steps_per_degree) + @left_track, @right_track, @steps_per_metre, @steps_per_degree = left_track, right_track, steps_per_metre, steps_per_degree + end + + def forward(metres) + @left_track.step(metres * @steps_per_metre) + @right_track.step(metres * @steps_per_metre) + wait + end + + def backward(metres) + forward(-metres) + end + + def left(degrees) + @left_track.step(-degrees * @steps_per_degree) + @right_track.step(+degrees * @steps_per_degree) + wait + end + + def right(degrees) + left(-degrees) + end + + def wait + while (@left_track.moving? or @right_track.moving?); end + end + + end + + def test_should_step_both_tracks_forward_ten_steps + left_track = mock('left_track') + right_track = mock('right_track') + steps_per_metre = 5 + rover = Rover.new(left_track, right_track, steps_per_metre, nil) + + left_track.expects(:step).with(10) + right_track.expects(:step).with(10) + + left_track.stubs(:moving?).returns(false) + right_track.stubs(:moving?).returns(false) + + rover.forward(2) + end + + def test_should_step_both_tracks_backward_ten_steps + left_track = mock('left_track') + right_track = mock('right_track') + steps_per_metre = 5 + rover = Rover.new(left_track, right_track, steps_per_metre, nil) + + left_track.expects(:step).with(-10) + right_track.expects(:step).with(-10) + + left_track.stubs(:moving?).returns(false) + right_track.stubs(:moving?).returns(false) + + rover.backward(2) + end + + def test_should_step_left_track_forwards_five_steps_and_right_track_backwards_five_steps + left_track = mock('left_track') + right_track = mock('right_track') + steps_per_degree = 5.0 / 90.0 + rover = Rover.new(left_track, right_track, nil, steps_per_degree) + + left_track.expects(:step).with(+5) + right_track.expects(:step).with(-5) + + left_track.stubs(:moving?).returns(false) + right_track.stubs(:moving?).returns(false) + + rover.right(90) + end + + def test_should_step_left_track_backwards_five_steps_and_right_track_forwards_five_steps + left_track = mock('left_track') + right_track = mock('right_track') + steps_per_degree = 5.0 / 90.0 + rover = Rover.new(left_track, right_track, nil, steps_per_degree) + + left_track.expects(:step).with(-5) + right_track.expects(:step).with(+5) + + left_track.stubs(:moving?).returns(false) + right_track.stubs(:moving?).returns(false) + + rover.left(90) + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/test/acceptance/mocha_test_result_test.rb b/vendor/gems/mocha-0.9.1/test/acceptance/mocha_test_result_test.rb new file mode 100644 index 0000000..70aa275 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/acceptance/mocha_test_result_test.rb @@ -0,0 +1,84 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' +require 'execution_point' + +class MochaTestResultTest < Test::Unit::TestCase + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_include_expectation_verification_in_assertion_count + test_result = run_test do + object = mock() + object.expects(:message) + object.message + end + assert_equal 1, test_result.assertion_count + end + + def test_should_include_assertions_in_assertion_count + test_result = run_test do + assert true + end + assert_equal 1, test_result.assertion_count + end + + def test_should_not_include_stubbing_expectation_verification_in_assertion_count + test_result = run_test do + object = mock() + object.stubs(:message) + object.message + end + assert_equal 0, test_result.assertion_count + end + + def test_should_include_expectation_verification_failure_in_failure_count + test_result = run_test do + object = mock() + object.expects(:message) + end + assert_equal 1, test_result.failure_count + end + + def test_should_include_unexpected_verification_failure_in_failure_count + test_result = run_test do + object = mock() + object.message + end + assert_equal 1, test_result.failure_count + end + + def test_should_include_assertion_failure_in_failure_count + test_result = run_test do + flunk + end + assert_equal 1, test_result.failure_count + end + + def test_should_display_backtrace_indicating_line_number_where_unexpected_method_was_called + execution_point = nil + test_result = run_test do + object = mock() + execution_point = ExecutionPoint.current; object.message + end + assert_equal 1, test_result.failure_count + assert_equal execution_point, ExecutionPoint.new(test_result.failures[0].location) + end + + def test_should_display_backtrace_indicating_line_number_where_failing_assertion_was_called + execution_point = nil + test_result = run_test do + execution_point = ExecutionPoint.current; flunk + end + assert_equal 1, test_result.failure_count + assert_equal execution_point, ExecutionPoint.new(test_result.failures[0].location) + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/test/acceptance/mock_test.rb b/vendor/gems/mocha-0.9.1/test/acceptance/mock_test.rb new file mode 100644 index 0000000..e3bbc22 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/acceptance/mock_test.rb @@ -0,0 +1,100 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' + +class MockTest < Test::Unit::TestCase + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_build_mock_and_explicitly_add_an_expectation_which_is_satisfied + test_result = run_test do + foo = mock() + foo.expects(:bar) + foo.bar + end + assert_passed(test_result) + end + + def test_should_build_mock_and_explicitly_add_an_expectation_which_is_not_satisfied + test_result = run_test do + foo = mock() + foo.expects(:bar) + end + assert_failed(test_result) + end + + def test_should_build_named_mock_and_explicitly_add_an_expectation_which_is_satisfied + test_result = run_test do + foo = mock('foo') + foo.expects(:bar) + foo.bar + end + assert_passed(test_result) + end + + def test_should_build_named_mock_and_explicitly_add_an_expectation_which_is_not_satisfied + test_result = run_test do + foo = mock('foo') + foo.expects(:bar) + end + assert_failed(test_result) + end + + def test_should_build_mock_incorporating_two_expectations_which_are_satisifed + test_result = run_test do + foo = mock(:bar => 'bar', :baz => 'baz') + foo.bar + foo.baz + end + assert_passed(test_result) + end + + def test_should_build_mock_incorporating_two_expectations_the_first_of_which_is_not_satisifed + test_result = run_test do + foo = mock(:bar => 'bar', :baz => 'baz') + foo.baz + end + assert_failed(test_result) + end + + def test_should_build_mock_incorporating_two_expectations_the_second_of_which_is_not_satisifed + test_result = run_test do + foo = mock(:bar => 'bar', :baz => 'baz') + foo.bar + end + assert_failed(test_result) + end + + def test_should_build_named_mock_incorporating_two_expectations_which_are_satisifed + test_result = run_test do + foo = mock('foo', :bar => 'bar', :baz => 'baz') + foo.bar + foo.baz + end + assert_passed(test_result) + end + + def test_should_build_named_mock_incorporating_two_expectations_the_first_of_which_is_not_satisifed + test_result = run_test do + foo = mock('foo', :bar => 'bar', :baz => 'baz') + foo.baz + end + assert_failed(test_result) + end + + def test_should_build_named_mock_incorporating_two_expectations_the_second_of_which_is_not_satisifed + test_result = run_test do + foo = mock('foo', :bar => 'bar', :baz => 'baz') + foo.bar + end + assert_failed(test_result) + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/test/acceptance/mock_with_initializer_block_test.rb b/vendor/gems/mocha-0.9.1/test/acceptance/mock_with_initializer_block_test.rb new file mode 100644 index 0000000..4ca2152 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/acceptance/mock_with_initializer_block_test.rb @@ -0,0 +1,51 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' + +class MockWithInitializerBlockTest < Test::Unit::TestCase + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_expect_two_method_invocations_and_receive_both_of_them + test_result = run_test do + mock = mock() do + expects(:method_1) + expects(:method_2) + end + mock.method_1 + mock.method_2 + end + assert_passed(test_result) + end + + def test_should_expect_two_method_invocations_but_receive_only_one_of_them + test_result = run_test do + mock = mock() do + expects(:method_1) + expects(:method_2) + end + mock.method_1 + end + assert_failed(test_result) + end + + def test_should_stub_methods + test_result = run_test do + mock = mock() do + stubs(:method_1).returns(1) + stubs(:method_2).returns(2) + end + assert_equal 1, mock.method_1 + assert_equal 2, mock.method_2 + end + assert_passed(test_result) + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/test/acceptance/mocked_methods_dispatch_test.rb b/vendor/gems/mocha-0.9.1/test/acceptance/mocked_methods_dispatch_test.rb new file mode 100644 index 0000000..b19b569 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/acceptance/mocked_methods_dispatch_test.rb @@ -0,0 +1,78 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' + +class MockedMethodDispatchTest < Test::Unit::TestCase + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_find_latest_matching_expectation + test_result = run_test do + mock = mock() + mock.stubs(:method).returns(1) + mock.stubs(:method).returns(2) + assert_equal 2, mock.method + assert_equal 2, mock.method + assert_equal 2, mock.method + end + assert_passed(test_result) + end + + def test_should_find_latest_expectation_which_has_not_stopped_matching + test_result = run_test do + mock = mock() + mock.stubs(:method).returns(1) + mock.stubs(:method).once.returns(2) + assert_equal 2, mock.method + assert_equal 1, mock.method + assert_equal 1, mock.method + end + assert_passed(test_result) + end + + def test_should_keep_finding_later_stub_and_so_never_satisfy_earlier_expectation + test_result = run_test do + mock = mock() + mock.expects(:method).returns(1) + mock.stubs(:method).returns(2) + assert_equal 2, mock.method + assert_equal 2, mock.method + assert_equal 2, mock.method + end + assert_failed(test_result) + end + + def test_should_find_later_expectation_until_it_stops_matching_then_find_earlier_stub + test_result = run_test do + mock = mock() + mock.stubs(:method).returns(1) + mock.expects(:method).returns(2) + assert_equal 2, mock.method + assert_equal 1, mock.method + assert_equal 1, mock.method + end + assert_passed(test_result) + end + + def test_should_find_latest_expectation_with_range_of_expected_invocation_count_which_has_not_stopped_matching + test_result = run_test do + mock = mock() + mock.stubs(:method).returns(1) + mock.stubs(:method).times(2..3).returns(2) + assert_equal 2, mock.method + assert_equal 2, mock.method + assert_equal 2, mock.method + assert_equal 1, mock.method + assert_equal 1, mock.method + end + assert_passed(test_result) + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/test/acceptance/optional_parameters_test.rb b/vendor/gems/mocha-0.9.1/test/acceptance/optional_parameters_test.rb new file mode 100644 index 0000000..e7e0528 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/acceptance/optional_parameters_test.rb @@ -0,0 +1,70 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' + +class OptionalParameterMatcherTest < Test::Unit::TestCase + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_pass_if_all_required_parameters_match_and_no_optional_parameters_are_supplied + test_result = run_test do + mock = mock() + mock.expects(:method).with(1, 2, optionally(3, 4)) + mock.method(1, 2) + end + assert_passed(test_result) + end + + def test_should_pass_if_all_required_and_optional_parameters_match_and_some_optional_parameters_are_supplied + test_result = run_test do + mock = mock() + mock.expects(:method).with(1, 2, optionally(3, 4)) + mock.method(1, 2, 3) + end + assert_passed(test_result) + end + + def test_should_pass_if_all_required_and_optional_parameters_match_and_all_optional_parameters_are_supplied + test_result = run_test do + mock = mock() + mock.expects(:method).with(1, 2, optionally(3, 4)) + mock.method(1, 2, 3, 4) + end + assert_passed(test_result) + end + + def test_should_fail_if_all_required_and_optional_parameters_match_but_too_many_optional_parameters_are_supplied + test_result = run_test do + mock = mock() + mock.expects(:method).with(1, 2, optionally(3, 4)) + mock.method(1, 2, 3, 4, 5) + end + assert_failed(test_result) + end + + def test_should_fail_if_all_required_parameters_match_but_some_optional_parameters_do_not_match + test_result = run_test do + mock = mock() + mock.expects(:method).with(1, 2, optionally(3, 4)) + mock.method(1, 2, 4) + end + assert_failed(test_result) + end + + def test_should_fail_if_all_required_parameters_match_but_no_optional_parameters_match + test_result = run_test do + mock = mock() + mock.expects(:method).with(1, 2, optionally(3, 4)) + mock.method(1, 2, 4, 5) + end + assert_failed(test_result) + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/test/acceptance/parameter_matcher_test.rb b/vendor/gems/mocha-0.9.1/test/acceptance/parameter_matcher_test.rb new file mode 100644 index 0000000..958a091 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/acceptance/parameter_matcher_test.rb @@ -0,0 +1,179 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' + +class ParameterMatcherTest < Test::Unit::TestCase + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_match_hash_parameter_with_specified_key + test_result = run_test do + mock = mock() + mock.expects(:method).with(has_key(:key_1)) + mock.method(:key_1 => 'value_1', :key_2 => 'value_2') + end + assert_passed(test_result) + end + + def test_should_not_match_hash_parameter_with_specified_key + test_result = run_test do + mock = mock() + mock.expects(:method).with(has_key(:key_1)) + mock.method(:key_2 => 'value_2') + end + assert_failed(test_result) + end + + def test_should_match_hash_parameter_with_specified_value + test_result = run_test do + mock = mock() + mock.expects(:method).with(has_value('value_1')) + mock.method(:key_1 => 'value_1', :key_2 => 'value_2') + end + assert_passed(test_result) + end + + def test_should_not_match_hash_parameter_with_specified_value + test_result = run_test do + mock = mock() + mock.expects(:method).with(has_value('value_1')) + mock.method(:key_2 => 'value_2') + end + assert_failed(test_result) + end + + def test_should_match_hash_parameter_with_specified_key_value_pair + test_result = run_test do + mock = mock() + mock.expects(:method).with(has_entry(:key_1, 'value_1')) + mock.method(:key_1 => 'value_1', :key_2 => 'value_2') + end + assert_passed(test_result) + end + + def test_should_not_match_hash_parameter_with_specified_key_value_pair + test_result = run_test do + mock = mock() + mock.expects(:method).with(has_entry(:key_1, 'value_2')) + mock.method(:key_1 => 'value_1', :key_2 => 'value_2') + end + assert_failed(test_result) + end + + def test_should_match_hash_parameter_with_specified_hash_entry + test_result = run_test do + mock = mock() + mock.expects(:method).with(has_entry(:key_1 => 'value_1')) + mock.method(:key_1 => 'value_1', :key_2 => 'value_2') + end + assert_passed(test_result) + end + + def test_should_not_match_hash_parameter_with_specified_hash_entry + test_result = run_test do + mock = mock() + mock.expects(:method).with(has_entry(:key_1 => 'value_2')) + mock.method(:key_1 => 'value_1', :key_2 => 'value_2') + end + assert_failed(test_result) + end + + def test_should_match_hash_parameter_with_specified_entries + test_result = run_test do + mock = mock() + mock.expects(:method).with(has_entries(:key_1 => 'value_1', :key_2 => 'value_2')) + mock.method(:key_1 => 'value_1', :key_2 => 'value_2', :key_3 => 'value_3') + end + assert_passed(test_result) + end + + def test_should_not_match_hash_parameter_with_specified_entries + test_result = run_test do + mock = mock() + mock.expects(:method).with(has_entries(:key_1 => 'value_1', :key_2 => 'value_2')) + mock.method(:key_1 => 'value_1', :key_2 => 'value_3') + end + assert_failed(test_result) + end + + def test_should_match_parameter_that_matches_regular_expression + test_result = run_test do + mock = mock() + mock.expects(:method).with(regexp_matches(/meter/)) + mock.method('this parameter should match') + end + assert_passed(test_result) + end + + def test_should_not_match_parameter_that_does_not_match_regular_expression + test_result = run_test do + mock = mock() + mock.expects(:method).with(regexp_matches(/something different/)) + mock.method('this parameter should not match') + end + assert_failed(test_result) + end + + def test_should_match_hash_parameter_with_specified_entries_using_nested_matchers + test_result = run_test do + mock = mock() + mock.expects(:method).with(has_entries(:key_1 => regexp_matches(/value_1/), kind_of(Symbol) => 'value_2')) + mock.method(:key_1 => 'value_1', :key_2 => 'value_2', :key_3 => 'value_3') + end + assert_passed(test_result) + end + + def test_should_not_match_hash_parameter_with_specified_entries_using_nested_matchers + test_result = run_test do + mock = mock() + mock.expects(:method).with(has_entries(:key_1 => regexp_matches(/value_1/), kind_of(String) => 'value_2')) + mock.method(:key_1 => 'value_2', :key_2 => 'value_3') + end + assert_failed(test_result) + end + + def test_should_match_parameter_that_matches_any_value + test_result = run_test do + mock = mock() + mock.expects(:method).with(any_of('value_1', 'value_2')).times(2) + mock.method('value_1') + mock.method('value_2') + end + assert_passed(test_result) + end + + def test_should_not_match_parameter_that_does_not_match_any_value + test_result = run_test do + mock = mock() + mock.expects(:method).with(any_of('value_1', 'value_2')) + mock.method('value_3') + end + assert_failed(test_result) + end + + def test_should_match_parameter_that_matches_all_values + test_result = run_test do + mock = mock() + mock.expects(:method).with(all_of('value_1', 'value_1')) + mock.method('value_1') + end + assert_passed(test_result) + end + + def test_should_not_match_parameter_that_does_not_match_all_values + test_result = run_test do + mock = mock() + mock.expects(:method).with(all_of('value_1', 'value_2')) + mock.method('value_1') + end + assert_failed(test_result) + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/test/acceptance/partial_mocks_test.rb b/vendor/gems/mocha-0.9.1/test/acceptance/partial_mocks_test.rb new file mode 100644 index 0000000..b44f8f5 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/acceptance/partial_mocks_test.rb @@ -0,0 +1,47 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' + +class PartialMockTest < Test::Unit::TestCase + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_pass_if_all_expectations_are_satisfied + test_result = run_test do + partial_mock_one = "partial_mock_one" + partial_mock_two = "partial_mock_two" + + partial_mock_one.expects(:first) + partial_mock_one.expects(:second) + partial_mock_two.expects(:third) + + partial_mock_one.first + partial_mock_one.second + partial_mock_two.third + end + assert_passed(test_result) + end + + def test_should_fail_if_all_expectations_are_not_satisfied + test_result = run_test do + partial_mock_one = "partial_mock_one" + partial_mock_two = "partial_mock_two" + + partial_mock_one.expects(:first) + partial_mock_one.expects(:second) + partial_mock_two.expects(:third) + + partial_mock_one.first + partial_mock_two.third + end + assert_failed(test_result) + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/test/acceptance/return_value_test.rb b/vendor/gems/mocha-0.9.1/test/acceptance/return_value_test.rb new file mode 100644 index 0000000..22dcbf3 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/acceptance/return_value_test.rb @@ -0,0 +1,52 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' + +class ReturnValueTest < Test::Unit::TestCase + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_build_mock_and_explicitly_add_an_expectation_with_a_return_value + test_result = run_test do + foo = mock('foo') + foo.expects(:bar).returns('bar') + assert_equal 'bar', foo.bar + end + assert_passed(test_result) + end + + def test_should_build_mock_incorporating_two_expectations_with_return_values + test_result = run_test do + foo = mock('foo', :bar => 'bar', :baz => 'baz') + assert_equal 'bar', foo.bar + assert_equal 'baz', foo.baz + end + assert_passed(test_result) + end + + def test_should_build_stub_and_explicitly_add_an_expectation_with_a_return_value + test_result = run_test do + foo = stub('foo') + foo.stubs(:bar).returns('bar') + assert_equal 'bar', foo.bar + end + assert_passed(test_result) + end + + def test_should_build_stub_incorporating_two_expectations_with_return_values + test_result = run_test do + foo = stub('foo', :bar => 'bar', :baz => 'baz') + assert_equal 'bar', foo.bar + assert_equal 'baz', foo.baz + end + assert_passed(test_result) + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/test/acceptance/sequence_test.rb b/vendor/gems/mocha-0.9.1/test/acceptance/sequence_test.rb new file mode 100644 index 0000000..421e313 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/acceptance/sequence_test.rb @@ -0,0 +1,186 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' + +class SequenceTest < Test::Unit::TestCase + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_constrain_invocations_to_occur_in_expected_order + test_result = run_test do + mock = mock() + sequence = sequence('one') + + mock.expects(:first).in_sequence(sequence) + mock.expects(:second).in_sequence(sequence) + + mock.second + end + assert_failed(test_result) + end + + def test_should_allow_invocations_in_sequence + test_result = run_test do + mock = mock() + sequence = sequence('one') + + mock.expects(:first).in_sequence(sequence) + mock.expects(:second).in_sequence(sequence) + + mock.first + mock.second + end + assert_passed(test_result) + end + + def test_should_constrain_invocations_to_occur_in_expected_order_even_if_expected_on_different_mocks + test_result = run_test do + mock_one = mock('1') + mock_two = mock('2') + sequence = sequence('one') + + mock_one.expects(:first).in_sequence(sequence) + mock_two.expects(:second).in_sequence(sequence) + + mock_two.second + end + assert_failed(test_result) + end + + def test_should_allow_invocations_in_sequence_even_if_expected_on_different_mocks + test_result = run_test do + mock_one = mock('1') + mock_two = mock('2') + sequence = sequence('one') + + mock_one.expects(:first).in_sequence(sequence) + mock_two.expects(:second).in_sequence(sequence) + + mock_one.first + mock_two.second + end + assert_passed(test_result) + end + + def test_should_constrain_invocations_to_occur_in_expected_order_even_if_expected_on_partial_mocks + test_result = run_test do + partial_mock_one = "1" + partial_mock_two = "2" + sequence = sequence('one') + + partial_mock_one.expects(:first).in_sequence(sequence) + partial_mock_two.expects(:second).in_sequence(sequence) + + partial_mock_two.second + end + assert_failed(test_result) + end + + def test_should_allow_invocations_in_sequence_even_if_expected_on_partial_mocks + test_result = run_test do + partial_mock_one = "1" + partial_mock_two = "2" + sequence = sequence('one') + + partial_mock_one.expects(:first).in_sequence(sequence) + partial_mock_two.expects(:second).in_sequence(sequence) + + partial_mock_one.first + partial_mock_two.second + end + assert_passed(test_result) + end + + def test_should_allow_stub_expectations_to_be_skipped_in_sequence + test_result = run_test do + mock = mock() + sequence = sequence('one') + + mock.expects(:first).in_sequence(sequence) + mock.stubs(:second).in_sequence(sequence) + mock.expects(:third).in_sequence(sequence) + + mock.first + mock.third + end + assert_passed(test_result) + end + + def test_should_regard_sequences_as_independent_of_each_other + test_result = run_test do + mock = mock() + sequence_one = sequence('one') + sequence_two = sequence('two') + + mock.expects(:first).in_sequence(sequence_one) + mock.expects(:second).in_sequence(sequence_one) + + mock.expects(:third).in_sequence(sequence_two) + mock.expects(:fourth).in_sequence(sequence_two) + + mock.first + mock.third + mock.second + mock.fourth + end + assert_passed(test_result) + end + + def test_should_include_sequence_in_failure_message + test_result = run_test do + mock = mock() + sequence = sequence('one') + + mock.expects(:first).in_sequence(sequence) + mock.expects(:second).in_sequence(sequence) + + mock.second + end + assert_failed(test_result) + assert_match Regexp.new("in sequence 'one'"), test_result.failures.first.message + end + + def test_should_allow_expectations_to_be_in_more_than_one_sequence + test_result = run_test do + mock = mock() + sequence_one = sequence('one') + sequence_two = sequence('two') + + mock.expects(:first).in_sequence(sequence_one) + mock.expects(:second).in_sequence(sequence_two) + mock.expects(:three).in_sequence(sequence_one).in_sequence(sequence_two) + + mock.first + mock.three + end + assert_failed(test_result) + assert_match Regexp.new("in sequence 'one'"), test_result.failures.first.message + assert_match Regexp.new("in sequence 'two'"), test_result.failures.first.message + end + + def test_should_have_shortcut_for_expectations_to_be_in_more_than_one_sequence + test_result = run_test do + mock = mock() + sequence_one = sequence('one') + sequence_two = sequence('two') + + mock.expects(:first).in_sequence(sequence_one) + mock.expects(:second).in_sequence(sequence_two) + mock.expects(:three).in_sequence(sequence_one, sequence_two) + + mock.first + mock.three + end + assert_failed(test_result) + assert_match Regexp.new("in sequence 'one'"), test_result.failures.first.message + assert_match Regexp.new("in sequence 'two'"), test_result.failures.first.message + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/test/acceptance/standalone_test.rb b/vendor/gems/mocha-0.9.1/test/acceptance/standalone_test.rb new file mode 100644 index 0000000..9ad0461 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/acceptance/standalone_test.rb @@ -0,0 +1,139 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha_standalone' +require 'simple_counter' + +class NotATestUnitAssertionFailedError < StandardError +end + +class NotATestUnitTestCase + + include Mocha::Standalone + + attr_reader :assertion_counter + + def initialize + @assertion_counter = SimpleCounter.new + end + + def run(test_method) + mocha_setup + begin + prepare + begin + send(test_method) + mocha_verify(@assertion_counter) + rescue Mocha::ExpectationError => e + new_error = NotATestUnitAssertionFailedError.new(e.message) + new_error.set_backtrace(e.backtrace) + raise new_error + ensure + cleanup + end + ensure + mocha_teardown + end + end + + def prepare + end + + def cleanup + end + +end + +class SampleTest < NotATestUnitTestCase + + def mocha_with_fulfilled_expectation + mockee = mock() + mockee.expects(:blah) + mockee.blah + end + + def mocha_with_unfulfilled_expectation + mockee = mock() + mockee.expects(:blah) + end + + def mocha_with_unexpected_invocation + mockee = mock() + mockee.blah + end + + def stubba_with_fulfilled_expectation + stubbee = Class.new { define_method(:blah) {} }.new + stubbee.expects(:blah) + stubbee.blah + end + + def stubba_with_unfulfilled_expectation + stubbee = Class.new { define_method(:blah) {} }.new + stubbee.expects(:blah) + end + + def mocha_with_matching_parameter + mockee = mock() + mockee.expects(:blah).with(has_key(:wibble)) + mockee.blah(:wibble => 1) + end + + def mocha_with_non_matching_parameter + mockee = mock() + mockee.expects(:blah).with(has_key(:wibble)) + mockee.blah(:wobble => 2) + end + +end + +require 'test/unit' + +class StandaloneTest < Test::Unit::TestCase + + attr_reader :sample_test + + include AcceptanceTest + + def setup + @sample_test = SampleTest.new + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_pass_mocha_test + assert_nothing_raised { sample_test.run(:mocha_with_fulfilled_expectation) } + assert_equal 1, sample_test.assertion_counter.count + end + + def test_should_fail_mocha_test_due_to_unfulfilled_exception + assert_raises(NotATestUnitAssertionFailedError) { sample_test.run(:mocha_with_unfulfilled_expectation) } + assert_equal 1, sample_test.assertion_counter.count + end + + def test_should_fail_mocha_test_due_to_unexpected_invocation + assert_raises(NotATestUnitAssertionFailedError) { sample_test.run(:mocha_with_unexpected_invocation) } + assert_equal 0, sample_test.assertion_counter.count + end + + def test_should_pass_stubba_test + assert_nothing_raised { sample_test.run(:stubba_with_fulfilled_expectation) } + assert_equal 1, sample_test.assertion_counter.count + end + + def test_should_fail_stubba_test + assert_raises(NotATestUnitAssertionFailedError) { sample_test.run(:stubba_with_unfulfilled_expectation) } + assert_equal 1, sample_test.assertion_counter.count + end + + def test_should_pass_mocha_test_with_matching_parameter + assert_nothing_raised { sample_test.run(:mocha_with_matching_parameter) } + assert_equal 1, sample_test.assertion_counter.count + end + + def test_should_fail_mocha_test_with_non_matching_parameter + assert_raises(NotATestUnitAssertionFailedError) { sample_test.run(:mocha_with_non_matching_parameter) } + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/test/acceptance/states_test.rb b/vendor/gems/mocha-0.9.1/test/acceptance/states_test.rb new file mode 100644 index 0000000..8b4df25 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/acceptance/states_test.rb @@ -0,0 +1,70 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' + +class StatesTest < Test::Unit::TestCase + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_constrain_expectations_to_occur_within_a_given_state + test_result = run_test do + mock = mock() + readiness = states('readiness') + + mock.stubs(:first).when(readiness.is('ready')) + mock.stubs(:second).then(readiness.is('ready')) + + mock.first + end + assert_failed(test_result) + end + + def test_should_allow_expectations_to_occur_in_correct_state + test_result = run_test do + mock = mock() + readiness = states('readiness') + + mock.stubs(:first).when(readiness.is('ready')) + mock.stubs(:second).then(readiness.is('ready')) + + mock.second + mock.first + end + assert_passed(test_result) + end + + def test_should_be_able_to_start_in_a_specific_state + test_result = run_test do + mock = mock() + readiness = states('readiness') + + mock.stubs(:first).when(readiness.is('ready')) + + readiness.starts_as('ready') + mock.first + end + assert_passed(test_result) + end + + def test_should_switch_state_when_method_raises_an_exception + test_result = run_test do + mock = mock() + readiness = states('readiness') + + mock.expects(:first).raises().then(readiness.is('ready')) + mock.expects(:second).when(readiness.is('ready')) + + mock.first rescue nil + mock.second + end + assert_passed(test_result) + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/test/acceptance/stub_any_instance_method_test.rb b/vendor/gems/mocha-0.9.1/test/acceptance/stub_any_instance_method_test.rb new file mode 100644 index 0000000..b7f3064 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/acceptance/stub_any_instance_method_test.rb @@ -0,0 +1,195 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' + +class StubAnyInstanceMethodTest < Test::Unit::TestCase + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_stub_method_within_test + klass = Class.new do + def my_instance_method + :original_return_value + end + end + instance = klass.new + test_result = run_test do + klass.any_instance.stubs(:my_instance_method).returns(:new_return_value) + assert_equal :new_return_value, instance.my_instance_method + end + assert_passed(test_result) + end + + def test_should_leave_stubbed_public_method_unchanged_after_test + klass = Class.new do + def my_instance_method + :original_return_value + end + end + instance = klass.new + run_test do + klass.any_instance.stubs(:my_instance_method).returns(:new_return_value) + end + assert instance.public_methods(false).any? { |m| m.to_s == 'my_instance_method' } + assert_equal :original_return_value, instance.my_instance_method + end + + def test_should_leave_stubbed_protected_method_unchanged_after_test + klass = Class.new do + def my_instance_method + :original_return_value + end + protected :my_instance_method + end + instance = klass.new + run_test do + klass.any_instance.stubs(:my_instance_method).returns(:new_return_value) + end + assert instance.protected_methods(false).any? { |m| m.to_s == 'my_instance_method' } + assert_equal :original_return_value, instance.send(:my_instance_method) + end + + def test_should_leave_stubbed_private_method_unchanged_after_test + klass = Class.new do + def my_instance_method + :original_return_value + end + private :my_instance_method + end + instance = klass.new + run_test do + klass.any_instance.stubs(:my_instance_method).returns(:new_return_value) + end + assert instance.private_methods(false).any? { |m| m.to_s == 'my_instance_method' } + assert_equal :original_return_value, instance.send(:my_instance_method) + end + + def test_should_reset_expectations_after_test + klass = Class.new do + def my_instance_method + :original_return_value + end + end + instance = klass.new + run_test do + klass.any_instance.stubs(:my_instance_method).returns(:new_return_value) + end + assert_equal 0, klass.any_instance.mocha.expectations.length + end + + def test_should_be_able_to_stub_a_superclass_method + superklass = Class.new do + def my_superclass_method + :original_return_value + end + end + klass = Class.new(superklass) + instance = klass.new + test_result = run_test do + klass.any_instance.stubs(:my_superclass_method).returns(:new_return_value) + assert_equal :new_return_value, instance.my_superclass_method + end + assert_passed(test_result) + assert instance.public_methods(true).any? { |m| m.to_s == 'my_superclass_method' } + assert !klass.public_methods(false).any? { |m| m.to_s == 'my_superclass_method' } + assert_equal :original_return_value, instance.my_superclass_method + end + + def test_should_be_able_to_stub_method_if_ruby18_public_instance_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy + ruby18_klass = Class.new do + class << self + def public_instance_methods(include_superclass = true) + ['my_instance_method'] + end + end + end + test_result = run_test do + ruby18_klass.any_instance.stubs(:my_instance_method).returns(:new_return_value) + assert_equal :new_return_value, ruby18_klass.new.my_instance_method + end + assert_passed(test_result) + end + + def test_should_be_able_to_stub_method_if_ruby19_public_instance_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy + ruby19_klass = Class.new do + class << self + def public_instance_methods(include_superclass = true) + [:my_instance_method] + end + end + end + test_result = run_test do + ruby19_klass.any_instance.stubs(:my_instance_method).returns(:new_return_value) + assert_equal :new_return_value, ruby19_klass.new.my_instance_method + end + assert_passed(test_result) + end + + def test_should_be_able_to_stub_method_if_ruby18_protected_instance_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy + ruby18_klass = Class.new do + class << self + def protected_instance_methods(include_superclass = true) + ['my_instance_method'] + end + end + end + test_result = run_test do + ruby18_klass.any_instance.stubs(:my_instance_method).returns(:new_return_value) + assert_equal :new_return_value, ruby18_klass.new.my_instance_method + end + assert_passed(test_result) + end + + def test_should_be_able_to_stub_method_if_ruby19_protected_instance_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy + ruby19_klass = Class.new do + class << self + def protected_instance_methods(include_superclass = true) + [:my_instance_method] + end + end + end + test_result = run_test do + ruby19_klass.any_instance.stubs(:my_instance_method).returns(:new_return_value) + assert_equal :new_return_value, ruby19_klass.new.my_instance_method + end + assert_passed(test_result) + end + + def test_should_be_able_to_stub_method_if_ruby18_private_instance_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy + ruby18_klass = Class.new do + class << self + def private_instance_methods(include_superclass = true) + ['my_instance_method'] + end + end + end + test_result = run_test do + ruby18_klass.any_instance.stubs(:my_instance_method).returns(:new_return_value) + assert_equal :new_return_value, ruby18_klass.new.my_instance_method + end + assert_passed(test_result) + end + + def test_should_be_able_to_stub_method_if_ruby19_private_instance_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy + ruby19_klass = Class.new do + class << self + def private_instance_methods(include_superclass = true) + [:my_instance_method] + end + end + end + test_result = run_test do + ruby19_klass.any_instance.stubs(:my_instance_method).returns(:new_return_value) + assert_equal :new_return_value, ruby19_klass.new.my_instance_method + end + assert_passed(test_result) + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/test/acceptance/stub_class_method_test.rb b/vendor/gems/mocha-0.9.1/test/acceptance/stub_class_method_test.rb new file mode 100644 index 0000000..2a21ba6 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/acceptance/stub_class_method_test.rb @@ -0,0 +1,203 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' + +class StubClassMethodTest < Test::Unit::TestCase + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_stub_method_within_test + klass = Class.new do + class << self + def my_class_method + :original_return_value + end + end + end + test_result = run_test do + klass.stubs(:my_class_method).returns(:new_return_value) + assert_equal :new_return_value, klass.my_class_method + end + assert_passed(test_result) + end + + def test_should_leave_stubbed_public_method_unchanged_after_test + klass = Class.new do + class << self + def my_class_method + :original_return_value + end + end + end + run_test do + klass.stubs(:my_class_method).returns(:new_return_value) + end + assert klass.public_methods(false).any? { |m| m.to_s == 'my_class_method' } + assert_equal :original_return_value, klass.my_class_method + end + + def test_should_leave_stubbed_protected_method_unchanged_after_test + klass = Class.new do + class << self + def my_class_method + :original_return_value + end + protected :my_class_method + end + end + run_test do + klass.stubs(:my_class_method).returns(:new_return_value) + end + assert klass.protected_methods(false).any? { |m| m.to_s == 'my_class_method' } + assert_equal :original_return_value, klass.send(:my_class_method) + end + + def test_should_leave_stubbed_private_method_unchanged_after_test + klass = Class.new do + class << self + def my_class_method + :original_return_value + end + private :my_class_method + end + end + run_test do + klass.stubs(:my_class_method).returns(:new_return_value) + end + assert klass.private_methods(false).any? { |m| m.to_s == 'my_class_method' } + assert_equal :original_return_value, klass.send(:my_class_method) + end + + def test_should_reset_class_expectations_after_test + klass = Class.new do + class << self + def my_class_method + :original_return_value + end + end + end + run_test do + klass.stubs(:my_class_method) + end + assert_equal 0, klass.mocha.expectations.length + end + + def test_should_be_able_to_stub_a_superclass_method + superklass = Class.new do + class << self + def my_superclass_method + :original_return_value + end + end + end + klass = Class.new(superklass) + test_result = run_test do + klass.stubs(:my_superclass_method).returns(:new_return_value) + assert_equal :new_return_value, klass.my_superclass_method + end + assert_passed(test_result) + superklass_public_methods = superklass.public_methods - superklass.superclass.public_methods + assert superklass_public_methods.any? { |m| m.to_s == 'my_superclass_method' } + klass_public_methods = klass.public_methods - klass.superclass.public_methods + assert !klass_public_methods.any? { |m| m.to_s == 'my_superclass_method' } + assert_equal :original_return_value, superklass.my_superclass_method + end + + def test_should_be_able_to_stub_method_if_ruby18_public_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy + ruby18_klass = Class.new do + class << self + def public_methods(include_superclass = true) + ['my_class_method'] + end + end + end + test_result = run_test do + ruby18_klass.stubs(:my_class_method).returns(:new_return_value) + assert_equal :new_return_value, ruby18_klass.my_class_method + end + assert_passed(test_result) + end + + def test_should_be_able_to_stub_method_if_ruby19_public_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy + ruby19_klass = Class.new do + class << self + def public_methods(include_superclass = true) + [:my_class_method] + end + end + end + test_result = run_test do + ruby19_klass.stubs(:my_class_method).returns(:new_return_value) + assert_equal :new_return_value, ruby19_klass.my_class_method + end + assert_passed(test_result) + end + + def test_should_be_able_to_stub_method_if_ruby18_protected_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy + ruby18_klass = Class.new do + class << self + def protected_methods(include_superclass = true) + ['my_class_method'] + end + end + end + test_result = run_test do + ruby18_klass.stubs(:my_class_method).returns(:new_return_value) + assert_equal :new_return_value, ruby18_klass.my_class_method + end + assert_passed(test_result) + end + + def test_should_be_able_to_stub_method_if_ruby19_protected_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy + ruby19_klass = Class.new do + class << self + def protected_methods(include_superclass = true) + [:my_class_method] + end + end + end + test_result = run_test do + ruby19_klass.stubs(:my_class_method).returns(:new_return_value) + assert_equal :new_return_value, ruby19_klass.my_class_method + end + assert_passed(test_result) + end + + def test_should_be_able_to_stub_method_if_ruby18_private_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy + ruby18_klass = Class.new do + class << self + def private_methods(include_superclass = true) + ['my_class_method'] + end + end + end + test_result = run_test do + ruby18_klass.stubs(:my_class_method).returns(:new_return_value) + assert_equal :new_return_value, ruby18_klass.my_class_method + end + assert_passed(test_result) + end + + def test_should_be_able_to_stub_method_if_ruby19_private_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy + ruby19_klass = Class.new do + class << self + def private_methods(include_superclass = true) + [:my_class_method] + end + end + end + test_result = run_test do + ruby19_klass.stubs(:my_class_method).returns(:new_return_value) + assert_equal :new_return_value, ruby19_klass.my_class_method + end + assert_passed(test_result) + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/test/acceptance/stub_everything_test.rb b/vendor/gems/mocha-0.9.1/test/acceptance/stub_everything_test.rb new file mode 100644 index 0000000..b792eda --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/acceptance/stub_everything_test.rb @@ -0,0 +1,56 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' + +class StubEverythingTest < Test::Unit::TestCase + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_build_stub_and_explicitly_add_an_expectation + test_result = run_test do + foo = stub_everything() + foo.stubs(:bar) + foo.bar + foo.unexpected_invocation + end + assert_passed(test_result) + end + + def test_should_build_named_stub_and_explicitly_add_an_expectation + test_result = run_test do + foo = stub_everything('foo') + foo.stubs(:bar) + foo.bar + foo.unexpected_invocation + end + assert_passed(test_result) + end + + def test_should_build_stub_incorporating_two_expectations + test_result = run_test do + foo = stub_everything(:bar => 'bar', :baz => 'baz') + foo.bar + foo.baz + foo.unexpected_invocation + end + assert_passed(test_result) + end + + def test_should_build_named_stub_incorporating_two_expectations + test_result = run_test do + foo = stub_everything('foo', :bar => 'bar', :baz => 'baz') + foo.bar + foo.baz + foo.unexpected_invocation + end + assert_passed(test_result) + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/test/acceptance/stub_instance_method_test.rb b/vendor/gems/mocha-0.9.1/test/acceptance/stub_instance_method_test.rb new file mode 100644 index 0000000..74b93ec --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/acceptance/stub_instance_method_test.rb @@ -0,0 +1,165 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' + +class StubInstanceMethodTest < Test::Unit::TestCase + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_leave_stubbed_public_method_unchanged_after_test + instance = Class.new do + def my_instance_method + :original_return_value + end + end.new + run_test do + instance.stubs(:my_instance_method).returns(:new_return_value) + end + assert instance.public_methods(false).any? { |m| m.to_s == 'my_instance_method' } + assert_equal :original_return_value, instance.my_instance_method + end + + def test_should_leave_stubbed_protected_method_unchanged_after_test + instance = Class.new do + def my_instance_method + :original_return_value + end + protected :my_instance_method + end.new + run_test do + instance.stubs(:my_instance_method).returns(:new_return_value) + end + assert instance.protected_methods(false).any? { |m| m.to_s == 'my_instance_method' } + assert_equal :original_return_value, instance.send(:my_instance_method) + end + + def test_should_leave_stubbed_private_method_unchanged_after_test + instance = Class.new do + def my_instance_method + :original_return_value + end + private :my_instance_method + end.new + run_test do + instance.stubs(:my_instance_method).returns(:new_return_value) + end + assert instance.private_methods(false).any? { |m| m.to_s == 'my_instance_method' } + assert_equal :original_return_value, instance.send(:my_instance_method) + end + + def test_should_reset_expectations_after_test + instance = Class.new do + def my_instance_method + :original_return_value + end + end.new + run_test do + instance.stubs(:my_instance_method).returns(:new_return_value) + end + assert_equal 0, instance.mocha.expectations.length + end + + def test_should_be_able_to_stub_a_superclass_method + superklass = Class.new do + def my_superclass_method + :original_return_value + end + end + klass = Class.new(superklass) + instance = klass.new + test_result = run_test do + instance.stubs(:my_superclass_method).returns(:new_return_value) + assert_equal :new_return_value, instance.my_superclass_method + end + assert_passed(test_result) + assert instance.public_methods(true).any? { |m| m.to_s == 'my_superclass_method' } + assert !instance.public_methods(false).any? { |m| m.to_s == 'my_superclass_method' } + assert_equal :original_return_value, instance.my_superclass_method + end + + def test_should_be_able_to_stub_method_if_ruby18_public_methods_include_method_but_method_does_not_exist_like_active_record_association_proxy + ruby18_instance = Class.new do + def public_methods(include_superclass = true) + ['my_instance_method'] + end + end.new + test_result = run_test do + ruby18_instance.stubs(:my_instance_method).returns(:new_return_value) + assert_equal :new_return_value, ruby18_instance.my_instance_method + end + assert_passed(test_result) + end + + def test_should_be_able_to_stub_method_if_ruby19_public_methods_include_method_but_method_does_not_exist_like_active_record_association_proxy + ruby19_instance = Class.new do + def public_methods(include_superclass = true) + [:my_instance_method] + end + end.new + test_result = run_test do + ruby19_instance.stubs(:my_instance_method).returns(:new_return_value) + assert_equal :new_return_value, ruby19_instance.my_instance_method + end + assert_passed(test_result) + end + + def test_should_be_able_to_stub_method_if_ruby18_protected_methods_include_method_but_method_does_not_exist_like_active_record_association_proxy + ruby18_instance = Class.new do + def protected_methods(include_superclass = true) + ['my_instance_method'] + end + end.new + test_result = run_test do + ruby18_instance.stubs(:my_instance_method).returns(:new_return_value) + assert_equal :new_return_value, ruby18_instance.my_instance_method + end + assert_passed(test_result) + end + + def test_should_be_able_to_stub_method_if_ruby19_protected_methods_include_method_but_method_does_not_exist_like_active_record_association_proxy + ruby19_instance = Class.new do + def protected_methods(include_superclass = true) + [:my_instance_method] + end + end.new + test_result = run_test do + ruby19_instance.stubs(:my_instance_method).returns(:new_return_value) + assert_equal :new_return_value, ruby19_instance.my_instance_method + end + assert_passed(test_result) + end + + def test_should_be_able_to_stub_method_if_ruby18_private_methods_include_method_but_method_does_not_exist_like_active_record_association_proxy + ruby18_instance = Class.new do + def private_methods(include_superclass = true) + ['my_instance_method'] + end + end.new + test_result = run_test do + ruby18_instance.stubs(:my_instance_method).returns(:new_return_value) + assert_equal :new_return_value, ruby18_instance.my_instance_method + end + assert_passed(test_result) + end + + def test_should_be_able_to_stub_method_if_ruby19_private_methods_include_method_but_method_does_not_exist_like_active_record_association_proxy + ruby19_instance = Class.new do + def private_methods(include_superclass = true) + [:my_instance_method] + end + end.new + test_result = run_test do + ruby19_instance.stubs(:my_instance_method).returns(:new_return_value) + assert_equal :new_return_value, ruby19_instance.my_instance_method + end + assert_passed(test_result) + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/test/acceptance/stub_module_method_test.rb b/vendor/gems/mocha-0.9.1/test/acceptance/stub_module_method_test.rb new file mode 100644 index 0000000..99da7db --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/acceptance/stub_module_method_test.rb @@ -0,0 +1,163 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' + +class StubModuleMethodTest < Test::Unit::TestCase + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_stub_method_within_test + mod = Module.new { def self.my_module_method; :original_return_value; end } + test_result = run_test do + mod.stubs(:my_module_method).returns(:new_return_value) + assert_equal :new_return_value, mod.my_module_method + end + assert_passed(test_result) + end + + def test_should_leave_stubbed_public_method_unchanged_after_test + mod = Module.new { class << self; def my_module_method; :original_return_value; end; public :my_module_method; end } + run_test do + mod.stubs(:my_module_method).returns(:new_return_value) + end + assert mod.public_methods(false).any? { |m| m.to_s == 'my_module_method' } + assert_equal :original_return_value, mod.my_module_method + end + + def test_should_leave_stubbed_protected_method_unchanged_after_test + mod = Module.new { class << self; def my_module_method; :original_return_value; end; protected :my_module_method; end } + run_test do + mod.stubs(:my_module_method).returns(:new_return_value) + end + assert mod.protected_methods(false).any? { |m| m.to_s == 'my_module_method' } + assert_equal :original_return_value, mod.send(:my_module_method) + end + + def test_should_leave_stubbed_private_method_unchanged_after_test + mod = Module.new { class << self; def my_module_method; :original_return_value; end; private :my_module_method; end } + run_test do + mod.stubs(:my_module_method).returns(:new_return_value) + end + assert mod.private_methods(false).any? { |m| m.to_s == 'my_module_method' } + assert_equal :original_return_value, mod.send(:my_module_method) + end + + def test_should_reset_expectations_after_test + mod = Module.new { def self.my_module_method; :original_return_value; end } + run_test do + mod.stubs(:my_module_method) + end + assert_equal 0, mod.mocha.expectations.length + end + + def test_should_be_able_to_stub_a_superclass_method + supermod = Module.new { def self.my_superclass_method; :original_return_value; end } + mod = Module.new { include supermod } + test_result = run_test do + mod.stubs(:my_superclass_method).returns(:new_return_value) + assert_equal :new_return_value, mod.my_superclass_method + end + assert_passed(test_result) + assert supermod.public_methods.any? { |m| m.to_s == 'my_superclass_method' } + assert !mod.public_methods(false).any? { |m| m.to_s == 'my_superclass_method' } + assert_equal :original_return_value, supermod.my_superclass_method + end + + def test_should_be_able_to_stub_method_if_ruby18_public_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy + ruby18_mod = Module.new do + class << self + def public_methods(include_superclass = true) + ['my_module_method'] + end + end + end + test_result = run_test do + ruby18_mod.stubs(:my_module_method).returns(:new_return_value) + assert_equal :new_return_value, ruby18_mod.my_module_method + end + assert_passed(test_result) + end + + def test_should_be_able_to_stub_method_if_ruby19_public_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy + ruby19_mod = Module.new do + class << self + def public_methods(include_superclass = true) + [:my_module_method] + end + end + end + test_result = run_test do + ruby19_mod.stubs(:my_module_method).returns(:new_return_value) + assert_equal :new_return_value, ruby19_mod.my_module_method + end + assert_passed(test_result) + end + + def test_should_be_able_to_stub_method_if_ruby_18_protected_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy + ruby18_mod = Module.new do + class << self + def protected_methods(include_superclass = true) + ['my_module_method'] + end + end + end + test_result = run_test do + ruby18_mod.stubs(:my_module_method).returns(:new_return_value) + assert_equal :new_return_value, ruby18_mod.my_module_method + end + assert_passed(test_result) + end + + def test_should_be_able_to_stub_method_if_ruby19_protected_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy + ruby19_mod = Module.new do + class << self + def protected_methods(include_superclass = true) + [:my_module_method] + end + end + end + test_result = run_test do + ruby19_mod.stubs(:my_module_method).returns(:new_return_value) + assert_equal :new_return_value, ruby19_mod.my_module_method + end + assert_passed(test_result) + end + + def test_should_be_able_to_stub_method_if_ruby18_private_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy + ruby18_mod = Module.new do + class << self + def private_methods(include_superclass = true) + ['my_module_method'] + end + end + end + test_result = run_test do + ruby18_mod.stubs(:my_module_method).returns(:new_return_value) + assert_equal :new_return_value, ruby18_mod.my_module_method + end + assert_passed(test_result) + end + + def test_should_be_able_to_stub_method_if_ruby19_private_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy + ruby19_mod = Module.new do + class << self + def private_methods(include_superclass = true) + [:my_module_method] + end + end + end + test_result = run_test do + ruby19_mod.stubs(:my_module_method).returns(:new_return_value) + assert_equal :new_return_value, ruby19_mod.my_module_method + end + assert_passed(test_result) + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/test/acceptance/stub_test.rb b/vendor/gems/mocha-0.9.1/test/acceptance/stub_test.rb new file mode 100644 index 0000000..5b12042 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/acceptance/stub_test.rb @@ -0,0 +1,52 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' + +class StubTest < Test::Unit::TestCase + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_build_stub_and_explicitly_add_an_expectation + test_result = run_test do + foo = stub() + foo.stubs(:bar) + foo.bar + end + assert_passed(test_result) + end + + def test_should_build_named_stub_and_explicitly_add_an_expectation + test_result = run_test do + foo = stub('foo') + foo.stubs(:bar) + foo.bar + end + assert_passed(test_result) + end + + def test_should_build_stub_incorporating_two_expectations + test_result = run_test do + foo = stub(:bar => 'bar', :baz => 'baz') + foo.bar + foo.baz + end + assert_passed(test_result) + end + + def test_should_build_named_stub_incorporating_two_expectations + test_result = run_test do + foo = stub('foo', :bar => 'bar', :baz => 'baz') + foo.bar + foo.baz + end + assert_passed(test_result) + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/test/acceptance/stubba_example_test.rb b/vendor/gems/mocha-0.9.1/test/acceptance/stubba_example_test.rb new file mode 100644 index 0000000..bd5a84d --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/acceptance/stubba_example_test.rb @@ -0,0 +1,102 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") +require 'mocha' + +class Widget + + def model + 'original_model' + end + + class << self + + def find(options) + [] + end + + def create(attributes) + Widget.new + end + + end + +end + +module Thingy + + def self.wotsit + :hoojamaflip + end + +end + +class StubbaExampleTest < Test::Unit::TestCase + + def test_should_stub_instance_method + widget = Widget.new + widget.expects(:model).returns('different_model') + assert_equal 'different_model', widget.model + end + + def test_should_stub_module_method + should_stub_module_method + end + + def test_should_stub_module_method_again + should_stub_module_method + end + + def test_should_stub_class_method + should_stub_class_method + end + + def test_should_stub_class_method_again + should_stub_class_method + end + + def test_should_stub_instance_method_on_any_instance_of_a_class + should_stub_instance_method_on_any_instance_of_a_class + end + + def test_should_stub_instance_method_on_any_instance_of_a_class_again + should_stub_instance_method_on_any_instance_of_a_class + end + + def test_should_stub_two_different_class_methods + should_stub_two_different_class_methods + end + + def test_should_stub_two_different_class_methods_again + should_stub_two_different_class_methods + end + + private + + def should_stub_module_method + Thingy.expects(:wotsit).returns(:dooda) + assert_equal :dooda, Thingy.wotsit + end + + def should_stub_class_method + widgets = [Widget.new] + Widget.expects(:find).with(:all).returns(widgets) + assert_equal widgets, Widget.find(:all) + end + + def should_stub_two_different_class_methods + found_widgets = [Widget.new] + created_widget = Widget.new + Widget.expects(:find).with(:all).returns(found_widgets) + Widget.expects(:create).with(:model => 'wombat').returns(created_widget) + assert_equal found_widgets, Widget.find(:all) + assert_equal created_widget, Widget.create(:model => 'wombat') + end + + def should_stub_instance_method_on_any_instance_of_a_class + Widget.any_instance.expects(:model).at_least_once.returns('another_model') + widget_1 = Widget.new + widget_2 = Widget.new + assert_equal 'another_model', widget_1.model + assert_equal 'another_model', widget_2.model + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/test/acceptance/stubba_test.rb b/vendor/gems/mocha-0.9.1/test/acceptance/stubba_test.rb new file mode 100644 index 0000000..120c86e --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/acceptance/stubba_test.rb @@ -0,0 +1,15 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") +require 'deprecation_disabler' + +class StubbaTest < Test::Unit::TestCase + + include DeprecationDisabler + + def test_should_report_deprecation_of_stubba_which_will_be_removed_in_a_future_release + disable_deprecations do + load 'stubba.rb' + end + assert_equal ["require 'stubba' is no longer needed and stubba.rb will soon be removed"], Mocha::Deprecation.messages + end + +end diff --git a/vendor/gems/mocha-0.9.1/test/acceptance/stubba_test_result_test.rb b/vendor/gems/mocha-0.9.1/test/acceptance/stubba_test_result_test.rb new file mode 100644 index 0000000..3f64078 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/acceptance/stubba_test_result_test.rb @@ -0,0 +1,66 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' +require 'execution_point' + +class StubbaTestResultTest < Test::Unit::TestCase + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_include_expectation_verification_in_assertion_count + test_result = run_test do + object = Class.new { def message; end }.new + object.expects(:message) + object.message + end + assert_equal 1, test_result.assertion_count + end + + def test_should_include_assertions_in_assertion_count + test_result = run_test do + assert true + end + assert_equal 1, test_result.assertion_count + end + + def test_should_not_include_stubbing_expectation_verification_in_assertion_count + test_result = run_test do + object = Class.new { def message; end }.new + object.stubs(:message) + object.message + end + assert_equal 0, test_result.assertion_count + end + + def test_should_include_expectation_verification_failure_in_failure_count + test_result = run_test do + object = Class.new { def message; end }.new + object.expects(:message) + end + assert_equal 1, test_result.failure_count + end + + def test_should_include_assertion_failure_in_failure_count + test_result = run_test do + flunk + end + assert_equal 1, test_result.failure_count + end + + def test_should_display_backtrace_indicating_line_number_where_failing_assertion_was_called + execution_point = nil + test_result = run_test do + execution_point = ExecutionPoint.current; flunk + end + assert_equal 1, test_result.failure_count + assert_equal execution_point, ExecutionPoint.new(test_result.failures[0].location) + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/test/acceptance/stubbing_error_backtrace_test.rb b/vendor/gems/mocha-0.9.1/test/acceptance/stubbing_error_backtrace_test.rb new file mode 100644 index 0000000..526761d --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/acceptance/stubbing_error_backtrace_test.rb @@ -0,0 +1,64 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' +require 'execution_point' + +class StubbingErrorBacktraceTest < Test::Unit::TestCase + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_display_backtrace_indicating_line_number_where_attempt_to_stub_non_existent_method_was_made + execution_point = nil + object = Object.new + Mocha::Configuration.prevent(:stubbing_non_existent_method) + test_result = run_test do + execution_point = ExecutionPoint.current; object.stubs(:non_existent_method) + end + assert_equal 1, test_result.error_count + assert_equal execution_point, ExecutionPoint.new(test_result.errors[0].exception.backtrace) + end + + def test_should_display_backtrace_indicating_line_number_where_attempt_to_stub_non_public_method_was_made + execution_point = nil + object = Class.new do + def non_public_method; end + private :non_public_method + end.new + Mocha::Configuration.prevent(:stubbing_non_public_method) + test_result = run_test do + execution_point = ExecutionPoint.current; object.stubs(:non_public_method) + end + assert_equal 1, test_result.error_count + assert_equal execution_point, ExecutionPoint.new(test_result.errors[0].exception.backtrace) + end + + def test_should_display_backtrace_indicating_line_number_where_attempt_to_stub_method_on_non_mock_object_was_made + execution_point = nil + object = Object.new + Mocha::Configuration.prevent(:stubbing_method_on_non_mock_object) + test_result = run_test do + execution_point = ExecutionPoint.current; object.stubs(:any_method) + end + assert_equal 1, test_result.error_count + assert_equal execution_point, ExecutionPoint.new(test_result.errors[0].exception.backtrace) + end + + def test_should_display_backtrace_indicating_line_number_where_method_was_unnecessarily_stubbed + execution_point = nil + object = Object.new + Mocha::Configuration.prevent(:stubbing_method_unnecessarily) + test_result = run_test do + execution_point = ExecutionPoint.current; object.stubs(:unused_method) + end + assert_equal 1, test_result.error_count + assert_equal execution_point, ExecutionPoint.new(test_result.errors[0].exception.backtrace) + end + +end diff --git a/vendor/gems/mocha-0.9.1/test/acceptance/stubbing_method_unnecessarily_test.rb b/vendor/gems/mocha-0.9.1/test/acceptance/stubbing_method_unnecessarily_test.rb new file mode 100644 index 0000000..1d2885a --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/acceptance/stubbing_method_unnecessarily_test.rb @@ -0,0 +1,65 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' + +class StubbingMethodUnnecessarilyTest < Test::Unit::TestCase + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_allow_stubbing_method_unnecessarily + Mocha::Configuration.allow(:stubbing_method_unnecessarily) + test_result = run_test do + mock = mock('mock') + mock.stubs(:public_method) + end + assert_passed(test_result) + assert !@logger.warnings.include?('stubbing method unnecessarily: #.public_method(any_parameters)') + end + + def test_should_warn_when_stubbing_method_unnecessarily + Mocha::Configuration.warn_when(:stubbing_method_unnecessarily) + test_result = run_test do + mock = mock('mock') + mock.stubs(:public_method) + end + assert_passed(test_result) + assert @logger.warnings.include?('stubbing method unnecessarily: #.public_method(any_parameters)') + end + + def test_should_prevent_stubbing_method_unnecessarily + Mocha::Configuration.prevent(:stubbing_method_unnecessarily) + test_result = run_test do + mock = mock('mock') + mock.stubs(:public_method) + end + assert_failed(test_result) + assert test_result.error_messages.include?('Mocha::StubbingError: stubbing method unnecessarily: #.public_method(any_parameters)') + end + + def test_should_default_to_allow_stubbing_method_unnecessarily + test_result = run_test do + mock = mock('mock') + mock.stubs(:public_method) + end + assert_passed(test_result) + assert !@logger.warnings.include?('stubbing method unnecessarily: #.public_method(any_parameters)') + end + + def test_should_allow_stubbing_method_when_stubbed_method_is_invoked + Mocha::Configuration.prevent(:stubbing_method_unnecessarily) + test_result = run_test do + mock = mock('mock') + mock.stubs(:public_method) + mock.public_method + end + assert_passed(test_result) + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/test/acceptance/stubbing_non_existent_any_instance_method_test.rb b/vendor/gems/mocha-0.9.1/test/acceptance/stubbing_non_existent_any_instance_method_test.rb new file mode 100644 index 0000000..eb7d408 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/acceptance/stubbing_non_existent_any_instance_method_test.rb @@ -0,0 +1,130 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' + +class StubbingNonExistentAnyInstanceMethodTest < Test::Unit::TestCase + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_allow_stubbing_non_existent_any_instance_method + Mocha::Configuration.allow(:stubbing_non_existent_method) + klass = Class.new + test_result = run_test do + klass.any_instance.stubs(:non_existent_method) + end + assert !@logger.warnings.include?("stubbing non-existent method: #{klass.any_instance}.non_existent_method") + assert_passed(test_result) + end + + def test_should_warn_when_stubbing_non_existent_any_instance_method + Mocha::Configuration.warn_when(:stubbing_non_existent_method) + klass = Class.new + test_result = run_test do + klass.any_instance.stubs(:non_existent_method) + end + assert_passed(test_result) + assert @logger.warnings.include?("stubbing non-existent method: #{klass.any_instance}.non_existent_method") + end + + def test_should_prevent_stubbing_non_existent_any_instance_method + Mocha::Configuration.prevent(:stubbing_non_existent_method) + klass = Class.new + test_result = run_test do + klass.any_instance.stubs(:non_existent_method) + end + assert_failed(test_result) + assert test_result.error_messages.include?("Mocha::StubbingError: stubbing non-existent method: #{klass.any_instance}.non_existent_method") + end + + def test_should_default_to_allow_stubbing_non_existent_any_instance_method + klass = Class.new + test_result = run_test do + klass.any_instance.stubs(:non_existent_method) + end + assert !@logger.warnings.include?("stubbing non-existent method: #{klass.any_instance}.non_existent_method") + assert_passed(test_result) + end + + def test_should_allow_stubbing_existing_public_any_instance_method + Mocha::Configuration.prevent(:stubbing_non_existent_method) + klass = Class.new do + def existing_public_method; end + public :existing_public_method + end + test_result = run_test do + klass.any_instance.stubs(:existing_public_method) + end + assert_passed(test_result) + end + + def test_should_allow_stubbing_existing_protected_any_instance_method + Mocha::Configuration.prevent(:stubbing_non_existent_method) + klass = Class.new do + def existing_protected_method; end + protected :existing_protected_method + end + test_result = run_test do + klass.any_instance.stubs(:existing_protected_method) + end + assert_passed(test_result) + end + + def test_should_allow_stubbing_existing_private_any_instance_method + Mocha::Configuration.prevent(:stubbing_non_existent_method) + klass = Class.new do + def existing_private_method; end + private :existing_private_method + end + test_result = run_test do + klass.any_instance.stubs(:existing_private_method) + end + assert_passed(test_result) + end + + def test_should_allow_stubbing_existing_public_any_instance_superclass_method + Mocha::Configuration.prevent(:stubbing_non_existent_method) + superklass = Class.new do + def existing_public_method; end + public :existing_public_method + end + klass = Class.new(superklass) + test_result = run_test do + klass.any_instance.stubs(:existing_public_method) + end + assert_passed(test_result) + end + + def test_should_allow_stubbing_existing_protected_any_instance_superclass_method + Mocha::Configuration.prevent(:stubbing_non_existent_method) + superklass = Class.new do + def existing_protected_method; end + protected :existing_protected_method + end + klass = Class.new(superklass) + test_result = run_test do + klass.any_instance.stubs(:existing_protected_method) + end + assert_passed(test_result) + end + + def test_should_allow_stubbing_existing_private_any_instance_superclass_method + Mocha::Configuration.prevent(:stubbing_non_existent_method) + superklass = Class.new do + def existing_private_method; end + private :existing_private_method + end + klass = Class.new(superklass) + test_result = run_test do + klass.any_instance.stubs(:existing_private_method) + end + assert_passed(test_result) + end + +end diff --git a/vendor/gems/mocha-0.9.1/test/acceptance/stubbing_non_existent_class_method_test.rb b/vendor/gems/mocha-0.9.1/test/acceptance/stubbing_non_existent_class_method_test.rb new file mode 100644 index 0000000..01195a7 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/acceptance/stubbing_non_existent_class_method_test.rb @@ -0,0 +1,155 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' + +class StubbingNonExistentClassMethodTest < Test::Unit::TestCase + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_allow_stubbing_non_existent_class_method + Mocha::Configuration.allow(:stubbing_non_existent_method) + klass = Class.new + test_result = run_test do + klass.stubs(:non_existent_method) + end + assert !@logger.warnings.include?("stubbing non-existent method: #{klass}.non_existent_method") + assert_passed(test_result) + end + + def test_should_warn_when_stubbing_non_existent_class_method + Mocha::Configuration.warn_when(:stubbing_non_existent_method) + klass = Class.new + test_result = run_test do + klass.stubs(:non_existent_method) + end + assert_passed(test_result) + assert @logger.warnings.include?("stubbing non-existent method: #{klass}.non_existent_method") + end + + def test_should_prevent_stubbing_non_existent_class_method + Mocha::Configuration.prevent(:stubbing_non_existent_method) + klass = Class.new + test_result = run_test do + klass.stubs(:non_existent_method) + end + assert_failed(test_result) + assert test_result.error_messages.include?("Mocha::StubbingError: stubbing non-existent method: #{klass}.non_existent_method") + end + + def test_should_default_to_allow_stubbing_non_existent_class_method + klass = Class.new + test_result = run_test do + klass.stubs(:non_existent_method) + end + assert !@logger.warnings.include?("stubbing non-existent method: #{klass}.non_existent_method") + assert_passed(test_result) + end + + def test_should_allow_stubbing_existing_public_class_method + Mocha::Configuration.prevent(:stubbing_non_existent_method) + klass = Class.new do + class << self + def existing_public_method; end + public :existing_public_method + end + end + test_result = run_test do + klass.stubs(:existing_public_method) + end + assert_passed(test_result) + end + + def test_should_allow_stubbing_method_to_which_class_responds + Mocha::Configuration.prevent(:stubbing_non_existent_method) + klass = Class.new do + class << self + def respond_to?(method, include_private = false); true; end + end + end + test_result = run_test do + klass.stubs(:method_to_which_class_responds) + end + assert_passed(test_result) + end + + def test_should_allow_stubbing_existing_protected_class_method + Mocha::Configuration.prevent(:stubbing_non_existent_method) + klass = Class.new do + class << self + def existing_protected_method; end + protected :existing_protected_method + end + end + test_result = run_test do + klass.stubs(:existing_protected_method) + end + assert_passed(test_result) + end + + def test_should_allow_stubbing_existing_private_class_method + Mocha::Configuration.prevent(:stubbing_non_existent_method) + klass = Class.new do + class << self + def existing_private_method; end + private :existing_private_method + end + end + test_result = run_test do + klass.stubs(:existing_private_method) + end + assert_passed(test_result) + end + + def test_should_allow_stubbing_existing_public_superclass_method + Mocha::Configuration.prevent(:stubbing_non_existent_method) + superklass = Class.new do + class << self + def existing_public_method; end + public :existing_public_method + end + end + klass = Class.new(superklass) + test_result = run_test do + klass.stubs(:existing_public_method) + end + assert_passed(test_result) + end + + def test_should_allow_stubbing_existing_protected_superclass_method + Mocha::Configuration.prevent(:stubbing_non_existent_method) + superklass = Class.new do + class << self + def existing_protected_method; end + protected :existing_protected_method + end + end + klass = Class.new(superklass) + test_result = run_test do + klass.stubs(:existing_protected_method) + end + assert_passed(test_result) + end + + def test_should_allow_stubbing_existing_private_superclass_method + Mocha::Configuration.prevent(:stubbing_non_existent_method) + superklass = Class.new do + class << self + def existing_private_method; end + protected :existing_private_method + end + end + klass = Class.new(superklass) + test_result = run_test do + klass.stubs(:existing_private_method) + end + assert_passed(test_result) + end + +end diff --git a/vendor/gems/mocha-0.9.1/test/acceptance/stubbing_non_existent_instance_method_test.rb b/vendor/gems/mocha-0.9.1/test/acceptance/stubbing_non_existent_instance_method_test.rb new file mode 100644 index 0000000..e3259b6 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/acceptance/stubbing_non_existent_instance_method_test.rb @@ -0,0 +1,145 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' + +class StubbingNonExistentInstanceMethodTest < Test::Unit::TestCase + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_allow_stubbing_non_existent_instance_method + Mocha::Configuration.allow(:stubbing_non_existent_method) + instance = Class.new.new + test_result = run_test do + instance.stubs(:non_existent_method) + end + assert !@logger.warnings.include?("stubbing non-existent method: #{instance}.non_existent_method") + assert_passed(test_result) + end + + def test_should_warn_when_stubbing_non_existent_instance_method + Mocha::Configuration.warn_when(:stubbing_non_existent_method) + instance = Class.new.new + test_result = run_test do + instance.stubs(:non_existent_method) + end + assert_passed(test_result) + assert @logger.warnings.include?("stubbing non-existent method: #{instance}.non_existent_method") + end + + def test_should_prevent_stubbing_non_existent_instance_method + Mocha::Configuration.prevent(:stubbing_non_existent_method) + instance = Class.new.new + test_result = run_test do + instance.stubs(:non_existent_method) + end + assert_failed(test_result) + assert test_result.error_messages.include?("Mocha::StubbingError: stubbing non-existent method: #{instance}.non_existent_method") + end + + def test_should_default_to_allow_stubbing_non_existent_instance_method + instance = Class.new.new + test_result = run_test do + instance.stubs(:non_existent_method) + end + assert !@logger.warnings.include?("stubbing non-existent method: #{instance}.non_existent_method") + assert_passed(test_result) + end + + def test_should_allow_stubbing_existing_public_instance_method + Mocha::Configuration.prevent(:stubbing_non_existent_method) + klass = Class.new do + def existing_public_method; end + public :existing_public_method + end + instance = klass.new + test_result = run_test do + instance.stubs(:existing_public_method) + end + assert_passed(test_result) + end + + def test_should_allow_stubbing_method_to_which_instance_responds + Mocha::Configuration.prevent(:stubbing_non_existent_method) + klass = Class.new do + def respond_to?(method, include_private = false); true; end + end + instance = klass.new + test_result = run_test do + instance.stubs(:method_to_which_instance_responds) + end + assert_passed(test_result) + end + + def test_should_allow_stubbing_existing_protected_instance_method + Mocha::Configuration.prevent(:stubbing_non_existent_method) + klass = Class.new do + def existing_protected_method; end + protected :existing_protected_method + end + instance = klass.new + test_result = run_test do + instance.stubs(:existing_protected_method) + end + assert_passed(test_result) + end + + def test_should_allow_stubbing_existing_private_instance_method + Mocha::Configuration.prevent(:stubbing_non_existent_method) + klass = Class.new do + def existing_private_method; end + private :existing_private_method + end + instance = klass.new + test_result = run_test do + instance.stubs(:existing_private_method) + end + assert_passed(test_result) + end + + def test_should_allow_stubbing_existing_public_instance_superclass_method + Mocha::Configuration.prevent(:stubbing_non_existent_method) + superklass = Class.new do + def existing_public_method; end + public :existing_public_method + end + instance = Class.new(superklass).new + test_result = run_test do + instance.stubs(:existing_public_method) + end + assert_passed(test_result) + end + + def test_should_allow_stubbing_existing_protected_instance_superclass_method + Mocha::Configuration.prevent(:stubbing_non_existent_method) + superklass = Class.new do + def existing_protected_method; end + protected :existing_protected_method + end + instance = Class.new(superklass).new + test_result = run_test do + instance.stubs(:existing_protected_method) + end + assert_passed(test_result) + end + + def test_should_allow_stubbing_existing_private_instance_superclass_method + Mocha::Configuration.prevent(:stubbing_non_existent_method) + superklass = Class.new do + def existing_private_method; end + private :existing_private_method + end + instance = Class.new(superklass).new + test_result = run_test do + instance.stubs(:existing_private_method) + end + assert_passed(test_result) + end + +end diff --git a/vendor/gems/mocha-0.9.1/test/acceptance/stubbing_non_public_any_instance_method_test.rb b/vendor/gems/mocha-0.9.1/test/acceptance/stubbing_non_public_any_instance_method_test.rb new file mode 100644 index 0000000..30ceeeb --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/acceptance/stubbing_non_public_any_instance_method_test.rb @@ -0,0 +1,130 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' + +class StubbingNonPublicAnyInstanceMethodTest < Test::Unit::TestCase + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_allow_stubbing_private_any_instance_method + Mocha::Configuration.allow(:stubbing_non_public_method) + klass = Class.new do + def private_method; end + private :private_method + end + test_result = run_test do + klass.any_instance.stubs(:private_method) + end + assert_passed(test_result) + assert !@logger.warnings.include?("stubbing non-public method: #{klass.any_instance}.private_method") + end + + def test_should_allow_stubbing_protected_any_instance_method + Mocha::Configuration.allow(:stubbing_non_public_method) + klass = Class.new do + def protected_method; end + protected :protected_method + end + test_result = run_test do + klass.any_instance.stubs(:protected_method) + end + assert_passed(test_result) + assert !@logger.warnings.include?("stubbing non-public method: #{klass.any_instance}.protected_method") + end + + def test_should_warn_when_stubbing_private_any_instance_method + Mocha::Configuration.warn_when(:stubbing_non_public_method) + klass = Class.new do + def private_method; end + private :private_method + end + test_result = run_test do + klass.any_instance.stubs(:private_method) + end + assert_passed(test_result) + assert @logger.warnings.include?("stubbing non-public method: #{klass.any_instance}.private_method") + end + + def test_should_warn_when_stubbing_protected_any_instance_method + Mocha::Configuration.warn_when(:stubbing_non_public_method) + klass = Class.new do + def protected_method; end + protected :protected_method + end + test_result = run_test do + klass.any_instance.stubs(:protected_method) + end + assert_passed(test_result) + assert @logger.warnings.include?("stubbing non-public method: #{klass.any_instance}.protected_method") + end + + def test_should_prevent_stubbing_private_any_instance_method + Mocha::Configuration.prevent(:stubbing_non_public_method) + klass = Class.new do + def private_method; end + private :private_method + end + test_result = run_test do + klass.any_instance.stubs(:private_method) + end + assert_failed(test_result) + assert test_result.error_messages.include?("Mocha::StubbingError: stubbing non-public method: #{klass.any_instance}.private_method") + end + + def test_should_prevent_stubbing_protected_any_instance_method + Mocha::Configuration.prevent(:stubbing_non_public_method) + klass = Class.new do + def protected_method; end + protected :protected_method + end + test_result = run_test do + klass.any_instance.stubs(:protected_method) + end + assert_failed(test_result) + assert test_result.error_messages.include?("Mocha::StubbingError: stubbing non-public method: #{klass.any_instance}.protected_method") + end + + def test_should_default_to_allow_stubbing_private_any_instance_method + klass = Class.new do + def private_method; end + private :private_method + end + test_result = run_test do + klass.any_instance.stubs(:private_method) + end + assert_passed(test_result) + assert !@logger.warnings.include?("stubbing non-public method: #{klass.any_instance}.private_method") + end + + def test_should_default_to_allow_stubbing_protected_any_instance_method + klass = Class.new do + def protected_method; end + protected :protected_method + end + test_result = run_test do + klass.any_instance.stubs(:protected_method) + end + assert_passed(test_result) + assert !@logger.warnings.include?("stubbing non-public method: #{klass.any_instance}.protected_method") + end + + def test_should_allow_stubbing_public_any_instance_method + Mocha::Configuration.prevent(:stubbing_non_public_method) + klass = Class.new do + def public_method; end + public :public_method + end + test_result = run_test do + klass.any_instance.stubs(:public_method) + end + assert_passed(test_result) + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/test/acceptance/stubbing_non_public_class_method_test.rb b/vendor/gems/mocha-0.9.1/test/acceptance/stubbing_non_public_class_method_test.rb new file mode 100644 index 0000000..72fe30e --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/acceptance/stubbing_non_public_class_method_test.rb @@ -0,0 +1,161 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' + +class StubbingNonPublicClassMethodTest < Test::Unit::TestCase + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_allow_stubbing_private_class_method + Mocha::Configuration.allow(:stubbing_non_public_method) + klass = Class.new do + class << self + def private_method; end + private :private_method + end + end + test_result = run_test do + klass.stubs(:private_method) + end + assert_passed(test_result) + assert !@logger.warnings.include?("stubbing non-public method: #{klass}.private_method") + end + + def test_should_allow_stubbing_protected_class_method + Mocha::Configuration.allow(:stubbing_non_public_method) + klass = Class.new do + class << self + def protected_method; end + protected :protected_method + end + end + test_result = run_test do + klass.stubs(:protected_method) + end + assert_passed(test_result) + assert !@logger.warnings.include?("stubbing non-public method: #{klass}.protected_method") + end + + def test_should_warn_when_stubbing_private_class_method + Mocha::Configuration.warn_when(:stubbing_non_public_method) + klass = Class.new do + class << self + def private_method; end + private :private_method + end + end + test_result = run_test do + klass.stubs(:private_method) + end + assert_passed(test_result) + assert @logger.warnings.include?("stubbing non-public method: #{klass}.private_method") + end + + def test_should_warn_when_stubbing_protected_class_method + Mocha::Configuration.warn_when(:stubbing_non_public_method) + klass = Class.new do + class << self + def protected_method; end + protected :protected_method + end + end + test_result = run_test do + klass.stubs(:protected_method) + end + assert_passed(test_result) + assert @logger.warnings.include?("stubbing non-public method: #{klass}.protected_method") + end + + def test_should_prevent_stubbing_private_class_method + Mocha::Configuration.prevent(:stubbing_non_public_method) + klass = Class.new do + class << self + def private_method; end + private :private_method + end + end + test_result = run_test do + klass.stubs(:private_method) + end + assert_failed(test_result) + assert test_result.error_messages.include?("Mocha::StubbingError: stubbing non-public method: #{klass}.private_method") + end + + def test_should_prevent_stubbing_protected_class_method + Mocha::Configuration.prevent(:stubbing_non_public_method) + klass = Class.new do + class << self + def protected_method; end + protected :protected_method + end + end + test_result = run_test do + klass.stubs(:protected_method) + end + assert_failed(test_result) + assert test_result.error_messages.include?("Mocha::StubbingError: stubbing non-public method: #{klass}.protected_method") + end + + def test_should_default_to_allow_stubbing_private_class_method + klass = Class.new do + class << self + def private_method; end + private :private_method + end + end + test_result = run_test do + klass.stubs(:private_method) + end + assert_passed(test_result) + assert !@logger.warnings.include?("stubbing non-public method: #{klass}.private_method") + end + + def test_should_default_to_allow_stubbing_protected_class_method + klass = Class.new do + class << self + def protected_method; end + protected :protected_method + end + end + test_result = run_test do + klass.stubs(:protected_method) + end + assert_passed(test_result) + assert !@logger.warnings.include?("stubbing non-public method: #{klass}.protected_method") + end + + def test_should_allow_stubbing_public_class_method + Mocha::Configuration.prevent(:stubbing_non_public_method) + klass = Class.new do + class << self + def public_method; end + public :public_method + end + end + test_result = run_test do + klass.stubs(:public_method) + end + assert_passed(test_result) + end + + def test_should_allow_stubbing_method_to_which_class_responds + Mocha::Configuration.prevent(:stubbing_non_public_method) + klass = Class.new do + class << self + def respond_to?(method, include_private_methods = false); true; end + end + end + test_result = run_test do + klass.stubs(:method_to_which_class_responds) + end + assert_passed(test_result) + end + +end diff --git a/vendor/gems/mocha-0.9.1/test/acceptance/stubbing_non_public_instance_method_test.rb b/vendor/gems/mocha-0.9.1/test/acceptance/stubbing_non_public_instance_method_test.rb new file mode 100644 index 0000000..a428834 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/acceptance/stubbing_non_public_instance_method_test.rb @@ -0,0 +1,141 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' + +class StubbingNonPublicInstanceMethodTest < Test::Unit::TestCase + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_allow_stubbing_private_instance_method + Mocha::Configuration.allow(:stubbing_non_public_method) + instance = Class.new do + def private_method; end + private :private_method + end.new + test_result = run_test do + instance.stubs(:private_method) + end + assert_passed(test_result) + assert !@logger.warnings.include?("stubbing non-public method: #{instance}.private_method") + end + + def test_should_allow_stubbing_protected_instance_method + Mocha::Configuration.allow(:stubbing_non_public_method) + instance = Class.new do + def protected_method; end + protected :protected_method + end.new + test_result = run_test do + instance.stubs(:protected_method) + end + assert_passed(test_result) + assert !@logger.warnings.include?("stubbing non-public method: #{instance}.protected_method") + end + + def test_should_warn_when_stubbing_private_instance_method + Mocha::Configuration.warn_when(:stubbing_non_public_method) + instance = Class.new do + def private_method; end + private :private_method + end.new + test_result = run_test do + instance.stubs(:private_method) + end + assert_passed(test_result) + assert @logger.warnings.include?("stubbing non-public method: #{instance}.private_method") + end + + def test_should_warn_when_stubbing_protected_instance_method + Mocha::Configuration.warn_when(:stubbing_non_public_method) + instance = Class.new do + def protected_method; end + protected :protected_method + end.new + test_result = run_test do + instance.stubs(:protected_method) + end + assert_passed(test_result) + assert @logger.warnings.include?("stubbing non-public method: #{instance}.protected_method") + end + + def test_should_prevent_stubbing_private_instance_method + Mocha::Configuration.prevent(:stubbing_non_public_method) + instance = Class.new do + def private_method; end + private :private_method + end.new + test_result = run_test do + instance.stubs(:private_method) + end + assert_failed(test_result) + assert test_result.error_messages.include?("Mocha::StubbingError: stubbing non-public method: #{instance}.private_method") + end + + def test_should_prevent_stubbing_protected_instance_method + Mocha::Configuration.prevent(:stubbing_non_public_method) + instance = Class.new do + def protected_method; end + protected :protected_method + end.new + test_result = run_test do + instance.stubs(:protected_method) + end + assert_failed(test_result) + assert test_result.error_messages.include?("Mocha::StubbingError: stubbing non-public method: #{instance}.protected_method") + end + + def test_should_default_to_allow_stubbing_private_instance_method + instance = Class.new do + def private_method; end + private :private_method + end.new + test_result = run_test do + instance.stubs(:private_method) + end + assert_passed(test_result) + assert !@logger.warnings.include?("stubbing non-public method: #{instance}.private_method") + end + + def test_should_default_to_allow_stubbing_protected_instance_method + instance = Class.new do + def protected_method; end + protected :protected_method + end.new + test_result = run_test do + instance.stubs(:protected_method) + end + assert_passed(test_result) + assert !@logger.warnings.include?("stubbing non-public method: #{instance}.protected_method") + end + + def test_should_allow_stubbing_public_instance_method + Mocha::Configuration.prevent(:stubbing_non_public_method) + instance = Class.new do + def public_method; end + public :public_method + end.new + test_result = run_test do + instance.stubs(:public_method) + end + assert_passed(test_result) + end + + def test_should_allow_stubbing_method_to_which_instance_responds + Mocha::Configuration.prevent(:stubbing_non_public_method) + instance = Class.new do + def respond_to?(method, include_private_methods = false); true; end + end.new + test_result = run_test do + instance.stubs(:method_to_which_instance_responds) + end + assert_passed(test_result) + end + +end diff --git a/vendor/gems/mocha-0.9.1/test/acceptance/stubbing_on_non_mock_object_test.rb b/vendor/gems/mocha-0.9.1/test/acceptance/stubbing_on_non_mock_object_test.rb new file mode 100644 index 0000000..93bdc0d --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/acceptance/stubbing_on_non_mock_object_test.rb @@ -0,0 +1,64 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' + +class StubbingOnNonMockObjectTest < Test::Unit::TestCase + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_allow_stubbing_method_on_non_mock_object + Mocha::Configuration.allow(:stubbing_method_on_non_mock_object) + non_mock_object = Class.new { def existing_method; end } + test_result = run_test do + non_mock_object.stubs(:existing_method) + end + assert_passed(test_result) + assert !@logger.warnings.include?("stubbing method on non-mock object: #{non_mock_object}.existing_method") + end + + def test_should_warn_on_stubbing_method_on_non_mock_object + Mocha::Configuration.warn_when(:stubbing_method_on_non_mock_object) + non_mock_object = Class.new { def existing_method; end } + test_result = run_test do + non_mock_object.stubs(:existing_method) + end + assert_passed(test_result) + assert @logger.warnings.include?("stubbing method on non-mock object: #{non_mock_object}.existing_method") + end + + def test_should_prevent_stubbing_method_on_non_mock_object + Mocha::Configuration.prevent(:stubbing_method_on_non_mock_object) + non_mock_object = Class.new { def existing_method; end } + test_result = run_test do + non_mock_object.stubs(:existing_method) + end + assert_failed(test_result) + assert test_result.error_messages.include?("Mocha::StubbingError: stubbing method on non-mock object: #{non_mock_object}.existing_method") + end + + def test_should_default_to_allow_stubbing_method_on_non_mock_object + non_mock_object = Class.new { def existing_method; end } + test_result = run_test do + non_mock_object.stubs(:existing_method) + end + assert_passed(test_result) + assert !@logger.warnings.include?("stubbing method on non-mock object: #{non_mock_object}.existing_method") + end + + def test_should_allow_stubbing_method_on_mock_object + Mocha::Configuration.prevent(:stubbing_method_on_non_mock_object) + test_result = run_test do + mock = mock('mock') + mock.stubs(:any_method) + end + assert_passed(test_result) + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/test/active_record_test_case.rb b/vendor/gems/mocha-0.9.1/test/active_record_test_case.rb new file mode 100644 index 0000000..ae65073 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/active_record_test_case.rb @@ -0,0 +1,36 @@ +module ActiveRecordTestCase + + def setup_with_fixtures + methods_called << :setup_with_fixtures + end + + alias_method :setup, :setup_with_fixtures + + def teardown_with_fixtures + methods_called << :teardown_with_fixtures + end + + alias_method :teardown, :teardown_with_fixtures + + def self.method_added(method) + case method.to_s + when 'setup' + unless method_defined?(:setup_without_fixtures) + alias_method :setup_without_fixtures, :setup + define_method(:setup) do + setup_with_fixtures + setup_without_fixtures + end + end + when 'teardown' + unless method_defined?(:teardown_without_fixtures) + alias_method :teardown_without_fixtures, :teardown + define_method(:teardown) do + teardown_without_fixtures + teardown_with_fixtures + end + end + end + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/test/deprecation_disabler.rb b/vendor/gems/mocha-0.9.1/test/deprecation_disabler.rb new file mode 100644 index 0000000..c57fb3c --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/deprecation_disabler.rb @@ -0,0 +1,15 @@ +require 'mocha/deprecation' + +module DeprecationDisabler + + def disable_deprecations + original_mode = Mocha::Deprecation.mode + Mocha::Deprecation.mode = :disabled + begin + yield + ensure + Mocha::Deprecation.mode = original_mode + end + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/test/execution_point.rb b/vendor/gems/mocha-0.9.1/test/execution_point.rb new file mode 100644 index 0000000..5824d2a --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/execution_point.rb @@ -0,0 +1,36 @@ +class ExecutionPoint + + attr_reader :backtrace + + def self.current + new(caller) + end + + def initialize(backtrace) + @backtrace = backtrace + end + + def file_name + return "unknown" unless @backtrace && @backtrace.first + /\A(.*?):\d+/.match(@backtrace.first)[1] + end + + def line_number + return "unknown" unless @backtrace && @backtrace.first + Integer(/\A.*?:(\d+)/.match(@backtrace.first)[1]) + end + + def ==(other) + return false unless other.is_a?(ExecutionPoint) + (file_name == other.file_name) and (line_number == other.line_number) + end + + def to_s + "file: #{file_name}; line: #{line_number}" + end + + def inspect + to_s + end + +end diff --git a/vendor/gems/mocha-0.9.1/test/method_definer.rb b/vendor/gems/mocha-0.9.1/test/method_definer.rb new file mode 100644 index 0000000..1aef886 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/method_definer.rb @@ -0,0 +1,18 @@ +require 'mocha/metaclass' + +class Object + + def define_instance_method(method_symbol, &block) + __metaclass__.send(:define_method, method_symbol, block) + end + + def replace_instance_method(method_symbol, &block) + raise "Cannot replace #{method_symbol} as #{self} does not respond to it." unless self.respond_to?(method_symbol) + define_instance_method(method_symbol, &block) + end + + def define_instance_accessor(*symbols) + symbols.each { |symbol| __metaclass__.send(:attr_accessor, symbol) } + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/test/simple_counter.rb b/vendor/gems/mocha-0.9.1/test/simple_counter.rb new file mode 100644 index 0000000..a7b5b37 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/simple_counter.rb @@ -0,0 +1,13 @@ +class SimpleCounter + + attr_reader :count + + def initialize + @count = 0 + end + + def increment + @count += 1 + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/test/test_helper.rb b/vendor/gems/mocha-0.9.1/test/test_helper.rb new file mode 100644 index 0000000..54d3476 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/test_helper.rb @@ -0,0 +1,11 @@ +unless defined?(STANDARD_OBJECT_PUBLIC_INSTANCE_METHODS) + STANDARD_OBJECT_PUBLIC_INSTANCE_METHODS = Object.public_instance_methods +end + +$:.unshift File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")) +$:.unshift File.expand_path(File.join(File.dirname(__FILE__))) +$:.unshift File.expand_path(File.join(File.dirname(__FILE__), 'unit')) +$:.unshift File.expand_path(File.join(File.dirname(__FILE__), 'unit', 'parameter_matchers')) +$:.unshift File.expand_path(File.join(File.dirname(__FILE__), 'acceptance')) + +require 'test/unit' \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/test/test_runner.rb b/vendor/gems/mocha-0.9.1/test/test_runner.rb new file mode 100644 index 0000000..6537991 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/test_runner.rb @@ -0,0 +1,33 @@ +require 'test/unit/testresult' +require 'test/unit/testcase' + +module TestRunner + + def run_test(test_result = Test::Unit::TestResult.new, &block) + test_class = Class.new(Test::Unit::TestCase) do + define_method(:test_me, &block) + end + test = test_class.new(:test_me) + test.run(test_result) {} + class << test_result + attr_reader :failures, :errors + def failure_messages + failures.map { |failure| failure.message } + end + def error_messages + errors.map { |error| error.message } + end + end + test_result + end + + def assert_passed(test_result) + flunk "Test failed unexpectedly with message: #{test_result.failures}" if test_result.failure_count > 0 + flunk "Test failed unexpectedly with message: #{test_result.errors}" if test_result.error_count > 0 + end + + def assert_failed(test_result) + flunk "Test passed unexpectedly" if test_result.passed? + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/test/unit/any_instance_method_test.rb b/vendor/gems/mocha-0.9.1/test/unit/any_instance_method_test.rb new file mode 100644 index 0000000..1bf4d2a --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/unit/any_instance_method_test.rb @@ -0,0 +1,126 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") +require 'method_definer' +require 'mocha/mock' +require 'mocha/any_instance_method' + +class AnyInstanceMethodTest < Test::Unit::TestCase + + include Mocha + + def test_should_hide_original_method + klass = Class.new { def method_x; end } + method = AnyInstanceMethod.new(klass, :method_x) + hidden_method_x = method.hidden_method.to_sym + + method.hide_original_method + + assert klass.method_defined?(hidden_method_x) + end + + def test_should_not_hide_original_method_if_it_is_not_defined + klass = Class.new + method = AnyInstanceMethod.new(klass, :method_x) + hidden_method_x = method.hidden_method.to_sym + + method.hide_original_method + + assert_equal false, klass.method_defined?(hidden_method_x) + end + + def test_should_define_a_new_method + klass = Class.new { def method_x; end } + method = AnyInstanceMethod.new(klass, :method_x) + mocha = Mock.new + mocha.expects(:method_x).with(:param1, :param2).returns(:result) + any_instance = Object.new + any_instance.define_instance_method(:mocha) { mocha } + klass.define_instance_method(:any_instance) { any_instance } + + method.hide_original_method + method.define_new_method + + instance = klass.new + result = instance.method_x(:param1, :param2) + + assert_equal :result, result + assert mocha.__verified__? + end + + def test_should_restore_original_method + klass = Class.new { def method_x; end } + method = AnyInstanceMethod.new(klass, :method_x) + hidden_method_x = method.hidden_method.to_sym + klass.send(:define_method, hidden_method_x, Proc.new { :original_result }) + + method.remove_new_method + method.restore_original_method + + instance = klass.new + assert_equal :original_result, instance.method_x + assert !klass.method_defined?(hidden_method_x) + end + + def test_should_not_restore_original_method_if_hidden_method_not_defined + klass = Class.new { def method_x; :new_result; end } + method = AnyInstanceMethod.new(klass, :method_x) + + method.restore_original_method + + instance = klass.new + assert_equal :new_result, instance.method_x + end + + def test_should_call_remove_new_method + klass = Class.new { def method_x; end } + any_instance = Mock.new + any_instance.stubs(:reset_mocha) + klass.define_instance_method(:any_instance) { any_instance } + method = AnyInstanceMethod.new(klass, :method_x) + method.replace_instance_method(:restore_original_method) { } + method.define_instance_accessor(:remove_called) + method.replace_instance_method(:remove_new_method) { self.remove_called = true } + + method.unstub + + assert method.remove_called + end + + def test_should_call_restore_original_method + klass = Class.new { def method_x; end } + any_instance = Mock.new + any_instance.stubs(:reset_mocha) + klass.define_instance_method(:any_instance) { any_instance } + method = AnyInstanceMethod.new(klass, :method_x) + method.replace_instance_method(:remove_new_method) { } + method.define_instance_accessor(:restore_called) + method.replace_instance_method(:restore_original_method) { self.restore_called = true } + + method.unstub + + assert method.restore_called + end + + def test_should_call_reset_mocha + klass = Class.new { def method_x; end } + any_instance = Class.new { attr_accessor :mocha_was_reset; def reset_mocha; self.mocha_was_reset = true; end }.new + klass.define_instance_method(:any_instance) { any_instance } + method = AnyInstanceMethod.new(klass, :method_x) + method.replace_instance_method(:remove_new_method) { } + method.replace_instance_method(:restore_original_method) { } + + method.unstub + + assert any_instance.mocha_was_reset + end + + def test_should_return_any_instance_mocha_for_stubbee + mocha = Object.new + any_instance = Object.new + any_instance.define_instance_method(:mocha) { mocha } + stubbee = Class.new + stubbee.define_instance_method(:any_instance) { any_instance } + method = AnyInstanceMethod.new(stubbee, :method_name) + assert_equal stubbee.any_instance.mocha, method.mock + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/test/unit/array_inspect_test.rb b/vendor/gems/mocha-0.9.1/test/unit/array_inspect_test.rb new file mode 100644 index 0000000..8e555cd --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/unit/array_inspect_test.rb @@ -0,0 +1,16 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") +require 'mocha/inspect' + +class ArrayInspectTest < Test::Unit::TestCase + + def test_should_use_inspect + array = [1, 2] + assert_equal array.inspect, array.mocha_inspect + end + + def test_should_use_mocha_inspect_on_each_item + array = [1, 2, "chris"] + assert_equal "[1, 2, 'chris']", array.mocha_inspect + end + +end diff --git a/vendor/gems/mocha-0.9.1/test/unit/backtrace_filter_test.rb b/vendor/gems/mocha-0.9.1/test/unit/backtrace_filter_test.rb new file mode 100644 index 0000000..6d9379f --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/unit/backtrace_filter_test.rb @@ -0,0 +1,19 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") +require 'mocha/backtrace_filter' + +class BacktraceFilterTest < Test::Unit::TestCase + + include Mocha + + def test_should_exclude_mocha_locations_from_backtrace + mocha_lib = "/username/workspace/mocha_wibble/lib/" + backtrace = [ mocha_lib + 'exclude/me/1', mocha_lib + 'exclude/me/2', '/keep/me', mocha_lib + 'exclude/me/3'] + filter = BacktraceFilter.new(mocha_lib) + assert_equal ['/keep/me'], filter.filtered(backtrace) + end + + def test_should_determine_path_for_mocha_lib_directory + assert_match Regexp.new("/lib/$"), BacktraceFilter::LIB_DIRECTORY + end + +end diff --git a/vendor/gems/mocha-0.9.1/test/unit/cardinality_test.rb b/vendor/gems/mocha-0.9.1/test/unit/cardinality_test.rb new file mode 100644 index 0000000..2a5ef9b --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/unit/cardinality_test.rb @@ -0,0 +1,56 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") +require 'mocha/cardinality' + +class CardinalityTest < Test::Unit::TestCase + + include Mocha + + def test_should_allow_invocations_if_invocation_count_has_not_yet_reached_maximum + cardinality = Cardinality.new(2, 3) + assert cardinality.invocations_allowed?(0) + assert cardinality.invocations_allowed?(1) + assert cardinality.invocations_allowed?(2) + assert !cardinality.invocations_allowed?(3) + end + + def test_should_be_satisfied_if_invocations_so_far_have_reached_required_threshold + cardinality = Cardinality.new(2, 3) + assert !cardinality.satisfied?(0) + assert !cardinality.satisfied?(1) + assert cardinality.satisfied?(2) + assert cardinality.satisfied?(3) + end + + def test_should_describe_cardinality + assert_equal 'allowed any number of times', Cardinality.at_least(0).mocha_inspect + + assert_equal 'expected at most once', Cardinality.at_most(1).mocha_inspect + assert_equal 'expected at most twice', Cardinality.at_most(2).mocha_inspect + assert_equal 'expected at most 3 times', Cardinality.at_most(3).mocha_inspect + + assert_equal 'expected at least once', Cardinality.at_least(1).mocha_inspect + assert_equal 'expected at least twice', Cardinality.at_least(2).mocha_inspect + assert_equal 'expected at least 3 times', Cardinality.at_least(3).mocha_inspect + + assert_equal 'expected never', Cardinality.exactly(0).mocha_inspect + assert_equal 'expected exactly once', Cardinality.exactly(1).mocha_inspect + assert_equal 'expected exactly twice', Cardinality.exactly(2).mocha_inspect + assert_equal 'expected exactly 3 times', Cardinality.times(3).mocha_inspect + + assert_equal 'expected between 2 and 4 times', Cardinality.times(2..4).mocha_inspect + assert_equal 'expected between 1 and 3 times', Cardinality.times(1..3).mocha_inspect + end + + def test_should_need_verifying + assert Cardinality.exactly(2).needs_verifying? + assert Cardinality.at_least(3).needs_verifying? + assert Cardinality.at_most(2).needs_verifying? + assert Cardinality.times(4).needs_verifying? + assert Cardinality.times(2..4).needs_verifying? + end + + def test_should_not_need_verifying + assert_equal false, Cardinality.at_least(0).needs_verifying? + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/test/unit/central_test.rb b/vendor/gems/mocha-0.9.1/test/unit/central_test.rb new file mode 100644 index 0000000..03bff91 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/unit/central_test.rb @@ -0,0 +1,65 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") + +require 'mocha/central' +require 'mocha/mock' +require 'method_definer' + +class CentralTest < Test::Unit::TestCase + + include Mocha + + def test_should_start_with_empty_stubba_methods + stubba = Central.new + + assert_equal [], stubba.stubba_methods + end + + def test_should_stub_method_if_not_already_stubbed + method = Mock.new + method.expects(:stub) + stubba = Central.new + + stubba.stub(method) + + assert method.__verified__? + end + + def test_should_not_stub_method_if_already_stubbed + method = Mock.new + method.expects(:stub).times(0) + stubba = Central.new + stubba_methods = Mock.new + stubba_methods.stubs(:include?).with(method).returns(true) + stubba.stubba_methods = stubba_methods + + stubba.stub(method) + + assert method.__verified__? + end + + def test_should_record_method + method = Mock.new + method.expects(:stub) + stubba = Central.new + + stubba.stub(method) + + assert_equal [method], stubba.stubba_methods + end + + def test_should_unstub_all_methods + stubba = Central.new + method_1 = Mock.new + method_1.expects(:unstub) + method_2 = Mock.new + method_2.expects(:unstub) + stubba.stubba_methods = [method_1, method_2] + + stubba.unstub_all + + assert_equal [], stubba.stubba_methods + assert method_1.__verified__? + assert method_2.__verified__? + end + +end diff --git a/vendor/gems/mocha-0.9.1/test/unit/change_state_side_effect_test.rb b/vendor/gems/mocha-0.9.1/test/unit/change_state_side_effect_test.rb new file mode 100644 index 0000000..b48beaa --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/unit/change_state_side_effect_test.rb @@ -0,0 +1,41 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") + +require 'mocha/change_state_side_effect' + +class ChangeStateSideEffectTest < Test::Unit::TestCase + + include Mocha + + class FakeState + + attr_reader :active + attr_writer :description + + def activate + @active = true + end + + def mocha_inspect + @description + end + + end + + def test_should_activate_the_given_state + state = FakeState.new + side_effect = ChangeStateSideEffect.new(state) + + side_effect.perform + + assert state.active + end + + def test_should_describe_itself_in_terms_of_the_activated_state + state = FakeState.new + state.description = 'the-new-state' + side_effect = ChangeStateSideEffect.new(state) + + assert_equal 'then the-new-state', side_effect.mocha_inspect + end + +end diff --git a/vendor/gems/mocha-0.9.1/test/unit/class_method_test.rb b/vendor/gems/mocha-0.9.1/test/unit/class_method_test.rb new file mode 100644 index 0000000..47c5999 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/unit/class_method_test.rb @@ -0,0 +1,237 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") +require 'method_definer' +require 'mocha/mock' + +require 'mocha/class_method' + +class ClassMethodTest < Test::Unit::TestCase + + include Mocha + + def test_should_provide_hidden_version_of_method_name_starting_with_prefix + method = ClassMethod.new(nil, :original_method_name) + assert_match(/^__stubba__/, method.hidden_method.to_s) + end + + def test_should_provide_hidden_version_of_method_name_ending_with_suffix + method = ClassMethod.new(nil, :original_method_name) + assert_match(/__stubba__$/, method.hidden_method.to_s) + end + + def test_should_provide_hidden_version_of_method_name_including_original_method_name + method = ClassMethod.new(nil, :original_method_name) + assert_match(/original_method_name/, method.hidden_method.to_s) + end + + def test_should_provide_hidden_version_of_method_name_substituting_question_mark + method = ClassMethod.new(nil, :question_mark?) + assert_no_match(/\?/, method.hidden_method.to_s) + assert_match(/question_mark_substituted_character_63/, method.hidden_method.to_s) + end + + def test_should_provide_hidden_version_of_method_name_substituting_exclamation_mark + method = ClassMethod.new(nil, :exclamation_mark!) + assert_no_match(/!/, method.hidden_method.to_s) + assert_match(/exclamation_mark_substituted_character_33/, method.hidden_method.to_s) + end + + def test_should_provide_hidden_version_of_method_name_substituting_equals_sign + method = ClassMethod.new(nil, :equals_sign=) + assert_no_match(/\=/, method.hidden_method.to_s) + assert_match(/equals_sign_substituted_character_61/, method.hidden_method.to_s) + end + + def test_should_provide_hidden_version_of_method_name_substituting_brackets + method = ClassMethod.new(nil, :[]) + assert_no_match(/\[\]/, method.hidden_method.to_s) + assert_match(/substituted_character_91__substituted_character_93/, method.hidden_method.to_s) + end + + def test_should_provide_hidden_version_of_method_name_substituting_plus_sign + method = ClassMethod.new(nil, :+) + assert_no_match(/\+/, method.hidden_method.to_s) + assert_match(/substituted_character_43/, method.hidden_method.to_s) + end + + def test_should_hide_original_method + klass = Class.new { def self.method_x; end } + method = ClassMethod.new(klass, :method_x) + hidden_method_x = method.hidden_method + + method.hide_original_method + + assert klass.respond_to?(hidden_method_x) + end + + def test_should_respond_to_original_method_name_after_original_method_has_been_hidden + klass = Class.new { def self.original_method_name; end } + method = ClassMethod.new(klass, :original_method_name) + hidden_method_x = method.hidden_method + + method.hide_original_method + + assert klass.respond_to?(:original_method_name) + end + + def test_should_not_hide_original_method_if_method_not_defined + klass = Class.new + method = ClassMethod.new(klass, :method_x) + hidden_method_x = method.hidden_method + + method.hide_original_method + + assert_equal false, klass.respond_to?(hidden_method_x) + end + + def test_should_define_a_new_method_which_should_call_mocha_method_missing + klass = Class.new { def self.method_x; end } + mocha = Mocha::Mock.new + klass.define_instance_method(:mocha) { mocha } + mocha.expects(:method_x).with(:param1, :param2).returns(:result) + method = ClassMethod.new(klass, :method_x) + + method.hide_original_method + method.define_new_method + result = klass.method_x(:param1, :param2) + + assert_equal :result, result + assert mocha.__verified__? + end + + def test_should_remove_new_method + klass = Class.new { def self.method_x; end } + method = ClassMethod.new(klass, :method_x) + + method.remove_new_method + + assert_equal false, klass.respond_to?(:method_x) + end + + def test_should_restore_original_method + klass = Class.new { def self.method_x; end } + method = ClassMethod.new(klass, :method_x) + hidden_method_x = method.hidden_method.to_sym + klass.define_instance_method(hidden_method_x) { :original_result } + + method.remove_new_method + method.restore_original_method + + assert_equal :original_result, klass.method_x + assert_equal false, klass.respond_to?(hidden_method_x) + end + + def test_should_not_restore_original_method_if_hidden_method_is_not_defined + klass = Class.new { def self.method_x; :new_result; end } + method = ClassMethod.new(klass, :method_x) + + method.restore_original_method + + assert_equal :new_result, klass.method_x + end + + def test_should_call_hide_original_method + klass = Class.new { def self.method_x; end } + method = ClassMethod.new(klass, :method_x) + method.hide_original_method + method.define_instance_accessor(:hide_called) + method.replace_instance_method(:hide_original_method) { self.hide_called = true } + + method.stub + + assert method.hide_called + end + + def test_should_call_define_new_method + klass = Class.new { def self.method_x; end } + method = ClassMethod.new(klass, :method_x) + method.define_instance_accessor(:define_called) + method.replace_instance_method(:define_new_method) { self.define_called = true } + + method.stub + + assert method.define_called + end + + def test_should_call_remove_new_method + klass = Class.new { def self.method_x; end } + klass.define_instance_method(:reset_mocha) { } + method = ClassMethod.new(klass, :method_x) + method.define_instance_accessor(:remove_called) + method.replace_instance_method(:remove_new_method) { self.remove_called = true } + + method.unstub + + assert method.remove_called + end + + def test_should_call_restore_original_method + klass = Class.new { def self.method_x; end } + klass.define_instance_method(:reset_mocha) { } + method = ClassMethod.new(klass, :method_x) + method.define_instance_accessor(:restore_called) + method.replace_instance_method(:restore_original_method) { self.restore_called = true } + + method.unstub + + assert method.restore_called + end + + def test_should_call_reset_mocha + klass = Class.new { def self.method_x; end } + klass.define_instance_accessor(:reset_called) + klass.define_instance_method(:reset_mocha) { self.reset_called = true } + method = ClassMethod.new(klass, :method_x) + method.replace_instance_method(:restore_original_method) { } + + method.unstub + + assert klass.reset_called + end + + def test_should_return_mock_for_stubbee + mocha = Object.new + stubbee = Object.new + stubbee.define_instance_accessor(:mocha) { mocha } + stubbee.mocha = nil + method = ClassMethod.new(stubbee, :method_name) + assert_equal stubbee.mocha, method.mock + end + + def test_should_not_be_equal_if_other_object_has_a_different_class + class_method = ClassMethod.new(Object.new, :method) + other_object = Object.new + assert class_method != other_object + end + + def test_should_not_be_equal_if_other_class_method_has_different_stubbee + stubbee_1 = Object.new + stubbee_2 = Object.new + class_method_1 = ClassMethod.new(stubbee_1, :method) + class_method_2 = ClassMethod.new(stubbee_2, :method) + assert class_method_1 != class_method_2 + end + + def test_should_not_be_equal_if_other_class_method_has_different_method + stubbee = Object.new + class_method_1 = ClassMethod.new(stubbee, :method_1) + class_method_2 = ClassMethod.new(stubbee, :method_2) + assert class_method_1 != class_method_2 + end + + def test_should_be_equal_if_other_class_method_has_same_stubbee_and_same_method_so_no_attempt_is_made_to_stub_a_method_twice + stubbee = Object.new + class_method_1 = ClassMethod.new(stubbee, :method) + class_method_2 = ClassMethod.new(stubbee, :method) + assert class_method_1 == class_method_2 + end + + def test_should_be_equal_if_other_class_method_has_same_stubbee_and_same_method_but_stubbee_equal_method_lies_like_active_record_association_proxy + stubbee = Class.new do + def equal?(other); false; end + end.new + class_method_1 = ClassMethod.new(stubbee, :method) + class_method_2 = ClassMethod.new(stubbee, :method) + assert class_method_1 == class_method_2 + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/test/unit/date_time_inspect_test.rb b/vendor/gems/mocha-0.9.1/test/unit/date_time_inspect_test.rb new file mode 100644 index 0000000..8557365 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/unit/date_time_inspect_test.rb @@ -0,0 +1,21 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") +require 'mocha/inspect' + +class DateTimeInspectTest < Test::Unit::TestCase + + def test_should_use_include_date_in_seconds + time = Time.now + assert_equal "#{time.inspect} (#{time.to_f} secs)", time.mocha_inspect + end + + def test_should_use_to_s_for_date + date = Date.new(2006, 1, 1) + assert_equal date.to_s, date.mocha_inspect + end + + def test_should_use_to_s_for_datetime + datetime = DateTime.new(2006, 1, 1) + assert_equal datetime.to_s, datetime.mocha_inspect + end + +end diff --git a/vendor/gems/mocha-0.9.1/test/unit/exception_raiser_test.rb b/vendor/gems/mocha-0.9.1/test/unit/exception_raiser_test.rb new file mode 100644 index 0000000..942300a --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/unit/exception_raiser_test.rb @@ -0,0 +1,42 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") + +require 'mocha/exception_raiser' +require 'timeout' + +class ExceptionRaiserTest < Test::Unit::TestCase + + include Mocha + + def test_should_raise_exception_with_specified_class_and_default_message + exception_class = Class.new(StandardError) + raiser = ExceptionRaiser.new(exception_class, nil) + exception = assert_raises(exception_class) { raiser.evaluate } + assert_equal exception_class.to_s, exception.message + end + + def test_should_raise_exception_with_specified_class_and_message + exception_class = Class.new(StandardError) + raiser = ExceptionRaiser.new(exception_class, 'message') + exception = assert_raises(exception_class) { raiser.evaluate } + assert_equal 'message', exception.message + end + + def test_should_raise_exception_instance + exception_class = Class.new(StandardError) + raiser = ExceptionRaiser.new(exception_class.new('message'), nil) + exception = assert_raises(exception_class) { raiser.evaluate } + assert_equal 'message', exception.message + end + + def test_should_raise_interrupt_exception_with_default_message_so_it_works_in_ruby_1_8_6 + raiser = ExceptionRaiser.new(Interrupt, nil) + assert_raises(Interrupt) { raiser.evaluate } + end + + def test_should_raise_subclass_of_interrupt_exception_with_default_message_so_it_works_in_ruby_1_8_6 + exception_class = Class.new(Interrupt) + raiser = ExceptionRaiser.new(exception_class, nil) + assert_raises(exception_class) { raiser.evaluate } + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/test/unit/expectation_list_test.rb b/vendor/gems/mocha-0.9.1/test/unit/expectation_list_test.rb new file mode 100644 index 0000000..bc641c5 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/unit/expectation_list_test.rb @@ -0,0 +1,57 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") +require 'mocha/expectation_list' +require 'mocha/expectation' +require 'set' +require 'method_definer' + +class ExpectationListTest < Test::Unit::TestCase + + include Mocha + + def test_should_return_added_expectation + expectation_list = ExpectationList.new + expectation = Expectation.new(nil, :my_method) + assert_same expectation, expectation_list.add(expectation) + end + + def test_should_find_matching_expectation + expectation_list = ExpectationList.new + expectation1 = Expectation.new(nil, :my_method).with(:argument1, :argument2) + expectation2 = Expectation.new(nil, :my_method).with(:argument3, :argument4) + expectation_list.add(expectation1) + expectation_list.add(expectation2) + assert_same expectation1, expectation_list.match(:my_method, :argument1, :argument2) + end + + def test_should_find_most_recent_matching_expectation + expectation_list = ExpectationList.new + expectation1 = Expectation.new(nil, :my_method).with(:argument1, :argument2) + expectation2 = Expectation.new(nil, :my_method).with(:argument1, :argument2) + expectation_list.add(expectation1) + expectation_list.add(expectation2) + assert_same expectation2, expectation_list.match(:my_method, :argument1, :argument2) + end + + def test_should_find_matching_expectation_allowing_invocation + expectation_list = ExpectationList.new + expectation1 = Expectation.new(nil, :my_method).with(:argument1, :argument2) + expectation2 = Expectation.new(nil, :my_method).with(:argument3, :argument4) + expectation1.define_instance_method(:invocations_allowed?) { true } + expectation2.define_instance_method(:invocations_allowed?) { true } + expectation_list.add(expectation1) + expectation_list.add(expectation2) + assert_same expectation1, expectation_list.match_allowing_invocation(:my_method, :argument1, :argument2) + end + + def test_should_find_most_recent_matching_expectation_allowing_invocation + expectation_list = ExpectationList.new + expectation1 = Expectation.new(nil, :my_method) + expectation2 = Expectation.new(nil, :my_method) + expectation1.define_instance_method(:invocations_allowed?) { true } + expectation2.define_instance_method(:invocations_allowed?) { false } + expectation_list.add(expectation1) + expectation_list.add(expectation2) + assert_same expectation1, expectation_list.match_allowing_invocation(:my_method) + end + +end diff --git a/vendor/gems/mocha-0.9.1/test/unit/expectation_test.rb b/vendor/gems/mocha-0.9.1/test/unit/expectation_test.rb new file mode 100644 index 0000000..b96385e --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/unit/expectation_test.rb @@ -0,0 +1,459 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") +require 'method_definer' +require 'mocha/expectation' +require 'mocha/sequence' +require 'execution_point' +require 'simple_counter' + +class ExpectationTest < Test::Unit::TestCase + + include Mocha + + def new_expectation + Expectation.new(nil, :expected_method) + end + + def test_should_match_calls_to_same_method_with_any_parameters + assert new_expectation.match?(:expected_method, 1, 2, 3) + end + + def test_should_match_calls_to_same_method_with_exactly_zero_parameters + expectation = new_expectation.with() + assert expectation.match?(:expected_method) + end + + def test_should_not_match_calls_to_same_method_with_more_than_zero_parameters + expectation = new_expectation.with() + assert !expectation.match?(:expected_method, 1, 2, 3) + end + + def test_should_match_calls_to_same_method_with_expected_parameter_values + expectation = new_expectation.with(1, 2, 3) + assert expectation.match?(:expected_method, 1, 2, 3) + end + + def test_should_match_calls_to_same_method_with_parameters_constrained_as_expected + expectation = new_expectation.with() {|x, y, z| x + y == z} + assert expectation.match?(:expected_method, 1, 2, 3) + end + + def test_should_not_match_calls_to_different_method_with_parameters_constrained_as_expected + expectation = new_expectation.with() {|x, y, z| x + y == z} + assert !expectation.match?(:different_method, 1, 2, 3) + end + + def test_should_not_match_calls_to_different_methods_with_no_parameters + assert !new_expectation.match?(:unexpected_method) + end + + def test_should_not_match_calls_to_same_method_with_too_few_parameters + expectation = new_expectation.with(1, 2, 3) + assert !expectation.match?(:unexpected_method, 1, 2) + end + + def test_should_not_match_calls_to_same_method_with_too_many_parameters + expectation = new_expectation.with(1, 2) + assert !expectation.match?(:unexpected_method, 1, 2, 3) + end + + def test_should_not_match_calls_to_same_method_with_unexpected_parameter_values + expectation = new_expectation.with(1, 2, 3) + assert !expectation.match?(:unexpected_method, 1, 0, 3) + end + + def test_should_not_match_calls_to_same_method_with_parameters_not_constrained_as_expected + expectation = new_expectation.with() {|x, y, z| x + y == z} + assert !expectation.match?(:expected_method, 1, 0, 3) + end + + def test_should_allow_invocations_until_expected_invocation_count_is_one_and_actual_invocation_count_would_be_two + expectation = new_expectation.times(1) + assert expectation.invocations_allowed? + expectation.invoke + assert !expectation.invocations_allowed? + end + + def test_should_allow_invocations_until_expected_invocation_count_is_two_and_actual_invocation_count_would_be_three + expectation = new_expectation.times(2) + assert expectation.invocations_allowed? + expectation.invoke + assert expectation.invocations_allowed? + expectation.invoke + assert !expectation.invocations_allowed? + end + + def test_should_allow_invocations_until_expected_invocation_count_is_a_range_from_two_to_three_and_actual_invocation_count_would_be_four + expectation = new_expectation.times(2..3) + assert expectation.invocations_allowed? + expectation.invoke + assert expectation.invocations_allowed? + expectation.invoke + assert expectation.invocations_allowed? + expectation.invoke + assert !expectation.invocations_allowed? + end + + def test_should_store_provided_backtrace + backtrace = Object.new + expectation = Expectation.new(nil, :expected_method, backtrace) + assert_equal backtrace, expectation.backtrace + end + + def test_should_default_backtrace_to_caller + execution_point = ExecutionPoint.current; expectation = Expectation.new(nil, :expected_method) + assert_equal execution_point, ExecutionPoint.new(expectation.backtrace) + end + + def test_should_not_yield + yielded = false + new_expectation.invoke() { yielded = true } + assert_equal false, yielded + end + + def test_should_yield_no_parameters + expectation = new_expectation().yields() + yielded_parameters = nil + expectation.invoke() { |*parameters| yielded_parameters = parameters } + assert_equal Array.new, yielded_parameters + end + + def test_should_yield_with_specified_parameters + expectation = new_expectation().yields(1, 2, 3) + yielded_parameters = nil + expectation.invoke() { |*parameters| yielded_parameters = parameters } + assert_equal [1, 2, 3], yielded_parameters + end + + def test_should_yield_different_parameters_on_consecutive_invocations + expectation = new_expectation().yields(1, 2, 3).yields(4, 5) + yielded_parameters = [] + expectation.invoke() { |*parameters| yielded_parameters << parameters } + expectation.invoke() { |*parameters| yielded_parameters << parameters } + assert_equal [[1, 2, 3], [4, 5]], yielded_parameters + end + + def test_should_yield_multiple_times_for_single_invocation + expectation = new_expectation().multiple_yields([1, 2, 3], [4, 5]) + yielded_parameters = [] + expectation.invoke() { |*parameters| yielded_parameters << parameters } + assert_equal [[1, 2, 3], [4, 5]], yielded_parameters + end + + def test_should_yield_multiple_times_for_first_invocation_and_once_for_second_invocation + expectation = new_expectation().multiple_yields([1, 2, 3], [4, 5]).then.yields(6, 7) + yielded_parameters = [] + expectation.invoke() { |*parameters| yielded_parameters << parameters } + expectation.invoke() { |*parameters| yielded_parameters << parameters } + assert_equal [[1, 2, 3], [4, 5], [6, 7]], yielded_parameters + end + + def test_should_return_specified_value + expectation = new_expectation.returns(99) + assert_equal 99, expectation.invoke + end + + def test_should_return_same_specified_value_multiple_times + expectation = new_expectation.returns(99) + assert_equal 99, expectation.invoke + assert_equal 99, expectation.invoke + end + + def test_should_return_specified_values_on_consecutive_calls + expectation = new_expectation.returns(99, 100, 101) + assert_equal 99, expectation.invoke + assert_equal 100, expectation.invoke + assert_equal 101, expectation.invoke + end + + def test_should_return_specified_values_on_consecutive_calls_even_if_values_are_modified + values = [99, 100, 101] + expectation = new_expectation.returns(*values) + values.shift + assert_equal 99, expectation.invoke + assert_equal 100, expectation.invoke + assert_equal 101, expectation.invoke + end + + def test_should_return_nil_by_default + assert_nil new_expectation.invoke + end + + def test_should_return_nil_if_no_value_specified + expectation = new_expectation.returns() + assert_nil expectation.invoke + end + + def test_should_raise_runtime_exception + expectation = new_expectation.raises + assert_raise(RuntimeError) { expectation.invoke } + end + + def test_should_raise_custom_exception + exception = Class.new(Exception) + expectation = new_expectation.raises(exception) + assert_raise(exception) { expectation.invoke } + end + + def test_should_raise_same_instance_of_custom_exception + exception_klass = Class.new(StandardError) + expected_exception = exception_klass.new + expectation = new_expectation.raises(expected_exception) + actual_exception = assert_raise(exception_klass) { expectation.invoke } + assert_same expected_exception, actual_exception + end + + def test_should_use_the_default_exception_message + expectation = new_expectation.raises(Exception) + exception = assert_raise(Exception) { expectation.invoke } + assert_equal Exception.new.message, exception.message + end + + def test_should_raise_custom_exception_with_message + exception_msg = "exception message" + expectation = new_expectation.raises(Exception, exception_msg) + exception = assert_raise(Exception) { expectation.invoke } + assert_equal exception_msg, exception.message + end + + def test_should_return_values_then_raise_exception + expectation = new_expectation.returns(1, 2).then.raises() + assert_equal 1, expectation.invoke + assert_equal 2, expectation.invoke + assert_raise(RuntimeError) { expectation.invoke } + end + + def test_should_raise_exception_then_return_values + expectation = new_expectation.raises().then.returns(1, 2) + assert_raise(RuntimeError) { expectation.invoke } + assert_equal 1, expectation.invoke + assert_equal 2, expectation.invoke + end + + def test_should_verify_successfully_if_expected_call_was_made + expectation = new_expectation + expectation.invoke + assert expectation.verified? + end + + def test_should_not_verify_successfully_if_call_expected_once_but_invoked_twice + expectation = new_expectation.once + expectation.invoke + expectation.invoke + assert !expectation.verified? + end + + def test_should_not_verify_successfully_if_call_expected_once_but_not_invoked + expectation = new_expectation.once + assert !expectation.verified? + end + + def test_should_verify_successfully_if_call_expected_once_and_invoked_once + expectation = new_expectation.once + expectation.invoke + assert expectation.verified? + end + + def test_should_verify_successfully_if_expected_call_was_made_at_least_once + expectation = new_expectation.at_least_once + 3.times {expectation.invoke} + assert expectation.verified? + end + + def test_should_not_verify_successfully_if_expected_call_was_not_made_at_least_once + expectation = new_expectation.with(1, 2, 3).at_least_once + assert !expectation.verified? + assert_match(/expected at least once, not yet invoked/i, expectation.mocha_inspect) + end + + def test_should_verify_successfully_if_expected_call_was_made_expected_number_of_times + expectation = new_expectation.times(2) + 2.times {expectation.invoke} + assert expectation.verified? + end + + def test_should_not_verify_successfully_if_expected_call_was_made_too_few_times + expectation = new_expectation.times(2) + 1.times {expectation.invoke} + assert !expectation.verified? + assert_match(/expected exactly twice, already invoked once/i, expectation.mocha_inspect) + end + + def test_should_not_verify_successfully_if_expected_call_was_made_too_many_times + expectation = new_expectation.times(2) + 3.times {expectation.invoke} + assert !expectation.verified? + end + + def test_should_increment_assertion_counter_for_expectation_because_it_does_need_verifyng + expectation = new_expectation + expectation.invoke + assertion_counter = SimpleCounter.new + expectation.verified?(assertion_counter) + assert_equal 1, assertion_counter.count + end + + def test_should_not_increment_assertion_counter_for_stub_because_it_does_not_need_verifying + stub = Expectation.new(nil, :expected_method).at_least(0) + assertion_counter = SimpleCounter.new + stub.verified?(assertion_counter) + assert_equal 0, assertion_counter.count + end + + def test_should_store_backtrace_from_point_where_expectation_was_created + execution_point = ExecutionPoint.current; expectation = Expectation.new(nil, :expected_method) + assert_equal execution_point, ExecutionPoint.new(expectation.backtrace) + end + + class FakeMock + + def initialize(name) + @name = name + end + + def mocha_inspect + @name + end + + end + + def test_should_raise_error_with_message_indicating_which_method_was_expected_to_be_called_on_which_mock_object_with_which_parameters_and_in_what_sequences + mock = FakeMock.new('mock') + sequence_one = Sequence.new('one') + sequence_two = Sequence.new('two') + expectation = Expectation.new(mock, :expected_method).with(1, 2, {'a' => true}, {:b => false}, [1, 2, 3]).in_sequence(sequence_one, sequence_two) + assert !expectation.verified? + assert_match "mock.expected_method(1, 2, {'a' => true}, {:b => false}, [1, 2, 3]); in sequence 'one'; in sequence 'two'", expectation.mocha_inspect + end + + class FakeConstraint + + def initialize(allows_invocation_now) + @allows_invocation_now = allows_invocation_now + end + + def allows_invocation_now? + @allows_invocation_now + end + + end + + def test_should_be_in_correct_order_if_all_ordering_constraints_allow_invocation_now + constraint_one = FakeConstraint.new(allows_invocation_now = true) + constraint_two = FakeConstraint.new(allows_invocation_now = true) + expectation = Expectation.new(nil, :method_one) + expectation.add_ordering_constraint(constraint_one) + expectation.add_ordering_constraint(constraint_two) + assert expectation.in_correct_order? + end + + def test_should_not_be_in_correct_order_if_one_ordering_constraint_does_not_allow_invocation_now + constraint_one = FakeConstraint.new(allows_invocation_now = true) + constraint_two = FakeConstraint.new(allows_invocation_now = false) + expectation = Expectation.new(nil, :method_one) + expectation.add_ordering_constraint(constraint_one) + expectation.add_ordering_constraint(constraint_two) + assert !expectation.in_correct_order? + end + + def test_should_match_if_all_ordering_constraints_allow_invocation_now + constraint_one = FakeConstraint.new(allows_invocation_now = true) + constraint_two = FakeConstraint.new(allows_invocation_now = true) + expectation = Expectation.new(nil, :method_one) + expectation.add_ordering_constraint(constraint_one) + expectation.add_ordering_constraint(constraint_two) + assert expectation.match?(:method_one) + end + + def test_should_not_match_if_one_ordering_constraints_does_not_allow_invocation_now + constraint_one = FakeConstraint.new(allows_invocation_now = true) + constraint_two = FakeConstraint.new(allows_invocation_now = false) + expectation = Expectation.new(nil, :method_one) + expectation.add_ordering_constraint(constraint_one) + expectation.add_ordering_constraint(constraint_two) + assert !expectation.match?(:method_one) + end + + def test_should_not_be_satisfied_when_required_invocation_has_not_been_made + expectation = Expectation.new(nil, :method_one).times(1) + assert !expectation.satisfied? + end + + def test_should_be_satisfied_when_required_invocation_has_been_made + expectation = Expectation.new(nil, :method_one).times(1) + expectation.invoke + assert expectation.satisfied? + end + + def test_should_not_be_satisfied_when_minimum_number_of_invocations_has_not_been_made + expectation = Expectation.new(nil, :method_one).at_least(2) + expectation.invoke + assert !expectation.satisfied? + end + + def test_should_be_satisfied_when_minimum_number_of_invocations_has_been_made + expectation = Expectation.new(nil, :method_one).at_least(2) + 2.times { expectation.invoke } + assert expectation.satisfied? + end + + class FakeSequence + + attr_reader :expectations + + def initialize + @expectations = [] + end + + def constrain_as_next_in_sequence(expectation) + @expectations << expectation + end + + end + + def test_should_tell_sequences_to_constrain_expectation_as_next_in_sequence + sequence_one = FakeSequence.new + sequence_two = FakeSequence.new + expectation = Expectation.new(nil, :method_one) + assert_equal expectation, expectation.in_sequence(sequence_one, sequence_two) + assert_equal [expectation], sequence_one.expectations + assert_equal [expectation], sequence_two.expectations + end + + class FakeState + + def initialize + @active = false + end + + def activate + @active = true + end + + def active? + @active + end + + end + + def test_should_change_state_when_expectation_is_invoked + state = FakeState.new + expectation = Expectation.new(nil, :method_one) + + expectation.then(state) + + expectation.invoke + assert state.active? + end + + def test_should_match_when_state_is_active + state = FakeState.new + expectation = Expectation.new(nil, :method_one) + + expectation.when(state) + assert !expectation.match?(:method_one) + + state.activate + assert expectation.match?(:method_one) + end + +end diff --git a/vendor/gems/mocha-0.9.1/test/unit/hash_inspect_test.rb b/vendor/gems/mocha-0.9.1/test/unit/hash_inspect_test.rb new file mode 100644 index 0000000..15ad415 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/unit/hash_inspect_test.rb @@ -0,0 +1,16 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") +require 'mocha/inspect' + +class HashInspectTest < Test::Unit::TestCase + + def test_should_keep_spacing_between_key_value + hash = {:a => true} + assert_equal '{:a => true}', hash.mocha_inspect + end + + def test_should_use_mocha_inspect_on_each_item + hash = {:a => 'mocha'} + assert_equal "{:a => 'mocha'}", hash.mocha_inspect + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/test/unit/in_state_ordering_constraint_test.rb b/vendor/gems/mocha-0.9.1/test/unit/in_state_ordering_constraint_test.rb new file mode 100644 index 0000000..96e20c5 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/unit/in_state_ordering_constraint_test.rb @@ -0,0 +1,43 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") + +require 'mocha/in_state_ordering_constraint' + +class InStateOrderingConstraintTest < Test::Unit::TestCase + + include Mocha + + class FakeStatePredicate + + attr_writer :active, :description + + def active? + @active + end + + def mocha_inspect + @description + end + + end + + def test_should_allow_invocation_when_state_is_active + state_predicate = FakeStatePredicate.new + ordering_constraint = InStateOrderingConstraint.new(state_predicate) + + state_predicate.active = true + assert ordering_constraint.allows_invocation_now? + + state_predicate.active = false + assert !ordering_constraint.allows_invocation_now? + end + + def test_should_describe_itself_in_terms_of_the_state_predicates_description + state_predicate = FakeStatePredicate.new + ordering_constraint = InStateOrderingConstraint.new(state_predicate) + + state_predicate.description = 'the-state-predicate' + + assert_equal 'when the-state-predicate', ordering_constraint.mocha_inspect + end + +end diff --git a/vendor/gems/mocha-0.9.1/test/unit/metaclass_test.rb b/vendor/gems/mocha-0.9.1/test/unit/metaclass_test.rb new file mode 100644 index 0000000..956bcb4 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/unit/metaclass_test.rb @@ -0,0 +1,22 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") +require 'mocha/metaclass' + +class MetaclassTest < Test::Unit::TestCase + + def test_should_return_objects_singleton_class + object = Object.new + assert_raises(NoMethodError) { object.success? } + + object = Object.new + assert object.__metaclass__.ancestors.include?(Object) + assert object.__metaclass__.ancestors.include?(Kernel) + assert object.__metaclass__.is_a?(Class) + + object.__metaclass__.class_eval { def success?; true; end } + assert object.success? + + object = Object.new + assert_raises(NoMethodError) { object.success? } + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/test/unit/method_matcher_test.rb b/vendor/gems/mocha-0.9.1/test/unit/method_matcher_test.rb new file mode 100644 index 0000000..0167433 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/unit/method_matcher_test.rb @@ -0,0 +1,23 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") +require 'mocha/method_matcher' + +class MethodMatcherTest < Test::Unit::TestCase + + include Mocha + + def test_should_match_if_actual_method_name_is_same_as_expected_method_name + method_matcher = MethodMatcher.new(:method_name) + assert method_matcher.match?(:method_name) + end + + def test_should_not_match_if_actual_method_name_is_not_same_as_expected_method_name + method_matcher = MethodMatcher.new(:method_name) + assert !method_matcher.match?(:different_method_name) + end + + def test_should_describe_what_method_is_expected + method_matcher = MethodMatcher.new(:method_name) + assert_equal "method_name", method_matcher.mocha_inspect + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/test/unit/mock_test.rb b/vendor/gems/mocha-0.9.1/test/unit/mock_test.rb new file mode 100644 index 0000000..849023e --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/unit/mock_test.rb @@ -0,0 +1,290 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") +require 'mocha/mock' +require 'mocha/expectation_error' +require 'set' +require 'simple_counter' + +class MockTest < Test::Unit::TestCase + + include Mocha + + def test_should_set_single_expectation + mock = Mock.new + mock.expects(:method1).returns(1) + assert_nothing_raised(ExpectationError) do + assert_equal 1, mock.method1 + end + end + + def test_should_build_and_store_expectations + mock = Mock.new + expectation = mock.expects(:method1) + assert_not_nil expectation + assert_equal [expectation], mock.expectations.to_a + end + + def test_should_not_stub_everything_by_default + mock = Mock.new + assert_equal false, mock.everything_stubbed + end + + def test_should_stub_everything + mock = Mock.new + mock.stub_everything + assert_equal true, mock.everything_stubbed + end + + def test_should_be_able_to_extend_mock_object_with_module + mock = Mock.new + assert_nothing_raised(ExpectationError) { mock.extend(Module.new) } + end + + def test_should_be_equal + mock = Mock.new + assert_equal true, mock.eql?(mock) + end + + if RUBY_VERSION < '1.9' + OBJECT_METHODS = STANDARD_OBJECT_PUBLIC_INSTANCE_METHODS.reject { |m| m =~ /^__.*__$/ } + else + OBJECT_METHODS = STANDARD_OBJECT_PUBLIC_INSTANCE_METHODS.reject { |m| m =~ /^__.*__$/ || m == :object_id } + end + + def test_should_be_able_to_mock_standard_object_methods + mock = Mock.new + OBJECT_METHODS.each { |method| mock.__expects__(method.to_sym).returns(method) } + OBJECT_METHODS.each { |method| assert_equal method, mock.__send__(method.to_sym) } + assert mock.__verified__? + end + + def test_should_be_able_to_stub_standard_object_methods + mock = Mock.new + OBJECT_METHODS.each { |method| mock.__stubs__(method.to_sym).returns(method) } + OBJECT_METHODS.each { |method| assert_equal method, mock.__send__(method.to_sym) } + end + + def test_should_create_and_add_expectations + mock = Mock.new + expectation1 = mock.expects(:method1) + expectation2 = mock.expects(:method2) + assert_equal [expectation1, expectation2].to_set, mock.expectations.to_set + end + + def test_should_pass_backtrace_into_expectation + mock = Mock.new + backtrace = Object.new + expectation = mock.expects(:method1, backtrace) + assert_equal backtrace, expectation.backtrace + end + + def test_should_pass_backtrace_into_stub + mock = Mock.new + backtrace = Object.new + stub = mock.stubs(:method1, backtrace) + assert_equal backtrace, stub.backtrace + end + + def test_should_create_and_add_stubs + mock = Mock.new + stub1 = mock.stubs(:method1) + stub2 = mock.stubs(:method2) + assert_equal [stub1, stub2].to_set, mock.expectations.to_set + end + + def test_should_invoke_expectation_and_return_result + mock = Mock.new + mock.expects(:my_method).returns(:result) + result = mock.my_method + assert_equal :result, result + end + + def test_should_not_raise_error_if_stubbing_everything + mock = Mock.new + mock.stub_everything + result = nil + assert_nothing_raised(ExpectationError) do + result = mock.unexpected_method + end + assert_nil result + end + + def test_should_raise_assertion_error_for_unexpected_method_call + mock = Mock.new + error = assert_raise(ExpectationError) do + mock.unexpected_method_called(:my_method, :argument1, :argument2) + end + assert_match(/unexpected invocation/, error.message) + assert_match(/my_method/, error.message) + assert_match(/argument1/, error.message) + assert_match(/argument2/, error.message) + end + + def test_should_not_verify_successfully_because_not_all_expectations_have_been_satisfied + mock = Mock.new + mock.expects(:method1) + mock.expects(:method2) + mock.method1 + assert !mock.__verified__? + end + + def test_should_increment_assertion_counter_for_every_verified_expectation + mock = Mock.new + + mock.expects(:method1) + mock.method1 + + mock.expects(:method2) + mock.method2 + + assertion_counter = SimpleCounter.new + + mock.__verified__?(assertion_counter) + + assert_equal 2, assertion_counter.count + end + + def test_should_yield_supplied_parameters_to_block + mock = Mock.new + parameters_for_yield = [1, 2, 3] + mock.expects(:method1).yields(*parameters_for_yield) + yielded_parameters = nil + mock.method1() { |*parameters| yielded_parameters = parameters } + assert_equal parameters_for_yield, yielded_parameters + end + + def test_should_set_up_multiple_expectations_with_return_values + mock = Mock.new + mock.expects(:method1 => :result1, :method2 => :result2) + assert_equal :result1, mock.method1 + assert_equal :result2, mock.method2 + end + + def test_should_set_up_multiple_stubs_with_return_values + mock = Mock.new + mock.stubs(:method1 => :result1, :method2 => :result2) + assert_equal :result1, mock.method1 + assert_equal :result2, mock.method2 + end + + def test_should_keep_returning_specified_value_for_stubs + mock = Mock.new + mock.stubs(:method1).returns(1) + assert_equal 1, mock.method1 + assert_equal 1, mock.method1 + end + + def test_should_keep_returning_specified_value_for_expects + mock = Mock.new + mock.expects(:method1).times(2).returns(1) + assert_equal 1, mock.method1 + assert_equal 1, mock.method1 + end + + def test_should_match_most_recent_call_to_expects + mock = Mock.new + mock.expects(:method1).returns(0) + mock.expects(:method1).returns(1) + assert_equal 1, mock.method1 + end + + def test_should_match_most_recent_call_to_stubs + mock = Mock.new + mock.stubs(:method1).returns(0) + mock.stubs(:method1).returns(1) + assert_equal 1, mock.method1 + end + + def test_should_match_most_recent_call_to_stubs_or_expects + mock = Mock.new + mock.stubs(:method1).returns(0) + mock.expects(:method1).returns(1) + assert_equal 1, mock.method1 + end + + def test_should_match_most_recent_call_to_expects_or_stubs + mock = Mock.new + mock.expects(:method1).returns(0) + mock.stubs(:method1).returns(1) + assert_equal 1, mock.method1 + end + + def test_should_respond_to_expected_method + mock = Mock.new + mock.expects(:method1) + assert_equal true, mock.respond_to?(:method1) + end + + def test_should_not_respond_to_unexpected_method + mock = Mock.new + assert_equal false, mock.respond_to?(:method1) + end + + def test_should_respond_to_methods_which_the_responder_does_responds_to + instance = Class.new do + define_method(:respond_to?) { |symbol| true } + end.new + mock = Mock.new + mock.responds_like(instance) + assert_equal true, mock.respond_to?(:invoked_method) + end + + def test_should_not_respond_to_methods_which_the_responder_does_not_responds_to + instance = Class.new do + define_method(:respond_to?) { |symbol| false } + end.new + mock = Mock.new + mock.responds_like(instance) + assert_equal false, mock.respond_to?(:invoked_method) + end + + def test_should_return_itself_to_allow_method_chaining + mock = Mock.new + assert_same mock.responds_like(Object.new), mock + end + + def test_should_not_raise_no_method_error_if_mock_is_not_restricted_to_respond_like_a_responder + instance = Class.new do + define_method(:respond_to?) { true } + end.new + mock = Mock.new + mock.stubs(:invoked_method) + assert_nothing_raised(NoMethodError) { mock.invoked_method } + end + + def test_should_not_raise_no_method_error_if_responder_does_respond_to_invoked_method + instance = Class.new do + define_method(:respond_to?) { |symbol| true } + end.new + mock = Mock.new + mock.responds_like(instance) + mock.stubs(:invoked_method) + assert_nothing_raised(NoMethodError) { mock.invoked_method } + end + + def test_should_raise_no_method_error_if_responder_does_not_respond_to_invoked_method + instance = Class.new do + define_method(:respond_to?) { |symbol| false } + define_method(:mocha_inspect) { 'mocha_inspect' } + end.new + mock = Mock.new + mock.responds_like(instance) + mock.stubs(:invoked_method) + assert_raises(NoMethodError) { mock.invoked_method } + end + + def test_should_raise_no_method_error_with_message_indicating_that_mock_is_constrained_to_respond_like_responder + instance = Class.new do + define_method(:respond_to?) { |symbol| false } + define_method(:mocha_inspect) { 'mocha_inspect' } + end.new + mock = Mock.new + mock.responds_like(instance) + mock.stubs(:invoked_method) + begin + mock.invoked_method + rescue NoMethodError => e + assert_match(/which responds like mocha_inspect/, e.message) + end + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/test/unit/mockery_test.rb b/vendor/gems/mocha-0.9.1/test/unit/mockery_test.rb new file mode 100644 index 0000000..db05ec2 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/unit/mockery_test.rb @@ -0,0 +1,149 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") +require 'mocha/mockery' +require 'mocha/state_machine' + +class MockeryTest < Test::Unit::TestCase + + include Mocha + + def test_should_build_instance_of_mockery + mockery = Mockery.instance + assert_not_nil mockery + assert_kind_of Mockery, mockery + end + + def test_should_cache_instance_of_mockery + mockery_1 = Mockery.instance + mockery_2 = Mockery.instance + assert_same mockery_1, mockery_2 + end + + def test_should_expire_mockery_instance_cache + mockery_1 = Mockery.instance + Mockery.reset_instance + mockery_2 = Mockery.instance + assert_not_same mockery_1, mockery_2 + end + + def test_should_raise_expectation_error_because_not_all_expectations_are_satisfied + mockery = Mockery.new + mock_1 = mockery.named_mock('mock-1') { expects(:method_1) } + mock_2 = mockery.named_mock('mock-2') { expects(:method_2) } + 1.times { mock_1.method_1 } + 0.times { mock_2.method_2 } + assert_raises(ExpectationError) { mockery.verify } + end + + def test_should_reset_list_of_mocks_on_teardown + mockery = Mockery.new + mock = mockery.unnamed_mock { expects(:my_method) } + mockery.teardown + assert_nothing_raised(ExpectationError) { mockery.verify } + end + + def test_should_build_instance_of_stubba_on_instantiation + mockery = Mockery.new + assert_not_nil mockery.stubba + assert_kind_of Central, mockery.stubba + end + + def test_should_build_new_instance_of_stubba_on_teardown + mockery = Mockery.new + stubba_1 = mockery.stubba + mockery.teardown + stubba_2 = mockery.stubba + assert_not_same stubba_1, stubba_2 + end + + def test_should_build_and_store_new_state_machine + mockery = Mockery.new + mockery.new_state_machine('state-machine-name') + assert_equal 1, mockery.state_machines.length + assert_kind_of StateMachine, mockery.state_machines[0] + end + + def test_should_reset_list_of_state_machines_on_teardown + mockery = Mockery.new + mockery.new_state_machine('state-machine-name') + mockery.teardown + assert_equal 0, mockery.state_machines.length + end + + class FakeMethod + def stub; end + def unstub; end + end + + def test_should_unstub_all_methods_on_teardown + mockery = Mockery.new + stubba = mockery.stubba + stubba.stub(FakeMethod.new) + mockery.teardown + assert stubba.stubba_methods.empty? + end + + def test_should_display_object_id_for_mocha_inspect_if_mock_has_no_name + mockery = Mockery.new + mock = mockery.unnamed_mock + assert_match Regexp.new("^#$"), mock.mocha_inspect + end + + def test_should_display_object_id_for_inspect_if_mock_has_no_name + mockery = Mockery.new + mock = mockery.unnamed_mock + assert_match Regexp.new("^#$"), mock.inspect + end + + def test_should_display_name_for_mocha_inspect_if_mock_has_string_name + mockery = Mockery.new + mock = mockery.named_mock('named_mock') + assert_equal "#", mock.mocha_inspect + end + + def test_should_display_name_for_mocha_inspect_if_mock_has_symbol_name + mockery = Mockery.new + mock = mockery.named_mock(:named_mock) + assert_equal "#", mock.mocha_inspect + end + + def test_should_display_name_for_inspect_if_mock_has_string_name + mockery = Mockery.new + mock = mockery.named_mock('named_mock') + assert_equal "#", mock.inspect + end + + def test_should_display_name_for_inspect_if_mock_has_symbol_name + mockery = Mockery.new + mock = mockery.named_mock(:named_mock) + assert_equal "#", mock.inspect + end + + def test_should_display_impersonated_object_for_mocha_inspect + mockery = Mockery.new + instance = Object.new + mock = mockery.mock_impersonating(instance) + assert_equal "#{instance.mocha_inspect}", mock.mocha_inspect + end + + def test_should_display_impersonated_object_for_inspect + mockery = Mockery.new + instance = Object.new + mock = mockery.mock_impersonating(instance) + assert_equal "#{instance.mocha_inspect}", mock.inspect + end + + class FakeClass; end + + def test_should_display_any_instance_prefix_followed_by_class_whose_instances_are_being_impersonated_for_mocha_inspect + mockery = Mockery.new + mock = mockery.mock_impersonating_any_instance_of(FakeClass) + assert_equal "#", mock.mocha_inspect + end + + def test_should_display_any_instance_prefix_followed_by_class_whose_instances_are_being_impersonated_for_inspect + mockery = Mockery.new + mock = mockery.mock_impersonating_any_instance_of(FakeClass) + assert_equal "#", mock.inspect + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/test/unit/multiple_yields_test.rb b/vendor/gems/mocha-0.9.1/test/unit/multiple_yields_test.rb new file mode 100644 index 0000000..65724a8 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/unit/multiple_yields_test.rb @@ -0,0 +1,18 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") + +require 'mocha/multiple_yields' + +class MultipleYieldsTest < Test::Unit::TestCase + + include Mocha + + def test_should_provide_parameters_for_multiple_yields_in_single_invocation + parameter_group = MultipleYields.new([1, 2, 3], [4, 5]) + parameter_groups = [] + parameter_group.each do |parameters| + parameter_groups << parameters + end + assert_equal [[1, 2, 3], [4, 5]], parameter_groups + end + +end diff --git a/vendor/gems/mocha-0.9.1/test/unit/no_yields_test.rb b/vendor/gems/mocha-0.9.1/test/unit/no_yields_test.rb new file mode 100644 index 0000000..544d1ef --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/unit/no_yields_test.rb @@ -0,0 +1,18 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") + +require 'mocha/no_yields' + +class NoYieldsTest < Test::Unit::TestCase + + include Mocha + + def test_should_provide_parameters_for_no_yields_in_single_invocation + parameter_group = NoYields.new + parameter_groups = [] + parameter_group.each do |parameters| + parameter_groups << parameters + end + assert_equal [], parameter_groups + end + +end diff --git a/vendor/gems/mocha-0.9.1/test/unit/object_inspect_test.rb b/vendor/gems/mocha-0.9.1/test/unit/object_inspect_test.rb new file mode 100644 index 0000000..56d84a9 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/unit/object_inspect_test.rb @@ -0,0 +1,37 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") +require 'mocha/inspect' +require 'method_definer' + +class ObjectInspectTest < Test::Unit::TestCase + + def test_should_return_default_string_representation_of_object_not_including_instance_variables + object = Object.new + class << object + attr_accessor :attribute + end + object.attribute = 'instance_variable' + assert_match Regexp.new("^#$"), object.mocha_inspect + assert_no_match(/instance_variable/, object.mocha_inspect) + end + + def test_should_return_customized_string_representation_of_object + object = Object.new + class << object + define_method(:inspect) { 'custom_inspect' } + end + assert_equal 'custom_inspect', object.mocha_inspect + end + + def test_should_use_underscored_id_instead_of_object_id_or_id_so_that_they_can_be_stubbed + object = Object.new + object.define_instance_accessor(:called) + object.called = false + object.replace_instance_method(:object_id) { self.called = true; 1 } + if RUBY_VERSION < '1.9' + object.replace_instance_method(:id) { self.called = true; 1 } + end + object.mocha_inspect + assert_equal false, object.called + end + +end diff --git a/vendor/gems/mocha-0.9.1/test/unit/object_test.rb b/vendor/gems/mocha-0.9.1/test/unit/object_test.rb new file mode 100644 index 0000000..57262e4 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/unit/object_test.rb @@ -0,0 +1,82 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") +require 'mocha/object' +require 'mocha/mockery' +require 'mocha/mock' +require 'method_definer' + +class ObjectTest < Test::Unit::TestCase + + include Mocha + + def test_should_build_mocha_referring_to_self + instance = Object.new + mocha = instance.mocha + assert_not_nil mocha + assert mocha.is_a?(Mock) + assert_equal instance.mocha_inspect, mocha.mocha_inspect + end + + def test_should_reuse_existing_mocha + instance = Object.new + mocha_1 = instance.mocha + mocha_2 = instance.mocha + assert_equal mocha_1, mocha_2 + end + + def test_should_reset_mocha + instance = Object.new + assert_nil instance.reset_mocha + end + + def test_should_build_any_instance_object + klass = Class.new + any_instance = klass.any_instance + assert_not_nil any_instance + assert any_instance.is_a?(Class::AnyInstance) + end + + def test_should_return_same_any_instance_object + klass = Class.new + any_instance_1 = klass.any_instance + any_instance_2 = klass.any_instance + assert_equal any_instance_1, any_instance_2 + end + + def test_should_use_stubba_instance_method_for_object + assert_equal Mocha::InstanceMethod, Object.new.stubba_method + end + + def test_should_use_stubba_module_method_for_module + assert_equal Mocha::ModuleMethod, Module.new.stubba_method + end + + def test_should_use_stubba_class_method_for_class + assert_equal Mocha::ClassMethod, Class.new.stubba_method + end + + def test_should_use_stubba_class_method_for_any_instance + assert_equal Mocha::AnyInstanceMethod, Class::AnyInstance.new(nil).stubba_method + end + + def test_should_stub_self_for_object + object = Object.new + assert_equal object, object.stubba_object + end + + def test_should_stub_self_for_module + mod = Module.new + assert_equal mod, mod.stubba_object + end + + def test_should_stub_self_for_class + klass = Class.new + assert_equal klass, klass.stubba_object + end + + def test_should_stub_relevant_class_for_any_instance + klass = Class.new + any_instance = Class::AnyInstance.new(klass) + assert_equal klass, any_instance.stubba_object + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/all_of_test.rb b/vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/all_of_test.rb new file mode 100644 index 0000000..14028f5 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/all_of_test.rb @@ -0,0 +1,26 @@ +require File.join(File.dirname(__FILE__), "..", "..", "test_helper") + +require 'mocha/parameter_matchers/all_of' +require 'mocha/inspect' +require 'stub_matcher' + +class AllOfTest < Test::Unit::TestCase + + include Mocha::ParameterMatchers + + def test_should_match_if_all_matchers_match + matcher = all_of(Stub::Matcher.new(true), Stub::Matcher.new(true), Stub::Matcher.new(true)) + assert matcher.matches?(['any_old_value']) + end + + def test_should_not_match_if_any_matcher_does_not_match + matcher = all_of(Stub::Matcher.new(true), Stub::Matcher.new(false), Stub::Matcher.new(true)) + assert !matcher.matches?(['any_old_value']) + end + + def test_should_describe_matcher + matcher = all_of(Stub::Matcher.new(true), Stub::Matcher.new(false), Stub::Matcher.new(true)) + assert_equal 'all_of(matcher(true), matcher(false), matcher(true))', matcher.mocha_inspect + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/any_of_test.rb b/vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/any_of_test.rb new file mode 100644 index 0000000..503d6dc --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/any_of_test.rb @@ -0,0 +1,26 @@ +require File.join(File.dirname(__FILE__), "..", "..", "test_helper") + +require 'mocha/parameter_matchers/any_of' +require 'mocha/inspect' +require 'stub_matcher' + +class AnyOfTest < Test::Unit::TestCase + + include Mocha::ParameterMatchers + + def test_should_match_if_any_matchers_match + matcher = any_of(Stub::Matcher.new(false), Stub::Matcher.new(true), Stub::Matcher.new(false)) + assert matcher.matches?(['any_old_value']) + end + + def test_should_not_match_if_no_matchers_match + matcher = any_of(Stub::Matcher.new(false), Stub::Matcher.new(false), Stub::Matcher.new(false)) + assert !matcher.matches?(['any_old_value']) + end + + def test_should_describe_matcher + matcher = any_of(Stub::Matcher.new(false), Stub::Matcher.new(true), Stub::Matcher.new(false)) + assert_equal 'any_of(matcher(false), matcher(true), matcher(false))', matcher.mocha_inspect + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/anything_test.rb b/vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/anything_test.rb new file mode 100644 index 0000000..42a88a1 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/anything_test.rb @@ -0,0 +1,21 @@ +require File.join(File.dirname(__FILE__), "..", "..", "test_helper") + +require 'mocha/parameter_matchers/anything' +require 'mocha/inspect' + +class AnythingTest < Test::Unit::TestCase + + include Mocha::ParameterMatchers + + def test_should_match_anything + matcher = anything + assert matcher.matches?([:something]) + assert matcher.matches?([{'x' => 'y'}]) + end + + def test_should_describe_matcher + matcher = anything + assert_equal "anything", matcher.mocha_inspect + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/equals_test.rb b/vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/equals_test.rb new file mode 100644 index 0000000..df1eb6e --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/equals_test.rb @@ -0,0 +1,25 @@ +require File.join(File.dirname(__FILE__), "..", "..", "test_helper") + +require 'mocha/parameter_matchers/equals' +require 'mocha/inspect' + +class EqualsTest < Test::Unit::TestCase + + include Mocha::ParameterMatchers + + def test_should_match_object_that_equals_value + matcher = equals('x') + assert matcher.matches?(['x']) + end + + def test_should_not_match_object_that_does_not_equal_value + matcher = equals('x') + assert !matcher.matches?(['y']) + end + + def test_should_describe_matcher + matcher = equals('x') + assert_equal "'x'", matcher.mocha_inspect + end + +end diff --git a/vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/has_entries_test.rb b/vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/has_entries_test.rb new file mode 100644 index 0000000..181c9b2 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/has_entries_test.rb @@ -0,0 +1,51 @@ +require File.join(File.dirname(__FILE__), "..", "..", "test_helper") + +require 'mocha/parameter_matchers/has_entries' +require 'mocha/parameter_matchers/object' +require 'mocha/inspect' + +class HasEntriesTest < Test::Unit::TestCase + + include Mocha::ParameterMatchers + + def test_should_match_hash_including_specified_entries + matcher = has_entries(:key_1 => 'value_1', :key_2 => 'value_2') + assert matcher.matches?([{ :key_1 => 'value_1', :key_2 => 'value_2', :key_3 => 'value_3' }]) + end + + def test_should_not_match_hash_not_including_specified_entries + matcher = has_entries(:key_1 => 'value_2', :key_2 => 'value_2', :key_3 => 'value_3') + assert !matcher.matches?([{ :key_1 => 'value_1', :key_2 => 'value_2' }]) + end + + def test_should_describe_matcher + matcher = has_entries(:key_1 => 'value_1', :key_2 => 'value_2') + description = matcher.mocha_inspect + matches = /has_entries\((.*)\)/.match(description) + assert_not_nil matches[0] + entries = eval(matches[1], binding, __FILE__, __LINE__) + assert_equal 'value_1', entries[:key_1] + assert_equal 'value_2', entries[:key_2] + end + + def test_should_match_hash_including_specified_entries_with_nested_key_matchers + matcher = has_entries(equals(:key_1) => 'value_1', equals(:key_2) => 'value_2') + assert matcher.matches?([{ :key_1 => 'value_1', :key_2 => 'value_2', :key_3 => 'value_3' }]) + end + + def test_should_not_match_hash_not_including_specified_entries_with_nested_key_matchers + matcher = has_entries(equals(:key_1) => 'value_2', equals(:key_2) => 'value_2', equals(:key_3) => 'value_3') + assert !matcher.matches?([{ :key_1 => 'value_1', :key_2 => 'value_2' }]) + end + + def test_should_match_hash_including_specified_entries_with_nested_value_matchers + matcher = has_entries(:key_1 => equals('value_1'), :key_2 => equals('value_2')) + assert matcher.matches?([{ :key_1 => 'value_1', :key_2 => 'value_2', :key_3 => 'value_3' }]) + end + + def test_should_not_match_hash_not_including_specified_entries_with_nested_value_matchers + matcher = has_entries(:key_1 => equals('value_2'), :key_2 => equals('value_2'), :key_3 => equals('value_3')) + assert !matcher.matches?([{ :key_1 => 'value_1', :key_2 => 'value_2' }]) + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/has_entry_test.rb b/vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/has_entry_test.rb new file mode 100644 index 0000000..5211c04 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/has_entry_test.rb @@ -0,0 +1,62 @@ +require File.join(File.dirname(__FILE__), "..", "..", "test_helper") + +require 'mocha/parameter_matchers/has_entry' +require 'mocha/parameter_matchers/object' +require 'mocha/parameter_matchers/equals' +require 'mocha/inspect' + +class HasEntryTest < Test::Unit::TestCase + + include Mocha::ParameterMatchers + + def test_should_match_hash_including_specified_key_value_pair + matcher = has_entry(:key_1, 'value_1') + assert matcher.matches?([{ :key_1 => 'value_1', :key_2 => 'value_2' }]) + end + + def test_should_not_match_hash_not_including_specified_key_value_pair + matcher = has_entry(:key_1, 'value_2') + assert !matcher.matches?([{ :key_1 => 'value_1', :key_2 => 'value_2' }]) + end + + def test_should_match_hash_including_specified_entry + matcher = has_entry(:key_1 => 'value_1') + assert matcher.matches?([{ :key_1 => 'value_1', :key_2 => 'value_2' }]) + end + + def test_should_not_match_hash_not_including_specified_entry + matcher = has_entry(:key_1 => 'value_2') + assert !matcher.matches?([{ :key_1 => 'value_1', :key_2 => 'value_2' }]) + end + + def test_should_describe_matcher_with_key_value_pair + matcher = has_entry(:key_1, 'value_1') + assert_equal "has_entry(:key_1 => 'value_1')", matcher.mocha_inspect + end + + def test_should_describe_matcher_with_entry + matcher = has_entry(:key_1 => 'value_1') + assert_equal "has_entry(:key_1 => 'value_1')", matcher.mocha_inspect + end + + def test_should_match_hash_including_specified_entry_with_nested_key_matcher + matcher = has_entry(equals(:key_1) => 'value_1') + assert matcher.matches?([{ :key_1 => 'value_1', :key_2 => 'value_2' }]) + end + + def test_should_match_hash_including_specified_entry_with_nested_value_matcher + matcher = has_entry(:key_1 => equals('value_1')) + assert matcher.matches?([{ :key_1 => 'value_1', :key_2 => 'value_2' }]) + end + + def test_should_not_match_hash_not_including_specified_entry_with_nested_key_matcher + matcher = has_entry(equals(:key_1) => 'value_2') + assert !matcher.matches?([{ :key_1 => 'value_1', :key_2 => 'value_2' }]) + end + + def test_should_not_match_hash_not_including_specified_entry_with_nested_value_matcher + matcher = has_entry(:key_1 => equals('value_2')) + assert !matcher.matches?([{ :key_1 => 'value_1', :key_2 => 'value_2' }]) + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/has_key_test.rb b/vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/has_key_test.rb new file mode 100644 index 0000000..ad8362e --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/has_key_test.rb @@ -0,0 +1,36 @@ +require File.join(File.dirname(__FILE__), "..", "..", "test_helper") + +require 'mocha/parameter_matchers/has_key' +require 'mocha/parameter_matchers/object' +require 'mocha/inspect' + +class HasKeyTest < Test::Unit::TestCase + + include Mocha::ParameterMatchers + + def test_should_match_hash_including_specified_key + matcher = has_key(:key_1) + assert matcher.matches?([{ :key_1 => 1, :key_2 => 2 }]) + end + + def test_should_not_match_hash_not_including_specified_key + matcher = has_key(:key_1) + assert !matcher.matches?([{ :key_2 => 2 }]) + end + + def test_should_describe_matcher + matcher = has_key(:key) + assert_equal 'has_key(:key)', matcher.mocha_inspect + end + + def test_should_match_hash_including_specified_key_with_nested_key_matcher + matcher = has_key(equals(:key_1)) + assert matcher.matches?([{ :key_1 => 1, :key_2 => 2 }]) + end + + def test_should_not_match_hash_not_including_specified_key_with_nested_key_matcher + matcher = has_key(equals(:key_1)) + assert !matcher.matches?([{ :key_2 => 2 }]) + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/has_value_test.rb b/vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/has_value_test.rb new file mode 100644 index 0000000..0219f6a --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/has_value_test.rb @@ -0,0 +1,37 @@ +require File.join(File.dirname(__FILE__), "..", "..", "test_helper") + +require 'mocha/parameter_matchers/has_value' +require 'mocha/parameter_matchers/object' +require 'mocha/parameter_matchers/equals' +require 'mocha/inspect' + +class HasValueTest < Test::Unit::TestCase + + include Mocha::ParameterMatchers + + def test_should_match_hash_including_specified_value + matcher = has_value('value_1') + assert matcher.matches?([{ :key_1 => 'value_1', :key_2 => 'value_2' }]) + end + + def test_should_not_match_hash_not_including_specified_value + matcher = has_value('value_1') + assert !matcher.matches?([{ :key_2 => 'value_2' }]) + end + + def test_should_describe_matcher + matcher = has_value('value_1') + assert_equal "has_value('value_1')", matcher.mocha_inspect + end + + def test_should_match_hash_including_specified_value_with_nested_value_matcher + matcher = has_value(equals('value_1')) + assert matcher.matches?([{ :key_1 => 'value_1', :key_2 => 'value_2' }]) + end + + def test_should_not_match_hash_not_including_specified_value_with_nested_value_matcher + matcher = has_value(equals('value_1')) + assert !matcher.matches?([{ :key_2 => 'value_2' }]) + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/includes_test.rb b/vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/includes_test.rb new file mode 100644 index 0000000..70fb649 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/includes_test.rb @@ -0,0 +1,25 @@ +require File.join(File.dirname(__FILE__), "..", "..", "test_helper") + +require 'mocha/parameter_matchers/includes' +require 'mocha/inspect' + +class IncludesTest < Test::Unit::TestCase + + include Mocha::ParameterMatchers + + def test_should_match_object_including_value + matcher = includes(:x) + assert matcher.matches?([[:x, :y, :z]]) + end + + def test_should_not_match_object_that_does_not_include_value + matcher = includes(:not_included) + assert !matcher.matches?([[:x, :y, :z]]) + end + + def test_should_describe_matcher + matcher = includes(:x) + assert_equal "includes(:x)", matcher.mocha_inspect + end + +end diff --git a/vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/instance_of_test.rb b/vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/instance_of_test.rb new file mode 100644 index 0000000..415b79a --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/instance_of_test.rb @@ -0,0 +1,25 @@ +require File.join(File.dirname(__FILE__), "..", "..", "test_helper") + +require 'mocha/parameter_matchers/instance_of' +require 'mocha/inspect' + +class InstanceOfTest < Test::Unit::TestCase + + include Mocha::ParameterMatchers + + def test_should_match_object_that_is_an_instance_of_specified_class + matcher = instance_of(String) + assert matcher.matches?(['string']) + end + + def test_should_not_match_object_that_is_not_an_instance_of_specified_class + matcher = instance_of(String) + assert !matcher.matches?([99]) + end + + def test_should_describe_matcher + matcher = instance_of(String) + assert_equal "instance_of(String)", matcher.mocha_inspect + end + +end diff --git a/vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/is_a_test.rb b/vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/is_a_test.rb new file mode 100644 index 0000000..c9ef919 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/is_a_test.rb @@ -0,0 +1,25 @@ +require File.join(File.dirname(__FILE__), "..", "..", "test_helper") + +require 'mocha/parameter_matchers/is_a' +require 'mocha/inspect' + +class IsATest < Test::Unit::TestCase + + include Mocha::ParameterMatchers + + def test_should_match_object_that_is_a_specified_class + matcher = is_a(Integer) + assert matcher.matches?([99]) + end + + def test_should_not_match_object_that_is_not_a_specified_class + matcher = is_a(Integer) + assert !matcher.matches?(['string']) + end + + def test_should_describe_matcher + matcher = is_a(Integer) + assert_equal "is_a(Integer)", matcher.mocha_inspect + end + +end diff --git a/vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/kind_of_test.rb b/vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/kind_of_test.rb new file mode 100644 index 0000000..1167e5c --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/kind_of_test.rb @@ -0,0 +1,25 @@ +require File.join(File.dirname(__FILE__), "..", "..", "test_helper") + +require 'mocha/parameter_matchers/kind_of' +require 'mocha/inspect' + +class KindOfTest < Test::Unit::TestCase + + include Mocha::ParameterMatchers + + def test_should_match_object_that_is_a_kind_of_specified_class + matcher = kind_of(Integer) + assert matcher.matches?([99]) + end + + def test_should_not_match_object_that_is_not_a_kind_of_specified_class + matcher = kind_of(Integer) + assert !matcher.matches?(['string']) + end + + def test_should_describe_matcher + matcher = kind_of(Integer) + assert_equal "kind_of(Integer)", matcher.mocha_inspect + end + +end diff --git a/vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/not_test.rb b/vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/not_test.rb new file mode 100644 index 0000000..4cb6790 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/not_test.rb @@ -0,0 +1,26 @@ +require File.join(File.dirname(__FILE__), "..", "..", "test_helper") + +require 'mocha/parameter_matchers/not' +require 'mocha/inspect' +require 'stub_matcher' + +class NotTest < Test::Unit::TestCase + + include Mocha::ParameterMatchers + + def test_should_match_if_matcher_does_not_match + matcher = Not(Stub::Matcher.new(false)) + assert matcher.matches?(['any_old_value']) + end + + def test_should_not_match_if_matcher_does_match + matcher = Not(Stub::Matcher.new(true)) + assert !matcher.matches?(['any_old_value']) + end + + def test_should_describe_matcher + matcher = Not(Stub::Matcher.new(true)) + assert_equal 'Not(matcher(true))', matcher.mocha_inspect + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/regexp_matches_test.rb b/vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/regexp_matches_test.rb new file mode 100644 index 0000000..5aec002 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/regexp_matches_test.rb @@ -0,0 +1,25 @@ +require File.join(File.dirname(__FILE__), "..", "..", "test_helper") + +require 'mocha/parameter_matchers/regexp_matches' +require 'mocha/inspect' + +class RegexpMatchesTest < Test::Unit::TestCase + + include Mocha::ParameterMatchers + + def test_should_match_parameter_matching_regular_expression + matcher = regexp_matches(/oo/) + assert matcher.matches?(['foo']) + end + + def test_should_not_match_parameter_not_matching_regular_expression + matcher = regexp_matches(/oo/) + assert !matcher.matches?(['bar']) + end + + def test_should_describe_matcher + matcher = regexp_matches(/oo/) + assert_equal "regexp_matches(/oo/)", matcher.mocha_inspect + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/responds_with_test.rb b/vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/responds_with_test.rb new file mode 100644 index 0000000..f32bf8b --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/responds_with_test.rb @@ -0,0 +1,25 @@ +require File.join(File.dirname(__FILE__), "..", "..", "test_helper") + +require 'mocha/parameter_matchers/responds_with' +require 'mocha/inspect' + +class RespondsWithTest < Test::Unit::TestCase + + include Mocha::ParameterMatchers + + def test_should_match_parameter_responding_with_expected_value + matcher = responds_with(:upcase, 'FOO') + assert matcher.matches?(['foo']) + end + + def test_should_not_match_parameter_responding_with_unexpected_value + matcher = responds_with(:upcase, 'FOO') + assert !matcher.matches?(['bar']) + end + + def test_should_describe_matcher + matcher = responds_with(:foo, :bar) + assert_equal 'responds_with(:foo, :bar)', matcher.mocha_inspect + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/stub_matcher.rb b/vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/stub_matcher.rb new file mode 100644 index 0000000..8bb8172 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/stub_matcher.rb @@ -0,0 +1,27 @@ +module Stub + + class Matcher + + attr_accessor :value + + def initialize(matches) + @matches = matches + end + + def matches?(available_parameters) + value = available_parameters.shift + @value = value + @matches + end + + def mocha_inspect + "matcher(#{@matches})" + end + + def to_matcher + self + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/yaml_equivalent_test.rb b/vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/yaml_equivalent_test.rb new file mode 100644 index 0000000..b163f30 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/yaml_equivalent_test.rb @@ -0,0 +1,25 @@ +require File.join(File.dirname(__FILE__), "..", "..", "test_helper") + +require 'mocha/parameter_matchers/yaml_equivalent' +require 'mocha/inspect' + +class YamlEquivalentTest < Test::Unit::TestCase + + include Mocha::ParameterMatchers + + def test_should_match_parameter_matching_yaml_representation_of_object + matcher = yaml_equivalent([1, 2, 3]) + assert matcher.matches?(["--- \n- 1\n- 2\n- 3\n"]) + end + + def test_should_not_match_parameter_matching_yaml_representation_of_object + matcher = yaml_equivalent([1, 2, 3]) + assert !matcher.matches?(["--- \n- 4\n- 5\n"]) + end + + def test_should_describe_matcher + matcher = yaml_equivalent([1, 2, 3]) + assert_equal "yaml_equivalent([1, 2, 3])", matcher.mocha_inspect + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/test/unit/parameters_matcher_test.rb b/vendor/gems/mocha-0.9.1/test/unit/parameters_matcher_test.rb new file mode 100644 index 0000000..612805e --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/unit/parameters_matcher_test.rb @@ -0,0 +1,121 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") +require 'mocha/parameters_matcher' + +class ParametersMatcherTest < Test::Unit::TestCase + + include Mocha + + def test_should_match_any_actual_parameters_if_no_expected_parameters_specified + parameters_matcher = ParametersMatcher.new + assert parameters_matcher.match?(actual_parameters = [1, 2, 3]) + end + + def test_should_match_if_actual_parameters_are_same_as_expected_parameters + parameters_matcher = ParametersMatcher.new(expected_parameters = [4, 5, 6]) + assert parameters_matcher.match?(actual_parameters = [4, 5, 6]) + end + + def test_should_not_match_if_actual_parameters_are_different_from_expected_parameters + parameters_matcher = ParametersMatcher.new(expected_parameters = [4, 5, 6]) + assert !parameters_matcher.match?(actual_parameters = [1, 2, 3]) + end + + def test_should_not_match_if_there_are_less_actual_parameters_than_expected_parameters + parameters_matcher = ParametersMatcher.new(expected_parameters = [4, 5, 6]) + assert !parameters_matcher.match?(actual_parameters = [4, 5]) + end + + def test_should_not_match_if_there_are_more_actual_parameters_than_expected_parameters + parameters_matcher = ParametersMatcher.new(expected_parameters = [4, 5]) + assert !parameters_matcher.match?(actual_parameters = [4, 5, 6]) + end + + def test_should_not_match_if_not_all_required_parameters_are_supplied + optionals = ParameterMatchers::Optionally.new(6, 7) + parameters_matcher = ParametersMatcher.new(expected_parameters = [4, 5, optionals]) + assert !parameters_matcher.match?(actual_parameters = [4]) + end + + def test_should_match_if_all_required_parameters_match_and_no_optional_parameters_are_supplied + optionals = ParameterMatchers::Optionally.new(6, 7) + parameters_matcher = ParametersMatcher.new(expected_parameters = [4, 5, optionals]) + assert parameters_matcher.match?(actual_parameters = [4, 5]) + end + + def test_should_match_if_all_required_and_optional_parameters_match_and_some_optional_parameters_are_supplied + optionals = ParameterMatchers::Optionally.new(6, 7) + parameters_matcher = ParametersMatcher.new(expected_parameters = [4, 5, optionals]) + assert parameters_matcher.match?(actual_parameters = [4, 5, 6]) + end + + def test_should_match_if_all_required_and_optional_parameters_match_and_all_optional_parameters_are_supplied + optionals = ParameterMatchers::Optionally.new(6, 7) + parameters_matcher = ParametersMatcher.new(expected_parameters = [4, 5, optionals]) + assert parameters_matcher.match?(actual_parameters = [4, 5, 6, 7]) + end + + def test_should_not_match_if_all_required_and_optional_parameters_match_but_too_many_optional_parameters_are_supplied + optionals = ParameterMatchers::Optionally.new(6, 7) + parameters_matcher = ParametersMatcher.new(expected_parameters = [4, 5, optionals]) + assert !parameters_matcher.match?(actual_parameters = [4, 5, 6, 7, 8]) + end + + def test_should_not_match_if_all_required_parameters_match_but_some_optional_parameters_do_not_match + optionals = ParameterMatchers::Optionally.new(6, 7) + parameters_matcher = ParametersMatcher.new(expected_parameters = [4, 5, optionals]) + assert !parameters_matcher.match?(actual_parameters = [4, 5, 6, 0]) + end + + def test_should_not_match_if_some_required_parameters_do_not_match_although_all_optional_parameters_do_match + optionals = ParameterMatchers::Optionally.new(6, 7) + parameters_matcher = ParametersMatcher.new(expected_parameters = [4, 5, optionals]) + assert !parameters_matcher.match?(actual_parameters = [4, 0, 6]) + end + + def test_should_not_match_if_all_required_parameters_match_but_no_optional_parameters_match + optionals = ParameterMatchers::Optionally.new(6, 7) + parameters_matcher = ParametersMatcher.new(expected_parameters = [4, 5, optionals]) + assert !parameters_matcher.match?(actual_parameters = [4, 5, 0, 0]) + end + + def test_should_match_if_actual_parameters_satisfy_matching_block + parameters_matcher = ParametersMatcher.new { |x, y| x + y == 3 } + assert parameters_matcher.match?(actual_parameters = [1, 2]) + end + + def test_should_not_match_if_actual_parameters_do_not_satisfy_matching_block + parameters_matcher = ParametersMatcher.new { |x, y| x + y == 3 } + assert !parameters_matcher.match?(actual_parameters = [2, 3]) + end + + def test_should_remove_outer_array_braces + params = [1, 2, [3, 4]] + parameters_matcher = ParametersMatcher.new(params) + assert_equal '(1, 2, [3, 4])', parameters_matcher.mocha_inspect + end + + def test_should_display_numeric_arguments_as_is + params = [1, 2, 3] + parameters_matcher = ParametersMatcher.new(params) + assert_equal '(1, 2, 3)', parameters_matcher.mocha_inspect + end + + def test_should_remove_curly_braces_if_hash_is_only_argument + params = [{:a => 1, :z => 2}] + parameters_matcher = ParametersMatcher.new(params) + assert_nil parameters_matcher.mocha_inspect.index('{') + assert_nil parameters_matcher.mocha_inspect.index('}') + end + + def test_should_not_remove_curly_braces_if_hash_is_not_the_only_argument + params = [1, {:a => 1}] + parameters_matcher = ParametersMatcher.new(params) + assert_equal '(1, {:a => 1})', parameters_matcher.mocha_inspect + end + + def test_should_indicate_that_matcher_will_match_any_actual_parameters + parameters_matcher = ParametersMatcher.new + assert_equal '(any_parameters)', parameters_matcher.mocha_inspect + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/test/unit/return_values_test.rb b/vendor/gems/mocha-0.9.1/test/unit/return_values_test.rb new file mode 100644 index 0000000..01ddfbc --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/unit/return_values_test.rb @@ -0,0 +1,63 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") + +require 'mocha/return_values' + +class ReturnValuesTest < Test::Unit::TestCase + + include Mocha + + def test_should_return_nil + values = ReturnValues.new + assert_nil values.next + end + + def test_should_keep_returning_nil + values = ReturnValues.new + values.next + assert_nil values.next + assert_nil values.next + end + + def test_should_return_evaluated_single_return_value + values = ReturnValues.new(SingleReturnValue.new('value')) + assert_equal 'value', values.next + end + + def test_should_keep_returning_evaluated_single_return_value + values = ReturnValues.new(SingleReturnValue.new('value')) + values.next + assert_equal 'value', values.next + assert_equal 'value', values.next + end + + def test_should_return_consecutive_evaluated_single_return_values + values = ReturnValues.new(SingleReturnValue.new('value_1'), SingleReturnValue.new('value_2')) + assert_equal 'value_1', values.next + assert_equal 'value_2', values.next + end + + def test_should_keep_returning_last_of_consecutive_evaluated_single_return_values + values = ReturnValues.new(SingleReturnValue.new('value_1'), SingleReturnValue.new('value_2')) + values.next + values.next + assert_equal 'value_2', values.next + assert_equal 'value_2', values.next + end + + def test_should_build_single_return_values_for_each_values + values = ReturnValues.build('value_1', 'value_2', 'value_3').values + assert_equal 'value_1', values[0].evaluate + assert_equal 'value_2', values[1].evaluate + assert_equal 'value_3', values[2].evaluate + end + + def test_should_combine_two_sets_of_return_values + values_1 = ReturnValues.build('value_1') + values_2 = ReturnValues.build('value_2a', 'value_2b') + values = (values_1 + values_2).values + assert_equal 'value_1', values[0].evaluate + assert_equal 'value_2a', values[1].evaluate + assert_equal 'value_2b', values[2].evaluate + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/test/unit/sequence_test.rb b/vendor/gems/mocha-0.9.1/test/unit/sequence_test.rb new file mode 100644 index 0000000..544b3fe --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/unit/sequence_test.rb @@ -0,0 +1,104 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") +require 'mocha/sequence' +require 'mocha/expectation' + +class SequenceTest < Test::Unit::TestCase + + include Mocha + + class FakeExpectation + + attr_reader :ordering_constraints + + def initialize(satisfied = false) + @satisfied = satisfied + @ordering_constraints = [] + end + + def add_ordering_constraint(ordering_constraint) + @ordering_constraints << ordering_constraint + end + + def satisfied? + @satisfied + end + + end + + def test_should_be_satisfied_if_no_expectations_added + sequence = Sequence.new('name') + assert sequence.satisfied_to_index?(0) + end + + def test_should_be_satisfied_if_one_unsatisfied_expectations_added_but_it_is_not_included_by_index + sequence = Sequence.new('name') + expectation = FakeExpectation.new(satisfied = false) + sequence.constrain_as_next_in_sequence(expectation) + assert sequence.satisfied_to_index?(0) + end + + def test_should_not_be_satisfied_if_one_unsatisfied_expectations_added_and_it_is_included_by_index + sequence = Sequence.new('name') + expectation = FakeExpectation.new(satisfied = false) + sequence.constrain_as_next_in_sequence(expectation) + assert !sequence.satisfied_to_index?(1) + end + + def test_should_be_satisfied_if_one_satisfied_expectations_added_and_it_is_included_by_index + sequence = Sequence.new('name') + expectation = FakeExpectation.new(satisfied = true) + sequence.constrain_as_next_in_sequence(expectation) + assert sequence.satisfied_to_index?(1) + end + + def test_should_not_be_satisfied_if_one_satisfied_and_one_unsatisfied_expectation_added_and_both_are_included_by_index + sequence = Sequence.new('name') + expectation_one = FakeExpectation.new(satisfied = true) + expectation_two = FakeExpectation.new(satisfied = false) + sequence.constrain_as_next_in_sequence(expectation_one) + sequence.constrain_as_next_in_sequence(expectation_two) + assert !sequence.satisfied_to_index?(2) + end + + def test_should_be_satisfied_if_two_satisfied_expectations_added_and_both_are_included_by_index + sequence = Sequence.new('name') + expectation_one = FakeExpectation.new(satisfied = true) + expectation_two = FakeExpectation.new(satisfied = true) + sequence.constrain_as_next_in_sequence(expectation_one) + sequence.constrain_as_next_in_sequence(expectation_two) + assert sequence.satisfied_to_index?(2) + end + + def test_should_add_ordering_constraint_to_expectation + sequence = Sequence.new('name') + expectation = FakeExpectation.new + sequence.constrain_as_next_in_sequence(expectation) + assert_equal 1, expectation.ordering_constraints.length + end + + def test_should_not_allow_invocation_of_second_method_when_first_n_sequence_has_not_been_invoked + sequence = Sequence.new('name') + expectation_one = FakeExpectation.new(satisfied = false) + expectation_two = FakeExpectation.new(satisfied = false) + sequence.constrain_as_next_in_sequence(expectation_one) + sequence.constrain_as_next_in_sequence(expectation_two) + assert !expectation_two.ordering_constraints[0].allows_invocation_now? + end + + def test_should_allow_invocation_of_second_method_when_first_in_sequence_has_been_invoked + sequence = Sequence.new('name') + expectation_one = FakeExpectation.new(satisfied = true) + expectation_two = FakeExpectation.new(satisfied = false) + sequence.constrain_as_next_in_sequence(expectation_one) + sequence.constrain_as_next_in_sequence(expectation_two) + assert expectation_two.ordering_constraints[0].allows_invocation_now? + end + + def test_should_describe_ordering_constraint_as_being_part_of_named_sequence + sequence = Sequence.new('wibble') + expectation = FakeExpectation.new + sequence.constrain_as_next_in_sequence(expectation) + assert_equal "in sequence 'wibble'", expectation.ordering_constraints[0].mocha_inspect + end + +end \ No newline at end of file diff --git a/vendor/gems/mocha-0.9.1/test/unit/single_return_value_test.rb b/vendor/gems/mocha-0.9.1/test/unit/single_return_value_test.rb new file mode 100644 index 0000000..9a94e09 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/unit/single_return_value_test.rb @@ -0,0 +1,14 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") + +require 'mocha/single_return_value' + +class SingleReturnValueTest < Test::Unit::TestCase + + include Mocha + + def test_should_return_value + value = SingleReturnValue.new('value') + assert_equal 'value', value.evaluate + end + +end diff --git a/vendor/gems/mocha-0.9.1/test/unit/single_yield_test.rb b/vendor/gems/mocha-0.9.1/test/unit/single_yield_test.rb new file mode 100644 index 0000000..12bd0a2 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/unit/single_yield_test.rb @@ -0,0 +1,18 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") + +require 'mocha/single_yield' + +class SingleYieldTest < Test::Unit::TestCase + + include Mocha + + def test_should_provide_parameters_for_single_yield_in_single_invocation + parameter_group = SingleYield.new(1, 2, 3) + parameter_groups = [] + parameter_group.each do |parameters| + parameter_groups << parameters + end + assert_equal [[1, 2, 3]], parameter_groups + end + +end diff --git a/vendor/gems/mocha-0.9.1/test/unit/state_machine_test.rb b/vendor/gems/mocha-0.9.1/test/unit/state_machine_test.rb new file mode 100644 index 0000000..4ccb229 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/unit/state_machine_test.rb @@ -0,0 +1,98 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") + +require 'mocha/state_machine' + +class StateMachineTest < Test::Unit::TestCase + + include Mocha + + def test_should_initially_be_in_no_state + state_machine = StateMachine.new('name') + any_state.each do |state| + assert !state_machine.is(state).active? + assert state_machine.is_not(state).active? + end + end + + def test_should_be_able_to_enter_a_state + state_machine = StateMachine.new('name') + state = 'A' + other_states = any_state.reject { |s| s == state } + + state_machine.is(state).activate + + assert state_machine.is(state).active? + assert !state_machine.is_not(state).active? + other_states.each do |s| + assert !state_machine.is(s).active? + assert state_machine.is_not(s).active? + end + end + + def test_should_be_able_to_change_state + state_machine = StateMachine.new('name') + state = 'B' + other_states = any_state.reject { |s| s == state } + + state_machine.is('A').activate + state_machine.is(state).activate + + assert state_machine.is(state).active? + assert !state_machine.is_not(state).active? + other_states.each do |s| + assert !state_machine.is(s).active? + assert state_machine.is_not(s).active? + end + end + + def test_should_be_put_into_an_initial_state + state_machine = StateMachine.new('name') + initial_state = 'A' + other_states = any_state.reject { |s| s == initial_state } + + state_machine.starts_as(initial_state) + + assert state_machine.is(initial_state).active? + assert !state_machine.is_not(initial_state).active? + other_states.each do |state| + assert !state_machine.is(state).active? + assert state_machine.is_not(state).active? + end + end + + def test_should_be_put_into_a_new_state + next_state = 'B' + + other_states = any_state.reject { |s| s == next_state } + state_machine = StateMachine.new('name').starts_as('A') + + state_machine.become(next_state) + + assert state_machine.is(next_state).active? + assert !state_machine.is_not(next_state).active? + other_states.each do |state| + assert !state_machine.is(state).active? + assert state_machine.is_not(state).active? + end + end + + def test_should_describe_itself_as_name_and_current_state + state_machine = StateMachine.new('state_machine_name') + assert_equal 'state_machine_name has no current state', state_machine.mocha_inspect + inspectable_state = Class.new { define_method(:mocha_inspect) { "'inspectable_state'" } }.new + state_machine.is(inspectable_state).activate + assert_equal "state_machine_name is 'inspectable_state'", state_machine.mocha_inspect + end + + def test_should_have_self_describing_states + state_machine = StateMachine.new('state_machine_name') + inspectable_state = Class.new { define_method(:mocha_inspect) { "'inspectable_state'" } }.new + assert_equal "state_machine_name is 'inspectable_state'", state_machine.is(inspectable_state).mocha_inspect + assert_equal "state_machine_name is not 'inspectable_state'", state_machine.is_not(inspectable_state).mocha_inspect + end + + def any_state + %w(A B C D) + end + +end diff --git a/vendor/gems/mocha-0.9.1/test/unit/string_inspect_test.rb b/vendor/gems/mocha-0.9.1/test/unit/string_inspect_test.rb new file mode 100644 index 0000000..43b9c4e --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/unit/string_inspect_test.rb @@ -0,0 +1,11 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") +require 'mocha/inspect' + +class StringInspectTest < Test::Unit::TestCase + + def test_should_replace_escaped_quotes_with_single_quote + string = "my_string" + assert_equal "'my_string'", string.mocha_inspect + end + +end diff --git a/vendor/gems/mocha-0.9.1/test/unit/yield_parameters_test.rb b/vendor/gems/mocha-0.9.1/test/unit/yield_parameters_test.rb new file mode 100644 index 0000000..4e93f13 --- /dev/null +++ b/vendor/gems/mocha-0.9.1/test/unit/yield_parameters_test.rb @@ -0,0 +1,93 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") + +require 'mocha/yield_parameters' +require 'mocha/no_yields' +require 'mocha/single_yield' +require 'mocha/multiple_yields' + +class YieldParametersTest < Test::Unit::TestCase + + include Mocha + + def test_should_return_null_yield_parameter_group_by_default + yield_parameters = YieldParameters.new + assert yield_parameters.next_invocation.is_a?(NoYields) + end + + def test_should_return_single_yield_parameter_group + yield_parameters = YieldParameters.new + yield_parameters.add(1, 2, 3) + parameter_group = yield_parameters.next_invocation + assert parameter_group.is_a?(SingleYield) + assert_equal [1, 2, 3], parameter_group.parameters + end + + def test_should_keep_returning_single_yield_parameter_group + yield_parameters = YieldParameters.new + yield_parameters.add(1, 2, 3) + yield_parameters.next_invocation + parameter_group = yield_parameters.next_invocation + assert parameter_group.is_a?(SingleYield) + assert_equal [1, 2, 3], parameter_group.parameters + parameter_group = yield_parameters.next_invocation + assert parameter_group.is_a?(SingleYield) + assert_equal [1, 2, 3], parameter_group.parameters + end + + def test_should_return_consecutive_single_yield_parameter_groups + yield_parameters = YieldParameters.new + yield_parameters.add(1, 2, 3) + yield_parameters.add(4, 5) + parameter_group = yield_parameters.next_invocation + assert parameter_group.is_a?(SingleYield) + assert_equal [1, 2, 3], parameter_group.parameters + parameter_group = yield_parameters.next_invocation + assert parameter_group.is_a?(SingleYield) + assert_equal [4, 5], parameter_group.parameters + end + + def test_should_return_multiple_yield_parameter_group + yield_parameters = YieldParameters.new + yield_parameters.multiple_add([1, 2, 3], [4, 5]) + parameter_group = yield_parameters.next_invocation + assert parameter_group.is_a?(MultipleYields) + assert_equal [[1, 2, 3], [4, 5]], parameter_group.parameter_groups + end + + def test_should_keep_returning_multiple_yield_parameter_group + yield_parameters = YieldParameters.new + yield_parameters.multiple_add([1, 2, 3], [4, 5]) + yield_parameters.next_invocation + parameter_group = yield_parameters.next_invocation + assert parameter_group.is_a?(MultipleYields) + assert_equal [[1, 2, 3], [4, 5]], parameter_group.parameter_groups + parameter_group = yield_parameters.next_invocation + assert parameter_group.is_a?(MultipleYields) + assert_equal [[1, 2, 3], [4, 5]], parameter_group.parameter_groups + end + + def test_should_return_consecutive_multiple_yield_parameter_groups + yield_parameters = YieldParameters.new + yield_parameters.multiple_add([1, 2, 3], [4, 5]) + yield_parameters.multiple_add([6, 7], [8, 9, 0]) + parameter_group = yield_parameters.next_invocation + assert parameter_group.is_a?(MultipleYields) + assert_equal [[1, 2, 3], [4, 5]], parameter_group.parameter_groups + parameter_group = yield_parameters.next_invocation + assert parameter_group.is_a?(MultipleYields) + assert_equal [[6, 7], [8, 9, 0]], parameter_group.parameter_groups + end + + def test_should_return_consecutive_single_and_multiple_yield_parameter_groups + yield_parameters = YieldParameters.new + yield_parameters.add(1, 2, 3) + yield_parameters.multiple_add([4, 5, 6], [7, 8]) + parameter_group = yield_parameters.next_invocation + assert parameter_group.is_a?(SingleYield) + assert_equal [1, 2, 3], parameter_group.parameters + parameter_group = yield_parameters.next_invocation + assert parameter_group.is_a?(MultipleYields) + assert_equal [[4, 5, 6], [7, 8]], parameter_group.parameter_groups + end + +end \ No newline at end of file