├── README ├── vendor └── gems │ ├── dust-0.1.6 │ ├── test │ │ ├── all_tests.rb │ │ ├── test_helper.rb │ │ ├── passing_with_setup_unit_test.rb │ │ ├── passing_with_helper_unit_test.rb │ │ ├── passing_unit_test.rb │ │ ├── functional_test.rb │ │ ├── passing_with_helpers_unit_test.rb │ │ ├── failing_with_setup_unit_test.rb │ │ └── failing_with_helper_unit_test.rb │ ├── lib │ │ ├── array_extension.rb │ │ ├── nil_extension.rb │ │ ├── symbol_extension.rb │ │ ├── string_extension.rb │ │ ├── dust.rb │ │ ├── definition_error.rb │ │ ├── object_extension.rb │ │ └── test_case_extension.rb │ ├── README │ └── rakefile.rb │ └── mocha-0.9.1 │ ├── lib │ ├── mocha_standalone.rb │ ├── mocha │ │ ├── metaclass.rb │ │ ├── is_a.rb │ │ ├── no_yields.rb │ │ ├── parameter_matchers │ │ │ ├── object.rb │ │ │ ├── base.rb │ │ │ ├── anything.rb │ │ │ ├── any_parameters.rb │ │ │ ├── includes.rb │ │ │ ├── equals.rb │ │ │ ├── is_a.rb │ │ │ ├── kind_of.rb │ │ │ ├── not.rb │ │ │ ├── instance_of.rb │ │ │ ├── has_key.rb │ │ │ ├── has_value.rb │ │ │ ├── regexp_matches.rb │ │ │ ├── yaml_equivalent.rb │ │ │ ├── all_of.rb │ │ │ ├── any_of.rb │ │ │ ├── responds_with.rb │ │ │ ├── has_entries.rb │ │ │ ├── optionally.rb │ │ │ └── has_entry.rb │ │ ├── logger.rb │ │ ├── single_return_value.rb │ │ ├── single_yield.rb │ │ ├── change_state_side_effect.rb │ │ ├── expectation_error.rb │ │ ├── in_state_ordering_constraint.rb │ │ ├── module_method.rb │ │ ├── multiple_yields.rb │ │ ├── instance_method.rb │ │ ├── stubbing_error.rb │ │ ├── backtrace_filter.rb │ │ ├── method_matcher.rb │ │ ├── exception_raiser.rb │ │ ├── deprecation.rb │ │ ├── central.rb │ │ ├── unexpected_invocation.rb │ │ ├── pretty_parameters.rb │ │ ├── return_values.rb │ │ ├── yield_parameters.rb │ │ ├── inspect.rb │ │ ├── names.rb │ │ ├── sequence.rb │ │ ├── parameter_matchers.rb │ │ ├── parameters_matcher.rb │ │ ├── expectation_list.rb │ │ ├── any_instance_method.rb │ │ ├── configuration.rb │ │ ├── state_machine.rb │ │ ├── cardinality.rb │ │ ├── class_method.rb │ │ ├── test_case_adapter.rb │ │ └── object.rb │ ├── stubba.rb │ └── mocha.rb │ ├── test │ ├── simple_counter.rb │ ├── deprecation_disabler.rb │ ├── unit │ │ ├── string_inspect_test.rb │ │ ├── single_return_value_test.rb │ │ ├── array_inspect_test.rb │ │ ├── hash_inspect_test.rb │ │ ├── parameter_matchers │ │ │ ├── stub_matcher.rb │ │ │ ├── anything_test.rb │ │ │ ├── equals_test.rb │ │ │ ├── is_a_test.rb │ │ │ ├── includes_test.rb │ │ │ ├── kind_of_test.rb │ │ │ ├── instance_of_test.rb │ │ │ ├── regexp_matches_test.rb │ │ │ ├── not_test.rb │ │ │ ├── responds_with_test.rb │ │ │ ├── yaml_equivalent_test.rb │ │ │ ├── all_of_test.rb │ │ │ ├── any_of_test.rb │ │ │ ├── has_key_test.rb │ │ │ ├── has_value_test.rb │ │ │ ├── has_entries_test.rb │ │ │ └── has_entry_test.rb │ │ ├── no_yields_test.rb │ │ ├── single_yield_test.rb │ │ ├── multiple_yields_test.rb │ │ ├── date_time_inspect_test.rb │ │ ├── metaclass_test.rb │ │ ├── backtrace_filter_test.rb │ │ ├── method_matcher_test.rb │ │ ├── change_state_side_effect_test.rb │ │ ├── in_state_ordering_constraint_test.rb │ │ ├── object_inspect_test.rb │ │ ├── exception_raiser_test.rb │ │ ├── central_test.rb │ │ ├── return_values_test.rb │ │ ├── cardinality_test.rb │ │ ├── object_test.rb │ │ ├── expectation_list_test.rb │ │ ├── state_machine_test.rb │ │ ├── yield_parameters_test.rb │ │ └── sequence_test.rb │ ├── acceptance │ │ ├── stubba_test.rb │ │ ├── bug_21563_test.rb │ │ ├── bug_21465_test.rb │ │ ├── acceptance_test_helper.rb │ │ ├── bug_18914_test.rb │ │ ├── stub_test.rb │ │ ├── partial_mocks_test.rb │ │ ├── mock_with_initializer_block_test.rb │ │ ├── stub_everything_test.rb │ │ ├── return_value_test.rb │ │ ├── states_test.rb │ │ ├── stubba_test_result_test.rb │ │ ├── failure_messages_test.rb │ │ ├── optional_parameters_test.rb │ │ ├── stubbing_method_unnecessarily_test.rb │ │ ├── mocked_methods_dispatch_test.rb │ │ ├── stubbing_on_non_mock_object_test.rb │ │ ├── stubbing_error_backtrace_test.rb │ │ ├── mocha_test_result_test.rb │ │ ├── stubba_example_test.rb │ │ ├── mock_test.rb │ │ ├── mocha_example_test.rb │ │ └── standalone_test.rb │ ├── test_helper.rb │ ├── method_definer.rb │ ├── execution_point.rb │ ├── active_record_test_case.rb │ └── test_runner.rb │ ├── COPYING │ ├── examples │ ├── mocha.rb │ ├── misc.rb │ └── stubba.rb │ ├── MIT-LICENSE │ └── README ├── ext └── system_timer │ └── extconf.rb ├── test ├── all_tests.rb ├── test_helper.rb ├── system_timer │ └── thread_timer_test.rb └── system_timer_unit_test.rb ├── .gitignore ├── experiments ├── Rakefile └── setitimer_process_isolation.c ├── lib ├── system_timer_stub.rb ├── system_timer │ ├── thread_timer.rb │ └── concurrent_timer_pool.rb └── system_timer.rb ├── ChangeLog ├── LICENSE └── Rakefile /README: -------------------------------------------------------------------------------- 1 | README.markdown -------------------------------------------------------------------------------- /vendor/gems/dust-0.1.6/test/all_tests.rb: -------------------------------------------------------------------------------- 1 | Dir['**/*_test.rb'].each { |test_case| require test_case } -------------------------------------------------------------------------------- /vendor/gems/dust-0.1.6/test/test_helper.rb: -------------------------------------------------------------------------------- 1 | require File.dirname(__FILE__) + '/../lib/dust' 2 | -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/lib/mocha_standalone.rb: -------------------------------------------------------------------------------- 1 | require 'mocha/standalone' 2 | require 'mocha/object' 3 | -------------------------------------------------------------------------------- /ext/system_timer/extconf.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require 'mkmf' 3 | create_makefile("system_timer_native") 4 | -------------------------------------------------------------------------------- /vendor/gems/dust-0.1.6/lib/array_extension.rb: -------------------------------------------------------------------------------- 1 | class Array #:nodoc: 2 | def arrayize 3 | self 4 | end 5 | end -------------------------------------------------------------------------------- /vendor/gems/dust-0.1.6/lib/nil_extension.rb: -------------------------------------------------------------------------------- 1 | class NilClass #:nodoc: 2 | def arrayize 3 | [] 4 | end 5 | end -------------------------------------------------------------------------------- /test/all_tests.rb: -------------------------------------------------------------------------------- 1 | Dir["#{File.dirname __FILE__}/**/*_test.rb"].each do |test_case| 2 | require test_case 3 | end 4 | -------------------------------------------------------------------------------- /vendor/gems/dust-0.1.6/lib/symbol_extension.rb: -------------------------------------------------------------------------------- 1 | class Symbol #:nodoc: 2 | def arrayize 3 | [self] 4 | end 5 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/lib/mocha/metaclass.rb: -------------------------------------------------------------------------------- 1 | class Object 2 | 3 | def __metaclass__ 4 | class << self; self; end 5 | end 6 | 7 | end -------------------------------------------------------------------------------- /vendor/gems/dust-0.1.6/lib/string_extension.rb: -------------------------------------------------------------------------------- 1 | class String #:nodoc: 2 | def to_class_name 3 | gsub(/(^|_)(.)/) { $2.upcase } 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/lib/mocha/is_a.rb: -------------------------------------------------------------------------------- 1 | class Object 2 | 3 | # :stopdoc: 4 | 5 | alias_method :__is_a__, :is_a? 6 | 7 | # :startdoc: 8 | 9 | end 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ext/system_timer/Makefile 2 | ext/system_timer/system_timer_native.bundle 3 | ext/system_timer/system_timer_native.o 4 | ext/system_timer/system_timer_native.so 5 | rdoc 6 | pkg 7 | -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/lib/mocha/no_yields.rb: -------------------------------------------------------------------------------- 1 | module Mocha # :nodoc: 2 | 3 | class NoYields # :nodoc: 4 | 5 | def each 6 | end 7 | 8 | end 9 | 10 | end 11 | 12 | -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/lib/stubba.rb: -------------------------------------------------------------------------------- 1 | # for backwards compatibility 2 | require 'mocha' 3 | require 'mocha/deprecation' 4 | Mocha::Deprecation.warning "require 'stubba' is no longer needed and stubba.rb will soon be removed" 5 | -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/simple_counter.rb: -------------------------------------------------------------------------------- 1 | class SimpleCounter 2 | 3 | attr_reader :count 4 | 5 | def initialize 6 | @count = 0 7 | end 8 | 9 | def increment 10 | @count += 1 11 | end 12 | 13 | end -------------------------------------------------------------------------------- /experiments/Rakefile: -------------------------------------------------------------------------------- 1 | require 'rake/clean' 2 | 3 | PROG = "setitimer_process_isolation" 4 | 5 | CLEAN.include(PROG) 6 | 7 | task :default => PROG 8 | 9 | file PROG => "#{PROG}.c" do 10 | sh "gcc -o #{PROG} #{PROG}.c" 11 | end 12 | 13 | 14 | -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/COPYING: -------------------------------------------------------------------------------- 1 | Copyright Revieworld Ltd. 2006 2 | 3 | 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). 4 | -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/object.rb: -------------------------------------------------------------------------------- 1 | require 'mocha/parameter_matchers/equals' 2 | 3 | class Object 4 | 5 | def to_matcher # :nodoc: 6 | Mocha::ParameterMatchers::Equals.new(self) 7 | end 8 | 9 | end 10 | -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/lib/mocha/logger.rb: -------------------------------------------------------------------------------- 1 | module Mocha 2 | 3 | class Logger 4 | 5 | def initialize(io) 6 | @io = io 7 | end 8 | 9 | def warn(message) 10 | @io.puts "WARNING: #{message}" 11 | end 12 | 13 | end 14 | 15 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/base.rb: -------------------------------------------------------------------------------- 1 | module Mocha 2 | 3 | module ParameterMatchers 4 | 5 | class Base # :nodoc: 6 | 7 | def to_matcher 8 | self 9 | end 10 | 11 | end 12 | 13 | end 14 | 15 | end 16 | -------------------------------------------------------------------------------- /vendor/gems/dust-0.1.6/test/passing_with_setup_unit_test.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path(File.dirname(__FILE__) + "/test_helper") 2 | 3 | Test::Unit::TestCase.disallow_setup! 4 | unit_tests :allow => :setup do 5 | def setup 6 | end 7 | 8 | test("true"){} 9 | end 10 | Test::Unit::TestCase.class_eval { @disallow_setup = nil } -------------------------------------------------------------------------------- /vendor/gems/dust-0.1.6/test/passing_with_helper_unit_test.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path(File.dirname(__FILE__) + "/test_helper") 2 | 3 | Test::Unit::TestCase.disallow_helpers! 4 | unit_tests :allow => :helper do 5 | def helper 6 | end 7 | 8 | test("true"){} 9 | end 10 | Test::Unit::TestCase.class_eval { @disallow_helpers = nil } -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/lib/mocha/single_return_value.rb: -------------------------------------------------------------------------------- 1 | require 'mocha/is_a' 2 | 3 | module Mocha # :nodoc: 4 | 5 | class SingleReturnValue # :nodoc: 6 | 7 | def initialize(value) 8 | @value = value 9 | end 10 | 11 | def evaluate 12 | @value 13 | end 14 | 15 | end 16 | 17 | end 18 | -------------------------------------------------------------------------------- /vendor/gems/dust-0.1.6/test/passing_unit_test.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path(File.dirname(__FILE__) + "/test_helper") 2 | 3 | unit_tests do 4 | test "assert true" do 5 | assert_equal true, true 6 | end 7 | 8 | test "class name is Units::PassingUnitTest" do 9 | assert_equal "Units::PassingUnitTest", self.class.name 10 | end 11 | end -------------------------------------------------------------------------------- /vendor/gems/dust-0.1.6/test/functional_test.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path(File.dirname(__FILE__) + "/test_helper") 2 | 3 | functional_tests do 4 | test "assert true" do 5 | assert_equal true, true 6 | end 7 | 8 | test "class name is Functionals::FunctionalTest" do 9 | assert_equal "Functionals::FunctionalTest", self.class.name 10 | end 11 | 12 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/lib/mocha/single_yield.rb: -------------------------------------------------------------------------------- 1 | module Mocha # :nodoc: 2 | 3 | class SingleYield # :nodoc: 4 | 5 | attr_reader :parameters 6 | 7 | def initialize(*parameters) 8 | @parameters = parameters 9 | end 10 | 11 | def each 12 | yield(@parameters) 13 | end 14 | 15 | end 16 | 17 | end 18 | 19 | -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/lib/mocha/change_state_side_effect.rb: -------------------------------------------------------------------------------- 1 | module Mocha 2 | 3 | class ChangeStateSideEffect 4 | 5 | def initialize(state) 6 | @state = state 7 | end 8 | 9 | def perform 10 | @state.activate 11 | end 12 | 13 | def mocha_inspect 14 | "then #{@state.mocha_inspect}" 15 | end 16 | 17 | end 18 | 19 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/deprecation_disabler.rb: -------------------------------------------------------------------------------- 1 | require 'mocha/deprecation' 2 | 3 | module DeprecationDisabler 4 | 5 | def disable_deprecations 6 | original_mode = Mocha::Deprecation.mode 7 | Mocha::Deprecation.mode = :disabled 8 | begin 9 | yield 10 | ensure 11 | Mocha::Deprecation.mode = original_mode 12 | end 13 | end 14 | 15 | end -------------------------------------------------------------------------------- /vendor/gems/dust-0.1.6/test/passing_with_helpers_unit_test.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path(File.dirname(__FILE__) + "/test_helper") 2 | 3 | Test::Unit::TestCase.disallow_helpers! 4 | unit_tests :allow => [:helper, :helper2] do 5 | def helper 6 | end 7 | 8 | def helper2 9 | end 10 | 11 | test("true"){} 12 | end 13 | Test::Unit::TestCase.class_eval { @disallow_helpers = nil } -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/lib/mocha.rb: -------------------------------------------------------------------------------- 1 | require 'mocha_standalone' 2 | require 'mocha/test_case_adapter' 3 | require 'mocha/configuration' 4 | 5 | require 'test/unit/testcase' 6 | 7 | module Test 8 | 9 | module Unit 10 | 11 | class TestCase 12 | 13 | include Mocha::Standalone 14 | include Mocha::TestCaseAdapter 15 | 16 | end 17 | 18 | end 19 | 20 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/lib/mocha/expectation_error.rb: -------------------------------------------------------------------------------- 1 | require 'mocha/backtrace_filter' 2 | 3 | module Mocha 4 | 5 | class ExpectationError < StandardError 6 | 7 | def initialize(message = nil, backtrace = []) 8 | super(message) 9 | filter = BacktraceFilter.new 10 | set_backtrace(filter.filtered(backtrace)) 11 | end 12 | 13 | end 14 | 15 | end 16 | -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/unit/string_inspect_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "..", "test_helper") 2 | require 'mocha/inspect' 3 | 4 | class StringInspectTest < Test::Unit::TestCase 5 | 6 | def test_should_replace_escaped_quotes_with_single_quote 7 | string = "my_string" 8 | assert_equal "'my_string'", string.mocha_inspect 9 | end 10 | 11 | end 12 | -------------------------------------------------------------------------------- /lib/system_timer_stub.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2008 David Vollbracht & Philippe Hanrigou 2 | 3 | require 'timeout' 4 | 5 | module SystemTimer 6 | class << self 7 | 8 | def timeout_after(seconds) 9 | Timeout::timeout(seconds) do 10 | yield 11 | end 12 | end 13 | 14 | # Backward compatibility with timeout.rb 15 | alias timeout timeout_after 16 | 17 | end 18 | 19 | end 20 | -------------------------------------------------------------------------------- /test/test_helper.rb: -------------------------------------------------------------------------------- 1 | $:.unshift File.dirname(__FILE__) + '/../lib' 2 | $:.unshift File.dirname(__FILE__) + '/../ext/system_timer' 3 | $: << File.dirname(__FILE__) + "/../vendor/gems/dust-0.1.6/lib" 4 | $: << File.dirname(__FILE__) + "/../vendor/gems/mocha-0.9.1/lib" 5 | require 'test/unit' 6 | require 'dust' 7 | require 'mocha' 8 | require 'stringio' 9 | require "open-uri" 10 | require 'system_timer' 11 | -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/unit/single_return_value_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "..", "test_helper") 2 | 3 | require 'mocha/single_return_value' 4 | 5 | class SingleReturnValueTest < Test::Unit::TestCase 6 | 7 | include Mocha 8 | 9 | def test_should_return_value 10 | value = SingleReturnValue.new('value') 11 | assert_equal 'value', value.evaluate 12 | end 13 | 14 | end 15 | -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/lib/mocha/in_state_ordering_constraint.rb: -------------------------------------------------------------------------------- 1 | module Mocha 2 | 3 | class InStateOrderingConstraint 4 | 5 | def initialize(state_predicate) 6 | @state_predicate = state_predicate 7 | end 8 | 9 | def allows_invocation_now? 10 | @state_predicate.active? 11 | end 12 | 13 | def mocha_inspect 14 | "when #{@state_predicate.mocha_inspect}" 15 | end 16 | 17 | end 18 | 19 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/lib/mocha/module_method.rb: -------------------------------------------------------------------------------- 1 | require 'mocha/module_method' 2 | 3 | module Mocha 4 | 5 | class ModuleMethod < ClassMethod 6 | 7 | def method_exists?(method) 8 | return true if stubbee.public_methods(false).include?(method) 9 | return true if stubbee.protected_methods(false).include?(method) 10 | return true if stubbee.private_methods(false).include?(method) 11 | return false 12 | end 13 | 14 | end 15 | 16 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/lib/mocha/multiple_yields.rb: -------------------------------------------------------------------------------- 1 | module Mocha # :nodoc: 2 | 3 | class MultipleYields # :nodoc: 4 | 5 | attr_reader :parameter_groups 6 | 7 | def initialize(*parameter_groups) 8 | @parameter_groups = parameter_groups 9 | end 10 | 11 | def each 12 | @parameter_groups.each do |parameter_group| 13 | yield(parameter_group) 14 | end 15 | end 16 | 17 | end 18 | 19 | end 20 | 21 | -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/lib/mocha/instance_method.rb: -------------------------------------------------------------------------------- 1 | require 'mocha/class_method' 2 | 3 | module Mocha 4 | 5 | class InstanceMethod < ClassMethod 6 | 7 | def method_exists?(method) 8 | return true if stubbee.public_methods(false).include?(method) 9 | return true if stubbee.protected_methods(false).include?(method) 10 | return true if stubbee.private_methods(false).include?(method) 11 | return false 12 | end 13 | 14 | end 15 | 16 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/lib/mocha/stubbing_error.rb: -------------------------------------------------------------------------------- 1 | require 'mocha/backtrace_filter' 2 | 3 | module Mocha # :nodoc: 4 | 5 | # Exception raised when an action prevented by Configuration#prevent is attempted. 6 | class StubbingError < StandardError 7 | 8 | def initialize(message = nil, backtrace = []) # :nodoc: 9 | super(message) 10 | filter = BacktraceFilter.new 11 | set_backtrace(filter.filtered(backtrace)) 12 | end 13 | 14 | end 15 | 16 | end 17 | -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/lib/mocha/backtrace_filter.rb: -------------------------------------------------------------------------------- 1 | module Mocha 2 | 3 | class BacktraceFilter 4 | 5 | LIB_DIRECTORY = File.expand_path(File.join(File.dirname(__FILE__), "..")) + File::SEPARATOR 6 | 7 | def initialize(lib_directory = LIB_DIRECTORY) 8 | @lib_directory = lib_directory 9 | end 10 | 11 | def filtered(backtrace) 12 | backtrace.reject { |location| Regexp.new(@lib_directory).match(File.expand_path(location)) } 13 | end 14 | 15 | end 16 | 17 | end 18 | -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/lib/mocha/method_matcher.rb: -------------------------------------------------------------------------------- 1 | module Mocha 2 | 3 | class MethodMatcher 4 | 5 | attr_reader :expected_method_name 6 | 7 | def initialize(expected_method_name) 8 | @expected_method_name = expected_method_name 9 | end 10 | 11 | def match?(actual_method_name) 12 | @expected_method_name == actual_method_name 13 | end 14 | 15 | def mocha_inspect 16 | "#{@expected_method_name}" 17 | end 18 | 19 | end 20 | 21 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/lib/mocha/exception_raiser.rb: -------------------------------------------------------------------------------- 1 | module Mocha # :nodoc: 2 | 3 | class ExceptionRaiser # :nodoc: 4 | 5 | def initialize(exception, message) 6 | @exception, @message = exception, message 7 | end 8 | 9 | def evaluate 10 | raise @exception, @exception.to_s if @exception.is_a?(Module) && @exception.ancestors.include?(Interrupt) 11 | raise @exception, @message if @message 12 | raise @exception 13 | end 14 | 15 | end 16 | 17 | end 18 | -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/unit/array_inspect_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "..", "test_helper") 2 | require 'mocha/inspect' 3 | 4 | class ArrayInspectTest < Test::Unit::TestCase 5 | 6 | def test_should_use_inspect 7 | array = [1, 2] 8 | assert_equal array.inspect, array.mocha_inspect 9 | end 10 | 11 | def test_should_use_mocha_inspect_on_each_item 12 | array = [1, 2, "chris"] 13 | assert_equal "[1, 2, 'chris']", array.mocha_inspect 14 | end 15 | 16 | end 17 | -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/unit/hash_inspect_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "..", "test_helper") 2 | require 'mocha/inspect' 3 | 4 | class HashInspectTest < Test::Unit::TestCase 5 | 6 | def test_should_keep_spacing_between_key_value 7 | hash = {:a => true} 8 | assert_equal '{:a => true}', hash.mocha_inspect 9 | end 10 | 11 | def test_should_use_mocha_inspect_on_each_item 12 | hash = {:a => 'mocha'} 13 | assert_equal "{:a => 'mocha'}", hash.mocha_inspect 14 | end 15 | 16 | end -------------------------------------------------------------------------------- /vendor/gems/dust-0.1.6/test/failing_with_setup_unit_test.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path(File.dirname(__FILE__) + "/test_helper") 2 | 3 | begin 4 | unit_tests do 5 | Test::Unit::TestCase.disallow_setup! 6 | def setup 7 | end 8 | 9 | test("true"){} 10 | end 11 | raise "shouldn't be here" 12 | rescue Dust::DefinitionError => ex 13 | raise unless ex.message == "setup is not allowed on class Units::FailingWithSetupUnitTest" 14 | ensure 15 | Test::Unit::TestCase.class_eval { @disallow_setup = nil } 16 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/lib/mocha/deprecation.rb: -------------------------------------------------------------------------------- 1 | module Mocha 2 | 3 | class Deprecation 4 | 5 | class << self 6 | 7 | attr_accessor :mode, :messages 8 | 9 | def warning(message) 10 | @messages << message 11 | $stderr.puts "Mocha deprecation warning: #{message}" unless mode == :disabled 12 | $stderr.puts caller.join("\n ") if mode == :debug 13 | end 14 | 15 | end 16 | 17 | self.mode = :enabled 18 | self.messages = [] 19 | 20 | end 21 | 22 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/stub_matcher.rb: -------------------------------------------------------------------------------- 1 | module Stub 2 | 3 | class Matcher 4 | 5 | attr_accessor :value 6 | 7 | def initialize(matches) 8 | @matches = matches 9 | end 10 | 11 | def matches?(available_parameters) 12 | value = available_parameters.shift 13 | @value = value 14 | @matches 15 | end 16 | 17 | def mocha_inspect 18 | "matcher(#{@matches})" 19 | end 20 | 21 | def to_matcher 22 | self 23 | end 24 | 25 | end 26 | 27 | end -------------------------------------------------------------------------------- /vendor/gems/dust-0.1.6/test/failing_with_helper_unit_test.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path(File.dirname(__FILE__) + "/test_helper") 2 | 3 | begin 4 | unit_tests do 5 | Test::Unit::TestCase.disallow_helpers! 6 | def helper_method 7 | end 8 | 9 | test("true"){} 10 | end 11 | raise "shouldn't be here" 12 | rescue Dust::DefinitionError => ex 13 | raise unless ex.message == "helper methods are not allowed on class Units::FailingWithHelperUnitTest" 14 | ensure 15 | Test::Unit::TestCase.class_eval { @disallow_helpers = nil } 16 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/unit/no_yields_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "..", "test_helper") 2 | 3 | require 'mocha/no_yields' 4 | 5 | class NoYieldsTest < Test::Unit::TestCase 6 | 7 | include Mocha 8 | 9 | def test_should_provide_parameters_for_no_yields_in_single_invocation 10 | parameter_group = NoYields.new 11 | parameter_groups = [] 12 | parameter_group.each do |parameters| 13 | parameter_groups << parameters 14 | end 15 | assert_equal [], parameter_groups 16 | end 17 | 18 | end 19 | -------------------------------------------------------------------------------- /vendor/gems/dust-0.1.6/lib/dust.rb: -------------------------------------------------------------------------------- 1 | require 'test/unit' 2 | require File.expand_path(File.dirname(__FILE__) + '/object_extension') 3 | require File.expand_path(File.dirname(__FILE__) + '/array_extension') 4 | require File.expand_path(File.dirname(__FILE__) + '/nil_extension') 5 | require File.expand_path(File.dirname(__FILE__) + '/string_extension') 6 | require File.expand_path(File.dirname(__FILE__) + '/symbol_extension') 7 | require File.expand_path(File.dirname(__FILE__) + '/test_case_extension') 8 | require File.expand_path(File.dirname(__FILE__) + '/definition_error') -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/acceptance/stubba_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "..", "test_helper") 2 | require 'deprecation_disabler' 3 | 4 | class StubbaTest < Test::Unit::TestCase 5 | 6 | include DeprecationDisabler 7 | 8 | def test_should_report_deprecation_of_stubba_which_will_be_removed_in_a_future_release 9 | disable_deprecations do 10 | load 'stubba.rb' 11 | end 12 | assert_equal ["require 'stubba' is no longer needed and stubba.rb will soon be removed"], Mocha::Deprecation.messages 13 | end 14 | 15 | end 16 | -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/unit/single_yield_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "..", "test_helper") 2 | 3 | require 'mocha/single_yield' 4 | 5 | class SingleYieldTest < Test::Unit::TestCase 6 | 7 | include Mocha 8 | 9 | def test_should_provide_parameters_for_single_yield_in_single_invocation 10 | parameter_group = SingleYield.new(1, 2, 3) 11 | parameter_groups = [] 12 | parameter_group.each do |parameters| 13 | parameter_groups << parameters 14 | end 15 | assert_equal [[1, 2, 3]], parameter_groups 16 | end 17 | 18 | end 19 | -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/lib/mocha/central.rb: -------------------------------------------------------------------------------- 1 | module Mocha 2 | 3 | class Central 4 | 5 | attr_accessor :stubba_methods 6 | 7 | def initialize 8 | self.stubba_methods = [] 9 | end 10 | 11 | def stub(method) 12 | unless stubba_methods.include?(method) 13 | method.stub 14 | stubba_methods.push(method) 15 | end 16 | end 17 | 18 | def unstub_all 19 | while stubba_methods.length > 0 20 | method = stubba_methods.pop 21 | method.unstub 22 | end 23 | end 24 | 25 | end 26 | 27 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/lib/mocha/unexpected_invocation.rb: -------------------------------------------------------------------------------- 1 | module Mocha # :nodoc: 2 | 3 | class UnexpectedInvocation 4 | 5 | def initialize(mock, symbol, *arguments) 6 | @mock = mock 7 | @method_matcher = MethodMatcher.new(symbol) 8 | @parameters_matcher = ParametersMatcher.new(arguments) 9 | end 10 | 11 | def to_s 12 | method_signature = "#{@mock.mocha_inspect}.#{@method_matcher.mocha_inspect}#{@parameters_matcher.mocha_inspect}" 13 | "unexpected invocation: #{method_signature}\n" 14 | end 15 | 16 | end 17 | 18 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/test_helper.rb: -------------------------------------------------------------------------------- 1 | unless defined?(STANDARD_OBJECT_PUBLIC_INSTANCE_METHODS) 2 | STANDARD_OBJECT_PUBLIC_INSTANCE_METHODS = Object.public_instance_methods 3 | end 4 | 5 | $:.unshift File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")) 6 | $:.unshift File.expand_path(File.join(File.dirname(__FILE__))) 7 | $:.unshift File.expand_path(File.join(File.dirname(__FILE__), 'unit')) 8 | $:.unshift File.expand_path(File.join(File.dirname(__FILE__), 'unit', 'parameter_matchers')) 9 | $:.unshift File.expand_path(File.join(File.dirname(__FILE__), 'acceptance')) 10 | 11 | require 'test/unit' -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/unit/multiple_yields_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "..", "test_helper") 2 | 3 | require 'mocha/multiple_yields' 4 | 5 | class MultipleYieldsTest < Test::Unit::TestCase 6 | 7 | include Mocha 8 | 9 | def test_should_provide_parameters_for_multiple_yields_in_single_invocation 10 | parameter_group = MultipleYields.new([1, 2, 3], [4, 5]) 11 | parameter_groups = [] 12 | parameter_group.each do |parameters| 13 | parameter_groups << parameters 14 | end 15 | assert_equal [[1, 2, 3], [4, 5]], parameter_groups 16 | end 17 | 18 | end 19 | -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/method_definer.rb: -------------------------------------------------------------------------------- 1 | require 'mocha/metaclass' 2 | 3 | class Object 4 | 5 | def define_instance_method(method_symbol, &block) 6 | __metaclass__.send(:define_method, method_symbol, block) 7 | end 8 | 9 | def replace_instance_method(method_symbol, &block) 10 | raise "Cannot replace #{method_symbol} as #{self} does not respond to it." unless self.respond_to?(method_symbol) 11 | define_instance_method(method_symbol, &block) 12 | end 13 | 14 | def define_instance_accessor(*symbols) 15 | symbols.each { |symbol| __metaclass__.send(:attr_accessor, symbol) } 16 | end 17 | 18 | end -------------------------------------------------------------------------------- /vendor/gems/dust-0.1.6/lib/definition_error.rb: -------------------------------------------------------------------------------- 1 | module Dust #:nodoc: 2 | # Dust::DefinitionError is raised when you attempt to define a disallowed method within a test file. 3 | # 4 | # Test::Unit::TestCase.disallow_setup! 5 | # 6 | # unit_tests do 7 | # def setup 8 | # ... 9 | # end 10 | # 11 | # test "name" do 12 | # ... 13 | # end 14 | # end 15 | # 16 | # The above code will generate the following error 17 | # Dust::DefinitionError: setup is not allowed on class Units::[TestClassName] 18 | class DefinitionError < StandardError 19 | end 20 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/examples/mocha.rb: -------------------------------------------------------------------------------- 1 | class Enterprise 2 | 3 | def initialize(dilithium) 4 | @dilithium = dilithium 5 | end 6 | 7 | def go(warp_factor) 8 | warp_factor.times { @dilithium.nuke(:anti_matter) } 9 | end 10 | 11 | end 12 | 13 | require 'test/unit' 14 | require 'rubygems' 15 | require 'mocha' 16 | 17 | class EnterpriseTest < Test::Unit::TestCase 18 | 19 | def test_should_boldly_go 20 | dilithium = mock() 21 | dilithium.expects(:nuke).with(:anti_matter).at_least_once # auto-verified at end of test 22 | enterprise = Enterprise.new(dilithium) 23 | enterprise.go(2) 24 | end 25 | 26 | end 27 | -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/anything_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "..", "..", "test_helper") 2 | 3 | require 'mocha/parameter_matchers/anything' 4 | require 'mocha/inspect' 5 | 6 | class AnythingTest < Test::Unit::TestCase 7 | 8 | include Mocha::ParameterMatchers 9 | 10 | def test_should_match_anything 11 | matcher = anything 12 | assert matcher.matches?([:something]) 13 | assert matcher.matches?([{'x' => 'y'}]) 14 | end 15 | 16 | def test_should_describe_matcher 17 | matcher = anything 18 | assert_equal "anything", matcher.mocha_inspect 19 | end 20 | 21 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/acceptance/bug_21563_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "acceptance_test_helper") 2 | require 'mocha' 3 | 4 | class Bug21563Test < Test::Unit::TestCase 5 | 6 | include AcceptanceTest 7 | 8 | def setup 9 | setup_acceptance_test 10 | end 11 | 12 | def teardown 13 | teardown_acceptance_test 14 | end 15 | 16 | def test_should_allow_stubbing_of_verified_method 17 | test_result = run_test do 18 | object = Object.new 19 | object.stubs(:verified?).returns(false) 20 | assert !object.verified? 21 | end 22 | assert_passed(test_result) 23 | end 24 | 25 | end 26 | -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/lib/mocha/pretty_parameters.rb: -------------------------------------------------------------------------------- 1 | require 'mocha/inspect' 2 | 3 | module Mocha 4 | 5 | class PrettyParameters 6 | 7 | def initialize(params) 8 | @params = params 9 | @params_string = params.mocha_inspect 10 | end 11 | 12 | def pretty 13 | remove_outer_array_braces! 14 | remove_outer_hash_braces! 15 | @params_string 16 | end 17 | 18 | def remove_outer_array_braces! 19 | @params_string = @params_string.gsub(/^\[|\]$/, '') 20 | end 21 | 22 | def remove_outer_hash_braces! 23 | @params_string = @params_string.gsub(/^\{|\}$/, '') if @params.length == 1 24 | end 25 | 26 | end 27 | 28 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/unit/date_time_inspect_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "..", "test_helper") 2 | require 'mocha/inspect' 3 | 4 | class DateTimeInspectTest < Test::Unit::TestCase 5 | 6 | def test_should_use_include_date_in_seconds 7 | time = Time.now 8 | assert_equal "#{time.inspect} (#{time.to_f} secs)", time.mocha_inspect 9 | end 10 | 11 | def test_should_use_to_s_for_date 12 | date = Date.new(2006, 1, 1) 13 | assert_equal date.to_s, date.mocha_inspect 14 | end 15 | 16 | def test_should_use_to_s_for_datetime 17 | datetime = DateTime.new(2006, 1, 1) 18 | assert_equal datetime.to_s, datetime.mocha_inspect 19 | end 20 | 21 | end 22 | -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/lib/mocha/return_values.rb: -------------------------------------------------------------------------------- 1 | require 'mocha/single_return_value' 2 | 3 | module Mocha # :nodoc: 4 | 5 | class ReturnValues # :nodoc: 6 | 7 | def self.build(*values) 8 | new(*values.map { |value| SingleReturnValue.new(value) }) 9 | end 10 | 11 | attr_accessor :values 12 | 13 | def initialize(*values) 14 | @values = values 15 | end 16 | 17 | def next 18 | case @values.length 19 | when 0 then nil 20 | when 1 then @values.first.evaluate 21 | else @values.shift.evaluate 22 | end 23 | end 24 | 25 | def +(other) 26 | self.class.new(*(@values + other.values)) 27 | end 28 | 29 | end 30 | 31 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/equals_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "..", "..", "test_helper") 2 | 3 | require 'mocha/parameter_matchers/equals' 4 | require 'mocha/inspect' 5 | 6 | class EqualsTest < Test::Unit::TestCase 7 | 8 | include Mocha::ParameterMatchers 9 | 10 | def test_should_match_object_that_equals_value 11 | matcher = equals('x') 12 | assert matcher.matches?(['x']) 13 | end 14 | 15 | def test_should_not_match_object_that_does_not_equal_value 16 | matcher = equals('x') 17 | assert !matcher.matches?(['y']) 18 | end 19 | 20 | def test_should_describe_matcher 21 | matcher = equals('x') 22 | assert_equal "'x'", matcher.mocha_inspect 23 | end 24 | 25 | end 26 | -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/unit/metaclass_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "..", "test_helper") 2 | require 'mocha/metaclass' 3 | 4 | class MetaclassTest < Test::Unit::TestCase 5 | 6 | def test_should_return_objects_singleton_class 7 | object = Object.new 8 | assert_raises(NoMethodError) { object.success? } 9 | 10 | object = Object.new 11 | assert object.__metaclass__.ancestors.include?(Object) 12 | assert object.__metaclass__.ancestors.include?(Kernel) 13 | assert object.__metaclass__.is_a?(Class) 14 | 15 | object.__metaclass__.class_eval { def success?; true; end } 16 | assert object.success? 17 | 18 | object = Object.new 19 | assert_raises(NoMethodError) { object.success? } 20 | end 21 | 22 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/unit/backtrace_filter_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "..", "test_helper") 2 | require 'mocha/backtrace_filter' 3 | 4 | class BacktraceFilterTest < Test::Unit::TestCase 5 | 6 | include Mocha 7 | 8 | def test_should_exclude_mocha_locations_from_backtrace 9 | mocha_lib = "/username/workspace/mocha_wibble/lib/" 10 | backtrace = [ mocha_lib + 'exclude/me/1', mocha_lib + 'exclude/me/2', '/keep/me', mocha_lib + 'exclude/me/3'] 11 | filter = BacktraceFilter.new(mocha_lib) 12 | assert_equal ['/keep/me'], filter.filtered(backtrace) 13 | end 14 | 15 | def test_should_determine_path_for_mocha_lib_directory 16 | assert_match Regexp.new("/lib/$"), BacktraceFilter::LIB_DIRECTORY 17 | end 18 | 19 | end 20 | -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/is_a_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "..", "..", "test_helper") 2 | 3 | require 'mocha/parameter_matchers/is_a' 4 | require 'mocha/inspect' 5 | 6 | class IsATest < Test::Unit::TestCase 7 | 8 | include Mocha::ParameterMatchers 9 | 10 | def test_should_match_object_that_is_a_specified_class 11 | matcher = is_a(Integer) 12 | assert matcher.matches?([99]) 13 | end 14 | 15 | def test_should_not_match_object_that_is_not_a_specified_class 16 | matcher = is_a(Integer) 17 | assert !matcher.matches?(['string']) 18 | end 19 | 20 | def test_should_describe_matcher 21 | matcher = is_a(Integer) 22 | assert_equal "is_a(Integer)", matcher.mocha_inspect 23 | end 24 | 25 | end 26 | -------------------------------------------------------------------------------- /lib/system_timer/thread_timer.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2008 David Vollbracht & Philippe Hanrigou 2 | 3 | module SystemTimer 4 | 5 | # Timer saving associated thread. This is needed because we trigger timers 6 | # from a Ruby signal handler and Ruby signals are always delivered to 7 | # main thread. 8 | class ThreadTimer 9 | attr_reader :trigger_time, :thread, :exception_class 10 | 11 | def initialize(trigger_time, thread, exception_class = nil) 12 | @trigger_time = trigger_time 13 | @thread = thread 14 | @exception_class = exception_class || Timeout::Error 15 | end 16 | 17 | def to_s 18 | " #{trigger_time}, :thread => #{thread}, :exception_class => #{exception_class}>" 19 | end 20 | 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/anything.rb: -------------------------------------------------------------------------------- 1 | require 'mocha/parameter_matchers/base' 2 | 3 | module Mocha 4 | 5 | module ParameterMatchers 6 | 7 | # :call-seq: anything() -> parameter_matcher 8 | # 9 | # Matches any object. 10 | # object = mock() 11 | # object.expects(:method_1).with(anything) 12 | # object.method_1('foo') 13 | # # no error raised 14 | def anything 15 | Anything.new 16 | end 17 | 18 | class Anything < Base # :nodoc: 19 | 20 | def matches?(available_parameters) 21 | available_parameters.shift 22 | return true 23 | end 24 | 25 | def mocha_inspect 26 | "anything" 27 | end 28 | 29 | end 30 | 31 | end 32 | 33 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/includes_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "..", "..", "test_helper") 2 | 3 | require 'mocha/parameter_matchers/includes' 4 | require 'mocha/inspect' 5 | 6 | class IncludesTest < Test::Unit::TestCase 7 | 8 | include Mocha::ParameterMatchers 9 | 10 | def test_should_match_object_including_value 11 | matcher = includes(:x) 12 | assert matcher.matches?([[:x, :y, :z]]) 13 | end 14 | 15 | def test_should_not_match_object_that_does_not_include_value 16 | matcher = includes(:not_included) 17 | assert !matcher.matches?([[:x, :y, :z]]) 18 | end 19 | 20 | def test_should_describe_matcher 21 | matcher = includes(:x) 22 | assert_equal "includes(:x)", matcher.mocha_inspect 23 | end 24 | 25 | end 26 | -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/kind_of_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "..", "..", "test_helper") 2 | 3 | require 'mocha/parameter_matchers/kind_of' 4 | require 'mocha/inspect' 5 | 6 | class KindOfTest < Test::Unit::TestCase 7 | 8 | include Mocha::ParameterMatchers 9 | 10 | def test_should_match_object_that_is_a_kind_of_specified_class 11 | matcher = kind_of(Integer) 12 | assert matcher.matches?([99]) 13 | end 14 | 15 | def test_should_not_match_object_that_is_not_a_kind_of_specified_class 16 | matcher = kind_of(Integer) 17 | assert !matcher.matches?(['string']) 18 | end 19 | 20 | def test_should_describe_matcher 21 | matcher = kind_of(Integer) 22 | assert_equal "kind_of(Integer)", matcher.mocha_inspect 23 | end 24 | 25 | end 26 | -------------------------------------------------------------------------------- /test/system_timer/thread_timer_test.rb: -------------------------------------------------------------------------------- 1 | require File.dirname(__FILE__) + '/../test_helper' 2 | 3 | unit_tests do 4 | 5 | test "trigger_time returns the time given in the constructor" do 6 | timer = SystemTimer::ThreadTimer.new(:a_tigger_time, nil) 7 | assert_equal :a_tigger_time, timer.trigger_time 8 | end 9 | 10 | test "thread returns the thread given in the constructor" do 11 | timer = SystemTimer::ThreadTimer.new(nil, :a_thread) 12 | assert_equal :a_thread, timer.thread 13 | end 14 | 15 | test "to_s retruns a human friendly description of the timer" do 16 | assert_match / 24, :thread => #, :exception_class => Timeout::Error>/, 17 | SystemTimer::ThreadTimer.new(24, Thread.current).to_s 18 | end 19 | 20 | end 21 | -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/lib/mocha/yield_parameters.rb: -------------------------------------------------------------------------------- 1 | require 'mocha/no_yields' 2 | require 'mocha/single_yield' 3 | require 'mocha/multiple_yields' 4 | 5 | module Mocha # :nodoc: 6 | 7 | class YieldParameters # :nodoc: 8 | 9 | def initialize 10 | @parameter_groups = [] 11 | end 12 | 13 | def next_invocation 14 | case @parameter_groups.length 15 | when 0 then NoYields.new 16 | when 1 then @parameter_groups.first 17 | else @parameter_groups.shift 18 | end 19 | end 20 | 21 | def add(*parameters) 22 | @parameter_groups << SingleYield.new(*parameters) 23 | end 24 | 25 | def multiple_add(*parameter_groups) 26 | @parameter_groups << MultipleYields.new(*parameter_groups) 27 | end 28 | 29 | end 30 | 31 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/instance_of_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "..", "..", "test_helper") 2 | 3 | require 'mocha/parameter_matchers/instance_of' 4 | require 'mocha/inspect' 5 | 6 | class InstanceOfTest < Test::Unit::TestCase 7 | 8 | include Mocha::ParameterMatchers 9 | 10 | def test_should_match_object_that_is_an_instance_of_specified_class 11 | matcher = instance_of(String) 12 | assert matcher.matches?(['string']) 13 | end 14 | 15 | def test_should_not_match_object_that_is_not_an_instance_of_specified_class 16 | matcher = instance_of(String) 17 | assert !matcher.matches?([99]) 18 | end 19 | 20 | def test_should_describe_matcher 21 | matcher = instance_of(String) 22 | assert_equal "instance_of(String)", matcher.mocha_inspect 23 | end 24 | 25 | end 26 | -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/regexp_matches_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "..", "..", "test_helper") 2 | 3 | require 'mocha/parameter_matchers/regexp_matches' 4 | require 'mocha/inspect' 5 | 6 | class RegexpMatchesTest < Test::Unit::TestCase 7 | 8 | include Mocha::ParameterMatchers 9 | 10 | def test_should_match_parameter_matching_regular_expression 11 | matcher = regexp_matches(/oo/) 12 | assert matcher.matches?(['foo']) 13 | end 14 | 15 | def test_should_not_match_parameter_not_matching_regular_expression 16 | matcher = regexp_matches(/oo/) 17 | assert !matcher.matches?(['bar']) 18 | end 19 | 20 | def test_should_describe_matcher 21 | matcher = regexp_matches(/oo/) 22 | assert_equal "regexp_matches(/oo/)", matcher.mocha_inspect 23 | end 24 | 25 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/lib/mocha/inspect.rb: -------------------------------------------------------------------------------- 1 | require 'date' 2 | 3 | class Object 4 | def mocha_inspect 5 | address = self.__id__ * 2 6 | address += 0x100000000 if address < 0 7 | inspect =~ /#" : inspect 8 | end 9 | end 10 | 11 | class String 12 | def mocha_inspect 13 | inspect.gsub(/\"/, "'") 14 | end 15 | end 16 | 17 | class Array 18 | def mocha_inspect 19 | "[#{collect { |member| member.mocha_inspect }.join(', ')}]" 20 | end 21 | end 22 | 23 | class Hash 24 | def mocha_inspect 25 | "{#{collect { |key, value| "#{key.mocha_inspect} => #{value.mocha_inspect}" }.join(', ')}}" 26 | end 27 | end 28 | 29 | class Time 30 | def mocha_inspect 31 | "#{inspect} (#{to_f} secs)" 32 | end 33 | end 34 | 35 | class Date 36 | def mocha_inspect 37 | to_s 38 | end 39 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/not_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "..", "..", "test_helper") 2 | 3 | require 'mocha/parameter_matchers/not' 4 | require 'mocha/inspect' 5 | require 'stub_matcher' 6 | 7 | class NotTest < Test::Unit::TestCase 8 | 9 | include Mocha::ParameterMatchers 10 | 11 | def test_should_match_if_matcher_does_not_match 12 | matcher = Not(Stub::Matcher.new(false)) 13 | assert matcher.matches?(['any_old_value']) 14 | end 15 | 16 | def test_should_not_match_if_matcher_does_match 17 | matcher = Not(Stub::Matcher.new(true)) 18 | assert !matcher.matches?(['any_old_value']) 19 | end 20 | 21 | def test_should_describe_matcher 22 | matcher = Not(Stub::Matcher.new(true)) 23 | assert_equal 'Not(matcher(true))', matcher.mocha_inspect 24 | end 25 | 26 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/acceptance/bug_21465_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "acceptance_test_helper") 2 | require 'mocha' 3 | 4 | class Bug21563Test < Test::Unit::TestCase 5 | 6 | include AcceptanceTest 7 | 8 | def setup 9 | setup_acceptance_test 10 | end 11 | 12 | def teardown 13 | teardown_acceptance_test 14 | end 15 | 16 | def test_should_allow_expected_method_name_to_be_a_string 17 | test_result = run_test do 18 | mock = mock() 19 | mock.expects('wibble') 20 | mock.wibble 21 | end 22 | assert_passed(test_result) 23 | end 24 | 25 | def test_should_allow_stubbed_method_name_to_be_a_string 26 | test_result = run_test do 27 | mock = mock() 28 | mock.stubs('wibble') 29 | mock.wibble 30 | end 31 | assert_passed(test_result) 32 | end 33 | 34 | end 35 | -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/unit/method_matcher_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "..", "test_helper") 2 | require 'mocha/method_matcher' 3 | 4 | class MethodMatcherTest < Test::Unit::TestCase 5 | 6 | include Mocha 7 | 8 | def test_should_match_if_actual_method_name_is_same_as_expected_method_name 9 | method_matcher = MethodMatcher.new(:method_name) 10 | assert method_matcher.match?(:method_name) 11 | end 12 | 13 | def test_should_not_match_if_actual_method_name_is_not_same_as_expected_method_name 14 | method_matcher = MethodMatcher.new(:method_name) 15 | assert !method_matcher.match?(:different_method_name) 16 | end 17 | 18 | def test_should_describe_what_method_is_expected 19 | method_matcher = MethodMatcher.new(:method_name) 20 | assert_equal "method_name", method_matcher.mocha_inspect 21 | end 22 | 23 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/responds_with_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "..", "..", "test_helper") 2 | 3 | require 'mocha/parameter_matchers/responds_with' 4 | require 'mocha/inspect' 5 | 6 | class RespondsWithTest < Test::Unit::TestCase 7 | 8 | include Mocha::ParameterMatchers 9 | 10 | def test_should_match_parameter_responding_with_expected_value 11 | matcher = responds_with(:upcase, 'FOO') 12 | assert matcher.matches?(['foo']) 13 | end 14 | 15 | def test_should_not_match_parameter_responding_with_unexpected_value 16 | matcher = responds_with(:upcase, 'FOO') 17 | assert !matcher.matches?(['bar']) 18 | end 19 | 20 | def test_should_describe_matcher 21 | matcher = responds_with(:foo, :bar) 22 | assert_equal 'responds_with(:foo, :bar)', matcher.mocha_inspect 23 | end 24 | 25 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/execution_point.rb: -------------------------------------------------------------------------------- 1 | class ExecutionPoint 2 | 3 | attr_reader :backtrace 4 | 5 | def self.current 6 | new(caller) 7 | end 8 | 9 | def initialize(backtrace) 10 | @backtrace = backtrace 11 | end 12 | 13 | def file_name 14 | return "unknown" unless @backtrace && @backtrace.first 15 | /\A(.*?):\d+/.match(@backtrace.first)[1] 16 | end 17 | 18 | def line_number 19 | return "unknown" unless @backtrace && @backtrace.first 20 | Integer(/\A.*?:(\d+)/.match(@backtrace.first)[1]) 21 | end 22 | 23 | def ==(other) 24 | return false unless other.is_a?(ExecutionPoint) 25 | (file_name == other.file_name) and (line_number == other.line_number) 26 | end 27 | 28 | def to_s 29 | "file: #{file_name}; line: #{line_number}" 30 | end 31 | 32 | def inspect 33 | to_s 34 | end 35 | 36 | end 37 | -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/yaml_equivalent_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "..", "..", "test_helper") 2 | 3 | require 'mocha/parameter_matchers/yaml_equivalent' 4 | require 'mocha/inspect' 5 | 6 | class YamlEquivalentTest < Test::Unit::TestCase 7 | 8 | include Mocha::ParameterMatchers 9 | 10 | def test_should_match_parameter_matching_yaml_representation_of_object 11 | matcher = yaml_equivalent([1, 2, 3]) 12 | assert matcher.matches?(["--- \n- 1\n- 2\n- 3\n"]) 13 | end 14 | 15 | def test_should_not_match_parameter_matching_yaml_representation_of_object 16 | matcher = yaml_equivalent([1, 2, 3]) 17 | assert !matcher.matches?(["--- \n- 4\n- 5\n"]) 18 | end 19 | 20 | def test_should_describe_matcher 21 | matcher = yaml_equivalent([1, 2, 3]) 22 | assert_equal "yaml_equivalent([1, 2, 3])", matcher.mocha_inspect 23 | end 24 | 25 | end -------------------------------------------------------------------------------- /vendor/gems/dust-0.1.6/README: -------------------------------------------------------------------------------- 1 | = Dust 2 | 3 | Dust adds descriptive block syntax test definition. 4 | 5 | by Jay[http://blog.jayfields.com] Fields[http://blog.jayfields.com] 6 | 7 | == Download and Installation 8 | 9 | You can download Dust from here[http://rubyforge.org/projects/dust] or install it with the following command. 10 | 11 | $ gem install dust 12 | 13 | == License 14 | 15 | You may use, copy and redistribute this library under the same terms as Ruby itself (see http://www.ruby-lang.org/en/LICENSE.txt). 16 | 17 | == Examples 18 | 19 | unit_tests do 20 | 21 | test "assert true" do 22 | assert_equal true, true 23 | end 24 | 25 | end 26 | 27 | See the tests for more examples 28 | 29 | == IDE specific files 30 | 31 | You can download TextMate and JEdit Run Focused Test Commands from http://rubyforge.org/projects/dust/ (in Files) 32 | 33 | == Contributors 34 | 35 | Dan Manges, David Vollbracht, Shane Harvie -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/acceptance/acceptance_test_helper.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "..", "test_helper") 2 | require 'test_runner' 3 | require 'mocha/configuration' 4 | 5 | module AcceptanceTest 6 | 7 | class FakeLogger 8 | 9 | attr_reader :warnings 10 | 11 | def initialize 12 | @warnings = [] 13 | end 14 | 15 | def warn(message) 16 | @warnings << message 17 | end 18 | 19 | end 20 | 21 | attr_reader :logger 22 | 23 | include TestRunner 24 | 25 | def setup_acceptance_test 26 | Mocha::Configuration.reset_configuration 27 | @logger = FakeLogger.new 28 | mockery = Mocha::Mockery.instance 29 | @original_logger = mockery.logger 30 | mockery.logger = @logger 31 | end 32 | 33 | def teardown_acceptance_test 34 | Mocha::Configuration.reset_configuration 35 | Mocha::Mockery.instance.logger = @original_logger 36 | end 37 | 38 | end 39 | -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/acceptance/bug_18914_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "acceptance_test_helper") 2 | require 'mocha' 3 | 4 | class Bug18914Test < Test::Unit::TestCase 5 | 6 | include AcceptanceTest 7 | 8 | def setup 9 | setup_acceptance_test 10 | end 11 | 12 | def teardown 13 | teardown_acceptance_test 14 | end 15 | 16 | class AlwaysEql 17 | 18 | def my_method 19 | true 20 | end 21 | 22 | def ==(o) 23 | true 24 | end 25 | 26 | def eql?(o) 27 | true 28 | end 29 | 30 | end 31 | 32 | def test_should_not_allow_stubbing_of_non_mock_instance_disrupted_by_legitimate_overriding_of_eql_method 33 | 34 | always_eql_1 = AlwaysEql.new 35 | always_eql_1.stubs(:my_method).returns(false) 36 | 37 | always_eql_2 = AlwaysEql.new 38 | always_eql_2.stubs(:my_method).returns(false) 39 | 40 | assert_equal false, always_eql_2.my_method 41 | end 42 | 43 | end 44 | -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/lib/mocha/names.rb: -------------------------------------------------------------------------------- 1 | module Mocha 2 | 3 | class ImpersonatingName 4 | 5 | def initialize(object) 6 | @object = object 7 | end 8 | 9 | def mocha_inspect 10 | @object.mocha_inspect 11 | end 12 | 13 | end 14 | 15 | class ImpersonatingAnyInstanceName 16 | 17 | def initialize(klass) 18 | @klass = klass 19 | end 20 | 21 | def mocha_inspect 22 | "#" 23 | end 24 | 25 | end 26 | 27 | class Name 28 | 29 | def initialize(name) 30 | @name = name 31 | end 32 | 33 | def mocha_inspect 34 | "#" 35 | end 36 | 37 | end 38 | 39 | class DefaultName 40 | 41 | def initialize(mock) 42 | @mock = mock 43 | end 44 | 45 | def mocha_inspect 46 | address = @mock.__id__ * 2 47 | address += 0x100000000 if address < 0 48 | "#" 49 | end 50 | 51 | end 52 | 53 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/all_of_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "..", "..", "test_helper") 2 | 3 | require 'mocha/parameter_matchers/all_of' 4 | require 'mocha/inspect' 5 | require 'stub_matcher' 6 | 7 | class AllOfTest < Test::Unit::TestCase 8 | 9 | include Mocha::ParameterMatchers 10 | 11 | def test_should_match_if_all_matchers_match 12 | matcher = all_of(Stub::Matcher.new(true), Stub::Matcher.new(true), Stub::Matcher.new(true)) 13 | assert matcher.matches?(['any_old_value']) 14 | end 15 | 16 | def test_should_not_match_if_any_matcher_does_not_match 17 | matcher = all_of(Stub::Matcher.new(true), Stub::Matcher.new(false), Stub::Matcher.new(true)) 18 | assert !matcher.matches?(['any_old_value']) 19 | end 20 | 21 | def test_should_describe_matcher 22 | matcher = all_of(Stub::Matcher.new(true), Stub::Matcher.new(false), Stub::Matcher.new(true)) 23 | assert_equal 'all_of(matcher(true), matcher(false), matcher(true))', matcher.mocha_inspect 24 | end 25 | 26 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/any_of_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "..", "..", "test_helper") 2 | 3 | require 'mocha/parameter_matchers/any_of' 4 | require 'mocha/inspect' 5 | require 'stub_matcher' 6 | 7 | class AnyOfTest < Test::Unit::TestCase 8 | 9 | include Mocha::ParameterMatchers 10 | 11 | def test_should_match_if_any_matchers_match 12 | matcher = any_of(Stub::Matcher.new(false), Stub::Matcher.new(true), Stub::Matcher.new(false)) 13 | assert matcher.matches?(['any_old_value']) 14 | end 15 | 16 | def test_should_not_match_if_no_matchers_match 17 | matcher = any_of(Stub::Matcher.new(false), Stub::Matcher.new(false), Stub::Matcher.new(false)) 18 | assert !matcher.matches?(['any_old_value']) 19 | end 20 | 21 | def test_should_describe_matcher 22 | matcher = any_of(Stub::Matcher.new(false), Stub::Matcher.new(true), Stub::Matcher.new(false)) 23 | assert_equal 'any_of(matcher(false), matcher(true), matcher(false))', matcher.mocha_inspect 24 | end 25 | 26 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/active_record_test_case.rb: -------------------------------------------------------------------------------- 1 | module ActiveRecordTestCase 2 | 3 | def setup_with_fixtures 4 | methods_called << :setup_with_fixtures 5 | end 6 | 7 | alias_method :setup, :setup_with_fixtures 8 | 9 | def teardown_with_fixtures 10 | methods_called << :teardown_with_fixtures 11 | end 12 | 13 | alias_method :teardown, :teardown_with_fixtures 14 | 15 | def self.method_added(method) 16 | case method.to_s 17 | when 'setup' 18 | unless method_defined?(:setup_without_fixtures) 19 | alias_method :setup_without_fixtures, :setup 20 | define_method(:setup) do 21 | setup_with_fixtures 22 | setup_without_fixtures 23 | end 24 | end 25 | when 'teardown' 26 | unless method_defined?(:teardown_without_fixtures) 27 | alias_method :teardown_without_fixtures, :teardown 28 | define_method(:teardown) do 29 | teardown_without_fixtures 30 | teardown_with_fixtures 31 | end 32 | end 33 | end 34 | end 35 | 36 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/any_parameters.rb: -------------------------------------------------------------------------------- 1 | require 'mocha/parameter_matchers/base' 2 | 3 | module Mocha 4 | 5 | module ParameterMatchers 6 | 7 | # :call-seq: any_parameters() -> parameter_matcher 8 | # 9 | # Matches any parameters. 10 | # object = mock() 11 | # object.expects(:method_1).with(any_parameters) 12 | # object.method_1(1, 2, 3, 4) 13 | # # no error raised 14 | # 15 | # object = mock() 16 | # object.expects(:method_1).with(any_parameters) 17 | # object.method_1(5, 6, 7, 8, 9, 0) 18 | # # no error raised 19 | def any_parameters 20 | AnyParameters.new 21 | end 22 | 23 | class AnyParameters < Base # :nodoc: 24 | 25 | def matches?(available_parameters) 26 | while available_parameters.length > 0 do 27 | available_parameters.shift 28 | end 29 | return true 30 | end 31 | 32 | def mocha_inspect 33 | "any_parameters" 34 | end 35 | 36 | end 37 | 38 | end 39 | 40 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/unit/change_state_side_effect_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "..", "test_helper") 2 | 3 | require 'mocha/change_state_side_effect' 4 | 5 | class ChangeStateSideEffectTest < Test::Unit::TestCase 6 | 7 | include Mocha 8 | 9 | class FakeState 10 | 11 | attr_reader :active 12 | attr_writer :description 13 | 14 | def activate 15 | @active = true 16 | end 17 | 18 | def mocha_inspect 19 | @description 20 | end 21 | 22 | end 23 | 24 | def test_should_activate_the_given_state 25 | state = FakeState.new 26 | side_effect = ChangeStateSideEffect.new(state) 27 | 28 | side_effect.perform 29 | 30 | assert state.active 31 | end 32 | 33 | def test_should_describe_itself_in_terms_of_the_activated_state 34 | state = FakeState.new 35 | state.description = 'the-new-state' 36 | side_effect = ChangeStateSideEffect.new(state) 37 | 38 | assert_equal 'then the-new-state', side_effect.mocha_inspect 39 | end 40 | 41 | end 42 | -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/includes.rb: -------------------------------------------------------------------------------- 1 | require 'mocha/parameter_matchers/base' 2 | 3 | module Mocha 4 | 5 | module ParameterMatchers 6 | 7 | # :call-seq: includes(item) -> parameter_matcher 8 | # 9 | # Matches any object that responds true to include?(item) 10 | # object = mock() 11 | # object.expects(:method_1).with(includes('foo')) 12 | # object.method_1(['foo', 'bar']) 13 | # # no error raised 14 | # 15 | # object.method_1(['baz']) 16 | # # error raised, because ['baz'] does not include 'foo'. 17 | def includes(item) 18 | Includes.new(item) 19 | end 20 | 21 | class Includes < Base # :nodoc: 22 | 23 | def initialize(item) 24 | @item = item 25 | end 26 | 27 | def matches?(available_parameters) 28 | parameter = available_parameters.shift 29 | return parameter.include?(@item) 30 | end 31 | 32 | def mocha_inspect 33 | "includes(#{@item.mocha_inspect})" 34 | end 35 | 36 | end 37 | 38 | end 39 | 40 | end 41 | -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/MIT-LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2006 Revieworld Ltd. 2 | 3 | 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: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | 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. -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/test_runner.rb: -------------------------------------------------------------------------------- 1 | require 'test/unit/testresult' 2 | require 'test/unit/testcase' 3 | 4 | module TestRunner 5 | 6 | def run_test(test_result = Test::Unit::TestResult.new, &block) 7 | test_class = Class.new(Test::Unit::TestCase) do 8 | define_method(:test_me, &block) 9 | end 10 | test = test_class.new(:test_me) 11 | test.run(test_result) {} 12 | class << test_result 13 | attr_reader :failures, :errors 14 | def failure_messages 15 | failures.map { |failure| failure.message } 16 | end 17 | def error_messages 18 | errors.map { |error| error.message } 19 | end 20 | end 21 | test_result 22 | end 23 | 24 | def assert_passed(test_result) 25 | flunk "Test failed unexpectedly with message: #{test_result.failures}" if test_result.failure_count > 0 26 | flunk "Test failed unexpectedly with message: #{test_result.errors}" if test_result.error_count > 0 27 | end 28 | 29 | def assert_failed(test_result) 30 | flunk "Test passed unexpectedly" if test_result.passed? 31 | end 32 | 33 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/lib/mocha/sequence.rb: -------------------------------------------------------------------------------- 1 | module Mocha # :nodoc: 2 | 3 | class Sequence 4 | 5 | class InSequenceOrderingConstraint 6 | 7 | def initialize(sequence, index) 8 | @sequence, @index = sequence, index 9 | end 10 | 11 | def allows_invocation_now? 12 | @sequence.satisfied_to_index?(@index) 13 | end 14 | 15 | def mocha_inspect 16 | "in sequence #{@sequence.mocha_inspect}" 17 | end 18 | 19 | end 20 | 21 | def initialize(name) 22 | @name = name 23 | @expectations = [] 24 | end 25 | 26 | def constrain_as_next_in_sequence(expectation) 27 | index = @expectations.length 28 | @expectations << expectation 29 | expectation.add_ordering_constraint(InSequenceOrderingConstraint.new(self, index)) 30 | end 31 | 32 | def satisfied_to_index?(index) 33 | @expectations[0...index].all? { |expectation| expectation.satisfied? } 34 | end 35 | 36 | def mocha_inspect 37 | "#{@name.mocha_inspect}" 38 | end 39 | 40 | end 41 | 42 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/equals.rb: -------------------------------------------------------------------------------- 1 | require 'mocha/parameter_matchers/base' 2 | 3 | module Mocha 4 | 5 | module ParameterMatchers 6 | 7 | # :call-seq: equals(value) -> parameter_matcher 8 | # 9 | # Matches +Object+ equalling +value+. 10 | # object = mock() 11 | # object.expects(:method_1).with(equals(2)) 12 | # object.method_1(2) 13 | # # no error raised 14 | # 15 | # object = mock() 16 | # object.expects(:method_1).with(equals(2)) 17 | # object.method_1(3) 18 | # # error raised, because method_1 was not called with Object equalling 3 19 | def equals(value) 20 | Equals.new(value) 21 | end 22 | 23 | class Equals < Base # :nodoc: 24 | 25 | def initialize(value) 26 | @value = value 27 | end 28 | 29 | def matches?(available_parameters) 30 | parameter = available_parameters.shift 31 | parameter == @value 32 | end 33 | 34 | def mocha_inspect 35 | @value.mocha_inspect 36 | end 37 | 38 | end 39 | 40 | end 41 | 42 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers.rb: -------------------------------------------------------------------------------- 1 | module Mocha 2 | 3 | # Used as parameters for Expectation#with to restrict the parameter values which will match the expectation. Can be nested. 4 | module ParameterMatchers; end 5 | 6 | end 7 | 8 | require 'mocha/parameter_matchers/object' 9 | 10 | require 'mocha/parameter_matchers/all_of' 11 | require 'mocha/parameter_matchers/any_of' 12 | require 'mocha/parameter_matchers/any_parameters' 13 | require 'mocha/parameter_matchers/anything' 14 | require 'mocha/parameter_matchers/equals' 15 | require 'mocha/parameter_matchers/has_entry' 16 | require 'mocha/parameter_matchers/has_entries' 17 | require 'mocha/parameter_matchers/has_key' 18 | require 'mocha/parameter_matchers/has_value' 19 | require 'mocha/parameter_matchers/includes' 20 | require 'mocha/parameter_matchers/instance_of' 21 | require 'mocha/parameter_matchers/is_a' 22 | require 'mocha/parameter_matchers/kind_of' 23 | require 'mocha/parameter_matchers/not' 24 | require 'mocha/parameter_matchers/optionally' 25 | require 'mocha/parameter_matchers/regexp_matches' 26 | require 'mocha/parameter_matchers/yaml_equivalent' 27 | -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/is_a.rb: -------------------------------------------------------------------------------- 1 | require 'mocha/parameter_matchers/base' 2 | 3 | module Mocha 4 | 5 | module ParameterMatchers 6 | 7 | # :call-seq: is_a(klass) -> parameter_matcher 8 | # 9 | # Matches any object that is a +klass+ 10 | # object = mock() 11 | # object.expects(:method_1).with(is_a(Integer)) 12 | # object.method_1(99) 13 | # # no error raised 14 | # 15 | # object = mock() 16 | # object.expects(:method_1).with(is_a(Integer)) 17 | # object.method_1('string') 18 | # # error raised, because method_1 was not called with an Integer 19 | def is_a(klass) 20 | IsA.new(klass) 21 | end 22 | 23 | class IsA < Base # :nodoc: 24 | 25 | def initialize(klass) 26 | @klass = klass 27 | end 28 | 29 | def matches?(available_parameters) 30 | parameter = available_parameters.shift 31 | parameter.is_a?(@klass) 32 | end 33 | 34 | def mocha_inspect 35 | "is_a(#{@klass.mocha_inspect})" 36 | end 37 | 38 | end 39 | 40 | end 41 | 42 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/kind_of.rb: -------------------------------------------------------------------------------- 1 | require 'mocha/parameter_matchers/base' 2 | 3 | module Mocha 4 | 5 | module ParameterMatchers 6 | 7 | # :call-seq: kind_of(klass) -> parameter_matcher 8 | # 9 | # Matches any object that is a kind of +klass+ 10 | # object = mock() 11 | # object.expects(:method_1).with(kind_of(Integer)) 12 | # object.method_1(99) 13 | # # no error raised 14 | # 15 | # object = mock() 16 | # object.expects(:method_1).with(kind_of(Integer)) 17 | # object.method_1('string') 18 | # # error raised, because method_1 was not called with a kind of Integer 19 | def kind_of(klass) 20 | KindOf.new(klass) 21 | end 22 | 23 | class KindOf < Base # :nodoc: 24 | 25 | def initialize(klass) 26 | @klass = klass 27 | end 28 | 29 | def matches?(available_parameters) 30 | parameter = available_parameters.shift 31 | parameter.kind_of?(@klass) 32 | end 33 | 34 | def mocha_inspect 35 | "kind_of(#{@klass.mocha_inspect})" 36 | end 37 | 38 | end 39 | 40 | end 41 | 42 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/lib/mocha/parameters_matcher.rb: -------------------------------------------------------------------------------- 1 | require 'mocha/inspect' 2 | require 'mocha/parameter_matchers' 3 | 4 | module Mocha 5 | 6 | class ParametersMatcher 7 | 8 | def initialize(expected_parameters = [ParameterMatchers::AnyParameters.new], &matching_block) 9 | @expected_parameters, @matching_block = expected_parameters, matching_block 10 | end 11 | 12 | def match?(actual_parameters = []) 13 | if @matching_block 14 | return @matching_block.call(*actual_parameters) 15 | else 16 | return parameters_match?(actual_parameters) 17 | end 18 | end 19 | 20 | def parameters_match?(actual_parameters) 21 | matchers.all? { |matcher| matcher.matches?(actual_parameters) } && (actual_parameters.length == 0) 22 | end 23 | 24 | def mocha_inspect 25 | signature = matchers.mocha_inspect 26 | signature = signature.gsub(/^\[|\]$/, '') 27 | signature = signature.gsub(/^\{|\}$/, '') if matchers.length == 1 28 | "(#{signature})" 29 | end 30 | 31 | def matchers 32 | @expected_parameters.map { |parameter| parameter.to_matcher } 33 | end 34 | 35 | end 36 | 37 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/not.rb: -------------------------------------------------------------------------------- 1 | require 'mocha/parameter_matchers/base' 2 | 3 | module Mocha 4 | 5 | module ParameterMatchers 6 | 7 | # :call-seq: Not(parameter_matcher) -> parameter_matcher 8 | # 9 | # Matches if +parameter_matcher+ does not match. 10 | # object = mock() 11 | # object.expects(:method_1).with(Not(includes(1))) 12 | # object.method_1([0, 2, 3]) 13 | # # no error raised 14 | # 15 | # object = mock() 16 | # object.expects(:method_1).with(Not(includes(1))) 17 | # object.method_1([0, 1, 2, 3]) 18 | # # error raised, because method_1 was not called with object not including 1 19 | def Not(matcher) 20 | Not.new(matcher) 21 | end 22 | 23 | class Not < Base # :nodoc: 24 | 25 | def initialize(matcher) 26 | @matcher = matcher 27 | end 28 | 29 | def matches?(available_parameters) 30 | parameter = available_parameters.shift 31 | !@matcher.matches?([parameter]) 32 | end 33 | 34 | def mocha_inspect 35 | "Not(#{@matcher.mocha_inspect})" 36 | end 37 | 38 | end 39 | 40 | end 41 | 42 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/instance_of.rb: -------------------------------------------------------------------------------- 1 | require 'mocha/parameter_matchers/base' 2 | 3 | module Mocha 4 | 5 | module ParameterMatchers 6 | 7 | # :call-seq: instance_of(klass) -> parameter_matcher 8 | # 9 | # Matches any object that is an instance of +klass+ 10 | # object = mock() 11 | # object.expects(:method_1).with(instance_of(String)) 12 | # object.method_1('string') 13 | # # no error raised 14 | # 15 | # object = mock() 16 | # object.expects(:method_1).with(instance_of(String)) 17 | # object.method_1(99) 18 | # # error raised, because method_1 was not called with an instance of String 19 | def instance_of(klass) 20 | InstanceOf.new(klass) 21 | end 22 | 23 | class InstanceOf < Base # :nodoc: 24 | 25 | def initialize(klass) 26 | @klass = klass 27 | end 28 | 29 | def matches?(available_parameters) 30 | parameter = available_parameters.shift 31 | parameter.instance_of?(@klass) 32 | end 33 | 34 | def mocha_inspect 35 | "instance_of(#{@klass.mocha_inspect})" 36 | end 37 | 38 | end 39 | 40 | end 41 | 42 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/has_key.rb: -------------------------------------------------------------------------------- 1 | require 'mocha/parameter_matchers/base' 2 | 3 | module Mocha 4 | 5 | module ParameterMatchers 6 | 7 | # :call-seq: has_key(key) -> parameter_matcher 8 | # 9 | # Matches +Hash+ containing +key+. 10 | # object = mock() 11 | # object.expects(:method_1).with(has_key('key_1')) 12 | # object.method_1('key_1' => 1, 'key_2' => 2) 13 | # # no error raised 14 | # 15 | # object = mock() 16 | # object.expects(:method_1).with(has_key('key_1')) 17 | # object.method_1('key_2' => 2) 18 | # # error raised, because method_1 was not called with Hash containing key: 'key_1' 19 | def has_key(key) 20 | HasKey.new(key) 21 | end 22 | 23 | class HasKey < Base # :nodoc: 24 | 25 | def initialize(key) 26 | @key = key 27 | end 28 | 29 | def matches?(available_parameters) 30 | parameter = available_parameters.shift 31 | parameter.keys.any? { |key| @key.to_matcher.matches?([key]) } 32 | end 33 | 34 | def mocha_inspect 35 | "has_key(#{@key.mocha_inspect})" 36 | end 37 | 38 | end 39 | 40 | end 41 | 42 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/has_value.rb: -------------------------------------------------------------------------------- 1 | require 'mocha/parameter_matchers/base' 2 | 3 | module Mocha 4 | 5 | module ParameterMatchers 6 | 7 | # :call-seq: has_value(value) -> parameter_matcher 8 | # 9 | # Matches +Hash+ containing +value+. 10 | # object = mock() 11 | # object.expects(:method_1).with(has_value(1)) 12 | # object.method_1('key_1' => 1, 'key_2' => 2) 13 | # # no error raised 14 | # 15 | # object = mock() 16 | # object.expects(:method_1).with(has_value(1)) 17 | # object.method_1('key_2' => 2) 18 | # # error raised, because method_1 was not called with Hash containing value: 1 19 | def has_value(value) 20 | HasValue.new(value) 21 | end 22 | 23 | class HasValue < Base # :nodoc: 24 | 25 | def initialize(value) 26 | @value = value 27 | end 28 | 29 | def matches?(available_parameters) 30 | parameter = available_parameters.shift 31 | parameter.values.any? { |value| @value.to_matcher.matches?([value]) } 32 | end 33 | 34 | def mocha_inspect 35 | "has_value(#{@value.mocha_inspect})" 36 | end 37 | 38 | end 39 | 40 | end 41 | 42 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/has_key_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "..", "..", "test_helper") 2 | 3 | require 'mocha/parameter_matchers/has_key' 4 | require 'mocha/parameter_matchers/object' 5 | require 'mocha/inspect' 6 | 7 | class HasKeyTest < Test::Unit::TestCase 8 | 9 | include Mocha::ParameterMatchers 10 | 11 | def test_should_match_hash_including_specified_key 12 | matcher = has_key(:key_1) 13 | assert matcher.matches?([{ :key_1 => 1, :key_2 => 2 }]) 14 | end 15 | 16 | def test_should_not_match_hash_not_including_specified_key 17 | matcher = has_key(:key_1) 18 | assert !matcher.matches?([{ :key_2 => 2 }]) 19 | end 20 | 21 | def test_should_describe_matcher 22 | matcher = has_key(:key) 23 | assert_equal 'has_key(:key)', matcher.mocha_inspect 24 | end 25 | 26 | def test_should_match_hash_including_specified_key_with_nested_key_matcher 27 | matcher = has_key(equals(:key_1)) 28 | assert matcher.matches?([{ :key_1 => 1, :key_2 => 2 }]) 29 | end 30 | 31 | def test_should_not_match_hash_not_including_specified_key_with_nested_key_matcher 32 | matcher = has_key(equals(:key_1)) 33 | assert !matcher.matches?([{ :key_2 => 2 }]) 34 | end 35 | 36 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/regexp_matches.rb: -------------------------------------------------------------------------------- 1 | require 'mocha/parameter_matchers/base' 2 | 3 | module Mocha 4 | 5 | module ParameterMatchers 6 | 7 | # :call-seq: regexp_matches(regular_expression) -> parameter_matcher 8 | # 9 | # Matches any object that matches +regular_expression+. 10 | # object = mock() 11 | # object.expects(:method_1).with(regexp_matches(/e/)) 12 | # object.method_1('hello') 13 | # # no error raised 14 | # 15 | # object = mock() 16 | # object.expects(:method_1).with(regexp_matches(/a/)) 17 | # object.method_1('hello') 18 | # # error raised, because method_1 was not called with a parameter that matched the 19 | # # regular expression 20 | def regexp_matches(regexp) 21 | RegexpMatches.new(regexp) 22 | end 23 | 24 | class RegexpMatches < Base # :nodoc: 25 | 26 | def initialize(regexp) 27 | @regexp = regexp 28 | end 29 | 30 | def matches?(available_parameters) 31 | parameter = available_parameters.shift 32 | parameter =~ @regexp 33 | end 34 | 35 | def mocha_inspect 36 | "regexp_matches(#{@regexp.mocha_inspect})" 37 | end 38 | 39 | end 40 | 41 | end 42 | 43 | end 44 | -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/yaml_equivalent.rb: -------------------------------------------------------------------------------- 1 | require 'mocha/parameter_matchers/base' 2 | require 'yaml' 3 | 4 | module Mocha 5 | 6 | module ParameterMatchers 7 | 8 | # :call-seq: yaml_equivalent(object) -> parameter_matcher 9 | # 10 | # Matches any YAML that represents the specified +object+ 11 | # object = mock() 12 | # object.expects(:method_1).with(yaml_equivalent(1, 2, 3)) 13 | # object.method_1("--- \n- 1\n- 2\n- 3\n") 14 | # # no error raised 15 | # 16 | # object = mock() 17 | # object.expects(:method_1).with(yaml_equivalent(1, 2, 3)) 18 | # object.method_1("--- \n- 1\n- 2\n") 19 | # # error raised, because method_1 was not called with YAML representing the specified Array 20 | def yaml_equivalent(object) 21 | YamlEquivalent.new(object) 22 | end 23 | 24 | class YamlEquivalent < Base # :nodoc: 25 | 26 | def initialize(object) 27 | @object = object 28 | end 29 | 30 | def matches?(available_parameters) 31 | parameter = available_parameters.shift 32 | @object == YAML.load(parameter) 33 | end 34 | 35 | def mocha_inspect 36 | "yaml_equivalent(#{@object.mocha_inspect})" 37 | end 38 | 39 | end 40 | 41 | end 42 | 43 | end 44 | -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/all_of.rb: -------------------------------------------------------------------------------- 1 | require 'mocha/parameter_matchers/base' 2 | 3 | module Mocha 4 | 5 | module ParameterMatchers 6 | 7 | # :call-seq: all_of(*parameter_matchers) -> parameter_matcher 8 | # 9 | # Matches if all +parameter_matchers+ match. 10 | # object = mock() 11 | # object.expects(:method_1).with(all_of(includes(1), includes(3))) 12 | # object.method_1([1, 3]) 13 | # # no error raised 14 | # 15 | # object = mock() 16 | # object.expects(:method_1).with(all_of(includes(1), includes(3))) 17 | # object.method_1([1, 2]) 18 | # # error raised, because method_1 was not called with object including 1 and 3 19 | def all_of(*matchers) 20 | AllOf.new(*matchers) 21 | end 22 | 23 | class AllOf < Base # :nodoc: 24 | 25 | def initialize(*matchers) 26 | @matchers = matchers 27 | end 28 | 29 | def matches?(available_parameters) 30 | parameter = available_parameters.shift 31 | @matchers.all? { |matcher| matcher.to_matcher.matches?([parameter]) } 32 | end 33 | 34 | def mocha_inspect 35 | "all_of(#{@matchers.map { |matcher| matcher.mocha_inspect }.join(", ") })" 36 | end 37 | 38 | end 39 | 40 | end 41 | 42 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/lib/mocha/expectation_list.rb: -------------------------------------------------------------------------------- 1 | module Mocha # :nodoc: 2 | 3 | class ExpectationList 4 | 5 | def initialize 6 | @expectations = [] 7 | end 8 | 9 | def add(expectation) 10 | @expectations.unshift(expectation) 11 | expectation 12 | end 13 | 14 | def matches_method?(method_name) 15 | @expectations.any? { |expectation| expectation.matches_method?(method_name) } 16 | end 17 | 18 | def match(method_name, *arguments) 19 | matching_expectations(method_name, *arguments).first 20 | end 21 | 22 | def match_allowing_invocation(method_name, *arguments) 23 | matching_expectations(method_name, *arguments).detect { |e| e.invocations_allowed? } 24 | end 25 | 26 | def verified?(assertion_counter = nil) 27 | @expectations.all? { |expectation| expectation.verified?(assertion_counter) } 28 | end 29 | 30 | def to_a 31 | @expectations 32 | end 33 | 34 | def to_set 35 | @expectations.to_set 36 | end 37 | 38 | def length 39 | @expectations.length 40 | end 41 | 42 | private 43 | 44 | def matching_expectations(method_name, *arguments) 45 | @expectations.select { |e| e.match?(method_name, *arguments) } 46 | end 47 | 48 | end 49 | 50 | end 51 | -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/unit/in_state_ordering_constraint_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "..", "test_helper") 2 | 3 | require 'mocha/in_state_ordering_constraint' 4 | 5 | class InStateOrderingConstraintTest < Test::Unit::TestCase 6 | 7 | include Mocha 8 | 9 | class FakeStatePredicate 10 | 11 | attr_writer :active, :description 12 | 13 | def active? 14 | @active 15 | end 16 | 17 | def mocha_inspect 18 | @description 19 | end 20 | 21 | end 22 | 23 | def test_should_allow_invocation_when_state_is_active 24 | state_predicate = FakeStatePredicate.new 25 | ordering_constraint = InStateOrderingConstraint.new(state_predicate) 26 | 27 | state_predicate.active = true 28 | assert ordering_constraint.allows_invocation_now? 29 | 30 | state_predicate.active = false 31 | assert !ordering_constraint.allows_invocation_now? 32 | end 33 | 34 | def test_should_describe_itself_in_terms_of_the_state_predicates_description 35 | state_predicate = FakeStatePredicate.new 36 | ordering_constraint = InStateOrderingConstraint.new(state_predicate) 37 | 38 | state_predicate.description = 'the-state-predicate' 39 | 40 | assert_equal 'when the-state-predicate', ordering_constraint.mocha_inspect 41 | end 42 | 43 | end 44 | -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/acceptance/stub_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "acceptance_test_helper") 2 | require 'mocha' 3 | 4 | class StubTest < Test::Unit::TestCase 5 | 6 | include AcceptanceTest 7 | 8 | def setup 9 | setup_acceptance_test 10 | end 11 | 12 | def teardown 13 | teardown_acceptance_test 14 | end 15 | 16 | def test_should_build_stub_and_explicitly_add_an_expectation 17 | test_result = run_test do 18 | foo = stub() 19 | foo.stubs(:bar) 20 | foo.bar 21 | end 22 | assert_passed(test_result) 23 | end 24 | 25 | def test_should_build_named_stub_and_explicitly_add_an_expectation 26 | test_result = run_test do 27 | foo = stub('foo') 28 | foo.stubs(:bar) 29 | foo.bar 30 | end 31 | assert_passed(test_result) 32 | end 33 | 34 | def test_should_build_stub_incorporating_two_expectations 35 | test_result = run_test do 36 | foo = stub(:bar => 'bar', :baz => 'baz') 37 | foo.bar 38 | foo.baz 39 | end 40 | assert_passed(test_result) 41 | end 42 | 43 | def test_should_build_named_stub_incorporating_two_expectations 44 | test_result = run_test do 45 | foo = stub('foo', :bar => 'bar', :baz => 'baz') 46 | foo.bar 47 | foo.baz 48 | end 49 | assert_passed(test_result) 50 | end 51 | 52 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/acceptance/partial_mocks_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "acceptance_test_helper") 2 | require 'mocha' 3 | 4 | class PartialMockTest < Test::Unit::TestCase 5 | 6 | include AcceptanceTest 7 | 8 | def setup 9 | setup_acceptance_test 10 | end 11 | 12 | def teardown 13 | teardown_acceptance_test 14 | end 15 | 16 | def test_should_pass_if_all_expectations_are_satisfied 17 | test_result = run_test do 18 | partial_mock_one = "partial_mock_one" 19 | partial_mock_two = "partial_mock_two" 20 | 21 | partial_mock_one.expects(:first) 22 | partial_mock_one.expects(:second) 23 | partial_mock_two.expects(:third) 24 | 25 | partial_mock_one.first 26 | partial_mock_one.second 27 | partial_mock_two.third 28 | end 29 | assert_passed(test_result) 30 | end 31 | 32 | def test_should_fail_if_all_expectations_are_not_satisfied 33 | test_result = run_test do 34 | partial_mock_one = "partial_mock_one" 35 | partial_mock_two = "partial_mock_two" 36 | 37 | partial_mock_one.expects(:first) 38 | partial_mock_one.expects(:second) 39 | partial_mock_two.expects(:third) 40 | 41 | partial_mock_one.first 42 | partial_mock_two.third 43 | end 44 | assert_failed(test_result) 45 | end 46 | 47 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/acceptance/mock_with_initializer_block_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "acceptance_test_helper") 2 | require 'mocha' 3 | 4 | class MockWithInitializerBlockTest < Test::Unit::TestCase 5 | 6 | include AcceptanceTest 7 | 8 | def setup 9 | setup_acceptance_test 10 | end 11 | 12 | def teardown 13 | teardown_acceptance_test 14 | end 15 | 16 | def test_should_expect_two_method_invocations_and_receive_both_of_them 17 | test_result = run_test do 18 | mock = mock() do 19 | expects(:method_1) 20 | expects(:method_2) 21 | end 22 | mock.method_1 23 | mock.method_2 24 | end 25 | assert_passed(test_result) 26 | end 27 | 28 | def test_should_expect_two_method_invocations_but_receive_only_one_of_them 29 | test_result = run_test do 30 | mock = mock() do 31 | expects(:method_1) 32 | expects(:method_2) 33 | end 34 | mock.method_1 35 | end 36 | assert_failed(test_result) 37 | end 38 | 39 | def test_should_stub_methods 40 | test_result = run_test do 41 | mock = mock() do 42 | stubs(:method_1).returns(1) 43 | stubs(:method_2).returns(2) 44 | end 45 | assert_equal 1, mock.method_1 46 | assert_equal 2, mock.method_2 47 | end 48 | assert_passed(test_result) 49 | end 50 | 51 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/has_value_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "..", "..", "test_helper") 2 | 3 | require 'mocha/parameter_matchers/has_value' 4 | require 'mocha/parameter_matchers/object' 5 | require 'mocha/parameter_matchers/equals' 6 | require 'mocha/inspect' 7 | 8 | class HasValueTest < Test::Unit::TestCase 9 | 10 | include Mocha::ParameterMatchers 11 | 12 | def test_should_match_hash_including_specified_value 13 | matcher = has_value('value_1') 14 | assert matcher.matches?([{ :key_1 => 'value_1', :key_2 => 'value_2' }]) 15 | end 16 | 17 | def test_should_not_match_hash_not_including_specified_value 18 | matcher = has_value('value_1') 19 | assert !matcher.matches?([{ :key_2 => 'value_2' }]) 20 | end 21 | 22 | def test_should_describe_matcher 23 | matcher = has_value('value_1') 24 | assert_equal "has_value('value_1')", matcher.mocha_inspect 25 | end 26 | 27 | def test_should_match_hash_including_specified_value_with_nested_value_matcher 28 | matcher = has_value(equals('value_1')) 29 | assert matcher.matches?([{ :key_1 => 'value_1', :key_2 => 'value_2' }]) 30 | end 31 | 32 | def test_should_not_match_hash_not_including_specified_value_with_nested_value_matcher 33 | matcher = has_value(equals('value_1')) 34 | assert !matcher.matches?([{ :key_2 => 'value_2' }]) 35 | end 36 | 37 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/any_of.rb: -------------------------------------------------------------------------------- 1 | require 'mocha/parameter_matchers/base' 2 | 3 | module Mocha 4 | 5 | module ParameterMatchers 6 | 7 | # :call-seq: any_of(*parameter_matchers) -> parameter_matcher 8 | # 9 | # Matches if any +parameter_matchers+ match. 10 | # object = mock() 11 | # object.expects(:method_1).with(any_of(1, 3)) 12 | # object.method_1(1) 13 | # # no error raised 14 | # 15 | # object = mock() 16 | # object.expects(:method_1).with(any_of(1, 3)) 17 | # object.method_1(3) 18 | # # no error raised 19 | # 20 | # object = mock() 21 | # object.expects(:method_1).with(any_of(1, 3)) 22 | # object.method_1(2) 23 | # # error raised, because method_1 was not called with 1 or 3 24 | def any_of(*matchers) 25 | AnyOf.new(*matchers) 26 | end 27 | 28 | class AnyOf < Base # :nodoc: 29 | 30 | def initialize(*matchers) 31 | @matchers = matchers 32 | end 33 | 34 | def matches?(available_parameters) 35 | parameter = available_parameters.shift 36 | @matchers.any? { |matcher| matcher.to_matcher.matches?([parameter]) } 37 | end 38 | 39 | def mocha_inspect 40 | "any_of(#{@matchers.map { |matcher| matcher.mocha_inspect }.join(", ") })" 41 | end 42 | 43 | end 44 | 45 | end 46 | 47 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/responds_with.rb: -------------------------------------------------------------------------------- 1 | require 'mocha/parameter_matchers/base' 2 | require 'yaml' 3 | 4 | module Mocha 5 | 6 | module ParameterMatchers 7 | 8 | # :call-seq: responds_with(message, result) -> parameter_matcher 9 | # 10 | # Matches any object that responds to +message+ with +result+. To put it another way, it tests the quack, not the duck. 11 | # object = mock() 12 | # object.expects(:method_1).with(responds_with(:upcase, "FOO")) 13 | # object.method_1("foo") 14 | # # no error raised, because "foo".upcase == "FOO" 15 | # 16 | # object = mock() 17 | # object.expects(:method_1).with(responds_with(:upcase, "BAR")) 18 | # object.method_1("foo") 19 | # # error raised, because "foo".upcase != "BAR" 20 | def responds_with(message, result) 21 | RespondsWith.new(message, result) 22 | end 23 | 24 | class RespondsWith < Base # :nodoc: 25 | 26 | def initialize(message, result) 27 | @message, @result = message, result 28 | end 29 | 30 | def matches?(available_parameters) 31 | parameter = available_parameters.shift 32 | parameter.__send__(@message) == @result 33 | end 34 | 35 | def mocha_inspect 36 | "responds_with(#{@message.mocha_inspect}, #{@result.mocha_inspect})" 37 | end 38 | 39 | end 40 | 41 | end 42 | 43 | end 44 | -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/unit/object_inspect_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "..", "test_helper") 2 | require 'mocha/inspect' 3 | require 'method_definer' 4 | 5 | class ObjectInspectTest < Test::Unit::TestCase 6 | 7 | def test_should_return_default_string_representation_of_object_not_including_instance_variables 8 | object = Object.new 9 | class << object 10 | attr_accessor :attribute 11 | end 12 | object.attribute = 'instance_variable' 13 | assert_match Regexp.new("^#$"), object.mocha_inspect 14 | assert_no_match(/instance_variable/, object.mocha_inspect) 15 | end 16 | 17 | def test_should_return_customized_string_representation_of_object 18 | object = Object.new 19 | class << object 20 | define_method(:inspect) { 'custom_inspect' } 21 | end 22 | assert_equal 'custom_inspect', object.mocha_inspect 23 | end 24 | 25 | def test_should_use_underscored_id_instead_of_object_id_or_id_so_that_they_can_be_stubbed 26 | object = Object.new 27 | object.define_instance_accessor(:called) 28 | object.called = false 29 | object.replace_instance_method(:object_id) { self.called = true; 1 } 30 | if RUBY_VERSION < '1.9' 31 | object.replace_instance_method(:id) { self.called = true; 1 } 32 | end 33 | object.mocha_inspect 34 | assert_equal false, object.called 35 | end 36 | 37 | end 38 | -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/examples/misc.rb: -------------------------------------------------------------------------------- 1 | require 'test/unit' 2 | require 'rubygems' 3 | require 'mocha' 4 | 5 | class MiscExampleTest < Test::Unit::TestCase 6 | 7 | def test_mocking_a_class_method 8 | product = Product.new 9 | Product.expects(:find).with(1).returns(product) 10 | assert_equal product, Product.find(1) 11 | end 12 | 13 | def test_mocking_an_instance_method_on_a_real_object 14 | product = Product.new 15 | product.expects(:save).returns(true) 16 | assert product.save 17 | end 18 | 19 | def test_stubbing_instance_methods_on_real_objects 20 | prices = [stub(:pence => 1000), stub(:pence => 2000)] 21 | product = Product.new 22 | product.stubs(:prices).returns(prices) 23 | assert_equal [1000, 2000], product.prices.collect {|p| p.pence} 24 | end 25 | 26 | def test_stubbing_an_instance_method_on_all_instances_of_a_class 27 | Product.any_instance.stubs(:name).returns('stubbed_name') 28 | product = Product.new 29 | assert_equal 'stubbed_name', product.name 30 | end 31 | 32 | def test_traditional_mocking 33 | object = mock() 34 | object.expects(:expected_method).with(:p1, :p2).returns(:result) 35 | assert_equal :result, object.expected_method(:p1, :p2) 36 | end 37 | 38 | def test_shortcuts 39 | object = stub(:method1 => :result1, :method2 => :result2) 40 | assert_equal :result1, object.method1 41 | assert_equal :result2, object.method2 42 | end 43 | 44 | end -------------------------------------------------------------------------------- /experiments/setitimer_process_isolation.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | /* 7 | * Launch multiple instances of this program on your machine with 8 | * different timeout values to convince yourself that itmer alarms 9 | * are specific to a particular process. 10 | */ 11 | 12 | int timeout; 13 | 14 | void install_next_timer() { 15 | struct itimerval val; 16 | 17 | val.it_interval.tv_sec = 0; /* ie. no repeat count */ 18 | val.it_interval.tv_usec = 0; 19 | val.it_value.tv_sec = timeout; /* initialise counter */ 20 | val.it_value.tv_usec = 0; 21 | 22 | setitimer(ITIMER_REAL, &val, 0); 23 | } 24 | 25 | 26 | void custom_signal_handler() 27 | { 28 | time_t the_time; 29 | 30 | time(&the_time); 31 | fprintf(stdout, "alarm ticked at %d (epoch time)\n", the_time); 32 | install_next_timer(); 33 | } 34 | 35 | 36 | main(int argc, char *argv[]) 37 | { 38 | int i; 39 | struct itimerval val, curval; 40 | 41 | if (argc != 2 ) { 42 | fprintf(stderr, "Usage: %s seconds\n", argv[0]); 43 | exit(1); 44 | } 45 | 46 | timeout = atoi(argv[1]); 47 | 48 | fprintf(stdout, "Setting alarm every %ds\n", timeout); 49 | 50 | signal(SIGALRM, custom_signal_handler); 51 | 52 | install_next_timer(); 53 | 54 | setitimer(ITIMER_REAL, &val, 0); 55 | for (;;) { 56 | sleep(1); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/has_entries.rb: -------------------------------------------------------------------------------- 1 | require 'mocha/parameter_matchers/base' 2 | require 'mocha/parameter_matchers/all_of' 3 | require 'mocha/parameter_matchers/has_entry' 4 | 5 | module Mocha 6 | 7 | module ParameterMatchers 8 | 9 | # :call-seq: has_entries(entries) -> parameter_matcher 10 | # 11 | # Matches +Hash+ containing all +entries+. 12 | # object = mock() 13 | # object.expects(:method_1).with(has_entries('key_1' => 1, 'key_2' => 2)) 14 | # object.method_1('key_1' => 1, 'key_2' => 2, 'key_3' => 3) 15 | # # no error raised 16 | # 17 | # object = mock() 18 | # object.expects(:method_1).with(has_entries('key_1' => 1, 'key_2' => 2)) 19 | # object.method_1('key_1' => 1, 'key_2' => 99) 20 | # # error raised, because method_1 was not called with Hash containing entries: 'key_1' => 1, 'key_2' => 2 21 | def has_entries(entries) 22 | HasEntries.new(entries) 23 | end 24 | 25 | class HasEntries < Base # :nodoc: 26 | 27 | def initialize(entries) 28 | @entries = entries 29 | end 30 | 31 | def matches?(available_parameters) 32 | parameter = available_parameters.shift 33 | has_entry_matchers = @entries.map { |key, value| HasEntry.new(key, value) } 34 | AllOf.new(*has_entry_matchers).matches?([parameter]) 35 | end 36 | 37 | def mocha_inspect 38 | "has_entries(#{@entries.mocha_inspect})" 39 | end 40 | 41 | end 42 | 43 | end 44 | 45 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/acceptance/stub_everything_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "acceptance_test_helper") 2 | require 'mocha' 3 | 4 | class StubEverythingTest < Test::Unit::TestCase 5 | 6 | include AcceptanceTest 7 | 8 | def setup 9 | setup_acceptance_test 10 | end 11 | 12 | def teardown 13 | teardown_acceptance_test 14 | end 15 | 16 | def test_should_build_stub_and_explicitly_add_an_expectation 17 | test_result = run_test do 18 | foo = stub_everything() 19 | foo.stubs(:bar) 20 | foo.bar 21 | foo.unexpected_invocation 22 | end 23 | assert_passed(test_result) 24 | end 25 | 26 | def test_should_build_named_stub_and_explicitly_add_an_expectation 27 | test_result = run_test do 28 | foo = stub_everything('foo') 29 | foo.stubs(:bar) 30 | foo.bar 31 | foo.unexpected_invocation 32 | end 33 | assert_passed(test_result) 34 | end 35 | 36 | def test_should_build_stub_incorporating_two_expectations 37 | test_result = run_test do 38 | foo = stub_everything(:bar => 'bar', :baz => 'baz') 39 | foo.bar 40 | foo.baz 41 | foo.unexpected_invocation 42 | end 43 | assert_passed(test_result) 44 | end 45 | 46 | def test_should_build_named_stub_incorporating_two_expectations 47 | test_result = run_test do 48 | foo = stub_everything('foo', :bar => 'bar', :baz => 'baz') 49 | foo.bar 50 | foo.baz 51 | foo.unexpected_invocation 52 | end 53 | assert_passed(test_result) 54 | end 55 | 56 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/acceptance/return_value_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "acceptance_test_helper") 2 | require 'mocha' 3 | 4 | class ReturnValueTest < Test::Unit::TestCase 5 | 6 | include AcceptanceTest 7 | 8 | def setup 9 | setup_acceptance_test 10 | end 11 | 12 | def teardown 13 | teardown_acceptance_test 14 | end 15 | 16 | def test_should_build_mock_and_explicitly_add_an_expectation_with_a_return_value 17 | test_result = run_test do 18 | foo = mock('foo') 19 | foo.expects(:bar).returns('bar') 20 | assert_equal 'bar', foo.bar 21 | end 22 | assert_passed(test_result) 23 | end 24 | 25 | def test_should_build_mock_incorporating_two_expectations_with_return_values 26 | test_result = run_test do 27 | foo = mock('foo', :bar => 'bar', :baz => 'baz') 28 | assert_equal 'bar', foo.bar 29 | assert_equal 'baz', foo.baz 30 | end 31 | assert_passed(test_result) 32 | end 33 | 34 | def test_should_build_stub_and_explicitly_add_an_expectation_with_a_return_value 35 | test_result = run_test do 36 | foo = stub('foo') 37 | foo.stubs(:bar).returns('bar') 38 | assert_equal 'bar', foo.bar 39 | end 40 | assert_passed(test_result) 41 | end 42 | 43 | def test_should_build_stub_incorporating_two_expectations_with_return_values 44 | test_result = run_test do 45 | foo = stub('foo', :bar => 'bar', :baz => 'baz') 46 | assert_equal 'bar', foo.bar 47 | assert_equal 'baz', foo.baz 48 | end 49 | assert_passed(test_result) 50 | end 51 | 52 | end -------------------------------------------------------------------------------- /vendor/gems/dust-0.1.6/rakefile.rb: -------------------------------------------------------------------------------- 1 | require 'rubygems' 2 | require 'rake/gempackagetask' 3 | require 'rake/rdoctask' 4 | require 'rake/contrib/sshpublisher' 5 | 6 | task :default => :test 7 | 8 | task :test do 9 | require File.dirname(__FILE__) + '/test/all_tests.rb' 10 | end 11 | 12 | desc 'Generate RDoc' 13 | Rake::RDocTask.new do |task| 14 | task.main = 'README' 15 | task.title = 'Dust' 16 | task.rdoc_dir = 'doc' 17 | task.options << "--line-numbers" << "--inline-source" 18 | task.rdoc_files.include('README', 'lib/**/*.rb') 19 | end 20 | 21 | desc "Upload RDoc to RubyForge" 22 | task :publish_rdoc => [:rdoc] do 23 | Rake::SshDirPublisher.new("jaycfields@rubyforge.org", "/var/www/gforge-projects/dust", "doc").upload 24 | end 25 | 26 | Gem::manage_gems 27 | 28 | specification = Gem::Specification.new do |s| 29 | s.name = "dust" 30 | s.summary = "Dust is an add on for Test::Unit that allows an alternative test definintion syntax." 31 | s.version = "0.1.6" 32 | s.author = 'Jay Fields' 33 | s.description = "Dust is an add on for Test::Unit that allows an alternative test definintion syntax." 34 | s.email = 'dust-developer@rubyforge.org' 35 | s.homepage = 'http://dust.rubyforge.org' 36 | s.rubyforge_project = 'dust' 37 | 38 | s.has_rdoc = true 39 | s.extra_rdoc_files = ['README'] 40 | s.rdoc_options << '--title' << 'Dust' << '--main' << 'README' << '--line-numbers' 41 | 42 | s.autorequire = 'dust' 43 | s.files = FileList['{lib,test}/**/*.rb', '[A-Z]*$', 'rakefile.rb'].to_a 44 | s.test_file = "test/all_tests.rb" 45 | end 46 | 47 | Rake::GemPackageTask.new(specification) do |package| 48 | package.need_zip = false 49 | package.need_tar = false 50 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/unit/exception_raiser_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "..", "test_helper") 2 | 3 | require 'mocha/exception_raiser' 4 | require 'timeout' 5 | 6 | class ExceptionRaiserTest < Test::Unit::TestCase 7 | 8 | include Mocha 9 | 10 | def test_should_raise_exception_with_specified_class_and_default_message 11 | exception_class = Class.new(StandardError) 12 | raiser = ExceptionRaiser.new(exception_class, nil) 13 | exception = assert_raises(exception_class) { raiser.evaluate } 14 | assert_equal exception_class.to_s, exception.message 15 | end 16 | 17 | def test_should_raise_exception_with_specified_class_and_message 18 | exception_class = Class.new(StandardError) 19 | raiser = ExceptionRaiser.new(exception_class, 'message') 20 | exception = assert_raises(exception_class) { raiser.evaluate } 21 | assert_equal 'message', exception.message 22 | end 23 | 24 | def test_should_raise_exception_instance 25 | exception_class = Class.new(StandardError) 26 | raiser = ExceptionRaiser.new(exception_class.new('message'), nil) 27 | exception = assert_raises(exception_class) { raiser.evaluate } 28 | assert_equal 'message', exception.message 29 | end 30 | 31 | def test_should_raise_interrupt_exception_with_default_message_so_it_works_in_ruby_1_8_6 32 | raiser = ExceptionRaiser.new(Interrupt, nil) 33 | assert_raises(Interrupt) { raiser.evaluate } 34 | end 35 | 36 | def test_should_raise_subclass_of_interrupt_exception_with_default_message_so_it_works_in_ruby_1_8_6 37 | exception_class = Class.new(Interrupt) 38 | raiser = ExceptionRaiser.new(exception_class, nil) 39 | assert_raises(exception_class) { raiser.evaluate } 40 | end 41 | 42 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/unit/central_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "..", "test_helper") 2 | 3 | require 'mocha/central' 4 | require 'mocha/mock' 5 | require 'method_definer' 6 | 7 | class CentralTest < Test::Unit::TestCase 8 | 9 | include Mocha 10 | 11 | def test_should_start_with_empty_stubba_methods 12 | stubba = Central.new 13 | 14 | assert_equal [], stubba.stubba_methods 15 | end 16 | 17 | def test_should_stub_method_if_not_already_stubbed 18 | method = Mock.new 19 | method.expects(:stub) 20 | stubba = Central.new 21 | 22 | stubba.stub(method) 23 | 24 | assert method.__verified__? 25 | end 26 | 27 | def test_should_not_stub_method_if_already_stubbed 28 | method = Mock.new 29 | method.expects(:stub).times(0) 30 | stubba = Central.new 31 | stubba_methods = Mock.new 32 | stubba_methods.stubs(:include?).with(method).returns(true) 33 | stubba.stubba_methods = stubba_methods 34 | 35 | stubba.stub(method) 36 | 37 | assert method.__verified__? 38 | end 39 | 40 | def test_should_record_method 41 | method = Mock.new 42 | method.expects(:stub) 43 | stubba = Central.new 44 | 45 | stubba.stub(method) 46 | 47 | assert_equal [method], stubba.stubba_methods 48 | end 49 | 50 | def test_should_unstub_all_methods 51 | stubba = Central.new 52 | method_1 = Mock.new 53 | method_1.expects(:unstub) 54 | method_2 = Mock.new 55 | method_2.expects(:unstub) 56 | stubba.stubba_methods = [method_1, method_2] 57 | 58 | stubba.unstub_all 59 | 60 | assert_equal [], stubba.stubba_methods 61 | assert method_1.__verified__? 62 | assert method_2.__verified__? 63 | end 64 | 65 | end 66 | -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/lib/mocha/any_instance_method.rb: -------------------------------------------------------------------------------- 1 | require 'mocha/class_method' 2 | 3 | module Mocha 4 | 5 | class AnyInstanceMethod < ClassMethod 6 | 7 | def unstub 8 | remove_new_method 9 | restore_original_method 10 | stubbee.any_instance.reset_mocha 11 | end 12 | 13 | def mock 14 | stubbee.any_instance.mocha 15 | end 16 | 17 | def hide_original_method 18 | if method_exists?(method) 19 | begin 20 | stubbee.class_eval("alias_method :#{hidden_method}, :#{method}", __FILE__, __LINE__) 21 | rescue NameError 22 | # deal with nasties like ActiveRecord::Associations::AssociationProxy 23 | end 24 | end 25 | end 26 | 27 | def define_new_method 28 | stubbee.class_eval("def #{method}(*args, &block); self.class.any_instance.mocha.method_missing(:#{method}, *args, &block); end", __FILE__, __LINE__) 29 | end 30 | 31 | def remove_new_method 32 | stubbee.class_eval("remove_method :#{method}", __FILE__, __LINE__) 33 | end 34 | 35 | def restore_original_method 36 | if method_exists?(hidden_method) 37 | begin 38 | stubbee.class_eval("alias_method :#{method}, :#{hidden_method}; remove_method :#{hidden_method}", __FILE__, __LINE__) 39 | rescue NameError 40 | # deal with nasties like ActiveRecord::Associations::AssociationProxy 41 | end 42 | end 43 | end 44 | 45 | def method_exists?(method) 46 | return true if stubbee.public_instance_methods(false).include?(method) 47 | return true if stubbee.protected_instance_methods(false).include?(method) 48 | return true if stubbee.private_instance_methods(false).include?(method) 49 | return false 50 | end 51 | 52 | end 53 | 54 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/optionally.rb: -------------------------------------------------------------------------------- 1 | module Mocha 2 | 3 | module ParameterMatchers 4 | 5 | # :call-seq: optionally(*parameter_matchers) -> parameter_matcher 6 | # 7 | # Matches optional parameters if available. 8 | # object = mock() 9 | # object.expects(:method_1).with(1, 2, optionally(3, 4)) 10 | # object.method_1(1, 2) 11 | # # no error raised 12 | # 13 | # object = mock() 14 | # object.expects(:method_1).with(1, 2, optionally(3, 4)) 15 | # object.method_1(1, 2, 3) 16 | # # no error raised 17 | # 18 | # object = mock() 19 | # object.expects(:method_1).with(1, 2, optionally(3, 4)) 20 | # object.method_1(1, 2, 3, 4) 21 | # # no error raised 22 | # 23 | # object = mock() 24 | # object.expects(:method_1).with(1, 2, optionally(3, 4)) 25 | # object.method_1(1, 2, 3, 5) 26 | # # error raised, because optional parameters did not match 27 | def optionally(*matchers) 28 | Optionally.new(*matchers) 29 | end 30 | 31 | class Optionally < Base # :nodoc: 32 | 33 | def initialize(*parameters) 34 | @matchers = parameters.map { |parameter| parameter.to_matcher } 35 | end 36 | 37 | def matches?(available_parameters) 38 | index = 0 39 | while (available_parameters.length > 0) && (index < @matchers.length) do 40 | matcher = @matchers[index] 41 | return false unless matcher.matches?(available_parameters) 42 | index += 1 43 | end 44 | return true 45 | end 46 | 47 | def mocha_inspect 48 | "optionally(#{@matchers.map { |matcher| matcher.mocha_inspect }.join(", ") })" 49 | end 50 | 51 | end 52 | 53 | end 54 | 55 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/README: -------------------------------------------------------------------------------- 1 | = Mocha 2 | 3 | Mocha is a library for mocking and stubbing using a syntax like that of JMock[http://www.jmock.org]. 4 | 5 | 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/]. 6 | 7 | Mocha provides a unified, simple and readable syntax for both traditional mocking and partial mocking. 8 | 9 | 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]. 10 | 11 | == Download and Installation 12 | 13 | Install the gem with the following command... 14 | 15 | $ gem install mocha 16 | 17 | Or install the Rails[http://www.rubyonrails.org] plugin... 18 | 19 | $ script/plugin install svn://rubyforge.org/var/svn/mocha/trunk 20 | 21 | Or download Mocha from here - http://rubyforge.org/projects/mocha 22 | 23 | == Examples 24 | 25 | * Quick Start - {Usage Examples}[link:examples/misc.html] 26 | * Traditional mocking - {Star Trek Example}[link:examples/mocha.html] 27 | * Setting expectations on real classes - {Order Example}[link:examples/stubba.html] 28 | * More examples on {Floehopper's Blog}[http://blog.floehopper.org] 29 | * {Mailing List Archives}[http://rubyforge.org/pipermail/mocha-developer/] 30 | 31 | == License 32 | 33 | Copyright Revieworld Ltd. 2006 34 | 35 | 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]. -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/acceptance/states_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "acceptance_test_helper") 2 | require 'mocha' 3 | 4 | class StatesTest < Test::Unit::TestCase 5 | 6 | include AcceptanceTest 7 | 8 | def setup 9 | setup_acceptance_test 10 | end 11 | 12 | def teardown 13 | teardown_acceptance_test 14 | end 15 | 16 | def test_should_constrain_expectations_to_occur_within_a_given_state 17 | test_result = run_test do 18 | mock = mock() 19 | readiness = states('readiness') 20 | 21 | mock.stubs(:first).when(readiness.is('ready')) 22 | mock.stubs(:second).then(readiness.is('ready')) 23 | 24 | mock.first 25 | end 26 | assert_failed(test_result) 27 | end 28 | 29 | def test_should_allow_expectations_to_occur_in_correct_state 30 | test_result = run_test do 31 | mock = mock() 32 | readiness = states('readiness') 33 | 34 | mock.stubs(:first).when(readiness.is('ready')) 35 | mock.stubs(:second).then(readiness.is('ready')) 36 | 37 | mock.second 38 | mock.first 39 | end 40 | assert_passed(test_result) 41 | end 42 | 43 | def test_should_be_able_to_start_in_a_specific_state 44 | test_result = run_test do 45 | mock = mock() 46 | readiness = states('readiness') 47 | 48 | mock.stubs(:first).when(readiness.is('ready')) 49 | 50 | readiness.starts_as('ready') 51 | mock.first 52 | end 53 | assert_passed(test_result) 54 | end 55 | 56 | def test_should_switch_state_when_method_raises_an_exception 57 | test_result = run_test do 58 | mock = mock() 59 | readiness = states('readiness') 60 | 61 | mock.expects(:first).raises().then(readiness.is('ready')) 62 | mock.expects(:second).when(readiness.is('ready')) 63 | 64 | mock.first rescue nil 65 | mock.second 66 | end 67 | assert_passed(test_result) 68 | end 69 | 70 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/examples/stubba.rb: -------------------------------------------------------------------------------- 1 | class Order 2 | 3 | attr_accessor :shipped_on 4 | 5 | def total_cost 6 | line_items.inject(0) { |total, line_item| total + line_item.price } + shipping_cost 7 | end 8 | 9 | def total_weight 10 | line_items.inject(0) { |total, line_item| total + line_item.weight } 11 | end 12 | 13 | def shipping_cost 14 | total_weight * 5 + 10 15 | end 16 | 17 | class << self 18 | 19 | def find_all 20 | # Database.connection.execute('select * from orders... 21 | end 22 | 23 | def number_shipped_since(date) 24 | find_all.select { |order| order.shipped_on > date }.length 25 | end 26 | 27 | def unshipped_value 28 | find_all.inject(0) { |total, order| order.shipped_on ? total : total + order.total_cost } 29 | end 30 | 31 | end 32 | 33 | end 34 | 35 | require 'test/unit' 36 | require 'rubygems' 37 | require 'mocha' 38 | 39 | class OrderTest < Test::Unit::TestCase 40 | 41 | # illustrates stubbing instance method 42 | def test_should_calculate_shipping_cost_based_on_total_weight 43 | order = Order.new 44 | order.stubs(:total_weight).returns(10) 45 | assert_equal 60, order.shipping_cost 46 | end 47 | 48 | # illustrates stubbing class method 49 | def test_should_count_number_of_orders_shipped_after_specified_date 50 | now = Time.now; week_in_secs = 7 * 24 * 60 * 60 51 | order_1 = Order.new; order_1.shipped_on = now - 1 * week_in_secs 52 | order_2 = Order.new; order_2.shipped_on = now - 3 * week_in_secs 53 | Order.stubs(:find_all).returns([order_1, order_2]) 54 | assert_equal 1, Order.number_shipped_since(now - 2 * week_in_secs) 55 | end 56 | 57 | # illustrates stubbing instance method for all instances of a class 58 | def test_should_calculate_value_of_unshipped_orders 59 | Order.stubs(:find_all).returns([Order.new, Order.new, Order.new]) 60 | Order.any_instance.stubs(:shipped_on).returns(nil) 61 | Order.any_instance.stubs(:total_cost).returns(10) 62 | assert_equal 30, Order.unshipped_value 63 | end 64 | 65 | end 66 | -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/has_entry.rb: -------------------------------------------------------------------------------- 1 | require 'mocha/parameter_matchers/base' 2 | 3 | module Mocha 4 | 5 | module ParameterMatchers 6 | 7 | # :call-seq: has_entry(key, value) -> parameter_matcher 8 | # has_entry(key => value) -> parameter_matcher 9 | # 10 | # Matches +Hash+ containing entry with +key+ and +value+. 11 | # object = mock() 12 | # object.expects(:method_1).with(has_entry('key_1', 1)) 13 | # object.method_1('key_1' => 1, 'key_2' => 2) 14 | # # no error raised 15 | # 16 | # object = mock() 17 | # object.expects(:method_1).with(has_entry('key_1' => 1)) 18 | # object.method_1('key_1' => 1, 'key_2' => 2) 19 | # # no error raised 20 | # 21 | # object = mock() 22 | # object.expects(:method_1).with(has_entry('key_1', 1)) 23 | # object.method_1('key_1' => 2, 'key_2' => 1) 24 | # # error raised, because method_1 was not called with Hash containing entry: 'key_1' => 1 25 | # 26 | # object = mock() 27 | # object.expects(:method_1).with(has_entry('key_1' => 1)) 28 | # object.method_1('key_1' => 2, 'key_2' => 1) 29 | # # error raised, because method_1 was not called with Hash containing entry: 'key_1' => 1 30 | def has_entry(*options) 31 | key, value = options.shift, options.shift 32 | key, value = key.to_a[0][0..1] if key.is_a?(Hash) 33 | HasEntry.new(key, value) 34 | end 35 | 36 | class HasEntry < Base # :nodoc: 37 | 38 | def initialize(key, value) 39 | @key, @value = key, value 40 | end 41 | 42 | def matches?(available_parameters) 43 | parameter = available_parameters.shift 44 | matching_keys = parameter.keys.select { |key| @key.to_matcher.matches?([key]) } 45 | matching_keys.any? { |key| @value.to_matcher.matches?([parameter[key]]) } 46 | end 47 | 48 | def mocha_inspect 49 | "has_entry(#{@key.mocha_inspect} => #{@value.mocha_inspect})" 50 | end 51 | 52 | end 53 | 54 | end 55 | 56 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/acceptance/stubba_test_result_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "acceptance_test_helper") 2 | require 'mocha' 3 | require 'execution_point' 4 | 5 | class StubbaTestResultTest < Test::Unit::TestCase 6 | 7 | include AcceptanceTest 8 | 9 | def setup 10 | setup_acceptance_test 11 | end 12 | 13 | def teardown 14 | teardown_acceptance_test 15 | end 16 | 17 | def test_should_include_expectation_verification_in_assertion_count 18 | test_result = run_test do 19 | object = Class.new { def message; end }.new 20 | object.expects(:message) 21 | object.message 22 | end 23 | assert_equal 1, test_result.assertion_count 24 | end 25 | 26 | def test_should_include_assertions_in_assertion_count 27 | test_result = run_test do 28 | assert true 29 | end 30 | assert_equal 1, test_result.assertion_count 31 | end 32 | 33 | def test_should_not_include_stubbing_expectation_verification_in_assertion_count 34 | test_result = run_test do 35 | object = Class.new { def message; end }.new 36 | object.stubs(:message) 37 | object.message 38 | end 39 | assert_equal 0, test_result.assertion_count 40 | end 41 | 42 | def test_should_include_expectation_verification_failure_in_failure_count 43 | test_result = run_test do 44 | object = Class.new { def message; end }.new 45 | object.expects(:message) 46 | end 47 | assert_equal 1, test_result.failure_count 48 | end 49 | 50 | def test_should_include_assertion_failure_in_failure_count 51 | test_result = run_test do 52 | flunk 53 | end 54 | assert_equal 1, test_result.failure_count 55 | end 56 | 57 | def test_should_display_backtrace_indicating_line_number_where_failing_assertion_was_called 58 | execution_point = nil 59 | test_result = run_test do 60 | execution_point = ExecutionPoint.current; flunk 61 | end 62 | assert_equal 1, test_result.failure_count 63 | assert_equal execution_point, ExecutionPoint.new(test_result.failures[0].location) 64 | end 65 | 66 | end -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- 1 | === 1.2.4 / 2011-06-11 2 | 3 | - Renamed the gem for seemless bundler integration: 4 | SystemTimer -> system_timer 5 | Per https://github.com/ph7/system-timer/issues/16 6 | (Suggested by David Heinemeier Hansson) 7 | 8 | === 1.2.3 / 2011-03-19 9 | 10 | - Fix for RubyGems 1.6 11 | (Contributed by James Tucker ) 12 | 13 | === 1.2.2 / 2011-01-25 14 | 15 | * Explicit required_ruby_version = '~> 1.8.7' in gem spec. 16 | (Contributed by Jesse Storimer ) 17 | 18 | === 1.2.1 / 2010-11-15 19 | 20 | * Better Rubinious support (Contributed by 21 | Evan Phoenix ) 22 | 23 | === 1.2 / 2010-02-25 24 | 25 | * Changed from using Mutex to Monitor. Mutex causes thread join 26 | errors when Ruby is compiled with -disable-pthreads 27 | (Contributed by Dmytro Shteflyuk ) 28 | 29 | * Timeouts can now be specified as a float and be a fraction of a second. 30 | e.g. `SystemTimer.timeout(0.5)` 31 | (Based on a contribution by Dmytro Shteflyuk ) 32 | 33 | * Added support for custom timeout exception. Useful to avoid interference 34 | with other libraries using `Timeout::Error` (e.g. `Net::HTTP`) 35 | (Contributed by runix ) 36 | 37 | === 1.1.3/ 2009-11-29 38 | 39 | * Preparing GemCutter migration 40 | 41 | === 1.1.2 + 1.1.3/ 2009-29-11 42 | 43 | * Preparing GemCutter migration 44 | 45 | === 1.1.1 / 2009-03-10 46 | 47 | * Fixing set_itimerval_with_minimum_1s_interval method signature 48 | which was incorrect and resulted in a segfault on 64 bits 49 | platform (int versus VALUE). Thanks to Mike Perham for 50 | investigating the problem and sending the patch! 51 | 52 | === 1.1.0 / 2008-11-05 53 | 54 | * New implementation supporting concurrent timers, i.e. : 55 | 56 | (1..10).each do 57 | Thread.new do 58 | SystemTimer.timeout_after(5) do 59 | sleep 60 60 | puts "hi there!" 61 | end 62 | end 63 | end 64 | 65 | === 1.0.0 / 2008-02-27 66 | 67 | * Initial Release 68 | 69 | -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/acceptance/failure_messages_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "acceptance_test_helper") 2 | require 'mocha' 3 | 4 | class FailureMessagesTest < Test::Unit::TestCase 5 | 6 | OBJECT_ADDRESS_PATTERN = '0x[0-9A-Fa-f]{1,12}' 7 | 8 | include AcceptanceTest 9 | 10 | def setup 11 | setup_acceptance_test 12 | end 13 | 14 | def teardown 15 | teardown_acceptance_test 16 | end 17 | 18 | class Foo; end 19 | 20 | def test_should_display_class_name_when_expectation_was_on_class 21 | test_result = run_test do 22 | Foo.expects(:bar) 23 | end 24 | assert_match Regexp.new('FailureMessagesTest::Foo'), test_result.failures[0].message 25 | end 26 | 27 | def test_should_display_class_name_and_address_when_expectation_was_on_instance 28 | test_result = run_test do 29 | Foo.new.expects(:bar) 30 | end 31 | assert_match Regexp.new("#"), test_result.failures[0].message 32 | end 33 | 34 | def test_should_display_class_name_and_any_instance_prefix_when_expectation_was_on_any_instance 35 | test_result = run_test do 36 | Foo.any_instance.expects(:bar) 37 | end 38 | assert_match Regexp.new('#'), test_result.failures[0].message 39 | end 40 | 41 | def test_should_display_mock_name_when_expectation_was_on_named_mock 42 | test_result = run_test do 43 | foo = mock('foo') 44 | foo.expects(:bar) 45 | end 46 | assert_match Regexp.new('#'), test_result.failures[0].message 47 | end 48 | 49 | def test_should_display_mock_address_when_expectation_was_on_unnamed_mock 50 | test_result = run_test do 51 | foo = mock() 52 | foo.expects(:bar) 53 | end 54 | assert_match Regexp.new("#"), test_result.failures[0].message 55 | end 56 | 57 | def test_should_display_string_when_expectation_was_on_string 58 | test_result = run_test do 59 | 'Foo'.expects(:bar) 60 | end 61 | assert_match Regexp.new("'Foo'"), test_result.failures[0].message 62 | end 63 | 64 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/lib/mocha/configuration.rb: -------------------------------------------------------------------------------- 1 | module Mocha # :nodoc: 2 | 3 | # Configuration settings 4 | class Configuration 5 | 6 | DEFAULTS = { :stubbing_method_unnecessarily => :allow, :stubbing_method_on_non_mock_object => :allow, :stubbing_non_existent_method => :allow, :stubbing_non_public_method => :allow } 7 | 8 | class << self 9 | 10 | # :call-seq: allow(action) 11 | # 12 | # Allow the specified action (as a symbol). 13 | # The actions currently available are :stubbing_method_unnecessarily, :stubbing_method_on_non_mock_object, :stubbing_non_existent_method, :stubbing_non_public_method. 14 | def allow(action) 15 | configuration[action] = :allow 16 | end 17 | 18 | def allow?(action) # :nodoc: 19 | configuration[action] == :allow 20 | end 21 | 22 | # :call-seq: warn_when(action) 23 | # 24 | # Warn if the specified action (as a symbol) is attempted. 25 | # The actions currently available are :stubbing_method_unnecessarily, :stubbing_method_on_non_mock_object, :stubbing_non_existent_method, :stubbing_non_public_method. 26 | def warn_when(action) 27 | configuration[action] = :warn 28 | end 29 | 30 | def warn_when?(action) # :nodoc: 31 | configuration[action] == :warn 32 | end 33 | 34 | # :call-seq: prevent(action) 35 | # 36 | # Raise a StubbingError if the specified action (as a symbol) is attempted. 37 | # The actions currently available are :stubbing_method_unnecessarily, :stubbing_method_on_non_mock_object, :stubbing_non_existent_method, :stubbing_non_public_method. 38 | def prevent(action) 39 | configuration[action] = :prevent 40 | end 41 | 42 | def prevent?(action) # :nodoc: 43 | configuration[action] == :prevent 44 | end 45 | 46 | def reset_configuration # :nodoc: 47 | @configuration = nil 48 | end 49 | 50 | private 51 | 52 | def configuration # :nodoc: 53 | @configuration ||= DEFAULTS.dup 54 | end 55 | 56 | end 57 | 58 | end 59 | 60 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/unit/return_values_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "..", "test_helper") 2 | 3 | require 'mocha/return_values' 4 | 5 | class ReturnValuesTest < Test::Unit::TestCase 6 | 7 | include Mocha 8 | 9 | def test_should_return_nil 10 | values = ReturnValues.new 11 | assert_nil values.next 12 | end 13 | 14 | def test_should_keep_returning_nil 15 | values = ReturnValues.new 16 | values.next 17 | assert_nil values.next 18 | assert_nil values.next 19 | end 20 | 21 | def test_should_return_evaluated_single_return_value 22 | values = ReturnValues.new(SingleReturnValue.new('value')) 23 | assert_equal 'value', values.next 24 | end 25 | 26 | def test_should_keep_returning_evaluated_single_return_value 27 | values = ReturnValues.new(SingleReturnValue.new('value')) 28 | values.next 29 | assert_equal 'value', values.next 30 | assert_equal 'value', values.next 31 | end 32 | 33 | def test_should_return_consecutive_evaluated_single_return_values 34 | values = ReturnValues.new(SingleReturnValue.new('value_1'), SingleReturnValue.new('value_2')) 35 | assert_equal 'value_1', values.next 36 | assert_equal 'value_2', values.next 37 | end 38 | 39 | def test_should_keep_returning_last_of_consecutive_evaluated_single_return_values 40 | values = ReturnValues.new(SingleReturnValue.new('value_1'), SingleReturnValue.new('value_2')) 41 | values.next 42 | values.next 43 | assert_equal 'value_2', values.next 44 | assert_equal 'value_2', values.next 45 | end 46 | 47 | def test_should_build_single_return_values_for_each_values 48 | values = ReturnValues.build('value_1', 'value_2', 'value_3').values 49 | assert_equal 'value_1', values[0].evaluate 50 | assert_equal 'value_2', values[1].evaluate 51 | assert_equal 'value_3', values[2].evaluate 52 | end 53 | 54 | def test_should_combine_two_sets_of_return_values 55 | values_1 = ReturnValues.build('value_1') 56 | values_2 = ReturnValues.build('value_2a', 'value_2b') 57 | values = (values_1 + values_2).values 58 | assert_equal 'value_1', values[0].evaluate 59 | assert_equal 'value_2a', values[1].evaluate 60 | assert_equal 'value_2b', values[2].evaluate 61 | end 62 | 63 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/acceptance/optional_parameters_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "acceptance_test_helper") 2 | require 'mocha' 3 | 4 | class OptionalParameterMatcherTest < Test::Unit::TestCase 5 | 6 | include AcceptanceTest 7 | 8 | def setup 9 | setup_acceptance_test 10 | end 11 | 12 | def teardown 13 | teardown_acceptance_test 14 | end 15 | 16 | def test_should_pass_if_all_required_parameters_match_and_no_optional_parameters_are_supplied 17 | test_result = run_test do 18 | mock = mock() 19 | mock.expects(:method).with(1, 2, optionally(3, 4)) 20 | mock.method(1, 2) 21 | end 22 | assert_passed(test_result) 23 | end 24 | 25 | def test_should_pass_if_all_required_and_optional_parameters_match_and_some_optional_parameters_are_supplied 26 | test_result = run_test do 27 | mock = mock() 28 | mock.expects(:method).with(1, 2, optionally(3, 4)) 29 | mock.method(1, 2, 3) 30 | end 31 | assert_passed(test_result) 32 | end 33 | 34 | def test_should_pass_if_all_required_and_optional_parameters_match_and_all_optional_parameters_are_supplied 35 | test_result = run_test do 36 | mock = mock() 37 | mock.expects(:method).with(1, 2, optionally(3, 4)) 38 | mock.method(1, 2, 3, 4) 39 | end 40 | assert_passed(test_result) 41 | end 42 | 43 | def test_should_fail_if_all_required_and_optional_parameters_match_but_too_many_optional_parameters_are_supplied 44 | test_result = run_test do 45 | mock = mock() 46 | mock.expects(:method).with(1, 2, optionally(3, 4)) 47 | mock.method(1, 2, 3, 4, 5) 48 | end 49 | assert_failed(test_result) 50 | end 51 | 52 | def test_should_fail_if_all_required_parameters_match_but_some_optional_parameters_do_not_match 53 | test_result = run_test do 54 | mock = mock() 55 | mock.expects(:method).with(1, 2, optionally(3, 4)) 56 | mock.method(1, 2, 4) 57 | end 58 | assert_failed(test_result) 59 | end 60 | 61 | def test_should_fail_if_all_required_parameters_match_but_no_optional_parameters_match 62 | test_result = run_test do 63 | mock = mock() 64 | mock.expects(:method).with(1, 2, optionally(3, 4)) 65 | mock.method(1, 2, 4, 5) 66 | end 67 | assert_failed(test_result) 68 | end 69 | 70 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/acceptance/stubbing_method_unnecessarily_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "acceptance_test_helper") 2 | require 'mocha' 3 | 4 | class StubbingMethodUnnecessarilyTest < Test::Unit::TestCase 5 | 6 | include AcceptanceTest 7 | 8 | def setup 9 | setup_acceptance_test 10 | end 11 | 12 | def teardown 13 | teardown_acceptance_test 14 | end 15 | 16 | def test_should_allow_stubbing_method_unnecessarily 17 | Mocha::Configuration.allow(:stubbing_method_unnecessarily) 18 | test_result = run_test do 19 | mock = mock('mock') 20 | mock.stubs(:public_method) 21 | end 22 | assert_passed(test_result) 23 | assert !@logger.warnings.include?('stubbing method unnecessarily: #.public_method(any_parameters)') 24 | end 25 | 26 | def test_should_warn_when_stubbing_method_unnecessarily 27 | Mocha::Configuration.warn_when(:stubbing_method_unnecessarily) 28 | test_result = run_test do 29 | mock = mock('mock') 30 | mock.stubs(:public_method) 31 | end 32 | assert_passed(test_result) 33 | assert @logger.warnings.include?('stubbing method unnecessarily: #.public_method(any_parameters)') 34 | end 35 | 36 | def test_should_prevent_stubbing_method_unnecessarily 37 | Mocha::Configuration.prevent(:stubbing_method_unnecessarily) 38 | test_result = run_test do 39 | mock = mock('mock') 40 | mock.stubs(:public_method) 41 | end 42 | assert_failed(test_result) 43 | assert test_result.error_messages.include?('Mocha::StubbingError: stubbing method unnecessarily: #.public_method(any_parameters)') 44 | end 45 | 46 | def test_should_default_to_allow_stubbing_method_unnecessarily 47 | test_result = run_test do 48 | mock = mock('mock') 49 | mock.stubs(:public_method) 50 | end 51 | assert_passed(test_result) 52 | assert !@logger.warnings.include?('stubbing method unnecessarily: #.public_method(any_parameters)') 53 | end 54 | 55 | def test_should_allow_stubbing_method_when_stubbed_method_is_invoked 56 | Mocha::Configuration.prevent(:stubbing_method_unnecessarily) 57 | test_result = run_test do 58 | mock = mock('mock') 59 | mock.stubs(:public_method) 60 | mock.public_method 61 | end 62 | assert_passed(test_result) 63 | end 64 | 65 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/lib/mocha/state_machine.rb: -------------------------------------------------------------------------------- 1 | module Mocha # :nodoc: 2 | 3 | # A state machine that is used to constrain the order of invocations. 4 | # An invocation can be constrained to occur when a state is, or is_not, active. 5 | class StateMachine 6 | 7 | class State # :nodoc: 8 | 9 | def initialize(state_machine, state) 10 | @state_machine, @state = state_machine, state 11 | end 12 | 13 | def activate 14 | @state_machine.current_state = @state 15 | end 16 | 17 | def active? 18 | @state_machine.current_state == @state 19 | end 20 | 21 | def mocha_inspect 22 | "#{@state_machine.name} is #{@state.mocha_inspect}" 23 | end 24 | 25 | end 26 | 27 | class StatePredicate # :nodoc: 28 | 29 | def initialize(state_machine, state) 30 | @state_machine, @state = state_machine, state 31 | end 32 | 33 | def active? 34 | @state_machine.current_state != @state 35 | end 36 | 37 | def mocha_inspect 38 | "#{@state_machine.name} is not #{@state.mocha_inspect}" 39 | end 40 | 41 | end 42 | 43 | attr_reader :name # :nodoc: 44 | 45 | attr_accessor :current_state # :nodoc: 46 | 47 | def initialize(name) # :nodoc: 48 | @name = name 49 | @current_state = nil 50 | end 51 | 52 | # :call-seq: starts_as(initial_state) -> state_machine 53 | # 54 | # Put the +state_machine+ into the +initial_state+. 55 | def starts_as(initial_state) 56 | become(initial_state) 57 | self 58 | end 59 | 60 | # :call-seq: become(next_state) 61 | # 62 | # Put the +state_machine+ into the +next_state+. 63 | def become(next_state) 64 | @current_state = next_state 65 | end 66 | 67 | # :call-seq: is(state) 68 | # 69 | # Determines whether the +state_machine+ is in the specified +state+. 70 | def is(state) 71 | State.new(self, state) 72 | end 73 | 74 | # :call-seq: is_not(state) 75 | # 76 | # Determines whether the +state_machine+ is not in the specified +state+. 77 | def is_not(state) 78 | StatePredicate.new(self, state) 79 | end 80 | 81 | def mocha_inspect # :nodoc: 82 | if @current_state 83 | "#{@name} is #{@current_state.mocha_inspect}" 84 | else 85 | "#{@name} has no current state" 86 | end 87 | end 88 | 89 | end 90 | 91 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/lib/mocha/cardinality.rb: -------------------------------------------------------------------------------- 1 | module Mocha 2 | 3 | class Cardinality 4 | 5 | INFINITY = 1 / 0.0 6 | 7 | class << self 8 | 9 | def exactly(count) 10 | new(count, count) 11 | end 12 | 13 | def at_least(count) 14 | new(count, INFINITY) 15 | end 16 | 17 | def at_most(count) 18 | new(0, count) 19 | end 20 | 21 | def times(range_or_count) 22 | case range_or_count 23 | when Range then new(range_or_count.first, range_or_count.last) 24 | else new(range_or_count, range_or_count) 25 | end 26 | end 27 | 28 | end 29 | 30 | def initialize(required, maximum) 31 | @required, @maximum = required, maximum 32 | end 33 | 34 | def invocations_allowed?(invocation_count) 35 | invocation_count < maximum 36 | end 37 | 38 | def satisfied?(invocations_so_far) 39 | invocations_so_far >= required 40 | end 41 | 42 | def needs_verifying? 43 | !allowed_any_number_of_times? 44 | end 45 | 46 | def verified?(invocation_count) 47 | (invocation_count >= required) && (invocation_count <= maximum) 48 | end 49 | 50 | def allowed_any_number_of_times? 51 | required == 0 && infinite?(maximum) 52 | end 53 | 54 | def used?(invocation_count) 55 | (invocation_count > 0) || (maximum == 0) 56 | end 57 | 58 | def mocha_inspect 59 | if allowed_any_number_of_times? 60 | "allowed any number of times" 61 | else 62 | if required == 0 && maximum == 0 63 | "expected never" 64 | elsif required == maximum 65 | "expected exactly #{times(required)}" 66 | elsif infinite?(maximum) 67 | "expected at least #{times(required)}" 68 | elsif required == 0 69 | "expected at most #{times(maximum)}" 70 | else 71 | "expected between #{required} and #{times(maximum)}" 72 | end 73 | end 74 | end 75 | 76 | protected 77 | 78 | attr_reader :required, :maximum 79 | 80 | def times(number) 81 | case number 82 | when 0 then "no times" 83 | when 1 then "once" 84 | when 2 then "twice" 85 | else "#{number} times" 86 | end 87 | end 88 | 89 | def infinite?(number) 90 | number.respond_to?(:infinite?) && number.infinite? 91 | end 92 | 93 | end 94 | 95 | end 96 | -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/has_entries_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "..", "..", "test_helper") 2 | 3 | require 'mocha/parameter_matchers/has_entries' 4 | require 'mocha/parameter_matchers/object' 5 | require 'mocha/inspect' 6 | 7 | class HasEntriesTest < Test::Unit::TestCase 8 | 9 | include Mocha::ParameterMatchers 10 | 11 | def test_should_match_hash_including_specified_entries 12 | matcher = has_entries(:key_1 => 'value_1', :key_2 => 'value_2') 13 | assert matcher.matches?([{ :key_1 => 'value_1', :key_2 => 'value_2', :key_3 => 'value_3' }]) 14 | end 15 | 16 | def test_should_not_match_hash_not_including_specified_entries 17 | matcher = has_entries(:key_1 => 'value_2', :key_2 => 'value_2', :key_3 => 'value_3') 18 | assert !matcher.matches?([{ :key_1 => 'value_1', :key_2 => 'value_2' }]) 19 | end 20 | 21 | def test_should_describe_matcher 22 | matcher = has_entries(:key_1 => 'value_1', :key_2 => 'value_2') 23 | description = matcher.mocha_inspect 24 | matches = /has_entries\((.*)\)/.match(description) 25 | assert_not_nil matches[0] 26 | entries = eval(matches[1], binding, __FILE__, __LINE__) 27 | assert_equal 'value_1', entries[:key_1] 28 | assert_equal 'value_2', entries[:key_2] 29 | end 30 | 31 | def test_should_match_hash_including_specified_entries_with_nested_key_matchers 32 | matcher = has_entries(equals(:key_1) => 'value_1', equals(:key_2) => 'value_2') 33 | assert matcher.matches?([{ :key_1 => 'value_1', :key_2 => 'value_2', :key_3 => 'value_3' }]) 34 | end 35 | 36 | def test_should_not_match_hash_not_including_specified_entries_with_nested_key_matchers 37 | matcher = has_entries(equals(:key_1) => 'value_2', equals(:key_2) => 'value_2', equals(:key_3) => 'value_3') 38 | assert !matcher.matches?([{ :key_1 => 'value_1', :key_2 => 'value_2' }]) 39 | end 40 | 41 | def test_should_match_hash_including_specified_entries_with_nested_value_matchers 42 | matcher = has_entries(:key_1 => equals('value_1'), :key_2 => equals('value_2')) 43 | assert matcher.matches?([{ :key_1 => 'value_1', :key_2 => 'value_2', :key_3 => 'value_3' }]) 44 | end 45 | 46 | def test_should_not_match_hash_not_including_specified_entries_with_nested_value_matchers 47 | matcher = has_entries(:key_1 => equals('value_2'), :key_2 => equals('value_2'), :key_3 => equals('value_3')) 48 | assert !matcher.matches?([{ :key_1 => 'value_1', :key_2 => 'value_2' }]) 49 | end 50 | 51 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/acceptance/mocked_methods_dispatch_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "acceptance_test_helper") 2 | require 'mocha' 3 | 4 | class MockedMethodDispatchTest < Test::Unit::TestCase 5 | 6 | include AcceptanceTest 7 | 8 | def setup 9 | setup_acceptance_test 10 | end 11 | 12 | def teardown 13 | teardown_acceptance_test 14 | end 15 | 16 | def test_should_find_latest_matching_expectation 17 | test_result = run_test do 18 | mock = mock() 19 | mock.stubs(:method).returns(1) 20 | mock.stubs(:method).returns(2) 21 | assert_equal 2, mock.method 22 | assert_equal 2, mock.method 23 | assert_equal 2, mock.method 24 | end 25 | assert_passed(test_result) 26 | end 27 | 28 | def test_should_find_latest_expectation_which_has_not_stopped_matching 29 | test_result = run_test do 30 | mock = mock() 31 | mock.stubs(:method).returns(1) 32 | mock.stubs(:method).once.returns(2) 33 | assert_equal 2, mock.method 34 | assert_equal 1, mock.method 35 | assert_equal 1, mock.method 36 | end 37 | assert_passed(test_result) 38 | end 39 | 40 | def test_should_keep_finding_later_stub_and_so_never_satisfy_earlier_expectation 41 | test_result = run_test do 42 | mock = mock() 43 | mock.expects(:method).returns(1) 44 | mock.stubs(:method).returns(2) 45 | assert_equal 2, mock.method 46 | assert_equal 2, mock.method 47 | assert_equal 2, mock.method 48 | end 49 | assert_failed(test_result) 50 | end 51 | 52 | def test_should_find_later_expectation_until_it_stops_matching_then_find_earlier_stub 53 | test_result = run_test do 54 | mock = mock() 55 | mock.stubs(:method).returns(1) 56 | mock.expects(:method).returns(2) 57 | assert_equal 2, mock.method 58 | assert_equal 1, mock.method 59 | assert_equal 1, mock.method 60 | end 61 | assert_passed(test_result) 62 | end 63 | 64 | def test_should_find_latest_expectation_with_range_of_expected_invocation_count_which_has_not_stopped_matching 65 | test_result = run_test do 66 | mock = mock() 67 | mock.stubs(:method).returns(1) 68 | mock.stubs(:method).times(2..3).returns(2) 69 | assert_equal 2, mock.method 70 | assert_equal 2, mock.method 71 | assert_equal 2, mock.method 72 | assert_equal 1, mock.method 73 | assert_equal 1, mock.method 74 | end 75 | assert_passed(test_result) 76 | end 77 | 78 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/acceptance/stubbing_on_non_mock_object_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "acceptance_test_helper") 2 | require 'mocha' 3 | 4 | class StubbingOnNonMockObjectTest < Test::Unit::TestCase 5 | 6 | include AcceptanceTest 7 | 8 | def setup 9 | setup_acceptance_test 10 | end 11 | 12 | def teardown 13 | teardown_acceptance_test 14 | end 15 | 16 | def test_should_allow_stubbing_method_on_non_mock_object 17 | Mocha::Configuration.allow(:stubbing_method_on_non_mock_object) 18 | non_mock_object = Class.new { def existing_method; end } 19 | test_result = run_test do 20 | non_mock_object.stubs(:existing_method) 21 | end 22 | assert_passed(test_result) 23 | assert !@logger.warnings.include?("stubbing method on non-mock object: #{non_mock_object}.existing_method") 24 | end 25 | 26 | def test_should_warn_on_stubbing_method_on_non_mock_object 27 | Mocha::Configuration.warn_when(:stubbing_method_on_non_mock_object) 28 | non_mock_object = Class.new { def existing_method; end } 29 | test_result = run_test do 30 | non_mock_object.stubs(:existing_method) 31 | end 32 | assert_passed(test_result) 33 | assert @logger.warnings.include?("stubbing method on non-mock object: #{non_mock_object}.existing_method") 34 | end 35 | 36 | def test_should_prevent_stubbing_method_on_non_mock_object 37 | Mocha::Configuration.prevent(:stubbing_method_on_non_mock_object) 38 | non_mock_object = Class.new { def existing_method; end } 39 | test_result = run_test do 40 | non_mock_object.stubs(:existing_method) 41 | end 42 | assert_failed(test_result) 43 | assert test_result.error_messages.include?("Mocha::StubbingError: stubbing method on non-mock object: #{non_mock_object}.existing_method") 44 | end 45 | 46 | def test_should_default_to_allow_stubbing_method_on_non_mock_object 47 | non_mock_object = Class.new { def existing_method; end } 48 | test_result = run_test do 49 | non_mock_object.stubs(:existing_method) 50 | end 51 | assert_passed(test_result) 52 | assert !@logger.warnings.include?("stubbing method on non-mock object: #{non_mock_object}.existing_method") 53 | end 54 | 55 | def test_should_allow_stubbing_method_on_mock_object 56 | Mocha::Configuration.prevent(:stubbing_method_on_non_mock_object) 57 | test_result = run_test do 58 | mock = mock('mock') 59 | mock.stubs(:any_method) 60 | end 61 | assert_passed(test_result) 62 | end 63 | 64 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/unit/cardinality_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "..", "test_helper") 2 | require 'mocha/cardinality' 3 | 4 | class CardinalityTest < Test::Unit::TestCase 5 | 6 | include Mocha 7 | 8 | def test_should_allow_invocations_if_invocation_count_has_not_yet_reached_maximum 9 | cardinality = Cardinality.new(2, 3) 10 | assert cardinality.invocations_allowed?(0) 11 | assert cardinality.invocations_allowed?(1) 12 | assert cardinality.invocations_allowed?(2) 13 | assert !cardinality.invocations_allowed?(3) 14 | end 15 | 16 | def test_should_be_satisfied_if_invocations_so_far_have_reached_required_threshold 17 | cardinality = Cardinality.new(2, 3) 18 | assert !cardinality.satisfied?(0) 19 | assert !cardinality.satisfied?(1) 20 | assert cardinality.satisfied?(2) 21 | assert cardinality.satisfied?(3) 22 | end 23 | 24 | def test_should_describe_cardinality 25 | assert_equal 'allowed any number of times', Cardinality.at_least(0).mocha_inspect 26 | 27 | assert_equal 'expected at most once', Cardinality.at_most(1).mocha_inspect 28 | assert_equal 'expected at most twice', Cardinality.at_most(2).mocha_inspect 29 | assert_equal 'expected at most 3 times', Cardinality.at_most(3).mocha_inspect 30 | 31 | assert_equal 'expected at least once', Cardinality.at_least(1).mocha_inspect 32 | assert_equal 'expected at least twice', Cardinality.at_least(2).mocha_inspect 33 | assert_equal 'expected at least 3 times', Cardinality.at_least(3).mocha_inspect 34 | 35 | assert_equal 'expected never', Cardinality.exactly(0).mocha_inspect 36 | assert_equal 'expected exactly once', Cardinality.exactly(1).mocha_inspect 37 | assert_equal 'expected exactly twice', Cardinality.exactly(2).mocha_inspect 38 | assert_equal 'expected exactly 3 times', Cardinality.times(3).mocha_inspect 39 | 40 | assert_equal 'expected between 2 and 4 times', Cardinality.times(2..4).mocha_inspect 41 | assert_equal 'expected between 1 and 3 times', Cardinality.times(1..3).mocha_inspect 42 | end 43 | 44 | def test_should_need_verifying 45 | assert Cardinality.exactly(2).needs_verifying? 46 | assert Cardinality.at_least(3).needs_verifying? 47 | assert Cardinality.at_most(2).needs_verifying? 48 | assert Cardinality.times(4).needs_verifying? 49 | assert Cardinality.times(2..4).needs_verifying? 50 | end 51 | 52 | def test_should_not_need_verifying 53 | assert_equal false, Cardinality.at_least(0).needs_verifying? 54 | end 55 | 56 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/unit/object_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "..", "test_helper") 2 | require 'mocha/object' 3 | require 'mocha/mockery' 4 | require 'mocha/mock' 5 | require 'method_definer' 6 | 7 | class ObjectTest < Test::Unit::TestCase 8 | 9 | include Mocha 10 | 11 | def test_should_build_mocha_referring_to_self 12 | instance = Object.new 13 | mocha = instance.mocha 14 | assert_not_nil mocha 15 | assert mocha.is_a?(Mock) 16 | assert_equal instance.mocha_inspect, mocha.mocha_inspect 17 | end 18 | 19 | def test_should_reuse_existing_mocha 20 | instance = Object.new 21 | mocha_1 = instance.mocha 22 | mocha_2 = instance.mocha 23 | assert_equal mocha_1, mocha_2 24 | end 25 | 26 | def test_should_reset_mocha 27 | instance = Object.new 28 | assert_nil instance.reset_mocha 29 | end 30 | 31 | def test_should_build_any_instance_object 32 | klass = Class.new 33 | any_instance = klass.any_instance 34 | assert_not_nil any_instance 35 | assert any_instance.is_a?(Class::AnyInstance) 36 | end 37 | 38 | def test_should_return_same_any_instance_object 39 | klass = Class.new 40 | any_instance_1 = klass.any_instance 41 | any_instance_2 = klass.any_instance 42 | assert_equal any_instance_1, any_instance_2 43 | end 44 | 45 | def test_should_use_stubba_instance_method_for_object 46 | assert_equal Mocha::InstanceMethod, Object.new.stubba_method 47 | end 48 | 49 | def test_should_use_stubba_module_method_for_module 50 | assert_equal Mocha::ModuleMethod, Module.new.stubba_method 51 | end 52 | 53 | def test_should_use_stubba_class_method_for_class 54 | assert_equal Mocha::ClassMethod, Class.new.stubba_method 55 | end 56 | 57 | def test_should_use_stubba_class_method_for_any_instance 58 | assert_equal Mocha::AnyInstanceMethod, Class::AnyInstance.new(nil).stubba_method 59 | end 60 | 61 | def test_should_stub_self_for_object 62 | object = Object.new 63 | assert_equal object, object.stubba_object 64 | end 65 | 66 | def test_should_stub_self_for_module 67 | mod = Module.new 68 | assert_equal mod, mod.stubba_object 69 | end 70 | 71 | def test_should_stub_self_for_class 72 | klass = Class.new 73 | assert_equal klass, klass.stubba_object 74 | end 75 | 76 | def test_should_stub_relevant_class_for_any_instance 77 | klass = Class.new 78 | any_instance = Class::AnyInstance.new(klass) 79 | assert_equal klass, any_instance.stubba_object 80 | end 81 | 82 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/unit/parameter_matchers/has_entry_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "..", "..", "test_helper") 2 | 3 | require 'mocha/parameter_matchers/has_entry' 4 | require 'mocha/parameter_matchers/object' 5 | require 'mocha/parameter_matchers/equals' 6 | require 'mocha/inspect' 7 | 8 | class HasEntryTest < Test::Unit::TestCase 9 | 10 | include Mocha::ParameterMatchers 11 | 12 | def test_should_match_hash_including_specified_key_value_pair 13 | matcher = has_entry(:key_1, 'value_1') 14 | assert matcher.matches?([{ :key_1 => 'value_1', :key_2 => 'value_2' }]) 15 | end 16 | 17 | def test_should_not_match_hash_not_including_specified_key_value_pair 18 | matcher = has_entry(:key_1, 'value_2') 19 | assert !matcher.matches?([{ :key_1 => 'value_1', :key_2 => 'value_2' }]) 20 | end 21 | 22 | def test_should_match_hash_including_specified_entry 23 | matcher = has_entry(:key_1 => 'value_1') 24 | assert matcher.matches?([{ :key_1 => 'value_1', :key_2 => 'value_2' }]) 25 | end 26 | 27 | def test_should_not_match_hash_not_including_specified_entry 28 | matcher = has_entry(:key_1 => 'value_2') 29 | assert !matcher.matches?([{ :key_1 => 'value_1', :key_2 => 'value_2' }]) 30 | end 31 | 32 | def test_should_describe_matcher_with_key_value_pair 33 | matcher = has_entry(:key_1, 'value_1') 34 | assert_equal "has_entry(:key_1 => 'value_1')", matcher.mocha_inspect 35 | end 36 | 37 | def test_should_describe_matcher_with_entry 38 | matcher = has_entry(:key_1 => 'value_1') 39 | assert_equal "has_entry(:key_1 => 'value_1')", matcher.mocha_inspect 40 | end 41 | 42 | def test_should_match_hash_including_specified_entry_with_nested_key_matcher 43 | matcher = has_entry(equals(:key_1) => 'value_1') 44 | assert matcher.matches?([{ :key_1 => 'value_1', :key_2 => 'value_2' }]) 45 | end 46 | 47 | def test_should_match_hash_including_specified_entry_with_nested_value_matcher 48 | matcher = has_entry(:key_1 => equals('value_1')) 49 | assert matcher.matches?([{ :key_1 => 'value_1', :key_2 => 'value_2' }]) 50 | end 51 | 52 | def test_should_not_match_hash_not_including_specified_entry_with_nested_key_matcher 53 | matcher = has_entry(equals(:key_1) => 'value_2') 54 | assert !matcher.matches?([{ :key_1 => 'value_1', :key_2 => 'value_2' }]) 55 | end 56 | 57 | def test_should_not_match_hash_not_including_specified_entry_with_nested_value_matcher 58 | matcher = has_entry(:key_1 => equals('value_2')) 59 | assert !matcher.matches?([{ :key_1 => 'value_1', :key_2 => 'value_2' }]) 60 | end 61 | 62 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/acceptance/stubbing_error_backtrace_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "acceptance_test_helper") 2 | require 'mocha' 3 | require 'execution_point' 4 | 5 | class StubbingErrorBacktraceTest < Test::Unit::TestCase 6 | 7 | include AcceptanceTest 8 | 9 | def setup 10 | setup_acceptance_test 11 | end 12 | 13 | def teardown 14 | teardown_acceptance_test 15 | end 16 | 17 | def test_should_display_backtrace_indicating_line_number_where_attempt_to_stub_non_existent_method_was_made 18 | execution_point = nil 19 | object = Object.new 20 | Mocha::Configuration.prevent(:stubbing_non_existent_method) 21 | test_result = run_test do 22 | execution_point = ExecutionPoint.current; object.stubs(:non_existent_method) 23 | end 24 | assert_equal 1, test_result.error_count 25 | assert_equal execution_point, ExecutionPoint.new(test_result.errors[0].exception.backtrace) 26 | end 27 | 28 | def test_should_display_backtrace_indicating_line_number_where_attempt_to_stub_non_public_method_was_made 29 | execution_point = nil 30 | object = Class.new do 31 | def non_public_method; end 32 | private :non_public_method 33 | end.new 34 | Mocha::Configuration.prevent(:stubbing_non_public_method) 35 | test_result = run_test do 36 | execution_point = ExecutionPoint.current; object.stubs(:non_public_method) 37 | end 38 | assert_equal 1, test_result.error_count 39 | assert_equal execution_point, ExecutionPoint.new(test_result.errors[0].exception.backtrace) 40 | end 41 | 42 | def test_should_display_backtrace_indicating_line_number_where_attempt_to_stub_method_on_non_mock_object_was_made 43 | execution_point = nil 44 | object = Object.new 45 | Mocha::Configuration.prevent(:stubbing_method_on_non_mock_object) 46 | test_result = run_test do 47 | execution_point = ExecutionPoint.current; object.stubs(:any_method) 48 | end 49 | assert_equal 1, test_result.error_count 50 | assert_equal execution_point, ExecutionPoint.new(test_result.errors[0].exception.backtrace) 51 | end 52 | 53 | def test_should_display_backtrace_indicating_line_number_where_method_was_unnecessarily_stubbed 54 | execution_point = nil 55 | object = Object.new 56 | Mocha::Configuration.prevent(:stubbing_method_unnecessarily) 57 | test_result = run_test do 58 | execution_point = ExecutionPoint.current; object.stubs(:unused_method) 59 | end 60 | assert_equal 1, test_result.error_count 61 | assert_equal execution_point, ExecutionPoint.new(test_result.errors[0].exception.backtrace) 62 | end 63 | 64 | end 65 | -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/acceptance/mocha_test_result_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "acceptance_test_helper") 2 | require 'mocha' 3 | require 'execution_point' 4 | 5 | class MochaTestResultTest < Test::Unit::TestCase 6 | 7 | include AcceptanceTest 8 | 9 | def setup 10 | setup_acceptance_test 11 | end 12 | 13 | def teardown 14 | teardown_acceptance_test 15 | end 16 | 17 | def test_should_include_expectation_verification_in_assertion_count 18 | test_result = run_test do 19 | object = mock() 20 | object.expects(:message) 21 | object.message 22 | end 23 | assert_equal 1, test_result.assertion_count 24 | end 25 | 26 | def test_should_include_assertions_in_assertion_count 27 | test_result = run_test do 28 | assert true 29 | end 30 | assert_equal 1, test_result.assertion_count 31 | end 32 | 33 | def test_should_not_include_stubbing_expectation_verification_in_assertion_count 34 | test_result = run_test do 35 | object = mock() 36 | object.stubs(:message) 37 | object.message 38 | end 39 | assert_equal 0, test_result.assertion_count 40 | end 41 | 42 | def test_should_include_expectation_verification_failure_in_failure_count 43 | test_result = run_test do 44 | object = mock() 45 | object.expects(:message) 46 | end 47 | assert_equal 1, test_result.failure_count 48 | end 49 | 50 | def test_should_include_unexpected_verification_failure_in_failure_count 51 | test_result = run_test do 52 | object = mock() 53 | object.message 54 | end 55 | assert_equal 1, test_result.failure_count 56 | end 57 | 58 | def test_should_include_assertion_failure_in_failure_count 59 | test_result = run_test do 60 | flunk 61 | end 62 | assert_equal 1, test_result.failure_count 63 | end 64 | 65 | def test_should_display_backtrace_indicating_line_number_where_unexpected_method_was_called 66 | execution_point = nil 67 | test_result = run_test do 68 | object = mock() 69 | execution_point = ExecutionPoint.current; object.message 70 | end 71 | assert_equal 1, test_result.failure_count 72 | assert_equal execution_point, ExecutionPoint.new(test_result.failures[0].location) 73 | end 74 | 75 | def test_should_display_backtrace_indicating_line_number_where_failing_assertion_was_called 76 | execution_point = nil 77 | test_result = run_test do 78 | execution_point = ExecutionPoint.current; flunk 79 | end 80 | assert_equal 1, test_result.failure_count 81 | assert_equal execution_point, ExecutionPoint.new(test_result.failures[0].location) 82 | end 83 | 84 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/unit/expectation_list_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "..", "test_helper") 2 | require 'mocha/expectation_list' 3 | require 'mocha/expectation' 4 | require 'set' 5 | require 'method_definer' 6 | 7 | class ExpectationListTest < Test::Unit::TestCase 8 | 9 | include Mocha 10 | 11 | def test_should_return_added_expectation 12 | expectation_list = ExpectationList.new 13 | expectation = Expectation.new(nil, :my_method) 14 | assert_same expectation, expectation_list.add(expectation) 15 | end 16 | 17 | def test_should_find_matching_expectation 18 | expectation_list = ExpectationList.new 19 | expectation1 = Expectation.new(nil, :my_method).with(:argument1, :argument2) 20 | expectation2 = Expectation.new(nil, :my_method).with(:argument3, :argument4) 21 | expectation_list.add(expectation1) 22 | expectation_list.add(expectation2) 23 | assert_same expectation1, expectation_list.match(:my_method, :argument1, :argument2) 24 | end 25 | 26 | def test_should_find_most_recent_matching_expectation 27 | expectation_list = ExpectationList.new 28 | expectation1 = Expectation.new(nil, :my_method).with(:argument1, :argument2) 29 | expectation2 = Expectation.new(nil, :my_method).with(:argument1, :argument2) 30 | expectation_list.add(expectation1) 31 | expectation_list.add(expectation2) 32 | assert_same expectation2, expectation_list.match(:my_method, :argument1, :argument2) 33 | end 34 | 35 | def test_should_find_matching_expectation_allowing_invocation 36 | expectation_list = ExpectationList.new 37 | expectation1 = Expectation.new(nil, :my_method).with(:argument1, :argument2) 38 | expectation2 = Expectation.new(nil, :my_method).with(:argument3, :argument4) 39 | expectation1.define_instance_method(:invocations_allowed?) { true } 40 | expectation2.define_instance_method(:invocations_allowed?) { true } 41 | expectation_list.add(expectation1) 42 | expectation_list.add(expectation2) 43 | assert_same expectation1, expectation_list.match_allowing_invocation(:my_method, :argument1, :argument2) 44 | end 45 | 46 | def test_should_find_most_recent_matching_expectation_allowing_invocation 47 | expectation_list = ExpectationList.new 48 | expectation1 = Expectation.new(nil, :my_method) 49 | expectation2 = Expectation.new(nil, :my_method) 50 | expectation1.define_instance_method(:invocations_allowed?) { true } 51 | expectation2.define_instance_method(:invocations_allowed?) { false } 52 | expectation_list.add(expectation1) 53 | expectation_list.add(expectation2) 54 | assert_same expectation1, expectation_list.match_allowing_invocation(:my_method) 55 | end 56 | 57 | end 58 | -------------------------------------------------------------------------------- /vendor/gems/dust-0.1.6/lib/object_extension.rb: -------------------------------------------------------------------------------- 1 | class Object 2 | # call-seq: unit_tests(options={}, &block) 3 | # 4 | # Used to define a block of unit tests. 5 | # 6 | # unit_tests do 7 | # test "verify something" do 8 | # ... 9 | # end 10 | # end 11 | # 12 | # Configuration Options: 13 | # * allow - Allows you to specify the methods that are allowed despite being disallowed. 14 | # See Test::Unit::TestCase.disallow_helpers! or Test::Unit::TestCase.disallow_setup! for more info 15 | def unit_tests(options={}, &block) 16 | do_tests("Units", options, &block) 17 | end 18 | 19 | # call-seq: functional_tests(options={}, &block) 20 | # 21 | # Used to define a block of functional tests. 22 | # 23 | # functional_tests do 24 | # test "verify something" do 25 | # ... 26 | # end 27 | # end 28 | # 29 | # Configuration Options: 30 | # * allow - Allows you to specify the methods that are allowed despite being disallowed. 31 | # See Test::Unit::TestCase.disallow_helpers! or Test::Unit::TestCase.disallow_setup! for more info 32 | def functional_tests(options={}, &block) 33 | do_tests("Functionals", options, &block) 34 | end 35 | 36 | protected 37 | def do_tests(type, options, &block) #:nodoc: 38 | options[:allow] = options[:allow].arrayize 39 | full_path_file_name = eval "__FILE__", block.binding 40 | test_name = File.basename(full_path_file_name, ".rb") 41 | test_class = eval "module #{type}; class #{test_name.to_class_name} < Test::Unit::TestCase; self; end; end" 42 | test_class.class_eval &block 43 | check_for_setup(test_class, options) 44 | check_for_helpers(test_class, options) 45 | end 46 | 47 | def check_for_setup(test_class, options) #:nodoc: 48 | if test_class.instance_methods(false).include?("setup") && Test::Unit::TestCase.disallow_setup? && 49 | !options[:allow].include?(:setup) 50 | raise Dust::DefinitionError.new("setup is not allowed on class #{test_class.name}") 51 | end 52 | end 53 | 54 | def check_for_helpers(test_class, options) #:nodoc: 55 | test_class.instance_methods(false).each do |method_name| 56 | if method_name !~ /^test_/ && Test::Unit::TestCase.disallow_helpers? && !options[:allow].include?(method_name.to_sym) 57 | p method_name.to_sym 58 | raise Dust::DefinitionError.new("helper methods are not allowed on class #{test_class.name}") 59 | end 60 | end 61 | end 62 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/lib/mocha/class_method.rb: -------------------------------------------------------------------------------- 1 | require 'mocha/metaclass' 2 | 3 | module Mocha 4 | 5 | class ClassMethod 6 | 7 | attr_reader :stubbee, :method 8 | 9 | def initialize(stubbee, method) 10 | @stubbee = stubbee 11 | @method = RUBY_VERSION < '1.9' ? method.to_s : method.to_sym 12 | end 13 | 14 | def stub 15 | hide_original_method 16 | define_new_method 17 | end 18 | 19 | def unstub 20 | remove_new_method 21 | restore_original_method 22 | stubbee.reset_mocha 23 | end 24 | 25 | def mock 26 | stubbee.mocha 27 | end 28 | 29 | def hide_original_method 30 | if method_exists?(method) 31 | begin 32 | stubbee.__metaclass__.class_eval("alias_method :#{hidden_method}, :#{method}", __FILE__, __LINE__) 33 | rescue NameError 34 | # deal with nasties like ActiveRecord::Associations::AssociationProxy 35 | end 36 | end 37 | end 38 | 39 | def define_new_method 40 | stubbee.__metaclass__.class_eval("def #{method}(*args, &block); mocha.method_missing(:#{method}, *args, &block); end", __FILE__, __LINE__) 41 | end 42 | 43 | def remove_new_method 44 | stubbee.__metaclass__.class_eval("remove_method :#{method}", __FILE__, __LINE__) 45 | end 46 | 47 | def restore_original_method 48 | if method_exists?(hidden_method) 49 | begin 50 | stubbee.__metaclass__.class_eval("alias_method :#{method}, :#{hidden_method}; remove_method :#{hidden_method}", __FILE__, __LINE__) 51 | rescue NameError 52 | # deal with nasties like ActiveRecord::Associations::AssociationProxy 53 | end 54 | end 55 | end 56 | 57 | def hidden_method 58 | if RUBY_VERSION < '1.9' 59 | method_name = method.to_s.gsub(/\W/) { |s| "_substituted_character_#{s[0]}_" } 60 | else 61 | method_name = method.to_s.gsub(/\W/) { |s| "_substituted_character_#{s.ord}_" } 62 | end 63 | hidden_method = "__stubba__#{method_name}__stubba__" 64 | RUBY_VERSION < '1.9' ? hidden_method.to_s : hidden_method.to_sym 65 | end 66 | 67 | def eql?(other) 68 | return false unless (other.class == self.class) 69 | (stubbee.object_id == other.stubbee.object_id) and (method == other.method) 70 | end 71 | 72 | alias_method :==, :eql? 73 | 74 | def to_s 75 | "#{stubbee}.#{method}" 76 | end 77 | 78 | def method_exists?(method) 79 | symbol = method.to_sym 80 | metaclass = stubbee.__metaclass__ 81 | metaclass.public_method_defined?(symbol) || metaclass.protected_method_defined?(symbol) || metaclass.private_method_defined?(symbol) 82 | end 83 | 84 | end 85 | 86 | end 87 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Ruby is copyrighted free software by Yukihiro Matsumoto . 2 | You can redistribute it and/or modify it under either the terms of the GPL 3 | (see COPYING.txt file), or the conditions below: 4 | 5 | 1. You may make and give away verbatim copies of the source form of the 6 | software without restriction, provided that you duplicate all of the 7 | original copyright notices and associated disclaimers. 8 | 9 | 2. You may modify your copy of the software in any way, provided that 10 | you do at least ONE of the following: 11 | 12 | a) place your modifications in the Public Domain or otherwise 13 | make them Freely Available, such as by posting said 14 | modifications to Usenet or an equivalent medium, or by allowing 15 | the author to include your modifications in the software. 16 | 17 | b) use the modified software only within your corporation or 18 | organization. 19 | 20 | c) rename any non-standard executables so the names do not conflict 21 | with standard executables, which must also be provided. 22 | 23 | d) make other distribution arrangements with the author. 24 | 25 | 3. You may distribute the software in object code or executable 26 | form, provided that you do at least ONE of the following: 27 | 28 | a) distribute the executables and library files of the software, 29 | together with instructions (in the manual page or equivalent) 30 | on where to get the original distribution. 31 | 32 | b) accompany the distribution with the machine-readable source of 33 | the software. 34 | 35 | c) give non-standard executables non-standard names, with 36 | instructions on where to get the original software distribution. 37 | 38 | d) make other distribution arrangements with the author. 39 | 40 | 4. You may modify and include the part of the software into any other 41 | software (possibly commercial). But some files in the distribution 42 | are not written by the author, so that they are not under this terms. 43 | 44 | They are gc.c(partly), utils.c(partly), regex.[ch], st.[ch] and some 45 | files under the ./missing directory. See each file for the copying 46 | condition. 47 | 48 | 5. The scripts and library files supplied as input to or produced as 49 | output from the software do not automatically fall under the 50 | copyright of the software, but belong to whomever generated them, 51 | and may be sold commercially, and may be aggregated with this 52 | software. 53 | 54 | 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR 55 | IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 56 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 57 | PURPOSE. 58 | 59 | -------------------------------------------------------------------------------- /vendor/gems/dust-0.1.6/lib/test_case_extension.rb: -------------------------------------------------------------------------------- 1 | module Test #:nodoc: 2 | module Unit #:nodoc: 3 | class TestCase 4 | # call-seq: disallow_setup! 5 | # 6 | # Used to disallow setup methods in test specifications. 7 | # 8 | # Test::Unit::TestCase.disallow_setup! 9 | # 10 | # A test specification can override this behavior by passing :setup in the :allow options. 11 | # 12 | # unit_tests :allow => :setup do 13 | # def setup 14 | # ... 15 | # end 16 | # 17 | # test "verify something" do 18 | # ... 19 | # end 20 | # end 21 | def self.disallow_setup! 22 | @disallow_setup = true 23 | end 24 | 25 | def self.disallow_setup? #:nodoc: 26 | @disallow_setup 27 | end 28 | 29 | # call-seq: disallow_helpers! 30 | # 31 | # Used to disallow helper methods in test specifications. 32 | # 33 | # Test::Unit::TestCase.disallow_helper! 34 | # 35 | # A test specification can override this behavior by passing the helper name (as a symbol) in the :allow options. 36 | # 37 | # unit_tests :allow => [:create_something, :destroy_something] do 38 | # test "verify something" do 39 | # ... 40 | # end 41 | # 42 | # def create_something 43 | # ... 44 | # end 45 | # 46 | # def destroy_something 47 | # ... 48 | # end 49 | # end 50 | def self.disallow_helpers! 51 | @disallow_helpers = true 52 | end 53 | 54 | def self.disallow_helpers? #:nodoc: 55 | @disallow_helpers 56 | end 57 | 58 | # call-seq: test(name, &block) 59 | # 60 | # Used to define a test and assign it a descriptive name. 61 | # 62 | # unit_tests do 63 | # test "verify something" do 64 | # ... 65 | # end 66 | # end 67 | def self.test(name, &block) 68 | test_name = "test_#{name.gsub(/[\s]/,'_')}".to_sym 69 | raise "#{test_name} is already defined in #{self}" if self.instance_methods.include? test_name.to_s 70 | define_method test_name do 71 | instance_eval &block 72 | end 73 | end 74 | end 75 | end 76 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/acceptance/stubba_example_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "..", "test_helper") 2 | require 'mocha' 3 | 4 | class Widget 5 | 6 | def model 7 | 'original_model' 8 | end 9 | 10 | class << self 11 | 12 | def find(options) 13 | [] 14 | end 15 | 16 | def create(attributes) 17 | Widget.new 18 | end 19 | 20 | end 21 | 22 | end 23 | 24 | module Thingy 25 | 26 | def self.wotsit 27 | :hoojamaflip 28 | end 29 | 30 | end 31 | 32 | class StubbaExampleTest < Test::Unit::TestCase 33 | 34 | def test_should_stub_instance_method 35 | widget = Widget.new 36 | widget.expects(:model).returns('different_model') 37 | assert_equal 'different_model', widget.model 38 | end 39 | 40 | def test_should_stub_module_method 41 | should_stub_module_method 42 | end 43 | 44 | def test_should_stub_module_method_again 45 | should_stub_module_method 46 | end 47 | 48 | def test_should_stub_class_method 49 | should_stub_class_method 50 | end 51 | 52 | def test_should_stub_class_method_again 53 | should_stub_class_method 54 | end 55 | 56 | def test_should_stub_instance_method_on_any_instance_of_a_class 57 | should_stub_instance_method_on_any_instance_of_a_class 58 | end 59 | 60 | def test_should_stub_instance_method_on_any_instance_of_a_class_again 61 | should_stub_instance_method_on_any_instance_of_a_class 62 | end 63 | 64 | def test_should_stub_two_different_class_methods 65 | should_stub_two_different_class_methods 66 | end 67 | 68 | def test_should_stub_two_different_class_methods_again 69 | should_stub_two_different_class_methods 70 | end 71 | 72 | private 73 | 74 | def should_stub_module_method 75 | Thingy.expects(:wotsit).returns(:dooda) 76 | assert_equal :dooda, Thingy.wotsit 77 | end 78 | 79 | def should_stub_class_method 80 | widgets = [Widget.new] 81 | Widget.expects(:find).with(:all).returns(widgets) 82 | assert_equal widgets, Widget.find(:all) 83 | end 84 | 85 | def should_stub_two_different_class_methods 86 | found_widgets = [Widget.new] 87 | created_widget = Widget.new 88 | Widget.expects(:find).with(:all).returns(found_widgets) 89 | Widget.expects(:create).with(:model => 'wombat').returns(created_widget) 90 | assert_equal found_widgets, Widget.find(:all) 91 | assert_equal created_widget, Widget.create(:model => 'wombat') 92 | end 93 | 94 | def should_stub_instance_method_on_any_instance_of_a_class 95 | Widget.any_instance.expects(:model).at_least_once.returns('another_model') 96 | widget_1 = Widget.new 97 | widget_2 = Widget.new 98 | assert_equal 'another_model', widget_1.model 99 | assert_equal 'another_model', widget_2.model 100 | end 101 | 102 | end -------------------------------------------------------------------------------- /lib/system_timer/concurrent_timer_pool.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2008 David Vollbracht & Philippe Hanrigou 2 | 3 | module SystemTimer 4 | 5 | class ConcurrentTimerPool 6 | 7 | def registered_timers 8 | @timers ||= [] 9 | end 10 | 11 | def register_timer(trigger_time, thread, exception_class=nil) 12 | new_timer = ThreadTimer.new(trigger_time, thread, exception_class) 13 | registered_timers << new_timer 14 | new_timer 15 | end 16 | 17 | def add_timer(interval_in_seconds, exception_class=nil) 18 | new_timer = register_timer(Time.now.to_f + interval_in_seconds, Thread.current, exception_class) 19 | log_registered_timers if SystemTimer.debug_enabled? 20 | new_timer 21 | end 22 | 23 | def cancel(registered_timer) 24 | registered_timers.delete registered_timer 25 | end 26 | 27 | def first_timer? 28 | registered_timers.size == 1 29 | end 30 | 31 | def next_timer 32 | registered_timers.sort {|x,y| x.trigger_time <=> y.trigger_time}.first 33 | end 34 | 35 | def next_trigger_time 36 | timer = next_timer 37 | timer.trigger_time unless timer.nil? 38 | end 39 | 40 | def next_trigger_interval_in_seconds 41 | timer = next_timer 42 | [0, (timer.trigger_time - Time.now.to_f)].max unless timer.nil? 43 | end 44 | 45 | def next_expired_timer(now_in_seconds_since_epoch) 46 | candidate_timer = next_timer 47 | if SystemTimer.debug_enabled? 48 | puts "Candidate timer at #{now_in_seconds_since_epoch} : " + 49 | candidate_timer.inspect 50 | end 51 | return nil if candidate_timer.nil? || 52 | candidate_timer.trigger_time > now_in_seconds_since_epoch 53 | candidate_timer 54 | end 55 | 56 | def trigger_next_expired_timer_at(now_in_seconds_since_epoch) 57 | timer = next_expired_timer(now_in_seconds_since_epoch) 58 | puts "Next expired timer : #{timer.inspect}" if SystemTimer.debug_enabled? 59 | return if timer.nil? 60 | 61 | cancel timer 62 | log_timeout_received(timer) if SystemTimer.debug_enabled? 63 | timer.thread.raise timer.exception_class.new("time's up!") 64 | end 65 | 66 | def trigger_next_expired_timer 67 | puts "Trigger next expired timer" if SystemTimer.debug_enabled? 68 | trigger_next_expired_timer_at Time.now.to_f 69 | end 70 | 71 | def log_timeout_received(thread_timer) #:nodoc: 72 | puts <<-EOS 73 | ==== Triger Timer ==== #{thread_timer} 74 | Main thread : #{Thread.main} 75 | Timed_thread : #{thread_timer.thread} 76 | All Threads : #{Thread.list.inspect} 77 | EOS 78 | log_registered_timers 79 | end 80 | 81 | def log_registered_timers #:nodoc: 82 | puts <<-EOS 83 | Registered Timers: #{registered_timers.map {|t| t.to_s}.join("\n ")} 84 | EOS 85 | end 86 | 87 | end 88 | 89 | end 90 | -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/acceptance/mock_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "acceptance_test_helper") 2 | require 'mocha' 3 | 4 | class MockTest < Test::Unit::TestCase 5 | 6 | include AcceptanceTest 7 | 8 | def setup 9 | setup_acceptance_test 10 | end 11 | 12 | def teardown 13 | teardown_acceptance_test 14 | end 15 | 16 | def test_should_build_mock_and_explicitly_add_an_expectation_which_is_satisfied 17 | test_result = run_test do 18 | foo = mock() 19 | foo.expects(:bar) 20 | foo.bar 21 | end 22 | assert_passed(test_result) 23 | end 24 | 25 | def test_should_build_mock_and_explicitly_add_an_expectation_which_is_not_satisfied 26 | test_result = run_test do 27 | foo = mock() 28 | foo.expects(:bar) 29 | end 30 | assert_failed(test_result) 31 | end 32 | 33 | def test_should_build_named_mock_and_explicitly_add_an_expectation_which_is_satisfied 34 | test_result = run_test do 35 | foo = mock('foo') 36 | foo.expects(:bar) 37 | foo.bar 38 | end 39 | assert_passed(test_result) 40 | end 41 | 42 | def test_should_build_named_mock_and_explicitly_add_an_expectation_which_is_not_satisfied 43 | test_result = run_test do 44 | foo = mock('foo') 45 | foo.expects(:bar) 46 | end 47 | assert_failed(test_result) 48 | end 49 | 50 | def test_should_build_mock_incorporating_two_expectations_which_are_satisifed 51 | test_result = run_test do 52 | foo = mock(:bar => 'bar', :baz => 'baz') 53 | foo.bar 54 | foo.baz 55 | end 56 | assert_passed(test_result) 57 | end 58 | 59 | def test_should_build_mock_incorporating_two_expectations_the_first_of_which_is_not_satisifed 60 | test_result = run_test do 61 | foo = mock(:bar => 'bar', :baz => 'baz') 62 | foo.baz 63 | end 64 | assert_failed(test_result) 65 | end 66 | 67 | def test_should_build_mock_incorporating_two_expectations_the_second_of_which_is_not_satisifed 68 | test_result = run_test do 69 | foo = mock(:bar => 'bar', :baz => 'baz') 70 | foo.bar 71 | end 72 | assert_failed(test_result) 73 | end 74 | 75 | def test_should_build_named_mock_incorporating_two_expectations_which_are_satisifed 76 | test_result = run_test do 77 | foo = mock('foo', :bar => 'bar', :baz => 'baz') 78 | foo.bar 79 | foo.baz 80 | end 81 | assert_passed(test_result) 82 | end 83 | 84 | def test_should_build_named_mock_incorporating_two_expectations_the_first_of_which_is_not_satisifed 85 | test_result = run_test do 86 | foo = mock('foo', :bar => 'bar', :baz => 'baz') 87 | foo.baz 88 | end 89 | assert_failed(test_result) 90 | end 91 | 92 | def test_should_build_named_mock_incorporating_two_expectations_the_second_of_which_is_not_satisifed 93 | test_result = run_test do 94 | foo = mock('foo', :bar => 'bar', :baz => 'baz') 95 | foo.bar 96 | end 97 | assert_failed(test_result) 98 | end 99 | 100 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/acceptance/mocha_example_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "..", "test_helper") 2 | require 'mocha' 3 | 4 | class MochaExampleTest < Test::Unit::TestCase 5 | 6 | class Rover 7 | 8 | def initialize(left_track, right_track, steps_per_metre, steps_per_degree) 9 | @left_track, @right_track, @steps_per_metre, @steps_per_degree = left_track, right_track, steps_per_metre, steps_per_degree 10 | end 11 | 12 | def forward(metres) 13 | @left_track.step(metres * @steps_per_metre) 14 | @right_track.step(metres * @steps_per_metre) 15 | wait 16 | end 17 | 18 | def backward(metres) 19 | forward(-metres) 20 | end 21 | 22 | def left(degrees) 23 | @left_track.step(-degrees * @steps_per_degree) 24 | @right_track.step(+degrees * @steps_per_degree) 25 | wait 26 | end 27 | 28 | def right(degrees) 29 | left(-degrees) 30 | end 31 | 32 | def wait 33 | while (@left_track.moving? or @right_track.moving?); end 34 | end 35 | 36 | end 37 | 38 | def test_should_step_both_tracks_forward_ten_steps 39 | left_track = mock('left_track') 40 | right_track = mock('right_track') 41 | steps_per_metre = 5 42 | rover = Rover.new(left_track, right_track, steps_per_metre, nil) 43 | 44 | left_track.expects(:step).with(10) 45 | right_track.expects(:step).with(10) 46 | 47 | left_track.stubs(:moving?).returns(false) 48 | right_track.stubs(:moving?).returns(false) 49 | 50 | rover.forward(2) 51 | end 52 | 53 | def test_should_step_both_tracks_backward_ten_steps 54 | left_track = mock('left_track') 55 | right_track = mock('right_track') 56 | steps_per_metre = 5 57 | rover = Rover.new(left_track, right_track, steps_per_metre, nil) 58 | 59 | left_track.expects(:step).with(-10) 60 | right_track.expects(:step).with(-10) 61 | 62 | left_track.stubs(:moving?).returns(false) 63 | right_track.stubs(:moving?).returns(false) 64 | 65 | rover.backward(2) 66 | end 67 | 68 | def test_should_step_left_track_forwards_five_steps_and_right_track_backwards_five_steps 69 | left_track = mock('left_track') 70 | right_track = mock('right_track') 71 | steps_per_degree = 5.0 / 90.0 72 | rover = Rover.new(left_track, right_track, nil, steps_per_degree) 73 | 74 | left_track.expects(:step).with(+5) 75 | right_track.expects(:step).with(-5) 76 | 77 | left_track.stubs(:moving?).returns(false) 78 | right_track.stubs(:moving?).returns(false) 79 | 80 | rover.right(90) 81 | end 82 | 83 | def test_should_step_left_track_backwards_five_steps_and_right_track_forwards_five_steps 84 | left_track = mock('left_track') 85 | right_track = mock('right_track') 86 | steps_per_degree = 5.0 / 90.0 87 | rover = Rover.new(left_track, right_track, nil, steps_per_degree) 88 | 89 | left_track.expects(:step).with(-5) 90 | right_track.expects(:step).with(+5) 91 | 92 | left_track.stubs(:moving?).returns(false) 93 | right_track.stubs(:moving?).returns(false) 94 | 95 | rover.left(90) 96 | end 97 | 98 | end -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # Copyright 2008 David Vollbracht & Philippe Hanrigou 2 | 3 | require 'rake' 4 | require 'rake/testtask' 5 | require 'rake/rdoctask' 6 | require 'rake/gempackagetask' 7 | require 'rake/clean' 8 | require 'rubygems' 9 | 10 | CLEAN.include '**/*.o' 11 | CLEAN.include '**/*.so' 12 | CLEAN.include '**/*.bundle' 13 | CLOBBER.include '**/*.log' 14 | CLOBBER.include '**/Makefile' 15 | CLOBBER.include '**/extconf.h' 16 | CLOBBER.include 'pkk/*' 17 | 18 | SYSTEM_TIMER_VERSION = "1.2.4" 19 | SYSTEM_TIMER_GEM_NAME = "system_timer" 20 | 21 | desc 'Default: run unit tests.' 22 | task :default => :test 23 | 24 | desc 'Install the gem into the local gem repository' 25 | task :install => 'package' do 26 | sh "gem install ./pkg/#{SYSTEM_TIMER_GEM_NAME}-#{SYSTEM_TIMER_VERSION}.gem" 27 | end 28 | 29 | desc 'Test SystemTimer' 30 | Rake::TestTask.new(:test) do |t| 31 | t.libs << 'lib' 32 | t.pattern = 'test/**/*_test.rb' 33 | t.verbose = true 34 | end 35 | task :test => 'ext/system_timer/libsystem_timer_native.so' 36 | 37 | desc 'Generate documentation for System Timer.' 38 | Rake::RDocTask.new(:rdoc) do |rdoc| 39 | rdoc.rdoc_dir = 'rdoc' 40 | rdoc.title = 'System Timer' 41 | rdoc.options << '--line-numbers' << '--inline-source' 42 | rdoc.rdoc_files.include('README') 43 | rdoc.rdoc_files.include('lib/**/*.rb') 44 | end 45 | 46 | file 'ext/system_timer/Makefile' => 'ext/system_timer/extconf.rb' do 47 | Dir.chdir('ext/system_timer') do 48 | ruby 'extconf.rb' 49 | end 50 | end 51 | 52 | file 'ext/system_timer/libsystem_timer_native.so' => 'ext/system_timer/Makefile' do 53 | Dir.chdir('ext/system_timer') do 54 | pid = fork { exec "make" } 55 | Process.waitpid pid 56 | end 57 | fail "Make failed (status #{m})" unless $?.exitstatus == 0 58 | end 59 | 60 | specification = Gem::Specification.new do |s| 61 | s.name = SYSTEM_TIMER_GEM_NAME 62 | s.summary = "Set a Timeout based on signals, which are more reliable than Timeout. Timeout is based on green threads." 63 | s.version = SYSTEM_TIMER_VERSION 64 | s.authors = ["Philippe Hanrigou", "David Vollbracht"] 65 | if ENV['PACKAGE_FOR_WIN32'] || PLATFORM['win32'] 66 | s.platform = Gem::Platform.new "mswin32" 67 | s.files = FileList['lib/system_timer_stub.rb'] 68 | s.autorequire = "system_timer_stub" 69 | else 70 | s.platform = Gem::Platform::RUBY 71 | s.files = [ "COPYING", "LICENSE", "ChangeLog"] + 72 | FileList['ext/**/*.c'] + 73 | FileList['ext/**/*.rb'] + 74 | FileList['lib/**/*.rb'] + 75 | FileList['test/**/*.rb'] 76 | s.autorequire = "system_timer" 77 | s.extensions = ["ext/system_timer/extconf.rb"] 78 | end 79 | s.require_path = "lib" 80 | s.rdoc_options << '--title' << 'System Timer' << '--main' << 'README' << '--line-numbers' 81 | s.has_rdoc = true 82 | s.extra_rdoc_files = ['README'] 83 | s.test_file = "test/all_tests.rb" 84 | s.rubyforge_project = "systemtimer" 85 | end 86 | 87 | Rake::GemPackageTask.new(specification) do |package| 88 | package.need_zip = false 89 | package.need_tar = false 90 | end 91 | 92 | desc "Publish RDoc on Rubyforge website" 93 | task :publish_rdoc => :rdoc do 94 | sh "scp -r rdoc/* #{ENV['USER']}@rubyforge.org:/var/www/gforge-projects/systemtimer" 95 | end 96 | -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/lib/mocha/test_case_adapter.rb: -------------------------------------------------------------------------------- 1 | require 'mocha/expectation_error' 2 | 3 | module Mocha 4 | 5 | module TestCaseAdapter 6 | 7 | class AssertionCounter 8 | 9 | def initialize(test_result) 10 | @test_result = test_result 11 | end 12 | 13 | def increment 14 | @test_result.add_assertion 15 | end 16 | 17 | end 18 | 19 | def self.included(base) 20 | if RUBY_VERSION < '1.8.6' 21 | base.class_eval do 22 | 23 | alias_method :run_before_mocha_test_case_adapter, :run 24 | 25 | def run(result) 26 | assertion_counter = AssertionCounter.new(result) 27 | yield(Test::Unit::TestCase::STARTED, name) 28 | @_result = result 29 | begin 30 | begin 31 | setup 32 | __send__(@method_name) 33 | mocha_verify(assertion_counter) 34 | rescue Mocha::ExpectationError => e 35 | add_failure(e.message, e.backtrace) 36 | rescue Test::Unit::AssertionFailedError => e 37 | add_failure(e.message, e.backtrace) 38 | rescue StandardError, ScriptError 39 | add_error($!) 40 | ensure 41 | begin 42 | teardown 43 | rescue Test::Unit::AssertionFailedError => e 44 | add_failure(e.message, e.backtrace) 45 | rescue StandardError, ScriptError 46 | add_error($!) 47 | end 48 | end 49 | ensure 50 | mocha_teardown 51 | end 52 | result.add_run 53 | yield(Test::Unit::TestCase::FINISHED, name) 54 | end 55 | 56 | end 57 | else 58 | base.class_eval do 59 | 60 | alias_method :run_before_mocha_test_case_adapter, :run 61 | 62 | def run(result) 63 | assertion_counter = AssertionCounter.new(result) 64 | yield(Test::Unit::TestCase::STARTED, name) 65 | @_result = result 66 | begin 67 | begin 68 | setup 69 | __send__(@method_name) 70 | mocha_verify(assertion_counter) 71 | rescue Mocha::ExpectationError => e 72 | add_failure(e.message, e.backtrace) 73 | rescue Test::Unit::AssertionFailedError => e 74 | add_failure(e.message, e.backtrace) 75 | rescue Exception 76 | raise if Test::Unit::TestCase::PASSTHROUGH_EXCEPTIONS.include? $!.class 77 | add_error($!) 78 | ensure 79 | begin 80 | teardown 81 | rescue Test::Unit::AssertionFailedError => e 82 | add_failure(e.message, e.backtrace) 83 | rescue Exception 84 | raise if Test::Unit::TestCase::PASSTHROUGH_EXCEPTIONS.include? $!.class 85 | add_error($!) 86 | end 87 | end 88 | ensure 89 | mocha_teardown 90 | end 91 | result.add_run 92 | yield(Test::Unit::TestCase::FINISHED, name) 93 | end 94 | 95 | end 96 | 97 | end 98 | 99 | end 100 | 101 | end 102 | 103 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/unit/state_machine_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "..", "test_helper") 2 | 3 | require 'mocha/state_machine' 4 | 5 | class StateMachineTest < Test::Unit::TestCase 6 | 7 | include Mocha 8 | 9 | def test_should_initially_be_in_no_state 10 | state_machine = StateMachine.new('name') 11 | any_state.each do |state| 12 | assert !state_machine.is(state).active? 13 | assert state_machine.is_not(state).active? 14 | end 15 | end 16 | 17 | def test_should_be_able_to_enter_a_state 18 | state_machine = StateMachine.new('name') 19 | state = 'A' 20 | other_states = any_state.reject { |s| s == state } 21 | 22 | state_machine.is(state).activate 23 | 24 | assert state_machine.is(state).active? 25 | assert !state_machine.is_not(state).active? 26 | other_states.each do |s| 27 | assert !state_machine.is(s).active? 28 | assert state_machine.is_not(s).active? 29 | end 30 | end 31 | 32 | def test_should_be_able_to_change_state 33 | state_machine = StateMachine.new('name') 34 | state = 'B' 35 | other_states = any_state.reject { |s| s == state } 36 | 37 | state_machine.is('A').activate 38 | state_machine.is(state).activate 39 | 40 | assert state_machine.is(state).active? 41 | assert !state_machine.is_not(state).active? 42 | other_states.each do |s| 43 | assert !state_machine.is(s).active? 44 | assert state_machine.is_not(s).active? 45 | end 46 | end 47 | 48 | def test_should_be_put_into_an_initial_state 49 | state_machine = StateMachine.new('name') 50 | initial_state = 'A' 51 | other_states = any_state.reject { |s| s == initial_state } 52 | 53 | state_machine.starts_as(initial_state) 54 | 55 | assert state_machine.is(initial_state).active? 56 | assert !state_machine.is_not(initial_state).active? 57 | other_states.each do |state| 58 | assert !state_machine.is(state).active? 59 | assert state_machine.is_not(state).active? 60 | end 61 | end 62 | 63 | def test_should_be_put_into_a_new_state 64 | next_state = 'B' 65 | 66 | other_states = any_state.reject { |s| s == next_state } 67 | state_machine = StateMachine.new('name').starts_as('A') 68 | 69 | state_machine.become(next_state) 70 | 71 | assert state_machine.is(next_state).active? 72 | assert !state_machine.is_not(next_state).active? 73 | other_states.each do |state| 74 | assert !state_machine.is(state).active? 75 | assert state_machine.is_not(state).active? 76 | end 77 | end 78 | 79 | def test_should_describe_itself_as_name_and_current_state 80 | state_machine = StateMachine.new('state_machine_name') 81 | assert_equal 'state_machine_name has no current state', state_machine.mocha_inspect 82 | inspectable_state = Class.new { define_method(:mocha_inspect) { "'inspectable_state'" } }.new 83 | state_machine.is(inspectable_state).activate 84 | assert_equal "state_machine_name is 'inspectable_state'", state_machine.mocha_inspect 85 | end 86 | 87 | def test_should_have_self_describing_states 88 | state_machine = StateMachine.new('state_machine_name') 89 | inspectable_state = Class.new { define_method(:mocha_inspect) { "'inspectable_state'" } }.new 90 | assert_equal "state_machine_name is 'inspectable_state'", state_machine.is(inspectable_state).mocha_inspect 91 | assert_equal "state_machine_name is not 'inspectable_state'", state_machine.is_not(inspectable_state).mocha_inspect 92 | end 93 | 94 | def any_state 95 | %w(A B C D) 96 | end 97 | 98 | end 99 | -------------------------------------------------------------------------------- /lib/system_timer.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2008 David Vollbracht & Philippe Hanrigou 2 | 3 | if defined?(RUBY_ENGINE) and RUBY_ENGINE == "rbx" 4 | require File.dirname(__FILE__) + '/system_timer_stub' 5 | else 6 | 7 | require 'thread' 8 | require 'timeout' 9 | require 'forwardable' 10 | require 'monitor' 11 | require File.dirname(__FILE__) + '/system_timer/thread_timer' 12 | require File.dirname(__FILE__) + '/system_timer/concurrent_timer_pool' 13 | 14 | # Timer based on underlying +ITIMER_REAL+ system timer. It is a 15 | # solution to Ruby processes which hang beyond the time limit when accessing 16 | # external resources. This is useful when timeout.rb, which relies on green 17 | # threads, does not work consistently. 18 | # 19 | # For more information and background check out: 20 | # 21 | # * http://ph7spot.com/articles/system_timer 22 | # * http://davidvollbracht.com/2008/6/2/30-days-of-teach-day-1-systemtimer 23 | # 24 | # == Usage 25 | # 26 | # require 'systemtimer' 27 | # 28 | # SystemTimer.timeout_after(5) do 29 | # 30 | # # Something that should be interrupted if it takes too much time... 31 | # # ... even if blocked on a system call! 32 | # 33 | # end 34 | # 35 | module SystemTimer 36 | 37 | Thread.exclusive do # Avoid race conditions for monitor and pool creation 38 | @timer_pool = ConcurrentTimerPool.new 39 | @monitor = Monitor.new 40 | end 41 | 42 | class << self 43 | attr_reader :timer_pool 44 | 45 | # Executes the method's block. If the block execution terminates before 46 | # +seconds+ seconds has passed, it returns true. If not, it terminates 47 | # the execution and raises a +Timeout::Error+. 48 | def timeout_after(seconds, exception_class = nil) 49 | new_timer = nil # just for scope 50 | @monitor.synchronize do 51 | new_timer = timer_pool.add_timer seconds, exception_class 52 | timer_interval = timer_pool.next_trigger_interval_in_seconds 53 | debug "==== Install Timer ==== at #{Time.now.to_f}, next interval: #{timer_interval}" 54 | if timer_pool.first_timer? 55 | install_first_timer_and_save_original_configuration timer_interval 56 | else 57 | install_next_timer timer_interval 58 | end 59 | end 60 | return yield 61 | ensure 62 | @monitor.synchronize do 63 | debug "==== Cleanup Timer ==== at #{Time.now.to_f}, #{new_timer} " 64 | timer_pool.cancel new_timer 65 | timer_pool.log_registered_timers if debug_enabled? 66 | next_interval = timer_pool.next_trigger_interval_in_seconds 67 | debug "Cleanup Timer : next interval #{next_interval.inspect} " 68 | if next_interval 69 | install_next_timer next_interval 70 | else 71 | restore_original_configuration 72 | end 73 | end 74 | end 75 | 76 | # Backward compatibility with timeout.rb 77 | alias timeout timeout_after 78 | 79 | protected 80 | 81 | def install_ruby_sigalrm_handler #:nodoc: 82 | @original_ruby_sigalrm_handler = trap('SIGALRM') do 83 | @monitor.synchronize do 84 | # Triggers timers one at a time to ensure more deterministic results 85 | timer_pool.trigger_next_expired_timer 86 | end 87 | end 88 | end 89 | 90 | def restore_original_ruby_sigalrm_handler #:nodoc: 91 | trap('SIGALRM', original_ruby_sigalrm_handler || 'DEFAULT') 92 | ensure 93 | reset_original_ruby_sigalrm_handler 94 | end 95 | 96 | def original_ruby_sigalrm_handler #:nodoc: 97 | @original_ruby_sigalrm_handler 98 | end 99 | 100 | def reset_original_ruby_sigalrm_handler #:nodoc: 101 | @original_ruby_sigalrm_handler = nil 102 | end 103 | 104 | def debug(message) #:nodoc 105 | puts message if debug_enabled? 106 | end 107 | 108 | end 109 | 110 | end 111 | 112 | require 'system_timer_native' 113 | 114 | 115 | end # stub guard 116 | -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/unit/yield_parameters_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "..", "test_helper") 2 | 3 | require 'mocha/yield_parameters' 4 | require 'mocha/no_yields' 5 | require 'mocha/single_yield' 6 | require 'mocha/multiple_yields' 7 | 8 | class YieldParametersTest < Test::Unit::TestCase 9 | 10 | include Mocha 11 | 12 | def test_should_return_null_yield_parameter_group_by_default 13 | yield_parameters = YieldParameters.new 14 | assert yield_parameters.next_invocation.is_a?(NoYields) 15 | end 16 | 17 | def test_should_return_single_yield_parameter_group 18 | yield_parameters = YieldParameters.new 19 | yield_parameters.add(1, 2, 3) 20 | parameter_group = yield_parameters.next_invocation 21 | assert parameter_group.is_a?(SingleYield) 22 | assert_equal [1, 2, 3], parameter_group.parameters 23 | end 24 | 25 | def test_should_keep_returning_single_yield_parameter_group 26 | yield_parameters = YieldParameters.new 27 | yield_parameters.add(1, 2, 3) 28 | yield_parameters.next_invocation 29 | parameter_group = yield_parameters.next_invocation 30 | assert parameter_group.is_a?(SingleYield) 31 | assert_equal [1, 2, 3], parameter_group.parameters 32 | parameter_group = yield_parameters.next_invocation 33 | assert parameter_group.is_a?(SingleYield) 34 | assert_equal [1, 2, 3], parameter_group.parameters 35 | end 36 | 37 | def test_should_return_consecutive_single_yield_parameter_groups 38 | yield_parameters = YieldParameters.new 39 | yield_parameters.add(1, 2, 3) 40 | yield_parameters.add(4, 5) 41 | parameter_group = yield_parameters.next_invocation 42 | assert parameter_group.is_a?(SingleYield) 43 | assert_equal [1, 2, 3], parameter_group.parameters 44 | parameter_group = yield_parameters.next_invocation 45 | assert parameter_group.is_a?(SingleYield) 46 | assert_equal [4, 5], parameter_group.parameters 47 | end 48 | 49 | def test_should_return_multiple_yield_parameter_group 50 | yield_parameters = YieldParameters.new 51 | yield_parameters.multiple_add([1, 2, 3], [4, 5]) 52 | parameter_group = yield_parameters.next_invocation 53 | assert parameter_group.is_a?(MultipleYields) 54 | assert_equal [[1, 2, 3], [4, 5]], parameter_group.parameter_groups 55 | end 56 | 57 | def test_should_keep_returning_multiple_yield_parameter_group 58 | yield_parameters = YieldParameters.new 59 | yield_parameters.multiple_add([1, 2, 3], [4, 5]) 60 | yield_parameters.next_invocation 61 | parameter_group = yield_parameters.next_invocation 62 | assert parameter_group.is_a?(MultipleYields) 63 | assert_equal [[1, 2, 3], [4, 5]], parameter_group.parameter_groups 64 | parameter_group = yield_parameters.next_invocation 65 | assert parameter_group.is_a?(MultipleYields) 66 | assert_equal [[1, 2, 3], [4, 5]], parameter_group.parameter_groups 67 | end 68 | 69 | def test_should_return_consecutive_multiple_yield_parameter_groups 70 | yield_parameters = YieldParameters.new 71 | yield_parameters.multiple_add([1, 2, 3], [4, 5]) 72 | yield_parameters.multiple_add([6, 7], [8, 9, 0]) 73 | parameter_group = yield_parameters.next_invocation 74 | assert parameter_group.is_a?(MultipleYields) 75 | assert_equal [[1, 2, 3], [4, 5]], parameter_group.parameter_groups 76 | parameter_group = yield_parameters.next_invocation 77 | assert parameter_group.is_a?(MultipleYields) 78 | assert_equal [[6, 7], [8, 9, 0]], parameter_group.parameter_groups 79 | end 80 | 81 | def test_should_return_consecutive_single_and_multiple_yield_parameter_groups 82 | yield_parameters = YieldParameters.new 83 | yield_parameters.add(1, 2, 3) 84 | yield_parameters.multiple_add([4, 5, 6], [7, 8]) 85 | parameter_group = yield_parameters.next_invocation 86 | assert parameter_group.is_a?(SingleYield) 87 | assert_equal [1, 2, 3], parameter_group.parameters 88 | parameter_group = yield_parameters.next_invocation 89 | assert parameter_group.is_a?(MultipleYields) 90 | assert_equal [[4, 5, 6], [7, 8]], parameter_group.parameter_groups 91 | end 92 | 93 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/acceptance/standalone_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "acceptance_test_helper") 2 | require 'mocha_standalone' 3 | require 'simple_counter' 4 | 5 | class NotATestUnitAssertionFailedError < StandardError 6 | end 7 | 8 | class NotATestUnitTestCase 9 | 10 | include Mocha::Standalone 11 | 12 | attr_reader :assertion_counter 13 | 14 | def initialize 15 | @assertion_counter = SimpleCounter.new 16 | end 17 | 18 | def run(test_method) 19 | mocha_setup 20 | begin 21 | prepare 22 | begin 23 | send(test_method) 24 | mocha_verify(@assertion_counter) 25 | rescue Mocha::ExpectationError => e 26 | new_error = NotATestUnitAssertionFailedError.new(e.message) 27 | new_error.set_backtrace(e.backtrace) 28 | raise new_error 29 | ensure 30 | cleanup 31 | end 32 | ensure 33 | mocha_teardown 34 | end 35 | end 36 | 37 | def prepare 38 | end 39 | 40 | def cleanup 41 | end 42 | 43 | end 44 | 45 | class SampleTest < NotATestUnitTestCase 46 | 47 | def mocha_with_fulfilled_expectation 48 | mockee = mock() 49 | mockee.expects(:blah) 50 | mockee.blah 51 | end 52 | 53 | def mocha_with_unfulfilled_expectation 54 | mockee = mock() 55 | mockee.expects(:blah) 56 | end 57 | 58 | def mocha_with_unexpected_invocation 59 | mockee = mock() 60 | mockee.blah 61 | end 62 | 63 | def stubba_with_fulfilled_expectation 64 | stubbee = Class.new { define_method(:blah) {} }.new 65 | stubbee.expects(:blah) 66 | stubbee.blah 67 | end 68 | 69 | def stubba_with_unfulfilled_expectation 70 | stubbee = Class.new { define_method(:blah) {} }.new 71 | stubbee.expects(:blah) 72 | end 73 | 74 | def mocha_with_matching_parameter 75 | mockee = mock() 76 | mockee.expects(:blah).with(has_key(:wibble)) 77 | mockee.blah(:wibble => 1) 78 | end 79 | 80 | def mocha_with_non_matching_parameter 81 | mockee = mock() 82 | mockee.expects(:blah).with(has_key(:wibble)) 83 | mockee.blah(:wobble => 2) 84 | end 85 | 86 | end 87 | 88 | require 'test/unit' 89 | 90 | class StandaloneTest < Test::Unit::TestCase 91 | 92 | attr_reader :sample_test 93 | 94 | include AcceptanceTest 95 | 96 | def setup 97 | @sample_test = SampleTest.new 98 | setup_acceptance_test 99 | end 100 | 101 | def teardown 102 | teardown_acceptance_test 103 | end 104 | 105 | def test_should_pass_mocha_test 106 | assert_nothing_raised { sample_test.run(:mocha_with_fulfilled_expectation) } 107 | assert_equal 1, sample_test.assertion_counter.count 108 | end 109 | 110 | def test_should_fail_mocha_test_due_to_unfulfilled_exception 111 | assert_raises(NotATestUnitAssertionFailedError) { sample_test.run(:mocha_with_unfulfilled_expectation) } 112 | assert_equal 1, sample_test.assertion_counter.count 113 | end 114 | 115 | def test_should_fail_mocha_test_due_to_unexpected_invocation 116 | assert_raises(NotATestUnitAssertionFailedError) { sample_test.run(:mocha_with_unexpected_invocation) } 117 | assert_equal 0, sample_test.assertion_counter.count 118 | end 119 | 120 | def test_should_pass_stubba_test 121 | assert_nothing_raised { sample_test.run(:stubba_with_fulfilled_expectation) } 122 | assert_equal 1, sample_test.assertion_counter.count 123 | end 124 | 125 | def test_should_fail_stubba_test 126 | assert_raises(NotATestUnitAssertionFailedError) { sample_test.run(:stubba_with_unfulfilled_expectation) } 127 | assert_equal 1, sample_test.assertion_counter.count 128 | end 129 | 130 | def test_should_pass_mocha_test_with_matching_parameter 131 | assert_nothing_raised { sample_test.run(:mocha_with_matching_parameter) } 132 | assert_equal 1, sample_test.assertion_counter.count 133 | end 134 | 135 | def test_should_fail_mocha_test_with_non_matching_parameter 136 | assert_raises(NotATestUnitAssertionFailedError) { sample_test.run(:mocha_with_non_matching_parameter) } 137 | end 138 | 139 | end -------------------------------------------------------------------------------- /test/system_timer_unit_test.rb: -------------------------------------------------------------------------------- 1 | require File.dirname(__FILE__) + '/test_helper' 2 | 3 | unit_tests do 4 | 5 | test "timeout_after registers a new timer in the timer pool" do 6 | pool = stub_everything 7 | Thread.stubs(:current).returns(:the_current_thread) 8 | SystemTimer.stubs(:timer_pool).returns(pool) 9 | SystemTimer.stubs(:install_next_timer) 10 | SystemTimer.stubs(:restore_original_configuration) 11 | 12 | pool.expects(:add_timer).with(5, nil).returns(stub_everything) 13 | SystemTimer.timeout_after(5) {} 14 | end 15 | 16 | test "timeout_after registers a new timer with a custom timeout exception in the timer pool" do 17 | MyCustomException = Class.new(Exception) 18 | pool = stub_everything 19 | Thread.stubs(:current).returns(:the_current_thread) 20 | SystemTimer.stubs(:timer_pool).returns(pool) 21 | SystemTimer.stubs(:install_next_timer) 22 | SystemTimer.stubs(:restore_original_configuration) 23 | 24 | pool.expects(:add_timer).with(5, MyCustomException).returns(stub_everything) 25 | SystemTimer.timeout_after(5, MyCustomException) {} 26 | end 27 | 28 | test "timeout_after installs a system timer saving the previous " + 29 | "configuration when there is only one timer" do 30 | 31 | now = Time.now 32 | Time.stubs(:now).returns(now) 33 | SystemTimer.stubs(:restore_original_configuration) 34 | SystemTimer.expects(:install_first_timer_and_save_original_configuration) \ 35 | .with {|value| value.between?(23.99, 24.01) } 36 | SystemTimer.timeout_after(24) {} 37 | end 38 | 39 | test "timeout_after installs a system timer without saving the previous " + 40 | "configuration when there is more than one timer" do 41 | 42 | now = Time.now 43 | Time.stubs(:now).returns(now) 44 | SystemTimer.timer_pool.register_timer now.to_f + 100, :a_thread 45 | SystemTimer.stubs(:restore_original_configuration) 46 | SystemTimer.stubs(:install_next_timer) 47 | 48 | SystemTimer.expects(:install_next_timer) \ 49 | .with {|value| value.between?(23.99, 24.01) } 50 | SystemTimer.timeout_after(24) {} 51 | end 52 | 53 | test "timeout_after installs a system timer with the interval before " + 54 | "the next timer to expire" do 55 | 56 | now = Time.now 57 | Time.stubs(:now).returns(now) 58 | SystemTimer.timer_pool.register_timer now.to_f + 24, :a_thread 59 | SystemTimer.stubs(:restore_original_configuration) 60 | SystemTimer.stubs(:install_next_timer) 61 | 62 | SystemTimer.expects(:install_next_timer) \ 63 | .with {|value| value.between?(23.99, 24.01) } 64 | SystemTimer.timeout_after(100) {} 65 | end 66 | 67 | test "timeout_after cancels the timer when the block completes without " + 68 | "timeout" do 69 | 70 | now = Time.now 71 | the_timer = stub_everything 72 | Time.stubs(:now).returns(now) 73 | SystemTimer.stubs(:restore_original_configuration) 74 | SystemTimer.stubs(:install_first_timer_and_save_original_configuration) 75 | SystemTimer.timer_pool.stubs(:add_timer).returns(the_timer) 76 | SystemTimer.timer_pool.stubs(:first_timer?).returns(true) 77 | 78 | SystemTimer.timer_pool.expects(:cancel).with(the_timer) 79 | SystemTimer.timeout_after(24) {} 80 | end 81 | 82 | test "debug does not output to stdout when debug is disabled" do 83 | SystemTimer.stubs(:debug_enabled?).returns(false) 84 | original_stdout = $stdout 85 | begin 86 | stdout = StringIO.new 87 | $stdout = stdout 88 | 89 | SystemTimer.send :debug, "a log message" 90 | assert stdout.string.empty? 91 | ensure 92 | $stdout = original_stdout 93 | end 94 | end 95 | 96 | test "debug logs messaget to stdout when debug is enabled" do 97 | SystemTimer.stubs(:debug_enabled?).returns(true) 98 | original_stdout = $stdout 99 | begin 100 | stdout = StringIO.new 101 | $stdout = stdout 102 | 103 | SystemTimer.send :debug, "a log message" 104 | assert_match /a log message/, stdout.string 105 | ensure 106 | $stdout = original_stdout 107 | end 108 | end 109 | 110 | end 111 | -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/test/unit/sequence_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "..", "test_helper") 2 | require 'mocha/sequence' 3 | require 'mocha/expectation' 4 | 5 | class SequenceTest < Test::Unit::TestCase 6 | 7 | include Mocha 8 | 9 | class FakeExpectation 10 | 11 | attr_reader :ordering_constraints 12 | 13 | def initialize(satisfied = false) 14 | @satisfied = satisfied 15 | @ordering_constraints = [] 16 | end 17 | 18 | def add_ordering_constraint(ordering_constraint) 19 | @ordering_constraints << ordering_constraint 20 | end 21 | 22 | def satisfied? 23 | @satisfied 24 | end 25 | 26 | end 27 | 28 | def test_should_be_satisfied_if_no_expectations_added 29 | sequence = Sequence.new('name') 30 | assert sequence.satisfied_to_index?(0) 31 | end 32 | 33 | def test_should_be_satisfied_if_one_unsatisfied_expectations_added_but_it_is_not_included_by_index 34 | sequence = Sequence.new('name') 35 | expectation = FakeExpectation.new(satisfied = false) 36 | sequence.constrain_as_next_in_sequence(expectation) 37 | assert sequence.satisfied_to_index?(0) 38 | end 39 | 40 | def test_should_not_be_satisfied_if_one_unsatisfied_expectations_added_and_it_is_included_by_index 41 | sequence = Sequence.new('name') 42 | expectation = FakeExpectation.new(satisfied = false) 43 | sequence.constrain_as_next_in_sequence(expectation) 44 | assert !sequence.satisfied_to_index?(1) 45 | end 46 | 47 | def test_should_be_satisfied_if_one_satisfied_expectations_added_and_it_is_included_by_index 48 | sequence = Sequence.new('name') 49 | expectation = FakeExpectation.new(satisfied = true) 50 | sequence.constrain_as_next_in_sequence(expectation) 51 | assert sequence.satisfied_to_index?(1) 52 | end 53 | 54 | def test_should_not_be_satisfied_if_one_satisfied_and_one_unsatisfied_expectation_added_and_both_are_included_by_index 55 | sequence = Sequence.new('name') 56 | expectation_one = FakeExpectation.new(satisfied = true) 57 | expectation_two = FakeExpectation.new(satisfied = false) 58 | sequence.constrain_as_next_in_sequence(expectation_one) 59 | sequence.constrain_as_next_in_sequence(expectation_two) 60 | assert !sequence.satisfied_to_index?(2) 61 | end 62 | 63 | def test_should_be_satisfied_if_two_satisfied_expectations_added_and_both_are_included_by_index 64 | sequence = Sequence.new('name') 65 | expectation_one = FakeExpectation.new(satisfied = true) 66 | expectation_two = FakeExpectation.new(satisfied = true) 67 | sequence.constrain_as_next_in_sequence(expectation_one) 68 | sequence.constrain_as_next_in_sequence(expectation_two) 69 | assert sequence.satisfied_to_index?(2) 70 | end 71 | 72 | def test_should_add_ordering_constraint_to_expectation 73 | sequence = Sequence.new('name') 74 | expectation = FakeExpectation.new 75 | sequence.constrain_as_next_in_sequence(expectation) 76 | assert_equal 1, expectation.ordering_constraints.length 77 | end 78 | 79 | def test_should_not_allow_invocation_of_second_method_when_first_n_sequence_has_not_been_invoked 80 | sequence = Sequence.new('name') 81 | expectation_one = FakeExpectation.new(satisfied = false) 82 | expectation_two = FakeExpectation.new(satisfied = false) 83 | sequence.constrain_as_next_in_sequence(expectation_one) 84 | sequence.constrain_as_next_in_sequence(expectation_two) 85 | assert !expectation_two.ordering_constraints[0].allows_invocation_now? 86 | end 87 | 88 | def test_should_allow_invocation_of_second_method_when_first_in_sequence_has_been_invoked 89 | sequence = Sequence.new('name') 90 | expectation_one = FakeExpectation.new(satisfied = true) 91 | expectation_two = FakeExpectation.new(satisfied = false) 92 | sequence.constrain_as_next_in_sequence(expectation_one) 93 | sequence.constrain_as_next_in_sequence(expectation_two) 94 | assert expectation_two.ordering_constraints[0].allows_invocation_now? 95 | end 96 | 97 | def test_should_describe_ordering_constraint_as_being_part_of_named_sequence 98 | sequence = Sequence.new('wibble') 99 | expectation = FakeExpectation.new 100 | sequence.constrain_as_next_in_sequence(expectation) 101 | assert_equal "in sequence 'wibble'", expectation.ordering_constraints[0].mocha_inspect 102 | end 103 | 104 | end -------------------------------------------------------------------------------- /vendor/gems/mocha-0.9.1/lib/mocha/object.rb: -------------------------------------------------------------------------------- 1 | require 'mocha/mockery' 2 | require 'mocha/instance_method' 3 | require 'mocha/class_method' 4 | require 'mocha/module_method' 5 | require 'mocha/any_instance_method' 6 | 7 | # Methods added all objects to allow mocking and stubbing on real objects. 8 | # 9 | # Methods return a Mocha::Expectation which can be further modified by methods on Mocha::Expectation. 10 | class Object 11 | 12 | def mocha # :nodoc: 13 | @mocha ||= Mocha::Mockery.instance.mock_impersonating(self) 14 | end 15 | 16 | def reset_mocha # :nodoc: 17 | @mocha = nil 18 | end 19 | 20 | def stubba_method # :nodoc: 21 | Mocha::InstanceMethod 22 | end 23 | 24 | def stubba_object # :nodoc: 25 | self 26 | end 27 | 28 | # :call-seq: expects(symbol) -> expectation 29 | # 30 | # Adds an expectation that a method identified by +symbol+ must be called exactly once with any parameters. 31 | # Returns the new expectation which can be further modified by methods on Mocha::Expectation. 32 | # product = Product.new 33 | # product.expects(:save).returns(true) 34 | # assert_equal false, product.save 35 | # 36 | # The original implementation of Product#save is replaced temporarily. 37 | # 38 | # The original implementation of Product#save is restored at the end of the test. 39 | def expects(symbol) 40 | mockery = Mocha::Mockery.instance 41 | mockery.on_stubbing(self, symbol) 42 | method = stubba_method.new(stubba_object, symbol) 43 | mockery.stubba.stub(method) 44 | mocha.expects(symbol, caller) 45 | end 46 | 47 | # :call-seq: stubs(symbol) -> expectation 48 | # 49 | # Adds an expectation that a method identified by +symbol+ may be called any number of times with any parameters. 50 | # Returns the new expectation which can be further modified by methods on Mocha::Expectation. 51 | # product = Product.new 52 | # product.stubs(:save).returns(true) 53 | # assert_equal false, product.save 54 | # 55 | # The original implementation of Product#save is replaced temporarily. 56 | # 57 | # The original implementation of Product#save is restored at the end of the test. 58 | def stubs(symbol) 59 | mockery = Mocha::Mockery.instance 60 | mockery.on_stubbing(self, symbol) 61 | method = stubba_method.new(stubba_object, symbol) 62 | mockery.stubba.stub(method) 63 | mocha.stubs(symbol, caller) 64 | end 65 | 66 | def method_exists?(method, include_public_methods = true) 67 | if include_public_methods 68 | return true if public_methods(include_superclass_methods = true).include?(method) 69 | return true if respond_to?(method) 70 | end 71 | return true if protected_methods(include_superclass_methods = true).include?(method) 72 | return true if private_methods(include_superclass_methods = true).include?(method) 73 | return false 74 | end 75 | 76 | end 77 | 78 | class Module # :nodoc: 79 | 80 | def stubba_method 81 | Mocha::ModuleMethod 82 | end 83 | 84 | end 85 | 86 | class Class 87 | 88 | def stubba_method # :nodoc: 89 | Mocha::ClassMethod 90 | end 91 | 92 | class AnyInstance # :nodoc: 93 | 94 | def initialize(klass) 95 | @stubba_object = klass 96 | end 97 | 98 | def mocha 99 | @mocha ||= Mocha::Mockery.instance.mock_impersonating_any_instance_of(@stubba_object) 100 | end 101 | 102 | def stubba_method 103 | Mocha::AnyInstanceMethod 104 | end 105 | 106 | def stubba_object 107 | @stubba_object 108 | end 109 | 110 | def method_exists?(method, include_public_methods = true) 111 | if include_public_methods 112 | return true if @stubba_object.public_instance_methods(include_superclass_methods = true).include?(method) 113 | end 114 | return true if @stubba_object.protected_instance_methods(include_superclass_methods = true).include?(method) 115 | return true if @stubba_object.private_instance_methods(include_superclass_methods = true).include?(method) 116 | return false 117 | end 118 | 119 | end 120 | 121 | # :call-seq: any_instance -> mock object 122 | # 123 | # Returns a mock object which will detect calls to any instance of this class. 124 | # Product.any_instance.stubs(:save).returns(false) 125 | # product_1 = Product.new 126 | # assert_equal false, product_1.save 127 | # product_2 = Product.new 128 | # assert_equal false, product_2.save 129 | def any_instance 130 | @any_instance ||= AnyInstance.new(self) 131 | end 132 | 133 | end 134 | 135 | --------------------------------------------------------------------------------