From 2c6fa43dde19512f1440424fe7a7173b479e37de Mon Sep 17 00:00:00 2001 From: Dan Croak Date: Fri, 24 Jul 2009 19:05:40 -0400 Subject: [PATCH] unpacking test gems --- vendor/gems/jferris-mocha-0.9.5.0.1241126838/COPYING | 3 +++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/MIT-LICENSE | 7 +++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/README | 37 +++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/RELEASE | 269 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/Rakefile | 217 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/examples/misc.rb | 43 +++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/examples/mocha.rb | 25 +++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/examples/stubba.rb | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha.rb | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/any_instance_method.rb | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/api.rb | 249 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/argument_iterator.rb | 21 +++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/backtrace_filter.rb | 17 +++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/cardinality.rb | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/central.rb | 27 +++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/change_state_side_effect.rb | 19 +++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/class_method.rb | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/configuration.rb | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/deprecation.rb | 22 ++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/exception_raiser.rb | 17 +++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/expectation.rb | 484 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/expectation_error.rb | 15 +++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/expectation_list.rb | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/in_state_ordering_constraint.rb | 19 +++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/inspect.rb | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/instance_method.rb | 16 ++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/bacon.rb | 1 + vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/bacon/assertion_counter.rb | 23 +++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/bacon/version_11_and_above.rb | 34 ++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/mini_test.rb | 1 + vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/mini_test/assertion_counter.rb | 23 +++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/mini_test/version_131_and_above.rb | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/test_unit.rb | 4 ++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/test_unit/assertion_counter.rb | 23 +++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/test_unit/gem_version_200.rb | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/test_unit/gem_version_201_and_above.rb | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/test_unit/ruby_version_185_and_below.rb | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/test_unit/ruby_version_186_and_above.rb | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/invocation.rb | 10 ++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/is_a.rb | 9 +++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/logger.rb | 15 +++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/metaclass.rb | 13 +++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/method_matcher.rb | 21 +++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/mock.rb | 200 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/mockery.rb | 189 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/module_method.rb | 16 ++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/multiple_yields.rb | 20 ++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/names.rb | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/no_yields.rb | 11 +++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/object.rb | 187 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers.rb | 27 +++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/all_of.rb | 42 ++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/any_of.rb | 47 +++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/any_parameters.rb | 40 ++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/anything.rb | 33 +++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/base.rb | 15 +++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/equals.rb | 42 ++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/has_entries.rb | 45 +++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/has_entry.rb | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/has_key.rb | 42 ++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/has_value.rb | 42 ++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/includes.rb | 40 ++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/instance_of.rb | 42 ++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/is_a.rb | 42 ++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/kind_of.rb | 42 ++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/not.rb | 42 ++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/object.rb | 15 +++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/optionally.rb | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/regexp_matches.rb | 43 +++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/responds_with.rb | 43 +++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/yaml_equivalent.rb | 43 +++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameters_matcher.rb | 37 +++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/pretty_parameters.rb | 28 ++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/return_values.rb | 31 +++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/sequence.rb | 42 ++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/single_return_value.rb | 17 +++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/single_yield.rb | 18 ++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/state_machine.rb | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/stubbing_error.rb | 16 ++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/unexpected_invocation.rb | 18 ++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/yield_parameters.rb | 31 +++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha_standalone.rb | 2 ++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/stubba.rb | 4 ++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/acceptance_test_helper.rb | 38 ++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/api_test.rb | 139 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/bacon_spec.rb | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/bacon_test.rb | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/bug_18914_test.rb | 43 +++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/bug_21465_test.rb | 34 ++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/bug_21563_test.rb | 25 +++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/expected_invocation_count_test.rb | 196 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/failure_messages_test.rb | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/minitest_test.rb | 146 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/mocha_example_test.rb | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/mocha_test_result_test.rb | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/mock_test.rb | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/mock_with_initializer_block_test.rb | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/mocked_methods_dispatch_test.rb | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/optional_parameters_test.rb | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/parameter_matcher_test.rb | 209 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/partial_mocks_test.rb | 47 +++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/return_value_test.rb | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/sequence_test.rb | 186 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/spy_test.rb | 134 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/states_test.rb | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stub_any_instance_method_test.rb | 195 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stub_class_method_test.rb | 203 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stub_everything_test.rb | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stub_instance_method_test.rb | 203 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stub_module_method_test.rb | 163 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stub_test.rb | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stubba_example_test.rb | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stubba_test.rb | 15 +++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stubba_test_result_test.rb | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stubbing_error_backtrace_test.rb | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stubbing_method_unnecessarily_test.rb | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stubbing_non_existent_any_instance_method_test.rb | 130 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stubbing_non_existent_class_method_test.rb | 157 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stubbing_non_existent_instance_method_test.rb | 147 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stubbing_non_public_any_instance_method_test.rb | 130 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stubbing_non_public_class_method_test.rb | 163 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stubbing_non_public_instance_method_test.rb | 143 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stubbing_on_non_mock_object_test.rb | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/deprecation_disabler.rb | 15 +++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/execution_point.rb | 36 ++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/matcher_helpers.rb | 5 +++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/method_definer.rb | 24 ++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/simple_counter.rb | 13 +++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/test_helper.rb | 16 ++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/test_runner.rb | 33 +++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/any_instance_method_test.rb | 126 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/array_inspect_test.rb | 16 ++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/assert_received_test.rb | 145 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/backtrace_filter_test.rb | 19 +++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/cardinality_test.rb | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/central_test.rb | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/change_state_side_effect_test.rb | 41 +++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/class_method_test.rb | 237 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/date_time_inspect_test.rb | 21 +++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/exception_raiser_test.rb | 42 ++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/expectation_list_test.rb | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/expectation_test.rb | 526 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/hash_inspect_test.rb | 16 ++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/have_received_test.rb | 192 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/in_state_ordering_constraint_test.rb | 43 +++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/invocation_test.rb | 17 +++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/metaclass_test.rb | 22 ++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/method_matcher_test.rb | 23 +++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/mock_test.rb | 329 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/mockery_test.rb | 163 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/multiple_yields_test.rb | 18 ++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/no_yields_test.rb | 18 ++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/object_inspect_test.rb | 37 +++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/object_test.rb | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/all_of_test.rb | 26 ++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/any_of_test.rb | 26 ++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/anything_test.rb | 21 +++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/equals_test.rb | 25 +++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/has_entries_test.rb | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/has_entry_test.rb | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/has_key_test.rb | 36 ++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/has_value_test.rb | 37 +++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/includes_test.rb | 25 +++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/instance_of_test.rb | 25 +++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/is_a_test.rb | 25 +++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/kind_of_test.rb | 25 +++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/not_test.rb | 26 ++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/regexp_matches_test.rb | 25 +++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/responds_with_test.rb | 25 +++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/stub_matcher.rb | 27 +++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/yaml_equivalent_test.rb | 25 +++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameters_matcher_test.rb | 121 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/return_values_test.rb | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/sequence_test.rb | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/single_return_value_test.rb | 14 ++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/single_yield_test.rb | 18 ++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/state_machine_test.rb | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/string_inspect_test.rb | 11 +++++++++++ vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/yield_parameters_test.rb | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-factory_girl-1.2.1/CONTRIBUTION_GUIDELINES.rdoc | 10 ++++++++++ vendor/gems/thoughtbot-factory_girl-1.2.1/Changelog | 29 +++++++++++++++++++++++++++++ vendor/gems/thoughtbot-factory_girl-1.2.1/LICENSE | 19 +++++++++++++++++++ vendor/gems/thoughtbot-factory_girl-1.2.1/README.rdoc | 228 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-factory_girl-1.2.1/Rakefile | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl.rb | 34 ++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/aliases.rb | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/attribute.rb | 28 ++++++++++++++++++++++++++++ vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/attribute/association.rb | 18 ++++++++++++++++++ vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/attribute/dynamic.rb | 17 +++++++++++++++++ vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/attribute/static.rb | 17 +++++++++++++++++ vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/factory.rb | 360 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/proxy.rb | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/proxy/attributes_for.rb | 21 +++++++++++++++++++++ vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/proxy/build.rb | 29 +++++++++++++++++++++++++++++ vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/proxy/create.rb | 10 ++++++++++ vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/proxy/stub.rb | 28 ++++++++++++++++++++++++++++ vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/sequence.rb | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/syntax.rb | 12 ++++++++++++ vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/syntax/blueprint.rb | 42 ++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/syntax/generate.rb | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/syntax/make.rb | 39 +++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/syntax/sham.rb | 42 ++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-factory_girl-1.2.1/test/aliases_test.rb | 29 +++++++++++++++++++++++++++++ vendor/gems/thoughtbot-factory_girl-1.2.1/test/association_attribute_test.rb | 31 +++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-factory_girl-1.2.1/test/attribute_test.rb | 32 ++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-factory_girl-1.2.1/test/attributes_for_strategy_test.rb | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-factory_girl-1.2.1/test/build_strategy_test.rb | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-factory_girl-1.2.1/test/create_strategy_test.rb | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-factory_girl-1.2.1/test/dynamic_attribute_test.rb | 41 +++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-factory_girl-1.2.1/test/factory_test.rb | 513 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-factory_girl-1.2.1/test/integration_test.rb | 235 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-factory_girl-1.2.1/test/models.rb | 43 +++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-factory_girl-1.2.1/test/sequence_test.rb | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-factory_girl-1.2.1/test/static_attribute_test.rb | 33 +++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-factory_girl-1.2.1/test/strategy_test.rb | 33 +++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-factory_girl-1.2.1/test/stub_strategy_test.rb | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-factory_girl-1.2.1/test/syntax/blueprint_test.rb | 39 +++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-factory_girl-1.2.1/test/syntax/generate_test.rb | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-factory_girl-1.2.1/test/syntax/make_test.rb | 39 +++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-factory_girl-1.2.1/test/syntax/sham_test.rb | 40 ++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-factory_girl-1.2.1/test/test_helper.rb | 11 +++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/CONTRIBUTION_GUIDELINES.rdoc | 12 ++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/MIT-LICENSE | 22 ++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/README.rdoc | 169 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/Rakefile | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/bin/convert_to_should_syntax | 42 ++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda.rb | 9 +++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller.rb | 28 ++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller/helpers.rb | 47 +++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller/macros.rb | 277 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller/matchers.rb | 37 +++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller/matchers/assign_to_matcher.rb | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller/matchers/filter_param_matcher.rb | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller/matchers/render_with_layout_matcher.rb | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller/matchers/respond_with_content_type_matcher.rb | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller/matchers/respond_with_matcher.rb | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller/matchers/route_matcher.rb | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller/matchers/set_session_matcher.rb | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller/matchers/set_the_flash_matcher.rb | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_mailer.rb | 10 ++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_mailer/assertions.rb | 38 ++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_view.rb | 10 ++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_view/macros.rb | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record.rb | 16 ++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/assertions.rb | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/helpers.rb | 40 ++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/macros.rb | 589 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers.rb | 42 ++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/allow_mass_assignment_of_matcher.rb | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/allow_value_matcher.rb | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/association_matcher.rb | 226 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/ensure_inclusion_of_matcher.rb | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/ensure_length_of_matcher.rb | 141 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/have_db_column_matcher.rb | 169 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/have_index_matcher.rb | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/have_named_scope_matcher.rb | 125 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/have_readonly_attribute_matcher.rb | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/validate_acceptance_of_matcher.rb | 41 +++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/validate_numericality_of_matcher.rb | 39 +++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/validate_presence_of_matcher.rb | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/validate_uniqueness_of_matcher.rb | 148 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/validation_matcher.rb | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/assertions.rb | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/autoload_macros.rb | 46 ++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/context.rb | 304 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/helpers.rb | 8 ++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/macros.rb | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/private_helpers.rb | 20 ++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/proc_extensions.rb | 14 ++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/rails.rb | 13 +++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/rspec.rb | 11 +++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/tasks.rb | 3 +++ vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/tasks/list_tests.rake | 29 +++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/tasks/yaml_to_shoulda.rake | 28 ++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/test_unit.rb | 19 +++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/rails/init.rb | 7 +++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/README | 36 ++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/fail_macros.rb | 34 ++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/fixtures/addresses.yml | 3 +++ vendor/gems/thoughtbot-shoulda-2.10.1/test/fixtures/friendships.yml | 0 vendor/gems/thoughtbot-shoulda-2.10.1/test/fixtures/posts.yml | 5 +++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/fixtures/products.yml | 0 vendor/gems/thoughtbot-shoulda-2.10.1/test/fixtures/taggings.yml | 0 vendor/gems/thoughtbot-shoulda-2.10.1/test/fixtures/tags.yml | 9 +++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/fixtures/users.yml | 6 ++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/functional/posts_controller_test.rb | 125 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/functional/users_controller_test.rb | 19 +++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/allow_mass_assignment_of_matcher_test.rb | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/allow_value_matcher_test.rb | 41 +++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/association_matcher_test.rb | 258 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/ensure_inclusion_of_matcher_test.rb | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/ensure_length_of_matcher_test.rb | 158 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/have_db_column_matcher_test.rb | 169 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/have_index_matcher_test.rb | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/have_named_scope_matcher_test.rb | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/have_readonly_attributes_matcher_test.rb | 29 +++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/validate_acceptance_of_matcher_test.rb | 44 ++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/validate_numericality_of_matcher_test.rb | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/validate_presence_of_matcher_test.rb | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/validate_uniqueness_of_matcher_test.rb | 147 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/controller/assign_to_matcher_test.rb | 35 +++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/controller/filter_param_matcher_test.rb | 32 ++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/controller/render_with_layout_matcher_test.rb | 33 +++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/controller/respond_with_content_type_matcher_test.rb | 27 +++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/controller/respond_with_matcher_test.rb | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/controller/route_matcher_test.rb | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/controller/set_session_matcher_test.rb | 31 +++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/controller/set_the_flash_matcher.rb | 41 +++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/model_builder.rb | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/other/autoload_macro_test.rb | 18 ++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/other/context_test.rb | 145 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/other/convert_to_should_syntax_test.rb | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/other/helpers_test.rb | 241 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/other/private_helpers_test.rb | 34 ++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/other/should_test.rb | 266 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/controllers/application.rb | 25 +++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/controllers/posts_controller.rb | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/controllers/users_controller.rb | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/helpers/application_helper.rb | 3 +++ vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/helpers/posts_helper.rb | 2 ++ vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/helpers/users_helper.rb | 2 ++ vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/models/address.rb | 7 +++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/models/flea.rb | 3 +++ vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/models/friendship.rb | 4 ++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/models/pets/dog.rb | 10 ++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/models/post.rb | 12 ++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/models/product.rb | 12 ++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/models/tag.rb | 8 ++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/models/tagging.rb | 4 ++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/models/treat.rb | 3 +++ vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/models/user.rb | 29 +++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/views/layouts/posts.rhtml | 19 +++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/views/layouts/users.rhtml | 17 +++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/views/layouts/wide.html.erb | 1 + vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/views/posts/edit.rhtml | 27 +++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/views/posts/index.rhtml | 25 +++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/views/posts/new.rhtml | 26 ++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/views/posts/show.rhtml | 18 ++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/views/users/edit.rhtml | 22 ++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/views/users/index.rhtml | 22 ++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/views/users/new.rhtml | 21 +++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/views/users/show.rhtml | 13 +++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/config/boot.rb | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/config/database.yml | 4 ++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/config/environment.rb | 14 ++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/config/environments/test.rb | 0 vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/config/initializers/new_rails_defaults.rb | 15 +++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/config/initializers/shoulda.rb | 8 ++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/config/routes.rb | 6 ++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/db/migrate/001_create_users.rb | 19 +++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/db/migrate/002_create_posts.rb | 13 +++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/db/migrate/003_create_taggings.rb | 12 ++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/db/migrate/004_create_tags.rb | 11 +++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/db/migrate/005_create_dogs.rb | 12 ++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/db/migrate/006_create_addresses.rb | 14 ++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/db/migrate/007_create_fleas.rb | 11 +++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/db/migrate/008_create_dogs_fleas.rb | 12 ++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/db/migrate/009_create_products.rb | 17 +++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/db/migrate/010_create_friendships.rb | 14 ++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/db/migrate/011_create_treats.rb | 12 ++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/db/schema.rb | 0 vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/public/404.html | 30 ++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/public/422.html | 30 ++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/public/500.html | 30 ++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/script/console | 3 +++ vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/script/generate | 3 +++ vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/test/shoulda_macros/custom_macro.rb | 6 ++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/vendor/gems/gem_with_macro-0.0.1/shoulda_macros/gem_macro.rb | 6 ++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/vendor/plugins/plugin_with_macro/shoulda_macros/plugin_macro.rb | 6 ++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/rspec_test.rb | 207 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/test_helper.rb | 35 +++++++++++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/unit/address_test.rb | 10 ++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/unit/dog_test.rb | 10 ++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/unit/flea_test.rb | 6 ++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/unit/friendship_test.rb | 6 ++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/unit/post_test.rb | 19 +++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/unit/product_test.rb | 27 +++++++++++++++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/unit/tag_test.rb | 15 +++++++++++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/unit/tagging_test.rb | 6 ++++++ vendor/gems/thoughtbot-shoulda-2.10.1/test/unit/user_test.rb | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 380 files changed, 23236 insertions(+), 0 deletions(-) create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/COPYING create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/MIT-LICENSE create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/README create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/RELEASE create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/Rakefile create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/examples/misc.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/examples/mocha.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/examples/stubba.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/any_instance_method.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/api.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/argument_iterator.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/backtrace_filter.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/cardinality.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/central.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/change_state_side_effect.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/class_method.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/configuration.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/deprecation.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/exception_raiser.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/expectation.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/expectation_error.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/expectation_list.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/in_state_ordering_constraint.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/inspect.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/instance_method.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/bacon.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/bacon/assertion_counter.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/bacon/version_11_and_above.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/mini_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/mini_test/assertion_counter.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/mini_test/version_131_and_above.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/test_unit.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/test_unit/assertion_counter.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/test_unit/gem_version_200.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/test_unit/gem_version_201_and_above.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/test_unit/ruby_version_185_and_below.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/test_unit/ruby_version_186_and_above.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/invocation.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/is_a.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/logger.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/metaclass.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/method_matcher.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/mock.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/mockery.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/module_method.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/multiple_yields.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/names.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/no_yields.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/object.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/all_of.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/any_of.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/any_parameters.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/anything.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/base.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/equals.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/has_entries.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/has_entry.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/has_key.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/has_value.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/includes.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/instance_of.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/is_a.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/kind_of.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/not.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/object.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/optionally.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/regexp_matches.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/responds_with.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/yaml_equivalent.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameters_matcher.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/pretty_parameters.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/return_values.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/sequence.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/single_return_value.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/single_yield.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/state_machine.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/stubbing_error.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/unexpected_invocation.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/yield_parameters.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha_standalone.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/stubba.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/acceptance_test_helper.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/api_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/bacon_spec.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/bacon_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/bug_18914_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/bug_21465_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/bug_21563_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/expected_invocation_count_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/failure_messages_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/minitest_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/mocha_example_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/mocha_test_result_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/mock_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/mock_with_initializer_block_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/mocked_methods_dispatch_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/optional_parameters_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/parameter_matcher_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/partial_mocks_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/return_value_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/sequence_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/spy_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/states_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stub_any_instance_method_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stub_class_method_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stub_everything_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stub_instance_method_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stub_module_method_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stub_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stubba_example_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stubba_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stubba_test_result_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stubbing_error_backtrace_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stubbing_method_unnecessarily_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stubbing_non_existent_any_instance_method_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stubbing_non_existent_class_method_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stubbing_non_existent_instance_method_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stubbing_non_public_any_instance_method_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stubbing_non_public_class_method_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stubbing_non_public_instance_method_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stubbing_on_non_mock_object_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/deprecation_disabler.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/execution_point.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/matcher_helpers.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/method_definer.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/simple_counter.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/test_helper.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/test_runner.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/any_instance_method_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/array_inspect_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/assert_received_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/backtrace_filter_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/cardinality_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/central_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/change_state_side_effect_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/class_method_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/date_time_inspect_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/exception_raiser_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/expectation_list_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/expectation_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/hash_inspect_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/have_received_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/in_state_ordering_constraint_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/invocation_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/metaclass_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/method_matcher_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/mock_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/mockery_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/multiple_yields_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/no_yields_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/object_inspect_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/object_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/all_of_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/any_of_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/anything_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/equals_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/has_entries_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/has_entry_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/has_key_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/has_value_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/includes_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/instance_of_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/is_a_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/kind_of_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/not_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/regexp_matches_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/responds_with_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/stub_matcher.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/yaml_equivalent_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameters_matcher_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/return_values_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/sequence_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/single_return_value_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/single_yield_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/state_machine_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/string_inspect_test.rb create mode 100644 vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/yield_parameters_test.rb create mode 100644 vendor/gems/thoughtbot-factory_girl-1.2.1/CONTRIBUTION_GUIDELINES.rdoc create mode 100644 vendor/gems/thoughtbot-factory_girl-1.2.1/Changelog create mode 100644 vendor/gems/thoughtbot-factory_girl-1.2.1/LICENSE create mode 100644 vendor/gems/thoughtbot-factory_girl-1.2.1/README.rdoc create mode 100644 vendor/gems/thoughtbot-factory_girl-1.2.1/Rakefile create mode 100644 vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl.rb create mode 100644 vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/aliases.rb create mode 100644 vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/attribute.rb create mode 100644 vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/attribute/association.rb create mode 100644 vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/attribute/dynamic.rb create mode 100644 vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/attribute/static.rb create mode 100644 vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/factory.rb create mode 100644 vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/proxy.rb create mode 100644 vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/proxy/attributes_for.rb create mode 100644 vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/proxy/build.rb create mode 100644 vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/proxy/create.rb create mode 100644 vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/proxy/stub.rb create mode 100644 vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/sequence.rb create mode 100644 vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/syntax.rb create mode 100644 vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/syntax/blueprint.rb create mode 100644 vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/syntax/generate.rb create mode 100644 vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/syntax/make.rb create mode 100644 vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/syntax/sham.rb create mode 100644 vendor/gems/thoughtbot-factory_girl-1.2.1/test/aliases_test.rb create mode 100644 vendor/gems/thoughtbot-factory_girl-1.2.1/test/association_attribute_test.rb create mode 100644 vendor/gems/thoughtbot-factory_girl-1.2.1/test/attribute_test.rb create mode 100644 vendor/gems/thoughtbot-factory_girl-1.2.1/test/attributes_for_strategy_test.rb create mode 100644 vendor/gems/thoughtbot-factory_girl-1.2.1/test/build_strategy_test.rb create mode 100644 vendor/gems/thoughtbot-factory_girl-1.2.1/test/create_strategy_test.rb create mode 100644 vendor/gems/thoughtbot-factory_girl-1.2.1/test/dynamic_attribute_test.rb create mode 100644 vendor/gems/thoughtbot-factory_girl-1.2.1/test/factory_test.rb create mode 100644 vendor/gems/thoughtbot-factory_girl-1.2.1/test/integration_test.rb create mode 100644 vendor/gems/thoughtbot-factory_girl-1.2.1/test/models.rb create mode 100644 vendor/gems/thoughtbot-factory_girl-1.2.1/test/sequence_test.rb create mode 100644 vendor/gems/thoughtbot-factory_girl-1.2.1/test/static_attribute_test.rb create mode 100644 vendor/gems/thoughtbot-factory_girl-1.2.1/test/strategy_test.rb create mode 100644 vendor/gems/thoughtbot-factory_girl-1.2.1/test/stub_strategy_test.rb create mode 100644 vendor/gems/thoughtbot-factory_girl-1.2.1/test/syntax/blueprint_test.rb create mode 100644 vendor/gems/thoughtbot-factory_girl-1.2.1/test/syntax/generate_test.rb create mode 100644 vendor/gems/thoughtbot-factory_girl-1.2.1/test/syntax/make_test.rb create mode 100644 vendor/gems/thoughtbot-factory_girl-1.2.1/test/syntax/sham_test.rb create mode 100644 vendor/gems/thoughtbot-factory_girl-1.2.1/test/test_helper.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/CONTRIBUTION_GUIDELINES.rdoc create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/MIT-LICENSE create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/README.rdoc create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/Rakefile create mode 100755 vendor/gems/thoughtbot-shoulda-2.10.1/bin/convert_to_should_syntax create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller/helpers.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller/macros.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller/matchers.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller/matchers/assign_to_matcher.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller/matchers/filter_param_matcher.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller/matchers/render_with_layout_matcher.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller/matchers/respond_with_content_type_matcher.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller/matchers/respond_with_matcher.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller/matchers/route_matcher.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller/matchers/set_session_matcher.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller/matchers/set_the_flash_matcher.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_mailer.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_mailer/assertions.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_view.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_view/macros.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/assertions.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/helpers.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/macros.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/allow_mass_assignment_of_matcher.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/allow_value_matcher.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/association_matcher.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/ensure_inclusion_of_matcher.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/ensure_length_of_matcher.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/have_db_column_matcher.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/have_index_matcher.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/have_named_scope_matcher.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/have_readonly_attribute_matcher.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/validate_acceptance_of_matcher.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/validate_numericality_of_matcher.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/validate_presence_of_matcher.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/validate_uniqueness_of_matcher.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/validation_matcher.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/assertions.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/autoload_macros.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/context.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/helpers.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/macros.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/private_helpers.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/proc_extensions.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/rails.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/rspec.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/tasks.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/tasks/list_tests.rake create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/tasks/yaml_to_shoulda.rake create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/test_unit.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/rails/init.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/README create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/fail_macros.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/fixtures/addresses.yml create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/fixtures/friendships.yml create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/fixtures/posts.yml create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/fixtures/products.yml create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/fixtures/taggings.yml create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/fixtures/tags.yml create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/fixtures/users.yml create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/functional/posts_controller_test.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/functional/users_controller_test.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/allow_mass_assignment_of_matcher_test.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/allow_value_matcher_test.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/association_matcher_test.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/ensure_inclusion_of_matcher_test.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/ensure_length_of_matcher_test.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/have_db_column_matcher_test.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/have_index_matcher_test.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/have_named_scope_matcher_test.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/have_readonly_attributes_matcher_test.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/validate_acceptance_of_matcher_test.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/validate_numericality_of_matcher_test.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/validate_presence_of_matcher_test.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/validate_uniqueness_of_matcher_test.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/controller/assign_to_matcher_test.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/controller/filter_param_matcher_test.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/controller/render_with_layout_matcher_test.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/controller/respond_with_content_type_matcher_test.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/controller/respond_with_matcher_test.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/controller/route_matcher_test.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/controller/set_session_matcher_test.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/controller/set_the_flash_matcher.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/model_builder.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/other/autoload_macro_test.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/other/context_test.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/other/convert_to_should_syntax_test.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/other/helpers_test.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/other/private_helpers_test.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/other/should_test.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/controllers/application.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/controllers/posts_controller.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/controllers/users_controller.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/helpers/application_helper.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/helpers/posts_helper.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/helpers/users_helper.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/models/address.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/models/flea.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/models/friendship.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/models/pets/dog.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/models/post.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/models/product.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/models/tag.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/models/tagging.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/models/treat.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/models/user.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/views/layouts/posts.rhtml create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/views/layouts/users.rhtml create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/views/layouts/wide.html.erb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/views/posts/edit.rhtml create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/views/posts/index.rhtml create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/views/posts/new.rhtml create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/views/posts/show.rhtml create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/views/users/edit.rhtml create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/views/users/index.rhtml create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/views/users/new.rhtml create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/views/users/show.rhtml create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/config/boot.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/config/database.yml create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/config/environment.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/config/environments/test.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/config/initializers/new_rails_defaults.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/config/initializers/shoulda.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/config/routes.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/db/migrate/001_create_users.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/db/migrate/002_create_posts.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/db/migrate/003_create_taggings.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/db/migrate/004_create_tags.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/db/migrate/005_create_dogs.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/db/migrate/006_create_addresses.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/db/migrate/007_create_fleas.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/db/migrate/008_create_dogs_fleas.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/db/migrate/009_create_products.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/db/migrate/010_create_friendships.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/db/migrate/011_create_treats.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/db/schema.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/public/404.html create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/public/422.html create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/public/500.html create mode 100755 vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/script/console create mode 100755 vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/script/generate create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/test/shoulda_macros/custom_macro.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/vendor/gems/gem_with_macro-0.0.1/shoulda_macros/gem_macro.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/vendor/plugins/plugin_with_macro/shoulda_macros/plugin_macro.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/rspec_test.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/test_helper.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/unit/address_test.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/unit/dog_test.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/unit/flea_test.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/unit/friendship_test.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/unit/post_test.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/unit/product_test.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/unit/tag_test.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/unit/tagging_test.rb create mode 100644 vendor/gems/thoughtbot-shoulda-2.10.1/test/unit/user_test.rb diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/COPYING b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/COPYING new file mode 100644 index 0000000..8f74d71 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/COPYING @@ -0,0 +1,3 @@ +Copyright Revieworld Ltd. 2006 + +You may use, copy and redistribute this library under the same terms as Ruby itself (see http://www.ruby-lang.org/en/LICENSE.txt) or under the MIT license (see MIT-LICENSE file). diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/MIT-LICENSE b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/MIT-LICENSE new file mode 100644 index 0000000..fa4efe7 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/MIT-LICENSE @@ -0,0 +1,7 @@ +Copyright (c) 2006 Revieworld Ltd. + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/README b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/README new file mode 100644 index 0000000..03f5351 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/README @@ -0,0 +1,37 @@ += Mocha + +Mocha is a library for mocking and stubbing using a syntax like that of JMock[http://www.jmock.org]. + +It can be used with many testing frameworks e.g. Test::Unit[http://www.ruby-doc.org/core/classes/Test/Unit.html], RSpec[http://rspec.info/], test/spec[http://chneukirchen.org/repos/testspec/README], expectations[http://expectations.rubyforge.org/], Dust[http://dust.rubyforge.org/], MiniTest[http://rubyforge.org/projects/bfts] and even JtestR[http://jtestr.codehaus.org/]. + +Mocha provides a unified, simple and readable syntax for both traditional mocking and partial mocking. + +Mocha was harvested from projects at Reevoo[http://www.reevoo.com] by me (James[http://blog.floehopper.org]) and my (then) colleagues Ben[http://www.techbelly.com/], Chris[http://chrisroos.co.uk] and Paul[http://po-ru.com]. + +== Download and Installation + +Install the gem with the following command... + + $ gem install mocha + +Or install the Rails[http://www.rubyonrails.org] plugin... + + $ script/plugin install git://github.com/floehopper/mocha.git + +Or download Mocha... + + http://rubyforge.org/frs/?group_id=1917 + +== Examples + +* Quick Start - {Usage Examples}[link:examples/misc.html] +* Traditional mocking - {Star Trek Example}[link:examples/mocha.html] +* Setting expectations on real classes - {Order Example}[link:examples/stubba.html] +* More examples on {Floehopper's Blog}[http://blog.floehopper.org] +* {Mailing List Archives}[http://groups.google.com/group/mocha-developer] + +== License + +Copyright Revieworld Ltd. 2006 + +You may use, copy and redistribute this library under the same terms as {Ruby itself}[http://www.ruby-lang.org/en/LICENSE.txt] or under the {MIT license}[http://mocha.rubyforge.org/files/MIT-LICENSE.html]. \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/RELEASE b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/RELEASE new file mode 100644 index 0000000..7b023c9 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/RELEASE @@ -0,0 +1,269 @@ += 0.9.5 (93cad010345ce5d68f31422cfc32ed9dd6de13ec) +* Fixed Lighthouse bug #32 - stub_everything should mean mock responds to anything. +* Added Expectation#twice to improve readability. Thanks to pull request from Celestino Gomes. +* In Ruby 1.9.1, requiring 'test/unit' loads a thin wrapper around MiniTest and Test::Unit::TestCase ends up inheriting from MiniTest::Unit::TestCase. So we need to avoid including the Mocha modules more than once to avoid nasty consequences. Thanks to Matthias Hennemeyer for help with this. +* Ruby 1.9 includes rake, but not rake/contrib. For the moment I've moved the sshpublisher require into the only rake task that needs it, so that I can at least run the tests in Ruby 1.9. It looks like I will need to build a rake/contrib gem or similar to get this working properly - http://intertwingly.net/blog/2008/01/07/Rake-Contrib-for-1-9 + += 0.9.4 (8a59c6ff0f99f34b02bd99f19536a7893be2b340) +* Added mocha.gemspec file generated with Chad Woolley's new rake task, so that a floehopper-mocha gem will get built on GitHub. +* Add rake task to update mocha.gemspec with unique version, which will cause gem to be auto-built on github +* As Tobias Crawley correctly pointed out in feature request #23055 "stubs(with_hash) not working with existing object" [1], following the principle of least surprise, it should be possible to call ObjectMethods#expects & ObjectMethods#stubs with a Hash of method_names vs return_values like you can with Mock#expects & Mock#stubs. I've also updated & improved the docs to reflect the changes. [1] http://rubyforge.org/tracker/index.php?func=detail&aid=23055&group_id=1917&atid=7480 +* Removed deprecated gem autorequire. + += 0.9.3 (8219bb2d2881c8529c93fc21e97a11d01203c759) +* Added support for MiniTest thanks to Jeff Smick. +* Fixed a possible bug with some of the non-default Configuration options relating to the argument to Object#respond_to? +* As per Jay Fields recommendations [1] and with further impetus from a talk at Ruby Manor, any methods added to core classes are now added by including a module. This means that Mocha is a better citizen of the Ruby world and it's behaviour is more easily extended. [1] http://blog.jayfields.com/2008/07/ruby-underuse-of-modules.html & http://blog.jayfields.com/2008/07/ruby-redefine-method-behavior.html +* Removed deprecated gem autorequire. + += 0.9.2 (r355) +* Improved documentation to address [#22530] 'Mock methods with multiple return values not possible?' +* respond_with parameter matcher was not available in tests. +* Patch [#22630] Fix for a bug in running Rails tests with Ruby 1.8.7. Array#flatten was being called which in turn was checking whether each element responded to #to_ary. This check was using the two parameter version of #respond_to?, but Mock was only defining a one parameter version. + += 0.9.1 (r349) + +* Fixed bug #21465 - expects & stubs should support method names as strings (as well as symbols) or fail fast. Convert all expectation method names to a symbol in case they were supplied as a string. +* By removing Mock#unexpected_method_called we reduce the number of methods vulnerable to the problem that surfaced in bug #21563. +* Fix bug #21563 - stubbing 'verified?' method is unsafe. Instance method names on the Mock class should be more obscure. +* Performance improvement. StubbaExampleTest goes twice as fast on my local machine. +* Added primitive performance test to default rake task. +* Fix format of case statements which don't work in Ruby 1.9 and make others consistent. +* There is no point in running (potentially expensive) checks if configuration is set to allow such checks to fail. This is a relatively quick fix in response to Chris McGrath's performance problems. +* Fix for bug #21161 - 'uninitialized constant Deprecation in stubba.rb'. +* It's more readable to talk about 'once' and 'twice' rather than '1 time' and '2 times'. +* Fix bug #20883 - never should raise when called to prevent follow up errors. Fail fast when there are no matching invokable expectations and handle the stub_everything case sensibly. This might not be entirely backwards compatible, but I think the benefits outweigh the risks. The most likely change is that a test that was already failing will now fail faster, which doesn't seem so awful. + += 0.9.0 (r316) + +* Configurable warnings or errors + * when a method on a non-public method is stubbed + * when a method on a non-existent method is stubbed + * when a method on a non-mock object is stubbed + * when a method is stubbed unnecessarily (i.e. the stubbed method is not called during the test) + +* Improved error messages + * User-friendly list of unsatisfied expectations, satisfied expectations and state machines. + * Improved readability of cardinality description. + * Display sensible failure message for any_instance expectations e.g. "#.bar - expected calls: 1, actual calls: 0" + +* Parameter matchers + * New to this release + * optionally (allows matching of optional parameters if available) + * yaml_equivalent (allows matching of YAML that represents the specified object) + * responds_with (tests the quack not the duck) + * Nesting of parameter matchers is now supported. + +* Optional block passed into mock initializer is evaluated in the context of the new mock instance and can be used as a shortcut to set up expectations. + +* Added JMock-style sequences for constraining the order of expected invocations. See Standalone#sequence and Expectation#in_sequence. + +* Added JMock-style states for constraining the order of expected invocations. See Standalone#states, Expectation#then, Expectation#when and StateMachine. + +* Compatibility with versions of Ruby + * Compatibility with Ruby v1.9. All test errors and warnings fixed. + * Nasty fix so that TestCaseAdaptor works consistently with earlier versions of Test::Unit as well as more recent versions. + * Added platform to gem specification to avoid bug in rubygems 0.9.5 - see http://www.dcmanges.com/blog/rubygems-0-9-5-platform-bug and http://rubygems.org/read/chapter/20#platform. + * Make ExpectationRaiser deal with subclasses of Interrupt which seem to need a message supplied in the raise statement in Ruby 1.8.6 (but not 1.8.4 or 1.9). Not sure this is really Mocha's responsibility. + +* Added deprecation warning in stubba.rb which is no longer needed and will be removed. + +* Supply positioning information to evals to improve any error messages. See http://ola-bini.blogspot.com/2008/01/ruby-antipattern-using-eval-without.html + +* Bug fixes + * 18914 in revision 296 - http://rubyforge.org/tracker/index.php?func=detail&aid=18914&group_id=1917&atid=7477 + * 18917 in revision 295 - http://rubyforge.org/tracker/index.php?func=detail&aid=18917&group_id=1917&atid=7477 + * 18336 in revision 287 - http://rubyforge.org/tracker/index.php?func=detail&aid=18336&group_id=1917&atid=7477 + * 17835 in revision 255 - http://rubyforge.org/tracker/index.php?func=detail&aid=17835&group_id=1917&atid=7477 + * 17412 in revision 242 - http://rubyforge.org/tracker/index.php?func=detail&aid=17412&group_id=1917&atid=7477 + * 15977 in revision 198 - http://rubyforge.org/tracker/index.php?func=detail&aid=15977&group_id=1917&atid=7477 + * 11885 in revision 156 - http://rubyforge.org/tracker/index.php?func=detail&aid=11885&group_id=1917&atid=7477 + += 0.5.5 (r167) + +- Renamed Matches parameter matcher to RegexpMatches for clarity. +- Added noframes tag to rdoc index to assist Google. + += 0.5.4 (r166) + +- Added matches parameter matcher for matching regular expressions. + += 0.5.3 (r165) + +- Attempt to fix packaging problems by switching to newer version (1.15.1) of gnutar and setting COPY_EXTENDED_ATTRIBUTES_DISABLE environment variable. +- Removed unused ExpectationSequenceError exception. +- Added instance_of and kind_of parameter matchers. +- Added Google Webmaster meta tag to rdoc template header. +- Put Google Webmaster meta tag in the right header i.e. the one for the index page. + += 0.5.2 (r159) + +- Fix bug 11885 - "never doesn't work with stub_everything" submitted by Alexander Lang. In fixing this bug, also fixed undiscoverd bug where expected & actual invocation counts were being incorrectly reported which seems to have been introduced when fixes were added for invocation dispatch (see MockedMethodDispatchAcceptanceTest). +- Previously when an expectation did not allow more invocations, it was treated as not matching. Now we prefer matching expectations which allow more invocations, but still match expectations which cannot allow more invocations. I think this may be overcomplicating things, but let's see how it goes. + += 0.5.1 (r149) + +- Fixed bug #11583 "Mocha 0.5.0 throwing unexpected warnings". Also switched on ruby warning for all rake test tasks. Fixed majority of warnings, but some left to fix. + += 0.5.0 (r147) + +- Parameter Matchers - I’ve added a few Hamcrest-style parameter matchers which are designed to be used inside Expectation#with. The following matchers are currently available: anything(), includes(), has_key(), has_value(), has_entry(), all_of() & any_of(). More to follow soon. The idea is eventually to get rid of the nasty parameter_block option on Expectation#with. + + object = mock() + object.expects(:method).with(has_key('key_1')) + object.method('key_1' => 1, 'key_2' => 2) + # no verification error raised + + object = mock() + object.expects(:method).with(has_key('key_1')) + object.method('key_2' => 2) + # verification error raised, because method was not called with Hash containing key: 'key_1' + +- Values Returned and Exceptions Raised on Consecutive Invocations - Allow multiple calls to Expectation#returns and Expectation#raises to build up a sequence of responses to invocations on the mock. Added syntactic sugar method Expectation#then to allow more readable expectations. + + object = mock() + object.stubs(:method).returns(1, 2).then.raises(Exception).then.returns(4) + object.method # => 1 + object.method # => 2 + object.method # => raises exception of class Exception + object.method # => 4 + +- Yields on Consecutive Invocations - Allow multiple calls to yields on single expectation to allow yield parameters to be specified for consecutive invocations. + + object = mock() + object.stubs(:method).yields(1, 2).then.yields(3) + object.method { |*values| p values } # => [1, 2] + object.method { |*values| p values } # => [3] + +- Multiple Yields on Single Invocation - Added Expectation#multiple_yields to allow a mocked or stubbed method to yield multiple times for a single invocation. + + object = mock() + object.stubs(:method).multiple_yields([1, 2], [3]) + object.method { |*values| p values } # => [1, 2] # => [3] + +- Invocation Dispatch - Expectations were already being matched in reverse order i.e. the most recently defined one was being found first. This is still the case, but we now stop matching an expectation when its maximum number of expected invocations is reached. c.f. JMock v1. A stub will never stop matching by default. Hopefully this means we can soon get rid of the need to pass a Proc to Expectation#returns. + + object = mock() + object.stubs(:method).returns(2) + object.expects(:method).once.returns(1) + object.method # => 1 + object.method # => 2 + object.method # => 2 + # no verification error raised + + # The following should still work... + + Time.stubs(:now).returns(Time.parse('Mon Jan 01 00:00:00 UTC 2007')) + Time.now # => Mon Jan 01 00:00:00 UTC 2007 + Time.stubs(:now).returns(Time.parse('Thu Feb 01 00:00:00 UTC 2007')) + Time.now # => Thu Feb 01 00:00:00 UTC 2007 + +- Deprecate passing an instance of Proc to Expectation#returns. +- Explicitly include all Rakefile dependencies in project. +- Fixed old Stubba example. +- Fix so that it is possible for a stubbed method to raise an Interrupt exception without a message in Ruby 1.8.6 +- Added responds_like and quacks_like. +- Capture standard object methods before Mocha adds any. +- Added Expectation#once method to make interface less surprising. +- Use Rake::TestTask to run tests. Created three separate tasks to run unit, integration & acceptance tests. Split inspect_test into one file per TestCase. Deleted superfluous all_tests file. +- Fiddled with mocha_inspect and tests to give more sensible results on x86 platform. +- Fixed bug #7834 "infinite_range.rb makes incorrect assumption about to_f" logged by James Moore. + += 0.4.0 (r92) + +- Allow naming of mocks (patch from Chris Roos). +- Specify multiple return values for consecutive calls. +- Improved consistency of expectation error messages. +- Allow mocking of Object instance methods e.g. kind_of?, type. +- Provide aliased versions of #expects and #stubs to allow mocking of these methods. +- Added at_least, at_most, at_most_once methods to expectation. +- Allow expects and stubs to take a hash of method and return values. +- Eliminate warning: "instance variable @yield not initialized" (patch from Xavier Shay). +- Restore instance methods on partial mocks (patch from Chris Roos). +- Allow stubbing of a method with non-word characters in its name (patch from Paul Battley). +- Removed coupling to Test::Unit. +- Allow specified exception instance to be raised (patch from Chris Roos). +- Make mock object_id appear in hex like normal Ruby inspect (patch from Paul Battley). +- Fix path to object.rb in rdoc rake task (patch from Tomas Pospisek). +- Reverse order in which expectations are matched, so that last expectation is matched first. This allows e.g. a call to #stubs to be effectively overridden by a call to #expects (patch from Tobias Lutke). +- Stubba & SmartTestCase modules incorporated into Mocha module so only need to require 'mocha' - no longer need to require 'stubba'. +- AutoMocha removed. + += 0.3.3 + +- Quick bug fix to restore instance methods on partial mocks (for Kevin Clark). + += 0.3.2 + +- Examples added. + += 0.3.1 + +- Dual licensing with MIT license added. + += 0.3.0 + +* Rails plugin. +* Auto-verify for expectations on concrete classes. +* Include each expectation verification in the test result assertion count. +* Filter out noise from assertion backtraces. +* Point assertion backtrace to line where failing expectation was created. +* New yields method for expectations. +* Create stubs which stub all method calls. +* Mocks now respond_to? expected methods. + += 0.2.1 + +* Rename MochaAcceptanceTest::Rover#move method to avoid conflict with Rake (in Ruby 1.8.4 only?) + += 0.2.0 + +* Small change to SetupAndTeardown#teardown_stubs suggested by Luke Redpath (http://www.lukeredpath.co.uk) to allow use of Stubba with RSpec (http://rspec.rubyforge.org). +* Reorganized directory structure and extracted addition of setup and teardown methods into SmartTestCase mini-library. +* Addition of auto-verify for Mocha (but not Stubba). This means there is more significance in the choice of expects or stubs in that any expects on a mock will automatically get verified. + +So instead of... + + wotsit = Mocha.new + wotsit.expects(:thingummy).with(5).returns(10) + doobrey = Doobrey.new(wotsit) + doobrey.hoojamaflip + wotsit.verify + +you need to do... + + wotsit = mock() + wotsit.expects(:thingummy).with(5).returns(10) + doobrey = Doobrey.new(wotsit) + doobrey.hoojamaflip + # no need to verify + +There are also shortcuts as follows... + +instead of... + + wotsit = Mocha.new + wotsit.expects(:thingummy).returns(10) + wotsit.expects(:summat).returns(25) + +you can have... + + wotsit = mock(:thingummy => 5, :summat => 25) + +and instead of... + + wotsit = Mocha.new + wotsit.stubs(:thingummy).returns(10) + wotsit.stubs(:summat).returns(25) + +you can have... + + wotsit = stub(:thingummy => 5, :summat => 25) + += 0.1.2 + +* Minor tweaks + += 0.1.1 + +* Initial release. diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/Rakefile b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/Rakefile new file mode 100644 index 0000000..0eb2109 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/Rakefile @@ -0,0 +1,217 @@ +require 'rake/rdoctask' +require 'rake/gempackagetask' +require 'rake/testtask' + +module Mocha + VERSION = "0.9.5" +end + +desc "Run all tests" +task 'default' => ['test:units', 'test:acceptance', 'test:performance'] + +namespace 'test' do + + unit_tests = FileList['test/unit/**/*_test.rb'] + acceptance_tests = FileList['test/acceptance/*_test.rb'] + + desc "Run unit tests" + Rake::TestTask.new('units') do |t| + t.libs << 'test' + t.test_files = unit_tests + t.verbose = true + t.warning = true + end + + desc "Run acceptance tests" + Rake::TestTask.new('acceptance') do |t| + t.libs << 'test' + t.test_files = acceptance_tests + t.verbose = true + t.warning = true + end + + # require 'rcov/rcovtask' + # Rcov::RcovTask.new('coverage') do |t| + # t.libs << 'test' + # t.test_files = unit_tests + acceptance_tests + # t.verbose = true + # t.warning = true + # t.rcov_opts << '--sort coverage' + # t.rcov_opts << '--xref' + # end + + desc "Run performance tests" + task 'performance' do + require 'test/acceptance/stubba_example_test' + require 'test/acceptance/mocha_example_test' + iterations = 1000 + puts "\nBenchmarking with #{iterations} iterations..." + [MochaExampleTest, StubbaExampleTest].each do |test_case| + puts "#{test_case}: #{benchmark_test_case(test_case, iterations)} seconds." + end + end + +end + +def benchmark_test_case(klass, iterations) + require 'benchmark' + require 'test/unit/ui/console/testrunner' + begin + require 'test/unit/ui/console/outputlevel' + silent_option = { :output_level => Test::Unit::UI::Console::OutputLevel::SILENT } + rescue LoadError + silent_option = Test::Unit::UI::SILENT + end + time = Benchmark.realtime { iterations.times { Test::Unit::UI::Console::TestRunner.run(klass, silent_option) } } +end + +desc 'Generate RDoc' +Rake::RDocTask.new('rdoc') do |task| + task.main = 'README' + task.title = "Mocha #{Mocha::VERSION}" + task.rdoc_dir = 'doc' + task.template = File.expand_path(File.join(File.dirname(__FILE__), "templates", "html_with_google_analytics")) + task.rdoc_files.include( + 'README', + 'RELEASE', + 'COPYING', + 'MIT-LICENSE', + 'agiledox.txt', + 'lib/mocha/api.rb', + 'lib/mocha/mock.rb', + 'lib/mocha/expectation.rb', + 'lib/mocha/object.rb', + 'lib/mocha/parameter_matchers.rb', + 'lib/mocha/parameter_matchers', + 'lib/mocha/state_machine.rb', + 'lib/mocha/configuration.rb', + 'lib/mocha/stubbing_error.rb' + ) +end + +desc "Generate all documentation" +task 'generate_docs' => ['clobber_rdoc', 'rdoc', 'examples', 'agiledox.txt'] + +desc "Upload RDoc to RubyForge" +task 'publish_docs' do + require 'rake/contrib/sshpublisher' + Rake::SshDirPublisher.new("jamesmead@rubyforge.org", "/var/www/gforge-projects/mocha", "doc").upload +end + +desc "Generate agiledox-like documentation for tests" +file 'agiledox.txt' do + File.open('agiledox.txt', 'w') do |output| + tests = FileList['test/**/*_test.rb'] + tests.each do |file| + m = %r".*/([^/].*)_test.rb".match(file) + output << m[1]+" should:\n" + test_definitions = File::readlines(file).select {|line| line =~ /.*def test.*/} + test_definitions.sort.each do |definition| + m = %r"test_(should_)?(.*)".match(definition) + output << " - "+m[2].gsub(/_/," ") << "\n" + end + end + end +end + +desc "Convert example ruby files to syntax-highlighted html" +task 'examples' do + require 'coderay' + mkdir_p 'doc/examples' + File.open('doc/examples/coderay.css', 'w') do |output| + output << CodeRay::Encoders[:html]::CSS.new.stylesheet + end + ['mocha', 'stubba', 'misc'].each do |filename| + File.open("doc/examples/#{filename}.html", 'w') do |file| + file << "" + file << "" + file << %q() + file << "" + file << "" + file << CodeRay.scan_file("examples/#{filename}.rb").html.div + file << "" + file << "" + end + end +end + +Gem.manage_gems if Gem::RubyGemsVersion < '1.2.0' + +def build_specification(version = Mocha::VERSION) + Gem::Specification.new do |s| + s.name = "mocha" + s.summary = "Mocking and stubbing library" + s.version = "#{version}.0.#{Time.now.to_i}" + s.platform = Gem::Platform::RUBY + s.author = 'James Mead' + s.description = <<-EOF + Mocking and stubbing library with JMock/SchMock syntax, which allows mocking and stubbing of methods on real (non-mock) classes. + EOF + s.email = 'mocha-developer@googlegroups.com' + s.homepage = 'http://mocha.rubyforge.org' + s.rubyforge_project = 'mocha' + + s.has_rdoc = true + s.extra_rdoc_files = ['README', 'COPYING'] + s.rdoc_options << '--title' << 'Mocha' << '--main' << 'README' << '--line-numbers' + + s.add_dependency('rake') + s.files = FileList['{lib,test,examples}/**/*.rb', '[A-Z]*'].exclude('TODO').to_a + end +end + +specification = build_specification + +Rake::GemPackageTask.new(specification) do |package| + package.need_zip = true + package.need_tar = true +end + +desc 'Generate updated gemspec with unique version, which will cause gem to be auto-built on github.' +task :update_gemspec do + File.open('mocha.gemspec', 'w') do |output| + output << build_specification(Mocha::VERSION + '.' + Time.now.strftime('%Y%m%d%H%M%S')).to_ruby + end +end + +task 'verify_user' do + raise "RUBYFORGE_USER environment variable not set!" unless ENV['RUBYFORGE_USER'] +end + +task 'verify_password' do + raise "RUBYFORGE_PASSWORD environment variable not set!" unless ENV['RUBYFORGE_PASSWORD'] +end + +desc "Publish package files on RubyForge." +task 'publish_packages' => ['verify_user', 'verify_password', 'clobber_package', 'package'] do + require 'meta_project' + require 'rake/contrib/xforge' + release_files = FileList[ + "pkg/mocha-#{Mocha::VERSION}.gem", + "pkg/mocha-#{Mocha::VERSION}.tgz", + "pkg/mocha-#{Mocha::VERSION}.zip" + ] + + Rake::XForge::Release.new(MetaProject::Project::XForge::RubyForge.new('mocha')) do |release| + release.user_name = ENV['RUBYFORGE_USER'] + release.password = ENV['RUBYFORGE_PASSWORD'] + release.files = release_files.to_a + release.release_name = "Mocha #{Mocha::VERSION}" + release.release_changes = '' + release.release_notes = '' + end +end + +desc "Do a full release." +task 'release' => ['default', 'generate_docs', 'publish_packages', 'publish_docs', 'update_gemspec'] do + puts + puts "*** Remember to commit newly generated gemspec after release ***" + puts +end + +desc "Generate a gemspec file" +task :gemspec do + File.open("#{specification.name}.gemspec", 'w') do |f| + f.write specification.to_yaml + end +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/examples/misc.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/examples/misc.rb new file mode 100644 index 0000000..9c9b9fb --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/examples/misc.rb @@ -0,0 +1,43 @@ +require 'test/unit' +require 'mocha' + +class MiscExampleTest < Test::Unit::TestCase + + def test_mocking_a_class_method + product = Product.new + Product.expects(:find).with(1).returns(product) + assert_equal product, Product.find(1) + end + + def test_mocking_an_instance_method_on_a_real_object + product = Product.new + product.expects(:save).returns(true) + assert product.save + end + + def test_stubbing_instance_methods_on_real_objects + prices = [stub(:pence => 1000), stub(:pence => 2000)] + product = Product.new + product.stubs(:prices).returns(prices) + assert_equal [1000, 2000], product.prices.collect {|p| p.pence} + end + + def test_stubbing_an_instance_method_on_all_instances_of_a_class + Product.any_instance.stubs(:name).returns('stubbed_name') + product = Product.new + assert_equal 'stubbed_name', product.name + end + + def test_traditional_mocking + object = mock() + object.expects(:expected_method).with(:p1, :p2).returns(:result) + assert_equal :result, object.expected_method(:p1, :p2) + end + + def test_shortcuts + object = stub(:method1 => :result1, :method2 => :result2) + assert_equal :result1, object.method1 + assert_equal :result2, object.method2 + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/examples/mocha.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/examples/mocha.rb new file mode 100644 index 0000000..6893ad0 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/examples/mocha.rb @@ -0,0 +1,25 @@ +class Enterprise + + def initialize(dilithium) + @dilithium = dilithium + end + + def go(warp_factor) + warp_factor.times { @dilithium.nuke(:anti_matter) } + end + +end + +require 'test/unit' +require 'mocha' + +class EnterpriseTest < Test::Unit::TestCase + + def test_should_boldly_go + dilithium = mock() + dilithium.expects(:nuke).with(:anti_matter).at_least_once # auto-verified at end of test + enterprise = Enterprise.new(dilithium) + enterprise.go(2) + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/examples/stubba.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/examples/stubba.rb new file mode 100644 index 0000000..75cbd21 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/examples/stubba.rb @@ -0,0 +1,64 @@ +class Order + + attr_accessor :shipped_on + + def total_cost + line_items.inject(0) { |total, line_item| total + line_item.price } + shipping_cost + end + + def total_weight + line_items.inject(0) { |total, line_item| total + line_item.weight } + end + + def shipping_cost + total_weight * 5 + 10 + end + + class << self + + def find_all + # Database.connection.execute('select * from orders... + end + + def number_shipped_since(date) + find_all.select { |order| order.shipped_on > date }.length + end + + def unshipped_value + find_all.inject(0) { |total, order| order.shipped_on ? total : total + order.total_cost } + end + + end + +end + +require 'test/unit' +require 'mocha' + +class OrderTest < Test::Unit::TestCase + + # illustrates stubbing instance method + def test_should_calculate_shipping_cost_based_on_total_weight + order = Order.new + order.stubs(:total_weight).returns(10) + assert_equal 60, order.shipping_cost + end + + # illustrates stubbing class method + def test_should_count_number_of_orders_shipped_after_specified_date + now = Time.now; week_in_secs = 7 * 24 * 60 * 60 + order_1 = Order.new; order_1.shipped_on = now - 1 * week_in_secs + order_2 = Order.new; order_2.shipped_on = now - 3 * week_in_secs + Order.stubs(:find_all).returns([order_1, order_2]) + assert_equal 1, Order.number_shipped_since(now - 2 * week_in_secs) + end + + # illustrates stubbing instance method for all instances of a class + def test_should_calculate_value_of_unshipped_orders + Order.stubs(:find_all).returns([Order.new, Order.new, Order.new]) + Order.any_instance.stubs(:shipped_on).returns(nil) + Order.any_instance.stubs(:total_cost).returns(10) + assert_equal 30, Order.unshipped_value + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha.rb new file mode 100644 index 0000000..2524ed3 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha.rb @@ -0,0 +1,69 @@ +require 'mocha_standalone' +require 'mocha/configuration' + +if defined?(MiniTest::Unit::TestCase) && !MiniTest::Unit::TestCase.ancestors.include?(Mocha::API) + require 'mocha/integration/mini_test' + + module MiniTest + class Unit + class TestCase + + include Mocha::API + + alias_method :run_before_mocha, :run + remove_method :run + + include Mocha::Integration::MiniTest::Version131AndAbove + + end + end + end +end + +if defined?(Bacon) && Bacon::VERSION >= "1.1" && defined?(Bacon::Context) && !Bacon::Context.ancestors.include?(Mocha::API) + + require 'mocha/integration/bacon' + + module Bacon + class Context + include Mocha::API + include Mocha::Integration::Bacon::Version11AndAbove + end + end + +end + +require 'test/unit/testcase' +require 'mocha/integration/test_unit' + +unless Test::Unit::TestCase.ancestors.include?(Mocha::API) + module Test + module Unit + class TestCase + + include Mocha::API + + alias_method :run_before_mocha, :run + remove_method :run + + test_unit_version = begin + require 'test/unit/version' + Test::Unit::VERSION + rescue LoadError + '1.x' + end + + if test_unit_version == '2.0.0' + include Mocha::Integration::TestUnit::GemVersion200 + elsif test_unit_version >= '2.0.1' + include Mocha::Integration::TestUnit::GemVersion201AndAbove + elsif RUBY_VERSION < '1.8.6' + include Mocha::Integration::TestUnit::RubyVersion185AndBelow + else + include Mocha::Integration::TestUnit::RubyVersion186AndAbove + end + + end + end + end +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/any_instance_method.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/any_instance_method.rb new file mode 100644 index 0000000..3482083 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/any_instance_method.rb @@ -0,0 +1,55 @@ +require 'mocha/class_method' + +module Mocha + + class AnyInstanceMethod < ClassMethod + + def unstub + remove_new_method + restore_original_method + stubbee.any_instance.reset_mocha + end + + def mock + stubbee.any_instance.mocha + end + + def hide_original_method + if method_exists?(method) + begin + stubbee.send(:alias_method, hidden_method, method) + rescue NameError + # deal with nasties like ActiveRecord::Associations::AssociationProxy + end + end + end + + def define_new_method + stubbee.class_eval("def #{method}(*args, &block); self.class.any_instance.mocha.method_missing(:#{method}, *args, &block); end", __FILE__, __LINE__) + end + + def remove_new_method + stubbee.send(:remove_method, method) + end + + def restore_original_method + if method_exists?(hidden_method) + begin + stubbee.send(:alias_method, method, hidden_method) + stubbee.send(:remove_method, hidden_method) + rescue NameError + # deal with nasties like ActiveRecord::Associations::AssociationProxy + end + end + end + + def method_exists?(method) + return true if stubbee.public_instance_methods(false).include?(method) + return true if stubbee.protected_instance_methods(false).include?(method) + return true if stubbee.private_instance_methods(false).include?(method) + return false + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/api.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/api.rb new file mode 100644 index 0000000..58fe143 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/api.rb @@ -0,0 +1,249 @@ +require 'mocha/parameter_matchers' +require 'mocha/mockery' +require 'mocha/sequence' + +module Mocha # :nodoc: + + # Methods added to Test::Unit::TestCase or equivalent. + module API + + include ParameterMatchers + + # :call-seq: mock(name, &block) -> mock object + # mock(expected_methods = {}, &block) -> mock object + # mock(name, expected_methods = {}, &block) -> mock object + # + # Creates a mock object. + # + # +name+ is a +String+ identifier for the mock object. + # + # +expected_methods+ is a +Hash+ with expected method name symbols as keys and corresponding return values as values. + # + # Note that (contrary to expectations set up by #stub) these expectations must be fulfilled during the test. + # def test_product + # product = mock('ipod_product', :manufacturer => 'ipod', :price => 100) + # assert_equal 'ipod', product.manufacturer + # assert_equal 100, product.price + # # an error will be raised unless both Product#manufacturer and Product#price have been called + # end + # + # +block+ is an optional block to be evaluated against the mock object instance, giving an alernative way to set up expectations & stubs. + # def test_product + # product = mock('ipod_product') do + # expects(:manufacturer).returns('ipod') + # expects(:price).returns(100) + # end + # assert_equal 'ipod', product.manufacturer + # assert_equal 100, product.price + # # an error will be raised unless both Product#manufacturer and Product#price have been called + # end + def mock(*arguments, &block) + name = arguments.shift if arguments.first.is_a?(String) + expectations = arguments.shift || {} + mock = name ? Mockery.instance.named_mock(name, &block) : Mockery.instance.unnamed_mock(&block) + mock.expects(expectations) + mock + end + + # :call-seq: stub(name, &block) -> mock object + # stub(stubbed_methods = {}, &block) -> mock object + # stub(name, stubbed_methods = {}, &block) -> mock object + # + # Creates a mock object. + # + # +name+ is a +String+ identifier for the mock object. + # + # +stubbed_methods+ is a +Hash+ with stubbed method name symbols as keys and corresponding return values as values. + # Note that (contrary to expectations set up by #mock) these expectations need not be fulfilled during the test. + # def test_product + # product = stub('ipod_product', :manufacturer => 'ipod', :price => 100) + # assert_equal 'ipod', product.manufacturer + # assert_equal 100, product.price + # # an error will not be raised even if Product#manufacturer and Product#price have not been called + # end + # + # +block+ is an optional block to be evaluated against the mock object instance, giving an alernative way to set up expectations & stubs. + # def test_product + # product = stub('ipod_product') do + # stubs(:manufacturer).returns('ipod') + # stubs(:price).returns(100) + # end + # assert_equal 'ipod', product.manufacturer + # assert_equal 100, product.price + # # an error will not be raised even if Product#manufacturer and Product#price have not been called + # end + def stub(*arguments, &block) + name = arguments.shift if arguments.first.is_a?(String) + expectations = arguments.shift || {} + stub = name ? Mockery.instance.named_mock(name, &block) : Mockery.instance.unnamed_mock(&block) + stub.stubs(expectations) + stub + end + + # :call-seq: stub_everything(name, &block) -> mock object + # stub_everything(stubbed_methods = {}, &block) -> mock object + # stub_everything(name, stubbed_methods = {}, &block) -> mock object + # + # Creates a mock object that accepts calls to any method. + # + # By default it will return +nil+ for any method call. + # + # +block+ is a block to be evaluated against the mock object instance, giving an alernative way to set up expectations & stubs. + # + # +name+ and +stubbed_methods+ work in the same way as for #stub. + # def test_product + # product = stub_everything('ipod_product', :price => 100) + # assert_nil product.manufacturer + # assert_nil product.any_old_method + # assert_equal 100, product.price + # end + def stub_everything(*arguments, &block) + name = arguments.shift if arguments.first.is_a?(String) + expectations = arguments.shift || {} + stub = name ? Mockery.instance.named_mock(name, &block) : Mockery.instance.unnamed_mock(&block) + stub.stub_everything + stub.stubs(expectations) + stub + end + + # :call-seq: sequence(name) -> sequence + # + # Returns a new sequence that is used to constrain the order in which expectations can occur. + # + # Specify that an expected invocation must occur in within a named +sequence+ by using Expectation#in_sequence. + # + # See also Expectation#in_sequence. + # breakfast = sequence('breakfast') + # + # egg = mock('egg') + # egg.expects(:crack).in_sequence(breakfast) + # egg.expects(:fry).in_sequence(breakfast) + # egg.expects(:eat).in_sequence(breakfast) + def sequence(name) + Sequence.new(name) + end + + # :call-seq: states(name) -> state_machine + # + # Returns a new +state_machine+ that is used to constrain the order in which expectations can occur. + # + # Specify the initial +state+ of the +state_machine+ by using StateMachine#starts_as. + # + # Specify that an expected invocation should change the +state+ of the +state_machine+ by using Expectation#then. + # + # Specify that an expected invocation should be constrained to occur within a particular +state+ by using Expectation#when. + # + # A test can contain multiple +state_machines+. + # + # See also Expectation#then, Expectation#when and StateMachine. + # power = states('power').starts_as('off') + # + # radio = mock('radio') + # radio.expects(:switch_on).then(power.is('on')) + # radio.expects(:select_channel).with('BBC Radio 4').when(power.is('on')) + # radio.expects(:adjust_volume).with(+5).when(power.is('on')) + # radio.expects(:select_channel).with('BBC World Service').when(power.is('on')) + # radio.expects(:adjust_volume).with(-5).when(power.is('on')) + # radio.expects(:switch_off).then(power.is('off')) + def states(name) + Mockery.instance.new_state_machine(name) + end + + # Asserts that the given mock received the given method. + # + # Examples: + # + # assert_received(mock, :to_s) + # assert_received(Radio, :new) {|expect| expect.with(1041) } + # assert_received(radio, :volume) {|expect| expect.with(11).twice } + def assert_received(mock, expected_method_name) + matcher = have_received(expected_method_name) + yield(matcher) if block_given? + assert matcher.matches?(mock), matcher.failure_message + end + + class HaveReceived #:nodoc: + def initialize(expected_method_name) + @expected_method_name = expected_method_name + @expectations = [] + end + + def method_missing(method, *args, &block) + @expectations << [method, args, block] + self + end + + def matches?(mock) + if mock.respond_to?(:mocha) + @mock = mock.mocha + else + @mock = mock + end + + @expectation = Expectation.new(@mock, @expected_method_name) + @expectations.each do |method, args, block| + @expectation.send(method, *args, &block) + end + @expectation.invocation_count = invocation_count + @expectation.verified? + end + + def failure_message + @expectation.mocha_inspect + end + + private + + def invocation_count + matching_invocations.size + end + + def matching_invocations + invocations.select do |invocation| + @expectation.match?(invocation.method_name, *invocation.arguments) + end + end + + def invocations + Mockery.instance.invocations.select do |invocation| + invocation.mock.equal?(@mock) + end + end + end + + # :call-seq: + # should have_received(method).with(arguments).times(times) + # + # Ensures that the given mock received the given method. + # + # Examples: + # + # mock.should have_received(:to_s) + # Radio.should have_received(:new).with(1041) + # radio.should have_received(:volume).with(11).twice + def have_received(expected_method_name) + HaveReceived.new(expected_method_name) + end + + def mocha_setup # :nodoc: + end + + def mocha_verify(assertion_counter = nil) # :nodoc: + Mockery.instance.verify(assertion_counter) + end + + def mocha_teardown # :nodoc: + Mockery.instance.teardown + Mockery.reset_instance + end + + end + + def self.const_missing(name) + return super unless name == :Standalone + require 'mocha/deprecation' + Deprecation.warning "Mocha::Standalone has been renamed to Mocha::API" + return API + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/argument_iterator.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/argument_iterator.rb new file mode 100644 index 0000000..ff58b48 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/argument_iterator.rb @@ -0,0 +1,21 @@ +module Mocha + + class ArgumentIterator + + def initialize(argument) + @argument = argument + end + + def each(&block) + if @argument.is_a?(Hash) then + @argument.each do |method_name, return_value| + block.call(method_name, return_value) + end + else + block.call(@argument) + end + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/backtrace_filter.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/backtrace_filter.rb new file mode 100644 index 0000000..69215e7 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/backtrace_filter.rb @@ -0,0 +1,17 @@ +module Mocha + + class BacktraceFilter + + LIB_DIRECTORY = File.expand_path(File.join(File.dirname(__FILE__), "..")) + File::SEPARATOR + + def initialize(lib_directory = LIB_DIRECTORY) + @lib_directory = lib_directory + end + + def filtered(backtrace) + backtrace.reject { |location| Regexp.new(@lib_directory).match(File.expand_path(location)) } + end + + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/cardinality.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/cardinality.rb new file mode 100644 index 0000000..b0c0ddf --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/cardinality.rb @@ -0,0 +1,95 @@ +module Mocha + + class Cardinality + + INFINITY = 1 / 0.0 + + class << self + + def exactly(count) + new(count, count) + end + + def at_least(count) + new(count, INFINITY) + end + + def at_most(count) + new(0, count) + end + + def times(range_or_count) + case range_or_count + when Range then new(range_or_count.first, range_or_count.last) + else new(range_or_count, range_or_count) + end + end + + end + + def initialize(required, maximum) + @required, @maximum = required, maximum + end + + def invocations_allowed?(invocation_count) + invocation_count < maximum + end + + def satisfied?(invocations_so_far) + invocations_so_far >= required + end + + def needs_verifying? + !allowed_any_number_of_times? + end + + def verified?(invocation_count) + (invocation_count >= required) && (invocation_count <= maximum) + end + + def allowed_any_number_of_times? + required == 0 && infinite?(maximum) + end + + def used?(invocation_count) + (invocation_count > 0) || (maximum == 0) + end + + def mocha_inspect + if allowed_any_number_of_times? + "allowed any number of times" + else + if required == 0 && maximum == 0 + "expected never" + elsif required == maximum + "expected exactly #{times(required)}" + elsif infinite?(maximum) + "expected at least #{times(required)}" + elsif required == 0 + "expected at most #{times(maximum)}" + else + "expected between #{required} and #{times(maximum)}" + end + end + end + + protected + + attr_reader :required, :maximum + + def times(number) + case number + when 0 then "no times" + when 1 then "once" + when 2 then "twice" + else "#{number} times" + end + end + + def infinite?(number) + number.respond_to?(:infinite?) && number.infinite? + end + + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/central.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/central.rb new file mode 100644 index 0000000..7bb287a --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/central.rb @@ -0,0 +1,27 @@ +module Mocha + + class Central + + attr_accessor :stubba_methods + + def initialize + self.stubba_methods = [] + end + + def stub(method) + unless stubba_methods.include?(method) + method.stub + stubba_methods.push(method) + end + end + + def unstub_all + while stubba_methods.length > 0 + method = stubba_methods.pop + method.unstub + end + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/change_state_side_effect.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/change_state_side_effect.rb new file mode 100644 index 0000000..fe85d6e --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/change_state_side_effect.rb @@ -0,0 +1,19 @@ +module Mocha + + class ChangeStateSideEffect + + def initialize(state) + @state = state + end + + def perform + @state.activate + end + + def mocha_inspect + "then #{@state.mocha_inspect}" + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/class_method.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/class_method.rb new file mode 100644 index 0000000..eef11d7 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/class_method.rb @@ -0,0 +1,87 @@ +require 'mocha/metaclass' + +module Mocha + + class ClassMethod + + attr_reader :stubbee, :method + + def initialize(stubbee, method) + @stubbee = stubbee + @method = RUBY_VERSION < '1.9' ? method.to_s : method.to_sym + end + + def stub + hide_original_method + define_new_method + end + + def unstub + remove_new_method + restore_original_method + stubbee.reset_mocha + end + + def mock + stubbee.mocha + end + + def hide_original_method + if method_exists?(method) + begin + stubbee.__metaclass__.send(:alias_method, hidden_method, method) + rescue NameError + # deal with nasties like ActiveRecord::Associations::AssociationProxy + end + end + end + + def define_new_method + stubbee.__metaclass__.class_eval("def #{method}(*args, &block); mocha.method_missing(:#{method}, *args, &block); end", __FILE__, __LINE__) + end + + def remove_new_method + stubbee.__metaclass__.send(:remove_method, method) + end + + def restore_original_method + if method_exists?(hidden_method) + begin + stubbee.__metaclass__.send(:alias_method, method, hidden_method) + stubbee.__metaclass__.send(:remove_method, hidden_method) + rescue NameError + # deal with nasties like ActiveRecord::Associations::AssociationProxy + end + end + end + + def hidden_method + if RUBY_VERSION < '1.9' + method_name = method.to_s.gsub(/\W/) { |s| "_substituted_character_#{s[0]}_" } + else + method_name = method.to_s.gsub(/\W/) { |s| "_substituted_character_#{s.ord}_" } + end + hidden_method = "__stubba__#{method_name}__stubba__" + RUBY_VERSION < '1.9' ? hidden_method.to_s : hidden_method.to_sym + end + + def eql?(other) + return false unless (other.class == self.class) + (stubbee.object_id == other.stubbee.object_id) and (method == other.method) + end + + alias_method :==, :eql? + + def to_s + "#{stubbee}.#{method}" + end + + def method_exists?(method) + symbol = method.to_sym + metaclass = stubbee.__metaclass__ + metaclass.public_method_defined?(symbol) || metaclass.protected_method_defined?(symbol) || metaclass.private_method_defined?(symbol) + end + + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/configuration.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/configuration.rb new file mode 100644 index 0000000..fb1ab6f --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/configuration.rb @@ -0,0 +1,60 @@ +module Mocha # :nodoc: + + # Configuration settings + class Configuration + + DEFAULTS = { :stubbing_method_unnecessarily => :allow, :stubbing_method_on_non_mock_object => :allow, :stubbing_non_existent_method => :allow, :stubbing_non_public_method => :allow } + + class << self + + # :call-seq: allow(action) + # + # Allow the specified action (as a symbol). + # The actions currently available are :stubbing_method_unnecessarily, :stubbing_method_on_non_mock_object, :stubbing_non_existent_method, :stubbing_non_public_method. + def allow(action) + configuration[action] = :allow + end + + def allow?(action) # :nodoc: + configuration[action] == :allow + end + + # :call-seq: warn_when(action) + # + # Warn if the specified action (as a symbol) is attempted. + # The actions currently available are :stubbing_method_unnecessarily, :stubbing_method_on_non_mock_object, :stubbing_non_existent_method, :stubbing_non_public_method. + def warn_when(action) + configuration[action] = :warn + end + + def warn_when?(action) # :nodoc: + configuration[action] == :warn + end + + # :call-seq: prevent(action) + # + # Raise a StubbingError if the specified action (as a symbol) is attempted. + # The actions currently available are :stubbing_method_unnecessarily, :stubbing_method_on_non_mock_object, :stubbing_non_existent_method, :stubbing_non_public_method. + def prevent(action) + configuration[action] = :prevent + end + + def prevent?(action) # :nodoc: + configuration[action] == :prevent + end + + def reset_configuration # :nodoc: + @configuration = nil + end + + private + + def configuration # :nodoc: + @configuration ||= DEFAULTS.dup + end + + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/deprecation.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/deprecation.rb new file mode 100644 index 0000000..7448510 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/deprecation.rb @@ -0,0 +1,22 @@ +module Mocha + + class Deprecation + + class << self + + attr_accessor :mode, :messages + + def warning(message) + @messages << message + $stderr.puts "Mocha deprecation warning: #{message}" unless mode == :disabled + $stderr.puts caller.join("\n ") if mode == :debug + end + + end + + self.mode = :enabled + self.messages = [] + + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/exception_raiser.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/exception_raiser.rb new file mode 100644 index 0000000..9e009cb --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/exception_raiser.rb @@ -0,0 +1,17 @@ +module Mocha # :nodoc: + + class ExceptionRaiser # :nodoc: + + def initialize(exception, message) + @exception, @message = exception, message + end + + def evaluate + raise @exception, @exception.to_s if @exception.is_a?(Module) && @exception.ancestors.include?(Interrupt) + raise @exception, @message if @message + raise @exception + end + + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/expectation.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/expectation.rb new file mode 100644 index 0000000..0a33c8b --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/expectation.rb @@ -0,0 +1,484 @@ +require 'mocha/method_matcher' +require 'mocha/parameters_matcher' +require 'mocha/expectation_error' +require 'mocha/return_values' +require 'mocha/exception_raiser' +require 'mocha/yield_parameters' +require 'mocha/is_a' +require 'mocha/in_state_ordering_constraint' +require 'mocha/change_state_side_effect' +require 'mocha/cardinality' + +module Mocha # :nodoc: + + # Methods on expectations returned from Mock#expects, Mock#stubs, Object#expects and Object#stubs. + class Expectation + + # :call-seq: times(range) -> expectation + # + # Modifies expectation so that the number of calls to the expected method must be within a specific +range+. + # + # +range+ can be specified as an exact integer or as a range of integers + # object = mock() + # object.expects(:expected_method).times(3) + # 3.times { object.expected_method } + # # => verify succeeds + # + # object = mock() + # object.expects(:expected_method).times(3) + # 2.times { object.expected_method } + # # => verify fails + # + # object = mock() + # object.expects(:expected_method).times(2..4) + # 3.times { object.expected_method } + # # => verify succeeds + # + # object = mock() + # object.expects(:expected_method).times(2..4) + # object.expected_method + # # => verify fails + def times(range) + @cardinality = Cardinality.times(range) + self + end + + # :call-seq: twice() -> expectation + # + # Modifies expectation so that the expected method must be called exactly twice. + # object = mock() + # object.expects(:expected_method).twice + # object.expected_method + # object.expected_method + # # => verify succeeds + # + # object = mock() + # object.expects(:expected_method).twice + # object.expected_method + # object.expected_method + # object.expected_method + # # => verify fails + # + # object = mock() + # object.expects(:expected_method).twice + # object.expected_method + # # => verify fails + def twice + @cardinality = Cardinality.exactly(2) + self + end + + # :call-seq: once() -> expectation + # + # Modifies expectation so that the expected method must be called exactly once. + # Note that this is the default behaviour for an expectation, but you may wish to use it for clarity/emphasis. + # object = mock() + # object.expects(:expected_method).once + # object.expected_method + # # => verify succeeds + # + # object = mock() + # object.expects(:expected_method).once + # object.expected_method + # object.expected_method + # # => verify fails + # + # object = mock() + # object.expects(:expected_method).once + # # => verify fails + def once + @cardinality = Cardinality.exactly(1) + self + end + + # :call-seq: never() -> expectation + # + # Modifies expectation so that the expected method must never be called. + # object = mock() + # object.expects(:expected_method).never + # object.expected_method + # # => verify fails + # + # object = mock() + # object.expects(:expected_method).never + # object.expected_method + # # => verify succeeds + def never + @cardinality = Cardinality.exactly(0) + self + end + + # :call-seq: at_least(minimum_number_of_times) -> expectation + # + # Modifies expectation so that the expected method must be called at least a +minimum_number_of_times+. + # object = mock() + # object.expects(:expected_method).at_least(2) + # 3.times { object.expected_method } + # # => verify succeeds + # + # object = mock() + # object.expects(:expected_method).at_least(2) + # object.expected_method + # # => verify fails + def at_least(minimum_number_of_times) + @cardinality = Cardinality.at_least(minimum_number_of_times) + self + end + + # :call-seq: at_least_once() -> expectation + # + # Modifies expectation so that the expected method must be called at least once. + # object = mock() + # object.expects(:expected_method).at_least_once + # object.expected_method + # # => verify succeeds + # + # object = mock() + # object.expects(:expected_method).at_least_once + # # => verify fails + def at_least_once + at_least(1) + self + end + + # :call-seq: at_most(maximum_number_of_times) -> expectation + # + # Modifies expectation so that the expected method must be called at most a +maximum_number_of_times+. + # object = mock() + # object.expects(:expected_method).at_most(2) + # 2.times { object.expected_method } + # # => verify succeeds + # + # object = mock() + # object.expects(:expected_method).at_most(2) + # 3.times { object.expected_method } + # # => verify fails + def at_most(maximum_number_of_times) + @cardinality = Cardinality.at_most(maximum_number_of_times) + self + end + + # :call-seq: at_most_once() -> expectation + # + # Modifies expectation so that the expected method must be called at most once. + # object = mock() + # object.expects(:expected_method).at_most_once + # object.expected_method + # # => verify succeeds + # + # object = mock() + # object.expects(:expected_method).at_most_once + # 2.times { object.expected_method } + # # => verify fails + def at_most_once() + at_most(1) + self + end + + # :call-seq: with(*expected_parameters, &matching_block) -> expectation + # + # Modifies expectation so that the expected method must be called with +expected_parameters+. + # object = mock() + # object.expects(:expected_method).with(:param1, :param2) + # object.expected_method(:param1, :param2) + # # => verify succeeds + # + # object = mock() + # object.expects(:expected_method).with(:param1, :param2) + # object.expected_method(:param3) + # # => verify fails + # May be used with parameter matchers in Mocha::ParameterMatchers. + # + # If a +matching_block+ is given, the block is called with the parameters passed to the expected method. + # The expectation is matched if the block evaluates to +true+. + # object = mock() + # object.expects(:expected_method).with() { |value| value % 4 == 0 } + # object.expected_method(16) + # # => verify succeeds + # + # object = mock() + # object.expects(:expected_method).with() { |value| value % 4 == 0 } + # object.expected_method(17) + # # => verify fails + def with(*expected_parameters, &matching_block) + @parameters_matcher = ParametersMatcher.new(expected_parameters, &matching_block) + self + end + + # :call-seq: yields(*parameters) -> expectation + # + # Modifies expectation so that when the expected method is called, it yields with the specified +parameters+. + # object = mock() + # object.expects(:expected_method).yields('result') + # yielded_value = nil + # object.expected_method { |value| yielded_value = value } + # yielded_value # => 'result' + # May be called multiple times on the same expectation for consecutive invocations. Also see Expectation#then. + # object = mock() + # object.stubs(:expected_method).yields(1).then.yields(2) + # yielded_values_from_first_invocation = [] + # yielded_values_from_second_invocation = [] + # object.expected_method { |value| yielded_values_from_first_invocation << value } # first invocation + # object.expected_method { |value| yielded_values_from_second_invocation << value } # second invocation + # yielded_values_from_first_invocation # => [1] + # yielded_values_from_second_invocation # => [2] + def yields(*parameters) + @yield_parameters.add(*parameters) + self + end + + # :call-seq: multiple_yields(*parameter_groups) -> expectation + # + # Modifies expectation so that when the expected method is called, it yields multiple times per invocation with the specified +parameter_groups+. + # object = mock() + # object.expects(:expected_method).multiple_yields(['result_1', 'result_2'], ['result_3']) + # yielded_values = [] + # object.expected_method { |*values| yielded_values << values } + # yielded_values # => [['result_1', 'result_2'], ['result_3]] + # May be called multiple times on the same expectation for consecutive invocations. Also see Expectation#then. + # object = mock() + # object.stubs(:expected_method).multiple_yields([1, 2], [3]).then.multiple_yields([4], [5, 6]) + # yielded_values_from_first_invocation = [] + # yielded_values_from_second_invocation = [] + # object.expected_method { |*values| yielded_values_from_first_invocation << values } # first invocation + # object.expected_method { |*values| yielded_values_from_second_invocation << values } # second invocation + # yielded_values_from_first_invocation # => [[1, 2], [3]] + # yielded_values_from_second_invocation # => [[4], [5, 6]] + def multiple_yields(*parameter_groups) + @yield_parameters.multiple_add(*parameter_groups) + self + end + + # :call-seq: returns(value) -> expectation + # returns(*values) -> expectation + # + # Modifies expectation so that when the expected method is called, it returns the specified +value+. + # object = mock() + # object.stubs(:stubbed_method).returns('result') + # object.stubbed_method # => 'result' + # object.stubbed_method # => 'result' + # If multiple +values+ are given, these are returned in turn on consecutive calls to the method. + # object = mock() + # object.stubs(:stubbed_method).returns(1, 2) + # object.stubbed_method # => 1 + # object.stubbed_method # => 2 + # May be called multiple times on the same expectation. Also see Expectation#then. + # object = mock() + # object.stubs(:expected_method).returns(1, 2).then.returns(3) + # object.expected_method # => 1 + # object.expected_method # => 2 + # object.expected_method # => 3 + # May be called in conjunction with Expectation#raises on the same expectation. + # object = mock() + # object.stubs(:expected_method).returns(1, 2).then.raises(Exception) + # object.expected_method # => 1 + # object.expected_method # => 2 + # object.expected_method # => raises exception of class Exception1 + # Note that in Ruby a method returning multiple values is exactly equivalent to a method returning an Array of those values. + # object = mock() + # object.stubs(:expected_method).returns([1, 2]) + # x, y = object.expected_method + # x # => 1 + # y # => 2 + def returns(*values) + @return_values += ReturnValues.build(*values) + self + end + + # :call-seq: raises(exception = RuntimeError, message = nil) -> expectation + # + # Modifies expectation so that when the expected method is called, it raises the specified +exception+ with the specified +message+. + # object = mock() + # object.expects(:expected_method).raises(Exception, 'message') + # object.expected_method # => raises exception of class Exception and with message 'message' + # May be called multiple times on the same expectation. Also see Expectation#then. + # object = mock() + # object.stubs(:expected_method).raises(Exception1).then.raises(Exception2) + # object.expected_method # => raises exception of class Exception1 + # object.expected_method # => raises exception of class Exception2 + # May be called in conjunction with Expectation#returns on the same expectation. + # object = mock() + # object.stubs(:expected_method).raises(Exception).then.returns(2, 3) + # object.expected_method # => raises exception of class Exception1 + # object.expected_method # => 2 + # object.expected_method # => 3 + def raises(exception = RuntimeError, message = nil) + @return_values += ReturnValues.new(ExceptionRaiser.new(exception, message)) + self + end + + # :call-seq: then() -> expectation + # then(state_machine.is(state)) -> expectation + # + # then() is used as syntactic sugar to improve readability. It has no effect on state of the expectation. + # object = mock() + # object.stubs(:expected_method).returns(1, 2).then.raises(Exception).then.returns(4) + # object.expected_method # => 1 + # object.expected_method # => 2 + # object.expected_method # => raises exception of class Exception + # object.expected_method # => 4 + # + # then(state_machine.is(state)) is used to change the +state_machine+ to the specified +state+ when the invocation occurs. + # + # See also API#states, StateMachine and Expectation#when. + # power = states('power').starts_as('off') + # + # radio = mock('radio') + # radio.expects(:switch_on).then(power.is('on')) + # radio.expects(:select_channel).with('BBC Radio 4').when(power.is('on')) + # radio.expects(:adjust_volume).with(+5).when(power.is('on')) + # radio.expects(:select_channel).with('BBC World Service').when(power.is('on')) + # radio.expects(:adjust_volume).with(-5).when(power.is('on')) + # radio.expects(:switch_off).then(power.is('off')) + def then(*parameters) + if parameters.length == 1 + state = parameters.first + add_side_effect(ChangeStateSideEffect.new(state)) + end + self + end + + # :call-seq: when(state_machine.is(state)) -> exception + # + # Constrains the expectation to occur only when the +state_machine+ is in the named +state+. + # + # See also API#states, StateMachine#starts_as and Expectation#then. + # power = states('power').starts_as('off') + # + # radio = mock('radio') + # radio.expects(:switch_on).then(power.is('on')) + # radio.expects(:select_channel).with('BBC Radio 4').when(power.is('on')) + # radio.expects(:adjust_volume).with(+5).when(power.is('on')) + # radio.expects(:select_channel).with('BBC World Service').when(power.is('on')) + # radio.expects(:adjust_volume).with(-5).when(power.is('on')) + # radio.expects(:switch_off).then(power.is('off')) + def when(state_predicate) + add_ordering_constraint(InStateOrderingConstraint.new(state_predicate)) + self + end + + # :call-seq: in_sequence(*sequences) -> expectation + # + # Constrains this expectation so that it must be invoked at the current point in the sequence. + # + # To expect a sequence of invocations, write the expectations in order and add the in_sequence(sequence) clause to each one. + # + # Expectations in a sequence can have any invocation count. + # + # If an expectation in a sequence is stubbed, rather than expected, it can be skipped in the sequence. + # + # See also API#sequence. + # breakfast = sequence('breakfast') + # + # egg = mock('egg') + # egg.expects(:crack).in_sequence(breakfast) + # egg.expects(:fry).in_sequence(breakfast) + # egg.expects(:eat).in_sequence(breakfast) + def in_sequence(*sequences) + sequences.each { |sequence| add_in_sequence_ordering_constraint(sequence) } + self + end + + # :stopdoc: + + attr_reader :backtrace + attr_accessor :invocation_count + + def initialize(mock, expected_method_name, backtrace = nil) + @mock = mock + @method_matcher = MethodMatcher.new(expected_method_name.to_sym) + @parameters_matcher = ParametersMatcher.new + @ordering_constraints = [] + @side_effects = [] + @cardinality, @invocation_count = Cardinality.exactly(1), 0 + @return_values = ReturnValues.new + @yield_parameters = YieldParameters.new + @backtrace = backtrace || caller + end + + def add_ordering_constraint(ordering_constraint) + @ordering_constraints << ordering_constraint + end + + def add_in_sequence_ordering_constraint(sequence) + sequence.constrain_as_next_in_sequence(self) + end + + def add_side_effect(side_effect) + @side_effects << side_effect + end + + def perform_side_effects + @side_effects.each { |side_effect| side_effect.perform } + end + + def in_correct_order? + @ordering_constraints.all? { |ordering_constraint| ordering_constraint.allows_invocation_now? } + end + + def matches_method?(method_name) + @method_matcher.match?(method_name) + end + + def match?(actual_method_name, *actual_parameters) + @method_matcher.match?(actual_method_name) && @parameters_matcher.match?(actual_parameters) && in_correct_order? + end + + def invocations_allowed? + @cardinality.invocations_allowed?(@invocation_count) + end + + def satisfied? + @cardinality.satisfied?(@invocation_count) + end + + def invoke(args) + @invocation_count += 1 + Mockery.instance.invocation(@mock, method_name, args) + perform_side_effects() + if block_given? then + @yield_parameters.next_invocation.each do |yield_parameters| + yield(*yield_parameters) + end + end + @return_values.next + end + + def verified?(assertion_counter = nil) + assertion_counter.increment if assertion_counter && @cardinality.needs_verifying? + @cardinality.verified?(@invocation_count) + end + + def used? + @cardinality.used?(@invocation_count) + end + + def mocha_inspect + message = "#{@cardinality.mocha_inspect}, " + message << case @invocation_count + when 0 then "not yet invoked" + when 1 then "already invoked once" + when 2 then "already invoked twice" + else "already invoked #{@invocation_count} times" + end + message << ": " + message << method_signature + message << "; #{@ordering_constraints.map { |oc| oc.mocha_inspect }.join("; ")}" unless @ordering_constraints.empty? + message + end + + def method_signature + "#{@mock.mocha_inspect}.#{@method_matcher.mocha_inspect}#{@parameters_matcher.mocha_inspect}" + end + + private + + def method_name + @method_matcher.expected_method_name + end + + # :startdoc: + + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/expectation_error.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/expectation_error.rb new file mode 100644 index 0000000..ffa9835 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/expectation_error.rb @@ -0,0 +1,15 @@ +require 'mocha/backtrace_filter' + +module Mocha + + class ExpectationError < StandardError + + def initialize(message = nil, backtrace = []) + super(message) + filter = BacktraceFilter.new + set_backtrace(filter.filtered(backtrace)) + end + + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/expectation_list.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/expectation_list.rb new file mode 100644 index 0000000..788d07c --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/expectation_list.rb @@ -0,0 +1,50 @@ +module Mocha # :nodoc: + + class ExpectationList + + def initialize + @expectations = [] + end + + def add(expectation) + @expectations.unshift(expectation) + expectation + end + + def matches_method?(method_name) + @expectations.any? { |expectation| expectation.matches_method?(method_name) } + end + + def match(method_name, *arguments) + matching_expectations(method_name, *arguments).first + end + + def match_allowing_invocation(method_name, *arguments) + matching_expectations(method_name, *arguments).detect { |e| e.invocations_allowed? } + end + + def verified?(assertion_counter = nil) + @expectations.all? { |expectation| expectation.verified?(assertion_counter) } + end + + def to_a + @expectations + end + + def to_set + @expectations.to_set + end + + def length + @expectations.length + end + + private + + def matching_expectations(method_name, *arguments) + @expectations.select { |e| e.match?(method_name, *arguments) } + end + + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/in_state_ordering_constraint.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/in_state_ordering_constraint.rb new file mode 100644 index 0000000..1ff0898 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/in_state_ordering_constraint.rb @@ -0,0 +1,19 @@ +module Mocha + + class InStateOrderingConstraint + + def initialize(state_predicate) + @state_predicate = state_predicate + end + + def allows_invocation_now? + @state_predicate.active? + end + + def mocha_inspect + "when #{@state_predicate.mocha_inspect}" + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/inspect.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/inspect.rb new file mode 100644 index 0000000..bca613d --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/inspect.rb @@ -0,0 +1,67 @@ +require 'date' + +module Mocha + + module ObjectMethods + def mocha_inspect + address = self.__id__ * 2 + address += 0x100000000 if address < 0 + inspect =~ /#" : inspect + end + end + + module StringMethods + def mocha_inspect + inspect.gsub(/\"/, "'") + end + end + + module ArrayMethods + def mocha_inspect + "[#{collect { |member| member.mocha_inspect }.join(', ')}]" + end + end + + module HashMethods + def mocha_inspect + "{#{collect { |key, value| "#{key.mocha_inspect} => #{value.mocha_inspect}" }.join(', ')}}" + end + end + + module TimeMethods + def mocha_inspect + "#{inspect} (#{to_f} secs)" + end + end + + module DateMethods + def mocha_inspect + to_s + end + end + +end + +class Object + include Mocha::ObjectMethods +end + +class String + include Mocha::StringMethods +end + +class Array + include Mocha::ArrayMethods +end + +class Hash + include Mocha::HashMethods +end + +class Time + include Mocha::TimeMethods +end + +class Date + include Mocha::DateMethods +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/instance_method.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/instance_method.rb new file mode 100644 index 0000000..49669ae --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/instance_method.rb @@ -0,0 +1,16 @@ +require 'mocha/class_method' + +module Mocha + + class InstanceMethod < ClassMethod + + def method_exists?(method) + return true if stubbee.public_methods(false).include?(method) + return true if stubbee.protected_methods(false).include?(method) + return true if stubbee.private_methods(false).include?(method) + return false + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/bacon.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/bacon.rb new file mode 100644 index 0000000..81aa0fc --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/bacon.rb @@ -0,0 +1 @@ +require 'mocha/integration/bacon/version_11_and_above.rb' diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/bacon/assertion_counter.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/bacon/assertion_counter.rb new file mode 100644 index 0000000..1976515 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/bacon/assertion_counter.rb @@ -0,0 +1,23 @@ +module Mocha + + module Integration + + module Bacon + + class AssertionCounter + + def initialize(counter) + @counter = counter + end + + def increment + @counter[:requirements] += 1 + end + + end + + end + + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/bacon/version_11_and_above.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/bacon/version_11_and_above.rb new file mode 100644 index 0000000..d82b743 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/bacon/version_11_and_above.rb @@ -0,0 +1,34 @@ +require 'mocha/integration/bacon/assertion_counter' + +module Mocha + + module Integration + + module Bacon + + module Version11AndAbove + + def self.included(base) + + base.class_eval do + alias :it_before_bacon :it + def it(description) + it_before_bacon(description) do + assertion_counter = ::Mocha::Integration::Bacon::AssertionCounter.new(::Bacon::Counter) + mocha_setup + yield + mocha_verify(assertion_counter) + mocha_teardown + end + end + end + + end + + end + + end + + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/mini_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/mini_test.rb new file mode 100644 index 0000000..47588c3 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/mini_test.rb @@ -0,0 +1 @@ +require 'mocha/integration/mini_test/version_131_and_above' \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/mini_test/assertion_counter.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/mini_test/assertion_counter.rb new file mode 100644 index 0000000..c303d6a --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/mini_test/assertion_counter.rb @@ -0,0 +1,23 @@ +module Mocha + + module Integration + + module MiniTest + + class AssertionCounter + + def initialize(test_case) + @test_case = test_case + end + + def increment + @test_case._assertions += 1 + end + + end + + end + + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/mini_test/version_131_and_above.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/mini_test/version_131_and_above.rb new file mode 100644 index 0000000..809ac30 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/mini_test/version_131_and_above.rb @@ -0,0 +1,49 @@ +require 'mocha/integration/mini_test/assertion_counter' +require 'mocha/expectation_error' + +module Mocha + + module Integration + + module MiniTest + + def self.translate(exception) + return exception unless exception.kind_of?(::Mocha::ExpectationError) + translated_exception = ::MiniTest::Assertion.new(exception.message) + translated_exception.set_backtrace(exception.backtrace) + translated_exception + end + + module Version131AndAbove + def run runner + assertion_counter = AssertionCounter.new(self) + result = '.' + begin + begin + @passed = nil + self.setup + self.__send__ self.name + mocha_verify(assertion_counter) + @passed = true + rescue Exception => e + @passed = false + result = runner.puke(self.class, self.name, Mocha::Integration::MiniTest.translate(e)) + ensure + begin + self.teardown + rescue Exception => e + result = runner.puke(self.class, self.name, Mocha::Integration::MiniTest.translate(e)) + end + end + ensure + mocha_teardown + end + result + end + end + + end + + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/test_unit.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/test_unit.rb new file mode 100644 index 0000000..39ea53d --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/test_unit.rb @@ -0,0 +1,4 @@ +require 'mocha/integration/test_unit/gem_version_200' +require 'mocha/integration/test_unit/gem_version_201_and_above' +require 'mocha/integration/test_unit/ruby_version_185_and_below' +require 'mocha/integration/test_unit/ruby_version_186_and_above' \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/test_unit/assertion_counter.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/test_unit/assertion_counter.rb new file mode 100644 index 0000000..61c4779 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/test_unit/assertion_counter.rb @@ -0,0 +1,23 @@ +module Mocha + + module Integration + + module TestUnit + + class AssertionCounter + + def initialize(test_result) + @test_result = test_result + end + + def increment + @test_result.add_assertion + end + + end + + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/test_unit/gem_version_200.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/test_unit/gem_version_200.rb new file mode 100644 index 0000000..0408fe5 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/test_unit/gem_version_200.rb @@ -0,0 +1,49 @@ +require 'test/unit/testcase' +require 'mocha/integration/test_unit/assertion_counter' +require 'mocha/expectation_error' + +module Mocha + + module Integration + + module TestUnit + + module GemVersion200 + def run(result) + assertion_counter = AssertionCounter.new(result) + begin + @_result = result + yield(Test::Unit::TestCase::STARTED, name) + begin + begin + run_setup + __send__(@method_name) + mocha_verify(assertion_counter) + rescue Mocha::ExpectationError => e + add_failure(e.message, e.backtrace) + rescue Exception + @interrupted = true + raise unless handle_exception($!) + ensure + begin + run_teardown + rescue Exception + raise unless handle_exception($!) + end + end + ensure + mocha_teardown + end + result.add_run + yield(Test::Unit::TestCase::FINISHED, name) + ensure + @_result = nil + end + end + end + + end + + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/test_unit/gem_version_201_and_above.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/test_unit/gem_version_201_and_above.rb new file mode 100644 index 0000000..f1730b5 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/test_unit/gem_version_201_and_above.rb @@ -0,0 +1,49 @@ +require 'test/unit/testcase' +require 'mocha/integration/test_unit/assertion_counter' +require 'mocha/expectation_error' + +module Mocha + + module Integration + + module TestUnit + + module GemVersion201AndAbove + def run(result) + assertion_counter = AssertionCounter.new(result) + begin + @_result = result + yield(Test::Unit::TestCase::STARTED, name) + begin + begin + run_setup + run_test + mocha_verify(assertion_counter) + rescue Mocha::ExpectationError => e + add_failure(e.message, e.backtrace) + rescue Exception + @interrupted = true + raise unless handle_exception($!) + ensure + begin + run_teardown + rescue Exception + raise unless handle_exception($!) + end + end + ensure + mocha_teardown + end + result.add_run + yield(Test::Unit::TestCase::FINISHED, name) + ensure + @_result = nil + end + end + end + + end + + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/test_unit/ruby_version_185_and_below.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/test_unit/ruby_version_185_and_below.rb new file mode 100644 index 0000000..b1ad2a3 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/test_unit/ruby_version_185_and_below.rb @@ -0,0 +1,48 @@ +require 'test/unit/testcase' +require 'mocha/integration/test_unit/assertion_counter' +require 'mocha/expectation_error' + +module Mocha + + module Integration + + module TestUnit + + module RubyVersion185AndBelow + def run(result) + assertion_counter = AssertionCounter.new(result) + yield(Test::Unit::TestCase::STARTED, name) + @_result = result + begin + begin + setup + __send__(@method_name) + mocha_verify(assertion_counter) + rescue Mocha::ExpectationError => e + add_failure(e.message, e.backtrace) + rescue Test::Unit::AssertionFailedError => e + add_failure(e.message, e.backtrace) + rescue StandardError, ScriptError + add_error($!) + ensure + begin + teardown + rescue Test::Unit::AssertionFailedError => e + add_failure(e.message, e.backtrace) + rescue StandardError, ScriptError + add_error($!) + end + end + ensure + mocha_teardown + end + result.add_run + yield(Test::Unit::TestCase::FINISHED, name) + end + end + + end + + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/test_unit/ruby_version_186_and_above.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/test_unit/ruby_version_186_and_above.rb new file mode 100644 index 0000000..b449f01 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/test_unit/ruby_version_186_and_above.rb @@ -0,0 +1,50 @@ +require 'test/unit/testcase' +require 'mocha/integration/test_unit/assertion_counter' +require 'mocha/expectation_error' + +module Mocha + + module Integration + + module TestUnit + + module RubyVersion186AndAbove + def run(result) + assertion_counter = AssertionCounter.new(result) + yield(Test::Unit::TestCase::STARTED, name) + @_result = result + begin + begin + setup + __send__(@method_name) + mocha_verify(assertion_counter) + rescue Mocha::ExpectationError => e + add_failure(e.message, e.backtrace) + rescue Test::Unit::AssertionFailedError => e + add_failure(e.message, e.backtrace) + rescue Exception + raise if Test::Unit::TestCase::PASSTHROUGH_EXCEPTIONS.include? $!.class + add_error($!) + ensure + begin + teardown + rescue Test::Unit::AssertionFailedError => e + add_failure(e.message, e.backtrace) + rescue Exception + raise if Test::Unit::TestCase::PASSTHROUGH_EXCEPTIONS.include? $!.class + add_error($!) + end + end + ensure + mocha_teardown + end + result.add_run + yield(Test::Unit::TestCase::FINISHED, name) + end + end + + end + + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/invocation.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/invocation.rb new file mode 100644 index 0000000..84d8fb2 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/invocation.rb @@ -0,0 +1,10 @@ +module Mocha + class Invocation # :nodoc: + attr_reader :mock, :method_name, :arguments + def initialize(mock, method_name, arguments) + @mock = mock + @method_name = method_name + @arguments = arguments + end + end +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/is_a.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/is_a.rb new file mode 100644 index 0000000..ee23c86 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/is_a.rb @@ -0,0 +1,9 @@ +class Object + + # :stopdoc: + + alias_method :__is_a__, :is_a? + + # :startdoc: + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/logger.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/logger.rb new file mode 100644 index 0000000..9f09300 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/logger.rb @@ -0,0 +1,15 @@ +module Mocha + + class Logger + + def initialize(io) + @io = io + end + + def warn(message) + @io.puts "WARNING: #{message}" + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/metaclass.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/metaclass.rb new file mode 100644 index 0000000..3c3680d --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/metaclass.rb @@ -0,0 +1,13 @@ +module Mocha + + module ObjectMethods + def __metaclass__ + class << self; self; end + end + end + +end + +class Object + include Mocha::ObjectMethods +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/method_matcher.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/method_matcher.rb new file mode 100644 index 0000000..6ce5f6d --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/method_matcher.rb @@ -0,0 +1,21 @@ +module Mocha + + class MethodMatcher + + attr_reader :expected_method_name + + def initialize(expected_method_name) + @expected_method_name = expected_method_name + end + + def match?(actual_method_name) + @expected_method_name == actual_method_name + end + + def mocha_inspect + "#{@expected_method_name}" + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/mock.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/mock.rb new file mode 100644 index 0000000..07f0bbb --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/mock.rb @@ -0,0 +1,200 @@ +require 'mocha/expectation' +require 'mocha/expectation_list' +require 'mocha/metaclass' +require 'mocha/names' +require 'mocha/mockery' +require 'mocha/method_matcher' +require 'mocha/parameters_matcher' +require 'mocha/unexpected_invocation' +require 'mocha/argument_iterator' + +module Mocha # :nodoc: + + # Traditional mock object. + # + # Methods return an Expectation which can be further modified by methods on Expectation. + class Mock + + # :call-seq: expects(method_name) -> expectation + # expects(method_names_vs_return_values) -> last expectation + # + # Adds an expectation that a method identified by +method_name+ Symbol/String must be called exactly once with any parameters. + # Returns the new expectation which can be further modified by methods on Expectation. + # object = mock() + # object.expects(:method1) + # object.method1 + # # no error raised + # + # object = mock() + # object.expects(:method1) + # # error raised, because method1 not called exactly once + # If +method_names_vs_return_values+ is a +Hash+, an expectation will be set up for each entry using the key as +method_name+ and value as +return_value+. + # object = mock() + # object.expects(:method1 => :result1, :method2 => :result2) + # + # # exactly equivalent to + # + # object = mock() + # object.expects(:method1).returns(:result1) + # object.expects(:method2).returns(:result2) + # + # Aliased by \_\_expects\_\_ + def expects(method_name_or_hash, backtrace = nil) + iterator = ArgumentIterator.new(method_name_or_hash) + iterator.each { |*args| + method_name = args.shift + ensure_method_not_already_defined(method_name) + expectation = Expectation.new(self, method_name, backtrace) + expectation.returns(args.shift) if args.length > 0 + @expectations.add(expectation) + } + end + + # :call-seq: stubs(method_name) -> expectation + # stubs(method_names_vs_return_values) -> last expectation + # + # Adds an expectation that a method identified by +method_name+ Symbol/String may be called any number of times with any parameters. + # Returns the new expectation which can be further modified by methods on Expectation. + # object = mock() + # object.stubs(:method1) + # object.method1 + # object.method1 + # # no error raised + # If +method_names_vs_return_values+ is a +Hash+, an expectation will be set up for each entry using the key as +method_name+ and value as +return_value+. + # object = mock() + # object.stubs(:method1 => :result1, :method2 => :result2) + # + # # exactly equivalent to + # + # object = mock() + # object.stubs(:method1).returns(:result1) + # object.stubs(:method2).returns(:result2) + # + # Aliased by \_\_stubs\_\_ + def stubs(method_name_or_hash, backtrace = nil) + iterator = ArgumentIterator.new(method_name_or_hash) + iterator.each { |*args| + method_name = args.shift + ensure_method_not_already_defined(method_name) + expectation = Expectation.new(self, method_name, backtrace) + expectation.at_least(0) + expectation.returns(args.shift) if args.length > 0 + @expectations.add(expectation) + } + end + + # :call-seq: responds_like(responder) -> mock + # + # Constrains the +mock+ so that it can only expect or stub methods to which +responder+ responds. The constraint is only applied at method invocation time. + # + # A +NoMethodError+ will be raised if the +responder+ does not respond_to? a method invocation (even if the method has been expected or stubbed). + # + # The +mock+ will delegate its respond_to? method to the +responder+. + # class Sheep + # def chew(grass); end + # def self.number_of_legs; end + # end + # + # sheep = mock('sheep') + # sheep.expects(:chew) + # sheep.expects(:foo) + # sheep.respond_to?(:chew) # => true + # sheep.respond_to?(:foo) # => true + # sheep.chew + # sheep.foo + # # no error raised + # + # sheep = mock('sheep') + # sheep.responds_like(Sheep.new) + # sheep.expects(:chew) + # sheep.expects(:foo) + # sheep.respond_to?(:chew) # => true + # sheep.respond_to?(:foo) # => false + # sheep.chew + # sheep.foo # => raises NoMethodError exception + # + # sheep_class = mock('sheep_class') + # sheep_class.responds_like(Sheep) + # sheep_class.stubs(:number_of_legs).returns(4) + # sheep_class.expects(:foo) + # sheep_class.respond_to?(:number_of_legs) # => true + # sheep_class.respond_to?(:foo) # => false + # assert_equal 4, sheep_class.number_of_legs + # sheep_class.foo # => raises NoMethodError exception + # + # Aliased by +quacks_like+ + def responds_like(object) + @responder = object + self + end + + # :stopdoc: + + def initialize(name = nil, &block) + @name = name || DefaultName.new(self) + @expectations = ExpectationList.new + @everything_stubbed = false + @responder = nil + instance_eval(&block) if block + end + + attr_reader :everything_stubbed, :expectations + + alias_method :__expects__, :expects + + alias_method :__stubs__, :stubs + + alias_method :quacks_like, :responds_like + + def stub_everything + @everything_stubbed = true + end + + def method_missing(symbol, *arguments, &block) + if @responder and not @responder.respond_to?(symbol) + raise NoMethodError, "undefined method `#{symbol}' for #{self.mocha_inspect} which responds like #{@responder.mocha_inspect}" + end + if matching_expectation_allowing_invocation = @expectations.match_allowing_invocation(symbol, *arguments) + matching_expectation_allowing_invocation.invoke(arguments, &block) + else + if (matching_expectation = @expectations.match(symbol, *arguments)) || (!matching_expectation && !@everything_stubbed) + message = UnexpectedInvocation.new(self, symbol, *arguments).to_s + message << Mockery.instance.mocha_inspect + raise ExpectationError.new(message, caller) + end + end + end + + def respond_to?(symbol, include_private = false) + if @responder then + if @responder.method(:respond_to?).arity > 1 + @responder.respond_to?(symbol, include_private) + else + @responder.respond_to?(symbol) + end + else + @everything_stubbed || @expectations.matches_method?(symbol) + end + end + + def __verified__?(assertion_counter = nil) + @expectations.verified?(assertion_counter) + end + + def mocha_inspect + @name.mocha_inspect + end + + def inspect + mocha_inspect + end + + def ensure_method_not_already_defined(method_name) + self.__metaclass__.send(:undef_method, method_name) if self.__metaclass__.method_defined?(method_name) + end + + # :startdoc: + + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/mockery.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/mockery.rb new file mode 100644 index 0000000..53f3363 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/mockery.rb @@ -0,0 +1,189 @@ +require 'mocha/central' +require 'mocha/mock' +require 'mocha/names' +require 'mocha/state_machine' +require 'mocha/logger' +require 'mocha/configuration' +require 'mocha/stubbing_error' +require 'mocha/invocation' + +module Mocha + + class Mockery + + class << self + + def instance + @instance ||= new + end + + def reset_instance + @instance = nil + end + + end + + def named_mock(name, &block) + add_mock(Mock.new(Name.new(name), &block)) + end + + def unnamed_mock(&block) + add_mock(Mock.new(&block)) + end + + def mock_impersonating(object, &block) + add_mock(Mock.new(ImpersonatingName.new(object), &block)) + end + + def mock_impersonating_any_instance_of(klass, &block) + add_mock(Mock.new(ImpersonatingAnyInstanceName.new(klass), &block)) + end + + def new_state_machine(name) + add_state_machine(StateMachine.new(name)) + end + + def invocation(mock, method_name, args) + invocations << Invocation.new(mock, method_name, args) + end + + def verify(assertion_counter = nil) + unless mocks.all? { |mock| mock.__verified__?(assertion_counter) } + message = "not all expectations were satisfied\n#{mocha_inspect}" + if unsatisfied_expectations.empty? + backtrace = caller + else + backtrace = unsatisfied_expectations[0].backtrace + end + raise ExpectationError.new(message, backtrace) + end + expectations.each do |e| + unless Mocha::Configuration.allow?(:stubbing_method_unnecessarily) + unless e.used? + on_stubbing_method_unnecessarily(e) + end + end + end + end + + def teardown + stubba.unstub_all + reset + end + + def stubba + @stubba ||= Central.new + end + + def mocks + @mocks ||= [] + end + + def state_machines + @state_machines ||= [] + end + + def mocha_inspect + message = "" + message << "unsatisfied expectations:\n- #{unsatisfied_expectations.map { |e| e.mocha_inspect }.join("\n- ")}\n" unless unsatisfied_expectations.empty? + message << "satisfied expectations:\n- #{satisfied_expectations.map { |e| e.mocha_inspect }.join("\n- ")}\n" unless satisfied_expectations.empty? + message << "states:\n- #{state_machines.map { |sm| sm.mocha_inspect }.join("\n- ")}" unless state_machines.empty? + message + end + + def on_stubbing(object, method) + method = RUBY_VERSION < '1.9' ? method.to_s : method.to_sym + unless Mocha::Configuration.allow?(:stubbing_non_existent_method) + unless object.method_exists?(method, include_public_methods = true) + on_stubbing_non_existent_method(object, method) + end + end + unless Mocha::Configuration.allow?(:stubbing_non_public_method) + if object.method_exists?(method, include_public_methods = false) + on_stubbing_non_public_method(object, method) + end + end + unless Mocha::Configuration.allow?(:stubbing_method_on_non_mock_object) + on_stubbing_method_on_non_mock_object(object, method) + end + end + + def on_stubbing_non_existent_method(object, method) + if Mocha::Configuration.prevent?(:stubbing_non_existent_method) + raise StubbingError.new("stubbing non-existent method: #{object.mocha_inspect}.#{method}", caller) + end + if Mocha::Configuration.warn_when?(:stubbing_non_existent_method) + logger.warn "stubbing non-existent method: #{object.mocha_inspect}.#{method}" + end + end + + def on_stubbing_non_public_method(object, method) + if Mocha::Configuration.prevent?(:stubbing_non_public_method) + raise StubbingError.new("stubbing non-public method: #{object.mocha_inspect}.#{method}", caller) + end + if Mocha::Configuration.warn_when?(:stubbing_non_public_method) + logger.warn "stubbing non-public method: #{object.mocha_inspect}.#{method}" + end + end + + def on_stubbing_method_on_non_mock_object(object, method) + if Mocha::Configuration.prevent?(:stubbing_method_on_non_mock_object) + raise StubbingError.new("stubbing method on non-mock object: #{object.mocha_inspect}.#{method}", caller) + end + if Mocha::Configuration.warn_when?(:stubbing_method_on_non_mock_object) + logger.warn "stubbing method on non-mock object: #{object.mocha_inspect}.#{method}" + end + end + + def on_stubbing_method_unnecessarily(expectation) + if Mocha::Configuration.prevent?(:stubbing_method_unnecessarily) + raise StubbingError.new("stubbing method unnecessarily: #{expectation.method_signature}", expectation.backtrace) + end + if Mocha::Configuration.warn_when?(:stubbing_method_unnecessarily) + logger.warn "stubbing method unnecessarily: #{expectation.method_signature}" + end + end + + attr_writer :logger + + def logger + @logger ||= Logger.new($stderr) + end + + def invocations + @invocations ||= [] + end + + private + + def expectations + mocks.map { |mock| mock.expectations.to_a }.flatten + end + + def unsatisfied_expectations + expectations.reject { |e| e.verified? } + end + + def satisfied_expectations + expectations.select { |e| e.verified? } + end + + def add_mock(mock) + mocks << mock + mock + end + + def add_state_machine(state_machine) + state_machines << state_machine + state_machine + end + + def reset + @stubba = nil + @mocks = nil + @state_machines = nil + end + + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/module_method.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/module_method.rb new file mode 100644 index 0000000..0c3b180 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/module_method.rb @@ -0,0 +1,16 @@ +require 'mocha/module_method' + +module Mocha + + class ModuleMethod < ClassMethod + + def method_exists?(method) + return true if stubbee.public_methods(false).include?(method) + return true if stubbee.protected_methods(false).include?(method) + return true if stubbee.private_methods(false).include?(method) + return false + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/multiple_yields.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/multiple_yields.rb new file mode 100644 index 0000000..8186c30 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/multiple_yields.rb @@ -0,0 +1,20 @@ +module Mocha # :nodoc: + + class MultipleYields # :nodoc: + + attr_reader :parameter_groups + + def initialize(*parameter_groups) + @parameter_groups = parameter_groups + end + + def each + @parameter_groups.each do |parameter_group| + yield(parameter_group) + end + end + + end + +end + diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/names.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/names.rb new file mode 100644 index 0000000..f59ebed --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/names.rb @@ -0,0 +1,53 @@ +module Mocha + + class ImpersonatingName + + def initialize(object) + @object = object + end + + def mocha_inspect + @object.mocha_inspect + end + + end + + class ImpersonatingAnyInstanceName + + def initialize(klass) + @klass = klass + end + + def mocha_inspect + "#" + end + + end + + class Name + + def initialize(name) + @name = name + end + + def mocha_inspect + "#" + end + + end + + class DefaultName + + def initialize(mock) + @mock = mock + end + + def mocha_inspect + address = @mock.__id__ * 2 + address += 0x100000000 if address < 0 + "#" + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/no_yields.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/no_yields.rb new file mode 100644 index 0000000..b0fba41 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/no_yields.rb @@ -0,0 +1,11 @@ +module Mocha # :nodoc: + + class NoYields # :nodoc: + + def each + end + + end + +end + diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/object.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/object.rb new file mode 100644 index 0000000..3fea086 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/object.rb @@ -0,0 +1,187 @@ +require 'mocha/mockery' +require 'mocha/instance_method' +require 'mocha/class_method' +require 'mocha/module_method' +require 'mocha/any_instance_method' +require 'mocha/argument_iterator' + +module Mocha + + # Methods added all objects to allow mocking and stubbing on real objects. + # + # Methods return a Mocha::Expectation which can be further modified by methods on Mocha::Expectation. + module ObjectMethods + + def mocha # :nodoc: + @mocha ||= Mocha::Mockery.instance.mock_impersonating(self) + end + + def reset_mocha # :nodoc: + @mocha = nil + end + + def stubba_method # :nodoc: + Mocha::InstanceMethod + end + + def stubba_object # :nodoc: + self + end + + # :call-seq: expects(method_name) -> expectation + # expects(method_names_vs_return_values) -> last expectation + # + # Adds an expectation that a method identified by +method_name+ Symbol must be called exactly once with any parameters. + # Returns the new expectation which can be further modified by methods on Mocha::Expectation. + # product = Product.new + # product.expects(:save).returns(true) + # assert_equal true, product.save + # + # The original implementation of Product#save is replaced temporarily. + # + # The original implementation of Product#save is restored at the end of the test. + # + # If +method_names_vs_return_values+ is a +Hash+, an expectation will be set up for each entry using the key as +method_name+ and value as +return_value+. + # product = Product.new + # product.expects(:valid? => true, :save => true) + # + # # exactly equivalent to + # + # product = Product.new + # product.expects(:valid?).returns(true) + # product.expects(:save).returns(true) + def expects(method_name_or_hash) + expectation = nil + mockery = Mocha::Mockery.instance + iterator = ArgumentIterator.new(method_name_or_hash) + iterator.each { |*args| + method_name = args.shift + mockery.on_stubbing(self, method_name) + method = stubba_method.new(stubba_object, method_name) + mockery.stubba.stub(method) + expectation = mocha.expects(method_name, caller) + expectation.returns(args.shift) if args.length > 0 + } + expectation + end + + # :call-seq: stubs(method_name) -> expectation + # stubs(method_names_vs_return_values) -> last expectation + # + # Adds an expectation that a method identified by +method_name+ Symbol may be called any number of times with any parameters. + # Returns the new expectation which can be further modified by methods on Mocha::Expectation. + # product = Product.new + # product.stubs(:save).returns(true) + # assert_equal true, product.save + # + # The original implementation of Product#save is replaced temporarily. + # + # The original implementation of Product#save is restored at the end of the test. + # + # If +method_names_vs_return_values+ is a +Hash+, an expectation will be set up for each entry using the key as +method_name+ and value as +return_value+. + # product = Product.new + # product.stubs(:valid? => true, :save => true) + # + # # exactly equivalent to + # + # product = Product.new + # product.stubs(:valid?).returns(true) + # product.stubs(:save).returns(true) + def stubs(method_name_or_hash) + expectation = nil + mockery = Mocha::Mockery.instance + iterator = ArgumentIterator.new(method_name_or_hash) + iterator.each { |*args| + method_name = args.shift + mockery.on_stubbing(self, method_name) + method = stubba_method.new(stubba_object, method_name) + mockery.stubba.stub(method) + expectation = mocha.stubs(method_name, caller) + expectation.returns(args.shift) if args.length > 0 + } + expectation + end + + def method_exists?(method, include_public_methods = true) # :nodoc: + if include_public_methods + return true if public_methods(include_superclass_methods = true).include?(method) + return true if respond_to?(method.to_sym) + end + return true if protected_methods(include_superclass_methods = true).include?(method) + return true if private_methods(include_superclass_methods = true).include?(method) + return false + end + + end + + module ModuleMethods # :nodoc: + + def stubba_method + Mocha::ModuleMethod + end + + end + + # Methods added all classes to allow mocking and stubbing on real objects. + module ClassMethods + + def stubba_method # :nodoc: + Mocha::ClassMethod + end + + class AnyInstance # :nodoc: + + def initialize(klass) + @stubba_object = klass + end + + def mocha + @mocha ||= Mocha::Mockery.instance.mock_impersonating_any_instance_of(@stubba_object) + end + + def stubba_method + Mocha::AnyInstanceMethod + end + + def stubba_object + @stubba_object + end + + def method_exists?(method, include_public_methods = true) + if include_public_methods + return true if @stubba_object.public_instance_methods(include_superclass_methods = true).include?(method) + end + return true if @stubba_object.protected_instance_methods(include_superclass_methods = true).include?(method) + return true if @stubba_object.private_instance_methods(include_superclass_methods = true).include?(method) + return false + end + + end + + # :call-seq: any_instance -> mock object + # + # Returns a mock object which will detect calls to any instance of this class. + # Product.any_instance.stubs(:save).returns(false) + # product_1 = Product.new + # assert_equal false, product_1.save + # product_2 = Product.new + # assert_equal false, product_2.save + def any_instance + @any_instance ||= AnyInstance.new(self) + end + + end + +end + +class Object # :nodoc: + include Mocha::ObjectMethods +end + +class Module # :nodoc: + include Mocha::ModuleMethods +end + +class Class # :nodoc: + include Mocha::ClassMethods +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers.rb new file mode 100644 index 0000000..7ce445f --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers.rb @@ -0,0 +1,27 @@ +module Mocha + + # Used as parameters for Expectation#with to restrict the parameter values which will match the expectation. Can be nested. + module ParameterMatchers; end + +end + +require 'mocha/parameter_matchers/object' + +require 'mocha/parameter_matchers/all_of' +require 'mocha/parameter_matchers/any_of' +require 'mocha/parameter_matchers/any_parameters' +require 'mocha/parameter_matchers/anything' +require 'mocha/parameter_matchers/equals' +require 'mocha/parameter_matchers/has_entry' +require 'mocha/parameter_matchers/has_entries' +require 'mocha/parameter_matchers/has_key' +require 'mocha/parameter_matchers/has_value' +require 'mocha/parameter_matchers/includes' +require 'mocha/parameter_matchers/instance_of' +require 'mocha/parameter_matchers/is_a' +require 'mocha/parameter_matchers/kind_of' +require 'mocha/parameter_matchers/not' +require 'mocha/parameter_matchers/optionally' +require 'mocha/parameter_matchers/regexp_matches' +require 'mocha/parameter_matchers/responds_with' +require 'mocha/parameter_matchers/yaml_equivalent' diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/all_of.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/all_of.rb new file mode 100644 index 0000000..50bf05b --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/all_of.rb @@ -0,0 +1,42 @@ +require 'mocha/parameter_matchers/base' + +module Mocha + + module ParameterMatchers + + # :call-seq: all_of(*parameter_matchers) -> parameter_matcher + # + # Matches if all +parameter_matchers+ match. + # object = mock() + # object.expects(:method_1).with(all_of(includes(1), includes(3))) + # object.method_1([1, 3]) + # # no error raised + # + # object = mock() + # object.expects(:method_1).with(all_of(includes(1), includes(3))) + # object.method_1([1, 2]) + # # error raised, because method_1 was not called with object including 1 and 3 + def all_of(*matchers) + AllOf.new(*matchers) + end + + class AllOf < Base # :nodoc: + + def initialize(*matchers) + @matchers = matchers + end + + def matches?(available_parameters) + parameter = available_parameters.shift + @matchers.all? { |matcher| matcher.to_matcher.matches?([parameter]) } + end + + def mocha_inspect + "all_of(#{@matchers.map { |matcher| matcher.mocha_inspect }.join(", ") })" + end + + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/any_of.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/any_of.rb new file mode 100644 index 0000000..b391ff3 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/any_of.rb @@ -0,0 +1,47 @@ +require 'mocha/parameter_matchers/base' + +module Mocha + + module ParameterMatchers + + # :call-seq: any_of(*parameter_matchers) -> parameter_matcher + # + # Matches if any +parameter_matchers+ match. + # object = mock() + # object.expects(:method_1).with(any_of(1, 3)) + # object.method_1(1) + # # no error raised + # + # object = mock() + # object.expects(:method_1).with(any_of(1, 3)) + # object.method_1(3) + # # no error raised + # + # object = mock() + # object.expects(:method_1).with(any_of(1, 3)) + # object.method_1(2) + # # error raised, because method_1 was not called with 1 or 3 + def any_of(*matchers) + AnyOf.new(*matchers) + end + + class AnyOf < Base # :nodoc: + + def initialize(*matchers) + @matchers = matchers + end + + def matches?(available_parameters) + parameter = available_parameters.shift + @matchers.any? { |matcher| matcher.to_matcher.matches?([parameter]) } + end + + def mocha_inspect + "any_of(#{@matchers.map { |matcher| matcher.mocha_inspect }.join(", ") })" + end + + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/any_parameters.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/any_parameters.rb new file mode 100644 index 0000000..11dae83 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/any_parameters.rb @@ -0,0 +1,40 @@ +require 'mocha/parameter_matchers/base' + +module Mocha + + module ParameterMatchers + + # :call-seq: any_parameters() -> parameter_matcher + # + # Matches any parameters. + # object = mock() + # object.expects(:method_1).with(any_parameters) + # object.method_1(1, 2, 3, 4) + # # no error raised + # + # object = mock() + # object.expects(:method_1).with(any_parameters) + # object.method_1(5, 6, 7, 8, 9, 0) + # # no error raised + def any_parameters + AnyParameters.new + end + + class AnyParameters < Base # :nodoc: + + def matches?(available_parameters) + while available_parameters.length > 0 do + available_parameters.shift + end + return true + end + + def mocha_inspect + "any_parameters" + end + + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/anything.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/anything.rb new file mode 100644 index 0000000..90510e2 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/anything.rb @@ -0,0 +1,33 @@ +require 'mocha/parameter_matchers/base' + +module Mocha + + module ParameterMatchers + + # :call-seq: anything() -> parameter_matcher + # + # Matches any object. + # object = mock() + # object.expects(:method_1).with(anything) + # object.method_1('foo') + # # no error raised + def anything + Anything.new + end + + class Anything < Base # :nodoc: + + def matches?(available_parameters) + available_parameters.shift + return true + end + + def mocha_inspect + "anything" + end + + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/base.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/base.rb new file mode 100644 index 0000000..6aaec51 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/base.rb @@ -0,0 +1,15 @@ +module Mocha + + module ParameterMatchers + + class Base # :nodoc: + + def to_matcher + self + end + + end + + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/equals.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/equals.rb new file mode 100644 index 0000000..bdc61a0 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/equals.rb @@ -0,0 +1,42 @@ +require 'mocha/parameter_matchers/base' + +module Mocha + + module ParameterMatchers + + # :call-seq: equals(value) -> parameter_matcher + # + # Matches +Object+ equalling +value+. + # object = mock() + # object.expects(:method_1).with(equals(2)) + # object.method_1(2) + # # no error raised + # + # object = mock() + # object.expects(:method_1).with(equals(2)) + # object.method_1(3) + # # error raised, because method_1 was not called with Object equalling 3 + def equals(value) + Equals.new(value) + end + + class Equals < Base # :nodoc: + + def initialize(value) + @value = value + end + + def matches?(available_parameters) + parameter = available_parameters.shift + parameter == @value + end + + def mocha_inspect + @value.mocha_inspect + end + + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/has_entries.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/has_entries.rb new file mode 100644 index 0000000..03e968f --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/has_entries.rb @@ -0,0 +1,45 @@ +require 'mocha/parameter_matchers/base' +require 'mocha/parameter_matchers/all_of' +require 'mocha/parameter_matchers/has_entry' + +module Mocha + + module ParameterMatchers + + # :call-seq: has_entries(entries) -> parameter_matcher + # + # Matches +Hash+ containing all +entries+. + # object = mock() + # object.expects(:method_1).with(has_entries('key_1' => 1, 'key_2' => 2)) + # object.method_1('key_1' => 1, 'key_2' => 2, 'key_3' => 3) + # # no error raised + # + # object = mock() + # object.expects(:method_1).with(has_entries('key_1' => 1, 'key_2' => 2)) + # object.method_1('key_1' => 1, 'key_2' => 99) + # # error raised, because method_1 was not called with Hash containing entries: 'key_1' => 1, 'key_2' => 2 + def has_entries(entries) + HasEntries.new(entries) + end + + class HasEntries < Base # :nodoc: + + def initialize(entries) + @entries = entries + end + + def matches?(available_parameters) + parameter = available_parameters.shift + has_entry_matchers = @entries.map { |key, value| HasEntry.new(key, value) } + AllOf.new(*has_entry_matchers).matches?([parameter]) + end + + def mocha_inspect + "has_entries(#{@entries.mocha_inspect})" + end + + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/has_entry.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/has_entry.rb new file mode 100644 index 0000000..aff9dc3 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/has_entry.rb @@ -0,0 +1,57 @@ +require 'mocha/parameter_matchers/base' + +module Mocha + + module ParameterMatchers + + # :call-seq: has_entry(key, value) -> parameter_matcher + # has_entry(key => value) -> parameter_matcher + # + # Matches +Hash+ containing entry with +key+ and +value+. + # object = mock() + # object.expects(:method_1).with(has_entry('key_1', 1)) + # object.method_1('key_1' => 1, 'key_2' => 2) + # # no error raised + # + # object = mock() + # object.expects(:method_1).with(has_entry('key_1' => 1)) + # object.method_1('key_1' => 1, 'key_2' => 2) + # # no error raised + # + # object = mock() + # object.expects(:method_1).with(has_entry('key_1', 1)) + # object.method_1('key_1' => 2, 'key_2' => 1) + # # error raised, because method_1 was not called with Hash containing entry: 'key_1' => 1 + # + # object = mock() + # object.expects(:method_1).with(has_entry('key_1' => 1)) + # object.method_1('key_1' => 2, 'key_2' => 1) + # # error raised, because method_1 was not called with Hash containing entry: 'key_1' => 1 + def has_entry(*options) + key, value = options.shift, options.shift + key, value = key.to_a[0][0..1] if key.is_a?(Hash) + HasEntry.new(key, value) + end + + class HasEntry < Base # :nodoc: + + def initialize(key, value) + @key, @value = key, value + end + + def matches?(available_parameters) + parameter = available_parameters.shift + return false unless parameter.respond_to?(:keys) && parameter.respond_to?(:[]) + matching_keys = parameter.keys.select { |key| @key.to_matcher.matches?([key]) } + matching_keys.any? { |key| @value.to_matcher.matches?([parameter[key]]) } + end + + def mocha_inspect + "has_entry(#{@key.mocha_inspect} => #{@value.mocha_inspect})" + end + + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/has_key.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/has_key.rb new file mode 100644 index 0000000..a4c2668 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/has_key.rb @@ -0,0 +1,42 @@ +require 'mocha/parameter_matchers/base' + +module Mocha + + module ParameterMatchers + + # :call-seq: has_key(key) -> parameter_matcher + # + # Matches +Hash+ containing +key+. + # object = mock() + # object.expects(:method_1).with(has_key('key_1')) + # object.method_1('key_1' => 1, 'key_2' => 2) + # # no error raised + # + # object = mock() + # object.expects(:method_1).with(has_key('key_1')) + # object.method_1('key_2' => 2) + # # error raised, because method_1 was not called with Hash containing key: 'key_1' + def has_key(key) + HasKey.new(key) + end + + class HasKey < Base # :nodoc: + + def initialize(key) + @key = key + end + + def matches?(available_parameters) + parameter = available_parameters.shift + parameter.keys.any? { |key| @key.to_matcher.matches?([key]) } + end + + def mocha_inspect + "has_key(#{@key.mocha_inspect})" + end + + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/has_value.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/has_value.rb new file mode 100644 index 0000000..6671237 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/has_value.rb @@ -0,0 +1,42 @@ +require 'mocha/parameter_matchers/base' + +module Mocha + + module ParameterMatchers + + # :call-seq: has_value(value) -> parameter_matcher + # + # Matches +Hash+ containing +value+. + # object = mock() + # object.expects(:method_1).with(has_value(1)) + # object.method_1('key_1' => 1, 'key_2' => 2) + # # no error raised + # + # object = mock() + # object.expects(:method_1).with(has_value(1)) + # object.method_1('key_2' => 2) + # # error raised, because method_1 was not called with Hash containing value: 1 + def has_value(value) + HasValue.new(value) + end + + class HasValue < Base # :nodoc: + + def initialize(value) + @value = value + end + + def matches?(available_parameters) + parameter = available_parameters.shift + parameter.values.any? { |value| @value.to_matcher.matches?([value]) } + end + + def mocha_inspect + "has_value(#{@value.mocha_inspect})" + end + + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/includes.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/includes.rb new file mode 100644 index 0000000..4539a5c --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/includes.rb @@ -0,0 +1,40 @@ +require 'mocha/parameter_matchers/base' + +module Mocha + + module ParameterMatchers + + # :call-seq: includes(item) -> parameter_matcher + # + # Matches any object that responds true to include?(item) + # object = mock() + # object.expects(:method_1).with(includes('foo')) + # object.method_1(['foo', 'bar']) + # # no error raised + # + # object.method_1(['baz']) + # # error raised, because ['baz'] does not include 'foo'. + def includes(item) + Includes.new(item) + end + + class Includes < Base # :nodoc: + + def initialize(item) + @item = item + end + + def matches?(available_parameters) + parameter = available_parameters.shift + return parameter.include?(@item) + end + + def mocha_inspect + "includes(#{@item.mocha_inspect})" + end + + end + + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/instance_of.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/instance_of.rb new file mode 100644 index 0000000..49b4a47 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/instance_of.rb @@ -0,0 +1,42 @@ +require 'mocha/parameter_matchers/base' + +module Mocha + + module ParameterMatchers + + # :call-seq: instance_of(klass) -> parameter_matcher + # + # Matches any object that is an instance of +klass+ + # object = mock() + # object.expects(:method_1).with(instance_of(String)) + # object.method_1('string') + # # no error raised + # + # object = mock() + # object.expects(:method_1).with(instance_of(String)) + # object.method_1(99) + # # error raised, because method_1 was not called with an instance of String + def instance_of(klass) + InstanceOf.new(klass) + end + + class InstanceOf < Base # :nodoc: + + def initialize(klass) + @klass = klass + end + + def matches?(available_parameters) + parameter = available_parameters.shift + parameter.instance_of?(@klass) + end + + def mocha_inspect + "instance_of(#{@klass.mocha_inspect})" + end + + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/is_a.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/is_a.rb new file mode 100644 index 0000000..a721db5 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/is_a.rb @@ -0,0 +1,42 @@ +require 'mocha/parameter_matchers/base' + +module Mocha + + module ParameterMatchers + + # :call-seq: is_a(klass) -> parameter_matcher + # + # Matches any object that is a +klass+ + # object = mock() + # object.expects(:method_1).with(is_a(Integer)) + # object.method_1(99) + # # no error raised + # + # object = mock() + # object.expects(:method_1).with(is_a(Integer)) + # object.method_1('string') + # # error raised, because method_1 was not called with an Integer + def is_a(klass) + IsA.new(klass) + end + + class IsA < Base # :nodoc: + + def initialize(klass) + @klass = klass + end + + def matches?(available_parameters) + parameter = available_parameters.shift + parameter.is_a?(@klass) + end + + def mocha_inspect + "is_a(#{@klass.mocha_inspect})" + end + + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/kind_of.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/kind_of.rb new file mode 100644 index 0000000..710d709 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/kind_of.rb @@ -0,0 +1,42 @@ +require 'mocha/parameter_matchers/base' + +module Mocha + + module ParameterMatchers + + # :call-seq: kind_of(klass) -> parameter_matcher + # + # Matches any object that is a kind of +klass+ + # object = mock() + # object.expects(:method_1).with(kind_of(Integer)) + # object.method_1(99) + # # no error raised + # + # object = mock() + # object.expects(:method_1).with(kind_of(Integer)) + # object.method_1('string') + # # error raised, because method_1 was not called with a kind of Integer + def kind_of(klass) + KindOf.new(klass) + end + + class KindOf < Base # :nodoc: + + def initialize(klass) + @klass = klass + end + + def matches?(available_parameters) + parameter = available_parameters.shift + parameter.kind_of?(@klass) + end + + def mocha_inspect + "kind_of(#{@klass.mocha_inspect})" + end + + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/not.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/not.rb new file mode 100644 index 0000000..7a9cf27 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/not.rb @@ -0,0 +1,42 @@ +require 'mocha/parameter_matchers/base' + +module Mocha + + module ParameterMatchers + + # :call-seq: Not(parameter_matcher) -> parameter_matcher + # + # Matches if +parameter_matcher+ does not match. + # object = mock() + # object.expects(:method_1).with(Not(includes(1))) + # object.method_1([0, 2, 3]) + # # no error raised + # + # object = mock() + # object.expects(:method_1).with(Not(includes(1))) + # object.method_1([0, 1, 2, 3]) + # # error raised, because method_1 was not called with object not including 1 + def Not(matcher) + Not.new(matcher) + end + + class Not < Base # :nodoc: + + def initialize(matcher) + @matcher = matcher + end + + def matches?(available_parameters) + parameter = available_parameters.shift + !@matcher.matches?([parameter]) + end + + def mocha_inspect + "Not(#{@matcher.mocha_inspect})" + end + + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/object.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/object.rb new file mode 100644 index 0000000..56a1940 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/object.rb @@ -0,0 +1,15 @@ +require 'mocha/parameter_matchers/equals' + +module Mocha + + module ObjectMethods + def to_matcher # :nodoc: + Mocha::ParameterMatchers::Equals.new(self) + end + end + +end + +class Object + include Mocha::ObjectMethods +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/optionally.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/optionally.rb new file mode 100644 index 0000000..fc2c3a9 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/optionally.rb @@ -0,0 +1,55 @@ +module Mocha + + module ParameterMatchers + + # :call-seq: optionally(*parameter_matchers) -> parameter_matcher + # + # Matches optional parameters if available. + # object = mock() + # object.expects(:method_1).with(1, 2, optionally(3, 4)) + # object.method_1(1, 2) + # # no error raised + # + # object = mock() + # object.expects(:method_1).with(1, 2, optionally(3, 4)) + # object.method_1(1, 2, 3) + # # no error raised + # + # object = mock() + # object.expects(:method_1).with(1, 2, optionally(3, 4)) + # object.method_1(1, 2, 3, 4) + # # no error raised + # + # object = mock() + # object.expects(:method_1).with(1, 2, optionally(3, 4)) + # object.method_1(1, 2, 3, 5) + # # error raised, because optional parameters did not match + def optionally(*matchers) + Optionally.new(*matchers) + end + + class Optionally < Base # :nodoc: + + def initialize(*parameters) + @matchers = parameters.map { |parameter| parameter.to_matcher } + end + + def matches?(available_parameters) + index = 0 + while (available_parameters.length > 0) && (index < @matchers.length) do + matcher = @matchers[index] + return false unless matcher.matches?(available_parameters) + index += 1 + end + return true + end + + def mocha_inspect + "optionally(#{@matchers.map { |matcher| matcher.mocha_inspect }.join(", ") })" + end + + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/regexp_matches.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/regexp_matches.rb new file mode 100644 index 0000000..a807d8b --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/regexp_matches.rb @@ -0,0 +1,43 @@ +require 'mocha/parameter_matchers/base' + +module Mocha + + module ParameterMatchers + + # :call-seq: regexp_matches(regular_expression) -> parameter_matcher + # + # Matches any object that matches +regular_expression+. + # object = mock() + # object.expects(:method_1).with(regexp_matches(/e/)) + # object.method_1('hello') + # # no error raised + # + # object = mock() + # object.expects(:method_1).with(regexp_matches(/a/)) + # object.method_1('hello') + # # error raised, because method_1 was not called with a parameter that matched the + # # regular expression + def regexp_matches(regexp) + RegexpMatches.new(regexp) + end + + class RegexpMatches < Base # :nodoc: + + def initialize(regexp) + @regexp = regexp + end + + def matches?(available_parameters) + parameter = available_parameters.shift + parameter =~ @regexp + end + + def mocha_inspect + "regexp_matches(#{@regexp.mocha_inspect})" + end + + end + + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/responds_with.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/responds_with.rb new file mode 100644 index 0000000..4355796 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/responds_with.rb @@ -0,0 +1,43 @@ +require 'mocha/parameter_matchers/base' +require 'yaml' + +module Mocha + + module ParameterMatchers + + # :call-seq: responds_with(message, result) -> parameter_matcher + # + # Matches any object that responds to +message+ with +result+. To put it another way, it tests the quack, not the duck. + # object = mock() + # object.expects(:method_1).with(responds_with(:upcase, "FOO")) + # object.method_1("foo") + # # no error raised, because "foo".upcase == "FOO" + # + # object = mock() + # object.expects(:method_1).with(responds_with(:upcase, "BAR")) + # object.method_1("foo") + # # error raised, because "foo".upcase != "BAR" + def responds_with(message, result) + RespondsWith.new(message, result) + end + + class RespondsWith < Base # :nodoc: + + def initialize(message, result) + @message, @result = message, result + end + + def matches?(available_parameters) + parameter = available_parameters.shift + parameter.__send__(@message) == @result + end + + def mocha_inspect + "responds_with(#{@message.mocha_inspect}, #{@result.mocha_inspect})" + end + + end + + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/yaml_equivalent.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/yaml_equivalent.rb new file mode 100644 index 0000000..6449717 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/yaml_equivalent.rb @@ -0,0 +1,43 @@ +require 'mocha/parameter_matchers/base' +require 'yaml' + +module Mocha + + module ParameterMatchers + + # :call-seq: yaml_equivalent(object) -> parameter_matcher + # + # Matches any YAML that represents the specified +object+ + # object = mock() + # object.expects(:method_1).with(yaml_equivalent(1, 2, 3)) + # object.method_1("--- \n- 1\n- 2\n- 3\n") + # # no error raised + # + # object = mock() + # object.expects(:method_1).with(yaml_equivalent(1, 2, 3)) + # object.method_1("--- \n- 1\n- 2\n") + # # error raised, because method_1 was not called with YAML representing the specified Array + def yaml_equivalent(object) + YamlEquivalent.new(object) + end + + class YamlEquivalent < Base # :nodoc: + + def initialize(object) + @object = object + end + + def matches?(available_parameters) + parameter = available_parameters.shift + @object == YAML.load(parameter) + end + + def mocha_inspect + "yaml_equivalent(#{@object.mocha_inspect})" + end + + end + + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameters_matcher.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameters_matcher.rb new file mode 100644 index 0000000..d43ae43 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameters_matcher.rb @@ -0,0 +1,37 @@ +require 'mocha/inspect' +require 'mocha/parameter_matchers' + +module Mocha + + class ParametersMatcher + + def initialize(expected_parameters = [ParameterMatchers::AnyParameters.new], &matching_block) + @expected_parameters, @matching_block = expected_parameters, matching_block + end + + def match?(actual_parameters = []) + if @matching_block + return @matching_block.call(*actual_parameters) + else + return parameters_match?(actual_parameters) + end + end + + def parameters_match?(actual_parameters) + matchers.all? { |matcher| matcher.matches?(actual_parameters) } && (actual_parameters.length == 0) + end + + def mocha_inspect + signature = matchers.mocha_inspect + signature = signature.gsub(/^\[|\]$/, '') + signature = signature.gsub(/^\{|\}$/, '') if matchers.length == 1 + "(#{signature})" + end + + def matchers + @expected_parameters.map { |parameter| parameter.to_matcher } + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/pretty_parameters.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/pretty_parameters.rb new file mode 100644 index 0000000..59ed636 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/pretty_parameters.rb @@ -0,0 +1,28 @@ +require 'mocha/inspect' + +module Mocha + + class PrettyParameters + + def initialize(params) + @params = params + @params_string = params.mocha_inspect + end + + def pretty + remove_outer_array_braces! + remove_outer_hash_braces! + @params_string + end + + def remove_outer_array_braces! + @params_string = @params_string.gsub(/^\[|\]$/, '') + end + + def remove_outer_hash_braces! + @params_string = @params_string.gsub(/^\{|\}$/, '') if @params.length == 1 + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/return_values.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/return_values.rb new file mode 100644 index 0000000..d93fb1a --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/return_values.rb @@ -0,0 +1,31 @@ +require 'mocha/single_return_value' + +module Mocha # :nodoc: + + class ReturnValues # :nodoc: + + def self.build(*values) + new(*values.map { |value| SingleReturnValue.new(value) }) + end + + attr_accessor :values + + def initialize(*values) + @values = values + end + + def next + case @values.length + when 0 then nil + when 1 then @values.first.evaluate + else @values.shift.evaluate + end + end + + def +(other) + self.class.new(*(@values + other.values)) + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/sequence.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/sequence.rb new file mode 100644 index 0000000..ed9852e --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/sequence.rb @@ -0,0 +1,42 @@ +module Mocha # :nodoc: + + class Sequence + + class InSequenceOrderingConstraint + + def initialize(sequence, index) + @sequence, @index = sequence, index + end + + def allows_invocation_now? + @sequence.satisfied_to_index?(@index) + end + + def mocha_inspect + "in sequence #{@sequence.mocha_inspect}" + end + + end + + def initialize(name) + @name = name + @expectations = [] + end + + def constrain_as_next_in_sequence(expectation) + index = @expectations.length + @expectations << expectation + expectation.add_ordering_constraint(InSequenceOrderingConstraint.new(self, index)) + end + + def satisfied_to_index?(index) + @expectations[0...index].all? { |expectation| expectation.satisfied? } + end + + def mocha_inspect + "#{@name.mocha_inspect}" + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/single_return_value.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/single_return_value.rb new file mode 100644 index 0000000..98bc4be --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/single_return_value.rb @@ -0,0 +1,17 @@ +require 'mocha/is_a' + +module Mocha # :nodoc: + + class SingleReturnValue # :nodoc: + + def initialize(value) + @value = value + end + + def evaluate + @value + end + + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/single_yield.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/single_yield.rb new file mode 100644 index 0000000..5af5716 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/single_yield.rb @@ -0,0 +1,18 @@ +module Mocha # :nodoc: + + class SingleYield # :nodoc: + + attr_reader :parameters + + def initialize(*parameters) + @parameters = parameters + end + + def each + yield(@parameters) + end + + end + +end + diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/state_machine.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/state_machine.rb new file mode 100644 index 0000000..1b9781a --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/state_machine.rb @@ -0,0 +1,91 @@ +module Mocha # :nodoc: + + # A state machine that is used to constrain the order of invocations. + # An invocation can be constrained to occur when a state is, or is_not, active. + class StateMachine + + class State # :nodoc: + + def initialize(state_machine, state) + @state_machine, @state = state_machine, state + end + + def activate + @state_machine.current_state = @state + end + + def active? + @state_machine.current_state == @state + end + + def mocha_inspect + "#{@state_machine.name} is #{@state.mocha_inspect}" + end + + end + + class StatePredicate # :nodoc: + + def initialize(state_machine, state) + @state_machine, @state = state_machine, state + end + + def active? + @state_machine.current_state != @state + end + + def mocha_inspect + "#{@state_machine.name} is not #{@state.mocha_inspect}" + end + + end + + attr_reader :name # :nodoc: + + attr_accessor :current_state # :nodoc: + + def initialize(name) # :nodoc: + @name = name + @current_state = nil + end + + # :call-seq: starts_as(initial_state) -> state_machine + # + # Put the +state_machine+ into the +initial_state+. + def starts_as(initial_state) + become(initial_state) + self + end + + # :call-seq: become(next_state) + # + # Put the +state_machine+ into the +next_state+. + def become(next_state) + @current_state = next_state + end + + # :call-seq: is(state) + # + # Determines whether the +state_machine+ is in the specified +state+. + def is(state) + State.new(self, state) + end + + # :call-seq: is_not(state) + # + # Determines whether the +state_machine+ is not in the specified +state+. + def is_not(state) + StatePredicate.new(self, state) + end + + def mocha_inspect # :nodoc: + if @current_state + "#{@name} is #{@current_state.mocha_inspect}" + else + "#{@name} has no current state" + end + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/stubbing_error.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/stubbing_error.rb new file mode 100644 index 0000000..34be289 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/stubbing_error.rb @@ -0,0 +1,16 @@ +require 'mocha/backtrace_filter' + +module Mocha # :nodoc: + + # Exception raised when an action prevented by Configuration#prevent is attempted. + class StubbingError < StandardError + + def initialize(message = nil, backtrace = []) # :nodoc: + super(message) + filter = BacktraceFilter.new + set_backtrace(filter.filtered(backtrace)) + end + + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/unexpected_invocation.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/unexpected_invocation.rb new file mode 100644 index 0000000..2eabb6a --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/unexpected_invocation.rb @@ -0,0 +1,18 @@ +module Mocha # :nodoc: + + class UnexpectedInvocation + + def initialize(mock, symbol, *arguments) + @mock = mock + @method_matcher = MethodMatcher.new(symbol) + @parameters_matcher = ParametersMatcher.new(arguments) + end + + def to_s + method_signature = "#{@mock.mocha_inspect}.#{@method_matcher.mocha_inspect}#{@parameters_matcher.mocha_inspect}" + "unexpected invocation: #{method_signature}\n" + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/yield_parameters.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/yield_parameters.rb new file mode 100644 index 0000000..7d6ad12 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/yield_parameters.rb @@ -0,0 +1,31 @@ +require 'mocha/no_yields' +require 'mocha/single_yield' +require 'mocha/multiple_yields' + +module Mocha # :nodoc: + + class YieldParameters # :nodoc: + + def initialize + @parameter_groups = [] + end + + def next_invocation + case @parameter_groups.length + when 0 then NoYields.new + when 1 then @parameter_groups.first + else @parameter_groups.shift + end + end + + def add(*parameters) + @parameter_groups << SingleYield.new(*parameters) + end + + def multiple_add(*parameter_groups) + @parameter_groups << MultipleYields.new(*parameter_groups) + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha_standalone.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha_standalone.rb new file mode 100644 index 0000000..e3dc645 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha_standalone.rb @@ -0,0 +1,2 @@ +require 'mocha/api' +require 'mocha/object' \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/stubba.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/stubba.rb new file mode 100644 index 0000000..ba4d93f --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/stubba.rb @@ -0,0 +1,4 @@ +# for backwards compatibility +require 'mocha' +require 'mocha/deprecation' +Mocha::Deprecation.warning "require 'stubba' is no longer needed and stubba.rb will soon be removed" diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/acceptance_test_helper.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/acceptance_test_helper.rb new file mode 100644 index 0000000..2341338 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/acceptance_test_helper.rb @@ -0,0 +1,38 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") +require 'test_runner' +require 'mocha/configuration' + +module AcceptanceTest + + class FakeLogger + + attr_reader :warnings + + def initialize + @warnings = [] + end + + def warn(message) + @warnings << message + end + + end + + attr_reader :logger + + include TestRunner + + def setup_acceptance_test + Mocha::Configuration.reset_configuration + @logger = FakeLogger.new + mockery = Mocha::Mockery.instance + @original_logger = mockery.logger + mockery.logger = @logger + end + + def teardown_acceptance_test + Mocha::Configuration.reset_configuration + Mocha::Mockery.instance.logger = @original_logger + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/api_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/api_test.rb new file mode 100644 index 0000000..46750a2 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/api_test.rb @@ -0,0 +1,139 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha_standalone' +require 'simple_counter' + +class NotATestUnitAssertionFailedError < StandardError +end + +class NotATestUnitTestCase + + include Mocha::API + + attr_reader :assertion_counter + + def initialize + @assertion_counter = SimpleCounter.new + end + + def run(test_method) + mocha_setup + begin + prepare + begin + send(test_method) + mocha_verify(@assertion_counter) + rescue Mocha::ExpectationError => e + new_error = NotATestUnitAssertionFailedError.new(e.message) + new_error.set_backtrace(e.backtrace) + raise new_error + ensure + cleanup + end + ensure + mocha_teardown + end + end + + def prepare + end + + def cleanup + end + +end + +class SampleTest < NotATestUnitTestCase + + def mocha_with_fulfilled_expectation + mockee = mock() + mockee.expects(:blah) + mockee.blah + end + + def mocha_with_unfulfilled_expectation + mockee = mock() + mockee.expects(:blah) + end + + def mocha_with_unexpected_invocation + mockee = mock() + mockee.blah + end + + def stubba_with_fulfilled_expectation + stubbee = Class.new { define_method(:blah) {} }.new + stubbee.expects(:blah) + stubbee.blah + end + + def stubba_with_unfulfilled_expectation + stubbee = Class.new { define_method(:blah) {} }.new + stubbee.expects(:blah) + end + + def mocha_with_matching_parameter + mockee = mock() + mockee.expects(:blah).with(has_key(:wibble)) + mockee.blah(:wibble => 1) + end + + def mocha_with_non_matching_parameter + mockee = mock() + mockee.expects(:blah).with(has_key(:wibble)) + mockee.blah(:wobble => 2) + end + +end + +require 'test/unit' + +class APITest < Test::Unit::TestCase + + attr_reader :sample_test + + include AcceptanceTest + + def setup + @sample_test = SampleTest.new + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_pass_mocha_test + assert_nothing_raised { sample_test.run(:mocha_with_fulfilled_expectation) } + assert_equal 1, sample_test.assertion_counter.count + end + + def test_should_fail_mocha_test_due_to_unfulfilled_exception + assert_raises(NotATestUnitAssertionFailedError) { sample_test.run(:mocha_with_unfulfilled_expectation) } + assert_equal 1, sample_test.assertion_counter.count + end + + def test_should_fail_mocha_test_due_to_unexpected_invocation + assert_raises(NotATestUnitAssertionFailedError) { sample_test.run(:mocha_with_unexpected_invocation) } + assert_equal 0, sample_test.assertion_counter.count + end + + def test_should_pass_stubba_test + assert_nothing_raised { sample_test.run(:stubba_with_fulfilled_expectation) } + assert_equal 1, sample_test.assertion_counter.count + end + + def test_should_fail_stubba_test + assert_raises(NotATestUnitAssertionFailedError) { sample_test.run(:stubba_with_unfulfilled_expectation) } + assert_equal 1, sample_test.assertion_counter.count + end + + def test_should_pass_mocha_test_with_matching_parameter + assert_nothing_raised { sample_test.run(:mocha_with_matching_parameter) } + assert_equal 1, sample_test.assertion_counter.count + end + + def test_should_fail_mocha_test_with_non_matching_parameter + assert_raises(NotATestUnitAssertionFailedError) { sample_test.run(:mocha_with_non_matching_parameter) } + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/bacon_spec.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/bacon_spec.rb new file mode 100644 index 0000000..8ca4456 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/bacon_spec.rb @@ -0,0 +1,67 @@ +# This is not meant to be run by itself. It will be run by bacon_test.rb +$:.unshift File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "lib")) +require 'bacon' +require 'mocha' + +module MetaTestOutput + def handle_specification(name) + yield + end + + def handle_requirement(description) + yield + end + + def handle_summary + puts + puts Bacon::ErrorLog if Bacon::Backtraces + puts "%d tests, %d assertions, %d failures, %d errors" % + Bacon::Counter.values_at(:specifications, :requirements, :failed, :errors) + end + +end + +Bacon.extend MetaTestOutput +Bacon.summary_on_exit + +describe "Bacon specs using Mocha" do + should "pass when all expectations were fulfilled" do + mockee = mock() + mockee.expects(:blah) + mockee.blah + end + + should "fail when not all expectations were fulfilled" do + mockee = mock() + mockee.expects(:blah) + end + + should "fail when there is an unexpected invocation" do + mockee = mock() + mockee.blah + end + + should "pass when they receive all expected parameters" do + mockee = mock() + mockee.expects(:blah).with(has_key(:wibble)) + mockee.blah(:wibble => 1) + end + + should "fail when they receive unexpected parameters" do + mockee = mock() + mockee.expects(:blah).with(has_key(:wibble)) + mockee.blah(:wobble => 2) + end + + should "pass when all Stubba expectations are fulfilled" do + stubbee = Class.new { define_method(:blah) {} }.new + stubbee.expects(:blah) + stubbee.blah + end + + should "fail when not all Stubba expectations were fulfilled" do + stubbee = Class.new { define_method(:blah) {} }.new + stubbee.expects(:blah) + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/bacon_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/bacon_test.rb new file mode 100644 index 0000000..fee2b5f --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/bacon_test.rb @@ -0,0 +1,110 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") + +begin + require 'bacon' +rescue LoadError + # Bacon not available +end + +if defined?(Bacon) && Bacon::VERSION >= "1.1" + + class BaconRunner + + attr_reader :output, :tests, :assertions, :failures, :errors + + def initialize(*paths) + @paths = paths + end + + def run(name) + @output = `bacon -n '#{name}' #{@paths.join(' ')}` + numbers = @output.scan(/(\d+) tests, (\d+) assertions, (\d+) failures, (\d+) errors/) + numbers.flatten!.map!{|e| e.to_i} + + @tests = numbers[0] + @assertions = numbers[1] + @failures = numbers[2] + @errors = numbers[3] + end + + end + + class BaconTest < Test::Unit::TestCase + + def setup + @runner = BaconRunner.new("#{File.dirname(__FILE__)}/bacon_spec.rb") + end + + def test_should_pass_mocha_test + + @runner.run('should pass when all expectations were fulfilled') + + assert_equal 0, @runner.errors + assert_equal 1, @runner.tests + end + + def test_should_fail_mocha_test_due_to_unfulfilled_expectation + + @runner.run('should fail when not all expectations were fulfilled') + + assert_equal 1, @runner.errors + assert_equal 1, @runner.tests + assert_not_all_expectation_were_satisfied(@runner.output) + + end + + def test_should_fail_mocha_test_due_to_unexpected_invocation + @runner.run('should fail when there is an unexpected invocation') + + assert_equal 1, @runner.errors + assert_equal 1, @runner.tests + assert_unexpected_invocation(@runner.output) + end + + + def test_should_pass_stubba_test + @runner.run('should pass when all Stubba expectations are fulfilled') + + assert_equal 0, @runner.errors + assert_equal 1, @runner.tests + end + + def test_should_fail_stubba_test_due_to_unfulfilled_expectation + @runner.run('should fail when not all Stubba expectations were fulfilled') + + assert_equal 1, @runner.errors + assert_equal 1, @runner.tests + assert_not_all_expectation_were_satisfied(@runner.output) + end + + def test_should_pass_mocha_test_with_matching_parameter + @runner.run('should pass when they receive all expected parameters') + + assert_equal 0, @runner.errors + assert_equal 1, @runner.tests + end + + def test_should_fail_mocha_test_with_non_matching_parameter + @runner.run('should fail when they receive unexpected parameters') + + assert_equal 1, @runner.errors + assert_equal 1, @runner.tests + assert_unexpected_invocation(@runner.output) + end + + private + + def assert_unexpected_invocation(string) + assert_match Regexp.new('unexpected invocation'), string, "Bacon output:\n#{string}" + end + + def assert_not_all_expectation_were_satisfied(string) + assert_match Regexp.new('not all expectations were satisfied'), string, "Bacon output:\n#{string}" + end + + end + +else + warn "Bacon is not available, so BaconTest has not been run." +end + diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/bug_18914_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/bug_18914_test.rb new file mode 100644 index 0000000..852a5f8 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/bug_18914_test.rb @@ -0,0 +1,43 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' + +class Bug18914Test < Test::Unit::TestCase + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + class AlwaysEql + + def my_method + true + end + + def ==(o) + true + end + + def eql?(o) + true + end + + end + + def test_should_not_allow_stubbing_of_non_mock_instance_disrupted_by_legitimate_overriding_of_eql_method + + always_eql_1 = AlwaysEql.new + always_eql_1.stubs(:my_method).returns(false) + + always_eql_2 = AlwaysEql.new + always_eql_2.stubs(:my_method).returns(false) + + assert_equal false, always_eql_2.my_method + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/bug_21465_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/bug_21465_test.rb new file mode 100644 index 0000000..bb65f6b --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/bug_21465_test.rb @@ -0,0 +1,34 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' + +class Bug21465Test < Test::Unit::TestCase + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_allow_expected_method_name_to_be_a_string + test_result = run_as_test do + mock = mock() + mock.expects('wibble') + mock.wibble + end + assert_passed(test_result) + end + + def test_should_allow_stubbed_method_name_to_be_a_string + test_result = run_as_test do + mock = mock() + mock.stubs('wibble') + mock.wibble + end + assert_passed(test_result) + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/bug_21563_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/bug_21563_test.rb new file mode 100644 index 0000000..8a031a0 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/bug_21563_test.rb @@ -0,0 +1,25 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' + +class Bug21563Test < Test::Unit::TestCase + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_allow_stubbing_of_verified_method + test_result = run_as_test do + object = Object.new + object.stubs(:verified?).returns(false) + assert !object.verified? + end + assert_passed(test_result) + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/expected_invocation_count_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/expected_invocation_count_test.rb new file mode 100644 index 0000000..1f076c4 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/expected_invocation_count_test.rb @@ -0,0 +1,196 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' + +class ExpectedInvocationCountTest < Test::Unit::TestCase + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_pass_if_method_is_never_expected_and_is_never_called + test_result = run_as_test do + mock = mock('mock') + mock.expects(:method).never + 0.times { mock.method } + end + assert_passed(test_result) + end + + def test_should_fail_fast_if_method_is_never_expected_but_is_called_once + test_result = run_as_test do + mock = mock('mock') + mock.expects(:method).never + 1.times { mock.method } + end + assert_failed(test_result) + assert_equal ["unexpected invocation: #.method()\nsatisfied expectations:\n- expected never, not yet invoked: #.method(any_parameters)\n"], test_result.failure_messages + end + + def test_should_pass_if_method_is_expected_twice_and_is_called_twice + test_result = run_as_test do + mock = mock('mock') + mock.expects(:method).twice + 2.times { mock.method } + end + assert_passed(test_result) + end + + def test_should_fail_if_method_is_expected_twice_but_is_called_once + test_result = run_as_test do + mock = mock('mock') + mock.expects(:method).twice + 1.times { mock.method } + end + assert_failed(test_result) + assert_equal ["not all expectations were satisfied\nunsatisfied expectations:\n- expected exactly twice, already invoked once: #.method(any_parameters)\n"], test_result.failure_messages + end + + def test_should_fail_fast_if_method_is_expected_twice_but_is_called_three_times + test_result = run_as_test do + mock = mock('mock') + mock.expects(:method).twice + 3.times { mock.method } + end + assert_failed(test_result) + assert_equal ["unexpected invocation: #.method()\nsatisfied expectations:\n- expected exactly twice, already invoked twice: #.method(any_parameters)\n"], test_result.failure_messages + end + + def test_should_pass_if_method_is_expected_between_two_and_four_times_and_is_called_twice + test_result = run_as_test do + mock = mock('mock') + mock.expects(:method).times(2..4) + 2.times { mock.method } + end + assert_passed(test_result) + end + + def test_should_pass_if_method_is_expected_between_two_and_four_times_and_is_called_three_times + test_result = run_as_test do + mock = mock('mock') + mock.expects(:method).times(2..4) + 3.times { mock.method } + end + assert_passed(test_result) + end + + def test_should_pass_if_method_is_expected_between_two_and_four_times_and_is_called_four_times + test_result = run_as_test do + mock = mock('mock') + mock.expects(:method).times(2..4) + 4.times { mock.method } + end + assert_passed(test_result) + end + + def test_should_fail_if_method_is_expected_between_two_and_four_times_and_is_called_once + test_result = run_as_test do + mock = mock('mock') + mock.expects(:method).times(2..4) + 1.times { mock.method } + end + assert_failed(test_result) + assert_equal ["not all expectations were satisfied\nunsatisfied expectations:\n- expected between 2 and 4 times, already invoked once: #.method(any_parameters)\n"], test_result.failure_messages + end + + def test_should_fail_fast_if_method_is_expected_between_two_and_four_times_and_is_called_five_times + test_result = run_as_test do + mock = mock('mock') + mock.expects(:method).times(2..4) + 5.times { mock.method } + end + assert_failed(test_result) + assert_equal ["unexpected invocation: #.method()\nsatisfied expectations:\n- expected between 2 and 4 times, already invoked 4 times: #.method(any_parameters)\n"], test_result.failure_messages + end + + def test_should_pass_if_method_is_expected_at_least_once_and_is_called_once + test_result = run_as_test do + mock = mock('mock') + mock.expects(:method).at_least_once + 1.times { mock.method } + end + assert_passed(test_result) + end + + def test_should_pass_if_method_is_expected_at_least_once_and_is_called_twice + test_result = run_as_test do + mock = mock('mock') + mock.expects(:method).at_least_once + 2.times { mock.method } + end + assert_passed(test_result) + end + + def test_should_fail_if_method_is_expected_at_least_once_but_is_never_called + test_result = run_as_test do + mock = mock('mock') + mock.expects(:method).at_least_once + 0.times { mock.method } + end + assert_failed(test_result) + assert_equal ["not all expectations were satisfied\nunsatisfied expectations:\n- expected at least once, not yet invoked: #.method(any_parameters)\n"], test_result.failure_messages + end + + def test_should_pass_if_method_is_expected_at_most_once_and_is_never_called + test_result = run_as_test do + mock = mock('mock') + mock.expects(:method).at_most_once + 0.times { mock.method } + end + assert_passed(test_result) + end + + def test_should_pass_if_method_is_expected_at_most_once_and_called_once + test_result = run_as_test do + mock = mock('mock') + mock.expects(:method).at_most_once + 1.times { mock.method } + end + assert_passed(test_result) + end + + def test_should_fail_fast_if_method_is_expected_at_most_once_but_is_called_twice + test_result = run_as_test do + mock = mock('mock') + mock.expects(:method).at_most_once + 2.times { mock.method } + end + assert_failed(test_result) + assert_equal ["unexpected invocation: #.method()\nsatisfied expectations:\n- expected at most once, already invoked once: #.method(any_parameters)\n"], test_result.failure_messages + end + + def test_should_pass_if_method_is_never_expected_and_is_never_called_even_if_everything_is_stubbed + test_result = run_as_test do + stub = stub_everything('stub') + stub.expects(:method).never + 0.times { stub.method } + end + assert_passed(test_result) + end + + def test_should_fail_fast_if_method_is_never_expected_but_is_called_once_even_if_everything_is_stubbed + test_result = run_as_test do + stub = stub_everything('stub') + stub.expects(:method).never + 1.times { stub.method } + end + assert_failed(test_result) + assert_equal ["unexpected invocation: #.method()\nsatisfied expectations:\n- expected never, not yet invoked: #.method(any_parameters)\n"], test_result.failure_messages + end + + def test_should_fail_fast_if_there_is_no_matching_expectation + test_result = run_as_test do + mock = mock('mock') + mock.expects(:method).with(1) + 1.times { mock.method } + end + assert_failed(test_result) + assert_equal ["unexpected invocation: #.method()\nunsatisfied expectations:\n- expected exactly once, not yet invoked: #.method(1)\n"], test_result.failure_messages + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/failure_messages_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/failure_messages_test.rb new file mode 100644 index 0000000..a2ae120 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/failure_messages_test.rb @@ -0,0 +1,64 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' + +class FailureMessagesTest < Test::Unit::TestCase + + OBJECT_ADDRESS_PATTERN = '0x[0-9A-Fa-f]{1,12}' + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + class Foo; end + + def test_should_display_class_name_when_expectation_was_on_class + test_result = run_as_test do + Foo.expects(:bar) + end + assert_match Regexp.new('FailureMessagesTest::Foo'), test_result.failures[0].message + end + + def test_should_display_class_name_and_address_when_expectation_was_on_instance + test_result = run_as_test do + Foo.new.expects(:bar) + end + assert_match Regexp.new("#"), test_result.failures[0].message + end + + def test_should_display_class_name_and_any_instance_prefix_when_expectation_was_on_any_instance + test_result = run_as_test do + Foo.any_instance.expects(:bar) + end + assert_match Regexp.new('#'), test_result.failures[0].message + end + + def test_should_display_mock_name_when_expectation_was_on_named_mock + test_result = run_as_test do + foo = mock('foo') + foo.expects(:bar) + end + assert_match Regexp.new('#'), test_result.failures[0].message + end + + def test_should_display_mock_address_when_expectation_was_on_unnamed_mock + test_result = run_as_test do + foo = mock() + foo.expects(:bar) + end + assert_match Regexp.new("#"), test_result.failures[0].message + end + + def test_should_display_string_when_expectation_was_on_string + test_result = run_as_test do + 'Foo'.expects(:bar) + end + assert_match Regexp.new("'Foo'"), test_result.failures[0].message + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/minitest_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/minitest_test.rb new file mode 100644 index 0000000..98f45e8 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/minitest_test.rb @@ -0,0 +1,146 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") + +begin + require 'minitest/unit' +rescue LoadError + # MiniTest not available +end + +# force load so that MiniTest is suitably monkey-patched +load 'mocha.rb' + +if defined?(MiniTest) + + class MiniTestSampleTest < MiniTest::Unit::TestCase + + def test_mocha_with_fulfilled_expectation + mockee = mock() + mockee.expects(:blah) + mockee.blah + end + + def test_mocha_with_unfulfilled_expectation + mockee = mock() + mockee.expects(:blah) + end + + def test_mocha_with_unexpected_invocation + mockee = mock() + mockee.blah + end + + def test_stubba_with_fulfilled_expectation + stubbee = Class.new { define_method(:blah) {} }.new + stubbee.expects(:blah) + stubbee.blah + end + + def test_stubba_with_unfulfilled_expectation + stubbee = Class.new { define_method(:blah) {} }.new + stubbee.expects(:blah) + end + + def test_mocha_with_matching_parameter + mockee = mock() + mockee.expects(:blah).with(has_key(:wibble)) + mockee.blah(:wibble => 1) + end + + def test_mocha_with_non_matching_parameter + mockee = mock() + mockee.expects(:blah).with(has_key(:wibble)) + mockee.blah(:wobble => 2) + end + + end + + class MiniTestTest < Test::Unit::TestCase + + def setup + @output = StringIO.new + MiniTest::Unit.output = @output + @runner = MiniTest::Unit.new + end + + attr_reader :runner + + def test_should_pass_mocha_test + runner.run(%w(-n test_mocha_with_fulfilled_expectation)) + + assert_equal 0, runner.failures + assert_equal 0, runner.errors + assert_equal 1, runner.assertion_count + end + + def test_should_fail_mocha_test_due_to_unfulfilled_expectation + runner.run(%w(-n test_mocha_with_unfulfilled_expectation)) + + assert_equal 1, runner.failures + assert_equal 0, runner.errors + assert_equal 1, runner.assertion_count + assert_not_all_expectation_were_satisfied + end + + def test_should_fail_mocha_test_due_to_unexpected_invocation + runner.run(%w(-n test_mocha_with_unexpected_invocation)) + + assert_equal 1, runner.failures + assert_equal 0, runner.errors + assert_equal 0, runner.assertion_count + assert_unexpected_invocation + end + + def test_should_pass_stubba_test + runner.run(%w(-n test_stubba_with_fulfilled_expectation)) + + assert_equal 0, runner.failures + assert_equal 0, runner.errors + assert_equal 1, runner.assertion_count + end + + def test_should_fail_stubba_test_due_to_unfulfilled_expectation + runner.run(%w(-n test_stubba_with_unfulfilled_expectation)) + + assert_equal 1, runner.failures + assert_equal 0, runner.errors + assert_equal 1, runner.assertion_count + assert_not_all_expectation_were_satisfied + end + + def test_should_pass_mocha_test_with_matching_parameter + runner.run(%w(-n test_mocha_with_matching_parameter)) + + assert_equal 0, runner.failures + assert_equal 0, runner.errors + assert_equal 1, runner.assertion_count + end + + def test_should_fail_mocha_test_with_non_matching_parameter + runner.run(%w(-n test_mocha_with_non_matching_parameter)) + + assert_equal 1, runner.failures + assert_equal 0, runner.errors + assert_equal 0, runner.assertion_count # unexpected invocation occurs before expectation is verified + assert_unexpected_invocation + end + + private + + def output + @output.rewind + @output.read + end + + def assert_unexpected_invocation + assert_match Regexp.new('unexpected invocation'), output, "MiniTest output:\n#{output}" + end + + def assert_not_all_expectation_were_satisfied + assert_match Regexp.new('not all expectations were satisfied'), output, "MiniTest output:\n#{output}" + end + + end + +else + warn "MiniTest is not available, so MiniTestAdapterTest has not been run." +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/mocha_example_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/mocha_example_test.rb new file mode 100644 index 0000000..34009c4 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/mocha_example_test.rb @@ -0,0 +1,98 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") +require 'mocha' + +class MochaExampleTest < Test::Unit::TestCase + + class Rover + + def initialize(left_track, right_track, steps_per_metre, steps_per_degree) + @left_track, @right_track, @steps_per_metre, @steps_per_degree = left_track, right_track, steps_per_metre, steps_per_degree + end + + def forward(metres) + @left_track.step(metres * @steps_per_metre) + @right_track.step(metres * @steps_per_metre) + wait + end + + def backward(metres) + forward(-metres) + end + + def left(degrees) + @left_track.step(-degrees * @steps_per_degree) + @right_track.step(+degrees * @steps_per_degree) + wait + end + + def right(degrees) + left(-degrees) + end + + def wait + while (@left_track.moving? or @right_track.moving?); end + end + + end + + def test_should_step_both_tracks_forward_ten_steps + left_track = mock('left_track') + right_track = mock('right_track') + steps_per_metre = 5 + rover = Rover.new(left_track, right_track, steps_per_metre, nil) + + left_track.expects(:step).with(10) + right_track.expects(:step).with(10) + + left_track.stubs(:moving?).returns(false) + right_track.stubs(:moving?).returns(false) + + rover.forward(2) + end + + def test_should_step_both_tracks_backward_ten_steps + left_track = mock('left_track') + right_track = mock('right_track') + steps_per_metre = 5 + rover = Rover.new(left_track, right_track, steps_per_metre, nil) + + left_track.expects(:step).with(-10) + right_track.expects(:step).with(-10) + + left_track.stubs(:moving?).returns(false) + right_track.stubs(:moving?).returns(false) + + rover.backward(2) + end + + def test_should_step_left_track_forwards_five_steps_and_right_track_backwards_five_steps + left_track = mock('left_track') + right_track = mock('right_track') + steps_per_degree = 5.0 / 90.0 + rover = Rover.new(left_track, right_track, nil, steps_per_degree) + + left_track.expects(:step).with(+5) + right_track.expects(:step).with(-5) + + left_track.stubs(:moving?).returns(false) + right_track.stubs(:moving?).returns(false) + + rover.right(90) + end + + def test_should_step_left_track_backwards_five_steps_and_right_track_forwards_five_steps + left_track = mock('left_track') + right_track = mock('right_track') + steps_per_degree = 5.0 / 90.0 + rover = Rover.new(left_track, right_track, nil, steps_per_degree) + + left_track.expects(:step).with(-5) + right_track.expects(:step).with(+5) + + left_track.stubs(:moving?).returns(false) + right_track.stubs(:moving?).returns(false) + + rover.left(90) + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/mocha_test_result_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/mocha_test_result_test.rb new file mode 100644 index 0000000..36c16f6 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/mocha_test_result_test.rb @@ -0,0 +1,84 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' +require 'execution_point' + +class MochaTestResultTest < Test::Unit::TestCase + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_include_expectation_verification_in_assertion_count + test_result = run_as_test do + object = mock() + object.expects(:message) + object.message + end + assert_equal 1, test_result.assertion_count + end + + def test_should_include_assertions_in_assertion_count + test_result = run_as_test do + assert true + end + assert_equal 1, test_result.assertion_count + end + + def test_should_not_include_stubbing_expectation_verification_in_assertion_count + test_result = run_as_test do + object = mock() + object.stubs(:message) + object.message + end + assert_equal 0, test_result.assertion_count + end + + def test_should_include_expectation_verification_failure_in_failure_count + test_result = run_as_test do + object = mock() + object.expects(:message) + end + assert_equal 1, test_result.failure_count + end + + def test_should_include_unexpected_verification_failure_in_failure_count + test_result = run_as_test do + object = mock() + object.message + end + assert_equal 1, test_result.failure_count + end + + def test_should_include_assertion_failure_in_failure_count + test_result = run_as_test do + flunk + end + assert_equal 1, test_result.failure_count + end + + def test_should_display_backtrace_indicating_line_number_where_unexpected_method_was_called + execution_point = nil + test_result = run_as_test do + object = mock() + execution_point = ExecutionPoint.current; object.message + end + assert_equal 1, test_result.failure_count + assert_equal execution_point, ExecutionPoint.new(test_result.failures[0].location) + end + + def test_should_display_backtrace_indicating_line_number_where_failing_assertion_was_called + execution_point = nil + test_result = run_as_test do + execution_point = ExecutionPoint.current; flunk + end + assert_equal 1, test_result.failure_count + assert_equal execution_point, ExecutionPoint.new(test_result.failures[0].location) + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/mock_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/mock_test.rb new file mode 100644 index 0000000..ecb7bb3 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/mock_test.rb @@ -0,0 +1,100 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' + +class MockTest < Test::Unit::TestCase + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_build_mock_and_explicitly_add_an_expectation_which_is_satisfied + test_result = run_as_test do + foo = mock() + foo.expects(:bar) + foo.bar + end + assert_passed(test_result) + end + + def test_should_build_mock_and_explicitly_add_an_expectation_which_is_not_satisfied + test_result = run_as_test do + foo = mock() + foo.expects(:bar) + end + assert_failed(test_result) + end + + def test_should_build_named_mock_and_explicitly_add_an_expectation_which_is_satisfied + test_result = run_as_test do + foo = mock('foo') + foo.expects(:bar) + foo.bar + end + assert_passed(test_result) + end + + def test_should_build_named_mock_and_explicitly_add_an_expectation_which_is_not_satisfied + test_result = run_as_test do + foo = mock('foo') + foo.expects(:bar) + end + assert_failed(test_result) + end + + def test_should_build_mock_incorporating_two_expectations_which_are_satisifed + test_result = run_as_test do + foo = mock(:bar => 'bar', :baz => 'baz') + foo.bar + foo.baz + end + assert_passed(test_result) + end + + def test_should_build_mock_incorporating_two_expectations_the_first_of_which_is_not_satisifed + test_result = run_as_test do + foo = mock(:bar => 'bar', :baz => 'baz') + foo.baz + end + assert_failed(test_result) + end + + def test_should_build_mock_incorporating_two_expectations_the_second_of_which_is_not_satisifed + test_result = run_as_test do + foo = mock(:bar => 'bar', :baz => 'baz') + foo.bar + end + assert_failed(test_result) + end + + def test_should_build_named_mock_incorporating_two_expectations_which_are_satisifed + test_result = run_as_test do + foo = mock('foo', :bar => 'bar', :baz => 'baz') + foo.bar + foo.baz + end + assert_passed(test_result) + end + + def test_should_build_named_mock_incorporating_two_expectations_the_first_of_which_is_not_satisifed + test_result = run_as_test do + foo = mock('foo', :bar => 'bar', :baz => 'baz') + foo.baz + end + assert_failed(test_result) + end + + def test_should_build_named_mock_incorporating_two_expectations_the_second_of_which_is_not_satisifed + test_result = run_as_test do + foo = mock('foo', :bar => 'bar', :baz => 'baz') + foo.bar + end + assert_failed(test_result) + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/mock_with_initializer_block_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/mock_with_initializer_block_test.rb new file mode 100644 index 0000000..7d21f24 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/mock_with_initializer_block_test.rb @@ -0,0 +1,51 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' + +class MockWithInitializerBlockTest < Test::Unit::TestCase + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_expect_two_method_invocations_and_receive_both_of_them + test_result = run_as_test do + mock = mock() do + expects(:method_1) + expects(:method_2) + end + mock.method_1 + mock.method_2 + end + assert_passed(test_result) + end + + def test_should_expect_two_method_invocations_but_receive_only_one_of_them + test_result = run_as_test do + mock = mock() do + expects(:method_1) + expects(:method_2) + end + mock.method_1 + end + assert_failed(test_result) + end + + def test_should_stub_methods + test_result = run_as_test do + mock = mock() do + stubs(:method_1).returns(1) + stubs(:method_2).returns(2) + end + assert_equal 1, mock.method_1 + assert_equal 2, mock.method_2 + end + assert_passed(test_result) + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/mocked_methods_dispatch_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/mocked_methods_dispatch_test.rb new file mode 100644 index 0000000..ebe3598 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/mocked_methods_dispatch_test.rb @@ -0,0 +1,78 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' + +class MockedMethodDispatchTest < Test::Unit::TestCase + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_find_latest_matching_expectation + test_result = run_as_test do + mock = mock() + mock.stubs(:method).returns(1) + mock.stubs(:method).returns(2) + assert_equal 2, mock.method + assert_equal 2, mock.method + assert_equal 2, mock.method + end + assert_passed(test_result) + end + + def test_should_find_latest_expectation_which_has_not_stopped_matching + test_result = run_as_test do + mock = mock() + mock.stubs(:method).returns(1) + mock.stubs(:method).once.returns(2) + assert_equal 2, mock.method + assert_equal 1, mock.method + assert_equal 1, mock.method + end + assert_passed(test_result) + end + + def test_should_keep_finding_later_stub_and_so_never_satisfy_earlier_expectation + test_result = run_as_test do + mock = mock() + mock.expects(:method).returns(1) + mock.stubs(:method).returns(2) + assert_equal 2, mock.method + assert_equal 2, mock.method + assert_equal 2, mock.method + end + assert_failed(test_result) + end + + def test_should_find_later_expectation_until_it_stops_matching_then_find_earlier_stub + test_result = run_as_test do + mock = mock() + mock.stubs(:method).returns(1) + mock.expects(:method).returns(2) + assert_equal 2, mock.method + assert_equal 1, mock.method + assert_equal 1, mock.method + end + assert_passed(test_result) + end + + def test_should_find_latest_expectation_with_range_of_expected_invocation_count_which_has_not_stopped_matching + test_result = run_as_test do + mock = mock() + mock.stubs(:method).returns(1) + mock.stubs(:method).times(2..3).returns(2) + assert_equal 2, mock.method + assert_equal 2, mock.method + assert_equal 2, mock.method + assert_equal 1, mock.method + assert_equal 1, mock.method + end + assert_passed(test_result) + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/optional_parameters_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/optional_parameters_test.rb new file mode 100644 index 0000000..9741d9d --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/optional_parameters_test.rb @@ -0,0 +1,70 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' + +class OptionalParameterMatcherTest < Test::Unit::TestCase + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_pass_if_all_required_parameters_match_and_no_optional_parameters_are_supplied + test_result = run_as_test do + mock = mock() + mock.expects(:method).with(1, 2, optionally(3, 4)) + mock.method(1, 2) + end + assert_passed(test_result) + end + + def test_should_pass_if_all_required_and_optional_parameters_match_and_some_optional_parameters_are_supplied + test_result = run_as_test do + mock = mock() + mock.expects(:method).with(1, 2, optionally(3, 4)) + mock.method(1, 2, 3) + end + assert_passed(test_result) + end + + def test_should_pass_if_all_required_and_optional_parameters_match_and_all_optional_parameters_are_supplied + test_result = run_as_test do + mock = mock() + mock.expects(:method).with(1, 2, optionally(3, 4)) + mock.method(1, 2, 3, 4) + end + assert_passed(test_result) + end + + def test_should_fail_if_all_required_and_optional_parameters_match_but_too_many_optional_parameters_are_supplied + test_result = run_as_test do + mock = mock() + mock.expects(:method).with(1, 2, optionally(3, 4)) + mock.method(1, 2, 3, 4, 5) + end + assert_failed(test_result) + end + + def test_should_fail_if_all_required_parameters_match_but_some_optional_parameters_do_not_match + test_result = run_as_test do + mock = mock() + mock.expects(:method).with(1, 2, optionally(3, 4)) + mock.method(1, 2, 4) + end + assert_failed(test_result) + end + + def test_should_fail_if_all_required_parameters_match_but_no_optional_parameters_match + test_result = run_as_test do + mock = mock() + mock.expects(:method).with(1, 2, optionally(3, 4)) + mock.method(1, 2, 4, 5) + end + assert_failed(test_result) + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/parameter_matcher_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/parameter_matcher_test.rb new file mode 100644 index 0000000..7663a69 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/parameter_matcher_test.rb @@ -0,0 +1,209 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' + +class ParameterMatcherTest < Test::Unit::TestCase + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_match_hash_parameter_with_specified_key + test_result = run_as_test do + mock = mock() + mock.expects(:method).with(has_key(:key_1)) + mock.method(:key_1 => 'value_1', :key_2 => 'value_2') + end + assert_passed(test_result) + end + + def test_should_not_match_hash_parameter_with_specified_key + test_result = run_as_test do + mock = mock() + mock.expects(:method).with(has_key(:key_1)) + mock.method(:key_2 => 'value_2') + end + assert_failed(test_result) + end + + def test_should_match_hash_parameter_with_specified_value + test_result = run_as_test do + mock = mock() + mock.expects(:method).with(has_value('value_1')) + mock.method(:key_1 => 'value_1', :key_2 => 'value_2') + end + assert_passed(test_result) + end + + def test_should_not_match_hash_parameter_with_specified_value + test_result = run_as_test do + mock = mock() + mock.expects(:method).with(has_value('value_1')) + mock.method(:key_2 => 'value_2') + end + assert_failed(test_result) + end + + def test_should_match_hash_parameter_with_specified_key_value_pair + test_result = run_as_test do + mock = mock() + mock.expects(:method).with(has_entry(:key_1, 'value_1')) + mock.method(:key_1 => 'value_1', :key_2 => 'value_2') + end + assert_passed(test_result) + end + + def test_should_not_match_hash_parameter_with_specified_key_value_pair + test_result = run_as_test do + mock = mock() + mock.expects(:method).with(has_entry(:key_1, 'value_2')) + mock.method(:key_1 => 'value_1', :key_2 => 'value_2') + end + assert_failed(test_result) + end + + def test_should_match_hash_parameter_with_specified_hash_entry + test_result = run_as_test do + mock = mock() + mock.expects(:method).with(has_entry(:key_1 => 'value_1')) + mock.method(:key_1 => 'value_1', :key_2 => 'value_2') + end + assert_passed(test_result) + end + + def test_should_not_match_hash_parameter_with_specified_hash_entry + test_result = run_as_test do + mock = mock() + mock.expects(:method).with(has_entry(:key_1 => 'value_2')) + mock.method(:key_1 => 'value_1', :key_2 => 'value_2') + end + assert_failed(test_result) + end + + def test_should_match_hash_parameter_with_specified_entries + test_result = run_as_test do + mock = mock() + mock.expects(:method).with(has_entries(:key_1 => 'value_1', :key_2 => 'value_2')) + mock.method(:key_1 => 'value_1', :key_2 => 'value_2', :key_3 => 'value_3') + end + assert_passed(test_result) + end + + def test_should_not_match_hash_parameter_with_specified_entries + test_result = run_as_test do + mock = mock() + mock.expects(:method).with(has_entries(:key_1 => 'value_1', :key_2 => 'value_2')) + mock.method(:key_1 => 'value_1', :key_2 => 'value_3') + end + assert_failed(test_result) + end + + def test_should_match_parameter_that_matches_regular_expression + test_result = run_as_test do + mock = mock() + mock.expects(:method).with(regexp_matches(/meter/)) + mock.method('this parameter should match') + end + assert_passed(test_result) + end + + def test_should_not_match_parameter_that_does_not_match_regular_expression + test_result = run_as_test do + mock = mock() + mock.expects(:method).with(regexp_matches(/something different/)) + mock.method('this parameter should not match') + end + assert_failed(test_result) + end + + def test_should_match_hash_parameter_with_specified_entries_using_nested_matchers + test_result = run_as_test do + mock = mock() + mock.expects(:method).with(has_entries(:key_1 => regexp_matches(/value_1/), kind_of(Symbol) => 'value_2')) + mock.method(:key_1 => 'value_1', :key_2 => 'value_2', :key_3 => 'value_3') + end + assert_passed(test_result) + end + + def test_should_not_match_hash_parameter_with_specified_entries_using_nested_matchers + test_result = run_as_test do + mock = mock() + mock.expects(:method).with(has_entries(:key_1 => regexp_matches(/value_1/), kind_of(String) => 'value_2')) + mock.method(:key_1 => 'value_2', :key_2 => 'value_3') + end + assert_failed(test_result) + end + + def test_should_match_parameter_that_matches_any_value + test_result = run_as_test do + mock = mock() + mock.expects(:method).with(any_of('value_1', 'value_2')).times(2) + mock.method('value_1') + mock.method('value_2') + end + assert_passed(test_result) + end + + def test_should_not_match_parameter_that_does_not_match_any_value + test_result = run_as_test do + mock = mock() + mock.expects(:method).with(any_of('value_1', 'value_2')) + mock.method('value_3') + end + assert_failed(test_result) + end + + def test_should_match_parameter_that_matches_all_values + test_result = run_as_test do + mock = mock() + mock.expects(:method).with(all_of('value_1', 'value_1')) + mock.method('value_1') + end + assert_passed(test_result) + end + + def test_should_not_match_parameter_that_does_not_match_all_values + test_result = run_as_test do + mock = mock() + mock.expects(:method).with(all_of('value_1', 'value_2')) + mock.method('value_1') + end + assert_failed(test_result) + end + + def test_should_match_parameter_that_responds_with_specified_value + klass = Class.new do + def quack + 'quack' + end + end + duck = klass.new + test_result = run_as_test do + mock = mock() + mock.expects(:method).with(responds_with(:quack, 'quack')) + mock.method(duck) + end + assert_passed(test_result) + end + + def test_should_not_match_parameter_that_does_not_respond_with_specified_value + klass = Class.new do + def quack + 'woof' + end + end + duck = klass.new + test_result = run_as_test do + mock = mock() + mock.expects(:method).with(responds_with(:quack, 'quack')) + mock.method(duck) + end + assert_failed(test_result) + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/partial_mocks_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/partial_mocks_test.rb new file mode 100644 index 0000000..bc93b85 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/partial_mocks_test.rb @@ -0,0 +1,47 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' + +class PartialMockTest < Test::Unit::TestCase + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_pass_if_all_expectations_are_satisfied + test_result = run_as_test do + partial_mock_one = "partial_mock_one" + partial_mock_two = "partial_mock_two" + + partial_mock_one.expects(:first) + partial_mock_one.expects(:second) + partial_mock_two.expects(:third) + + partial_mock_one.first + partial_mock_one.second + partial_mock_two.third + end + assert_passed(test_result) + end + + def test_should_fail_if_all_expectations_are_not_satisfied + test_result = run_as_test do + partial_mock_one = "partial_mock_one" + partial_mock_two = "partial_mock_two" + + partial_mock_one.expects(:first) + partial_mock_one.expects(:second) + partial_mock_two.expects(:third) + + partial_mock_one.first + partial_mock_two.third + end + assert_failed(test_result) + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/return_value_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/return_value_test.rb new file mode 100644 index 0000000..be3cc8f --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/return_value_test.rb @@ -0,0 +1,52 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' + +class ReturnValueTest < Test::Unit::TestCase + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_build_mock_and_explicitly_add_an_expectation_with_a_return_value + test_result = run_as_test do + foo = mock('foo') + foo.expects(:bar).returns('bar') + assert_equal 'bar', foo.bar + end + assert_passed(test_result) + end + + def test_should_build_mock_incorporating_two_expectations_with_return_values + test_result = run_as_test do + foo = mock('foo', :bar => 'bar', :baz => 'baz') + assert_equal 'bar', foo.bar + assert_equal 'baz', foo.baz + end + assert_passed(test_result) + end + + def test_should_build_stub_and_explicitly_add_an_expectation_with_a_return_value + test_result = run_as_test do + foo = stub('foo') + foo.stubs(:bar).returns('bar') + assert_equal 'bar', foo.bar + end + assert_passed(test_result) + end + + def test_should_build_stub_incorporating_two_expectations_with_return_values + test_result = run_as_test do + foo = stub('foo', :bar => 'bar', :baz => 'baz') + assert_equal 'bar', foo.bar + assert_equal 'baz', foo.baz + end + assert_passed(test_result) + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/sequence_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/sequence_test.rb new file mode 100644 index 0000000..f6c4b4f --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/sequence_test.rb @@ -0,0 +1,186 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' + +class SequenceTest < Test::Unit::TestCase + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_constrain_invocations_to_occur_in_expected_order + test_result = run_as_test do + mock = mock() + sequence = sequence('one') + + mock.expects(:first).in_sequence(sequence) + mock.expects(:second).in_sequence(sequence) + + mock.second + end + assert_failed(test_result) + end + + def test_should_allow_invocations_in_sequence + test_result = run_as_test do + mock = mock() + sequence = sequence('one') + + mock.expects(:first).in_sequence(sequence) + mock.expects(:second).in_sequence(sequence) + + mock.first + mock.second + end + assert_passed(test_result) + end + + def test_should_constrain_invocations_to_occur_in_expected_order_even_if_expected_on_different_mocks + test_result = run_as_test do + mock_one = mock('1') + mock_two = mock('2') + sequence = sequence('one') + + mock_one.expects(:first).in_sequence(sequence) + mock_two.expects(:second).in_sequence(sequence) + + mock_two.second + end + assert_failed(test_result) + end + + def test_should_allow_invocations_in_sequence_even_if_expected_on_different_mocks + test_result = run_as_test do + mock_one = mock('1') + mock_two = mock('2') + sequence = sequence('one') + + mock_one.expects(:first).in_sequence(sequence) + mock_two.expects(:second).in_sequence(sequence) + + mock_one.first + mock_two.second + end + assert_passed(test_result) + end + + def test_should_constrain_invocations_to_occur_in_expected_order_even_if_expected_on_partial_mocks + test_result = run_as_test do + partial_mock_one = "1" + partial_mock_two = "2" + sequence = sequence('one') + + partial_mock_one.expects(:first).in_sequence(sequence) + partial_mock_two.expects(:second).in_sequence(sequence) + + partial_mock_two.second + end + assert_failed(test_result) + end + + def test_should_allow_invocations_in_sequence_even_if_expected_on_partial_mocks + test_result = run_as_test do + partial_mock_one = "1" + partial_mock_two = "2" + sequence = sequence('one') + + partial_mock_one.expects(:first).in_sequence(sequence) + partial_mock_two.expects(:second).in_sequence(sequence) + + partial_mock_one.first + partial_mock_two.second + end + assert_passed(test_result) + end + + def test_should_allow_stub_expectations_to_be_skipped_in_sequence + test_result = run_as_test do + mock = mock() + sequence = sequence('one') + + mock.expects(:first).in_sequence(sequence) + mock.stubs(:second).in_sequence(sequence) + mock.expects(:third).in_sequence(sequence) + + mock.first + mock.third + end + assert_passed(test_result) + end + + def test_should_regard_sequences_as_independent_of_each_other + test_result = run_as_test do + mock = mock() + sequence_one = sequence('one') + sequence_two = sequence('two') + + mock.expects(:first).in_sequence(sequence_one) + mock.expects(:second).in_sequence(sequence_one) + + mock.expects(:third).in_sequence(sequence_two) + mock.expects(:fourth).in_sequence(sequence_two) + + mock.first + mock.third + mock.second + mock.fourth + end + assert_passed(test_result) + end + + def test_should_include_sequence_in_failure_message + test_result = run_as_test do + mock = mock() + sequence = sequence('one') + + mock.expects(:first).in_sequence(sequence) + mock.expects(:second).in_sequence(sequence) + + mock.second + end + assert_failed(test_result) + assert_match Regexp.new("in sequence 'one'"), test_result.failures.first.message + end + + def test_should_allow_expectations_to_be_in_more_than_one_sequence + test_result = run_as_test do + mock = mock() + sequence_one = sequence('one') + sequence_two = sequence('two') + + mock.expects(:first).in_sequence(sequence_one) + mock.expects(:second).in_sequence(sequence_two) + mock.expects(:three).in_sequence(sequence_one).in_sequence(sequence_two) + + mock.first + mock.three + end + assert_failed(test_result) + assert_match Regexp.new("in sequence 'one'"), test_result.failures.first.message + assert_match Regexp.new("in sequence 'two'"), test_result.failures.first.message + end + + def test_should_have_shortcut_for_expectations_to_be_in_more_than_one_sequence + test_result = run_as_test do + mock = mock() + sequence_one = sequence('one') + sequence_two = sequence('two') + + mock.expects(:first).in_sequence(sequence_one) + mock.expects(:second).in_sequence(sequence_two) + mock.expects(:three).in_sequence(sequence_one, sequence_two) + + mock.first + mock.three + end + assert_failed(test_result) + assert_match Regexp.new("in sequence 'one'"), test_result.failures.first.message + assert_match Regexp.new("in sequence 'two'"), test_result.failures.first.message + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/spy_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/spy_test.rb new file mode 100644 index 0000000..09cda3a --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/spy_test.rb @@ -0,0 +1,134 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' +require 'matcher_helpers' + +module SpyTestMethods + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_accept_wildcard_stub_call_without_arguments + instance = new_instance + instance.stubs(:to_s) + instance.to_s + assert_received(instance, :to_s) + assert_matcher_accepts have_received(:to_s), instance + end + + def test_should_accept_wildcard_stub_call_with_arguments + instance = new_instance + instance.stubs(:to_s) + instance.to_s(:argument) + assert_received(instance, :to_s) + assert_matcher_accepts have_received(:to_s), instance + end + + def test_should_not_accept_wildcard_stub_without_call + instance = new_instance + instance.stubs(:to_s) + assert_fails { assert_received(instance, :to_s) } + assert_fails { assert_matcher_accepts have_received(:to_s), instance } + end + + def test_should_not_accept_call_without_arguments + instance = new_instance + instance.stubs(:to_s) + instance.to_s + assert_fails { assert_received(instance, :to_s) {|expect| expect.with(1) } } + assert_fails { assert_matcher_accepts have_received(:to_s).with(1), instance } + end + + def test_should_not_accept_call_with_different_arguments + instance = new_instance + instance.stubs(:to_s) + instance.to_s(2) + assert_fails { assert_received(instance, :to_s) {|expect| expect.with(1) } } + assert_fails { assert_matcher_accepts have_received(:to_s).with(1), instance } + end + + def test_should_accept_call_with_correct_arguments + instance = new_instance + instance.stubs(:to_s) + instance.to_s(1) + assert_received(instance, :to_s) {|expect| expect.with(1) } + assert_matcher_accepts have_received(:to_s).with(1), instance + end + + def test_should_accept_call_with_wildcard_arguments + instance = new_instance + instance.stubs(:to_s) + instance.to_s('hello') + assert_received(instance, :to_s) {|expect| expect.with(is_a(String)) } + assert_matcher_accepts have_received(:to_s).with(is_a(String)), instance + end + + def test_should_reject_call_on_different_mock + instance = new_instance + other = new_instance + instance.stubs(:to_s) + other.stubs(:to_s) + other.to_s('hello') + assert_fails { assert_received(instance, :to_s) {|expect| expect.with(is_a(String)) } } + assert_fails { assert_matcher_accepts have_received(:to_s).with(is_a(String)), instance } + end + + def test_should_accept_correct_number_of_calls + instance = new_instance + instance.stubs(:to_s) + 2.times { instance.to_s } + assert_received(instance, :to_s) {|expect| expect.twice } + assert_matcher_accepts have_received(:to_s).twice, instance + end + + def test_should_reject_not_enough_calls + instance = new_instance + instance.stubs(:to_s) + instance.to_s + message = /expected exactly twice/ + assert_fails(message) { assert_received(instance, :to_s) {|expect| expect.twice } } + assert_fails(message) { assert_matcher_accepts have_received(:to_s).twice, instance } + end + + def test_should_reject_too_many_calls + instance = new_instance + instance.stubs(:to_s) + 2.times { instance.to_s } + message = /expected exactly once/ + assert_fails(message) { assert_received(instance, :to_s) {|expect| expect.once } } + assert_fails(message) { assert_matcher_accepts have_received(:to_s).once, instance } + end + + def assert_fails(message=/not yet invoked/) + begin + yield + rescue Test::Unit::AssertionFailedError => exception + assert_match message, exception.message, "Test failed, but with the wrong message" + return + end + flunk("Expected to fail") + end + +end + +class PartialSpyTest < Test::Unit::TestCase + include AcceptanceTest + include SpyTestMethods + + def new_instance + Object.new + end +end + +class PureSpyTest < Test::Unit::TestCase + include AcceptanceTest + include SpyTestMethods + + def new_instance + stub + end +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/states_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/states_test.rb new file mode 100644 index 0000000..0b94d9b --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/states_test.rb @@ -0,0 +1,70 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' + +class StatesTest < Test::Unit::TestCase + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_constrain_expectations_to_occur_within_a_given_state + test_result = run_as_test do + mock = mock() + readiness = states('readiness') + + mock.stubs(:first).when(readiness.is('ready')) + mock.stubs(:second).then(readiness.is('ready')) + + mock.first + end + assert_failed(test_result) + end + + def test_should_allow_expectations_to_occur_in_correct_state + test_result = run_as_test do + mock = mock() + readiness = states('readiness') + + mock.stubs(:first).when(readiness.is('ready')) + mock.stubs(:second).then(readiness.is('ready')) + + mock.second + mock.first + end + assert_passed(test_result) + end + + def test_should_be_able_to_start_in_a_specific_state + test_result = run_as_test do + mock = mock() + readiness = states('readiness') + + mock.stubs(:first).when(readiness.is('ready')) + + readiness.starts_as('ready') + mock.first + end + assert_passed(test_result) + end + + def test_should_switch_state_when_method_raises_an_exception + test_result = run_as_test do + mock = mock() + readiness = states('readiness') + + mock.expects(:first).raises().then(readiness.is('ready')) + mock.expects(:second).when(readiness.is('ready')) + + mock.first rescue nil + mock.second + end + assert_passed(test_result) + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stub_any_instance_method_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stub_any_instance_method_test.rb new file mode 100644 index 0000000..8e73402 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stub_any_instance_method_test.rb @@ -0,0 +1,195 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' + +class StubAnyInstanceMethodTest < Test::Unit::TestCase + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_stub_method_within_test + klass = Class.new do + def my_instance_method + :original_return_value + end + end + instance = klass.new + test_result = run_as_test do + klass.any_instance.stubs(:my_instance_method).returns(:new_return_value) + assert_equal :new_return_value, instance.my_instance_method + end + assert_passed(test_result) + end + + def test_should_leave_stubbed_public_method_unchanged_after_test + klass = Class.new do + def my_instance_method + :original_return_value + end + end + instance = klass.new + run_as_test do + klass.any_instance.stubs(:my_instance_method).returns(:new_return_value) + end + assert instance.public_methods(false).any? { |m| m.to_s == 'my_instance_method' } + assert_equal :original_return_value, instance.my_instance_method + end + + def test_should_leave_stubbed_protected_method_unchanged_after_test + klass = Class.new do + def my_instance_method + :original_return_value + end + protected :my_instance_method + end + instance = klass.new + run_as_test do + klass.any_instance.stubs(:my_instance_method).returns(:new_return_value) + end + assert instance.protected_methods(false).any? { |m| m.to_s == 'my_instance_method' } + assert_equal :original_return_value, instance.send(:my_instance_method) + end + + def test_should_leave_stubbed_private_method_unchanged_after_test + klass = Class.new do + def my_instance_method + :original_return_value + end + private :my_instance_method + end + instance = klass.new + run_as_test do + klass.any_instance.stubs(:my_instance_method).returns(:new_return_value) + end + assert instance.private_methods(false).any? { |m| m.to_s == 'my_instance_method' } + assert_equal :original_return_value, instance.send(:my_instance_method) + end + + def test_should_reset_expectations_after_test + klass = Class.new do + def my_instance_method + :original_return_value + end + end + instance = klass.new + run_as_test do + klass.any_instance.stubs(:my_instance_method).returns(:new_return_value) + end + assert_equal 0, klass.any_instance.mocha.expectations.length + end + + def test_should_be_able_to_stub_a_superclass_method + superklass = Class.new do + def my_superclass_method + :original_return_value + end + end + klass = Class.new(superklass) + instance = klass.new + test_result = run_as_test do + klass.any_instance.stubs(:my_superclass_method).returns(:new_return_value) + assert_equal :new_return_value, instance.my_superclass_method + end + assert_passed(test_result) + assert instance.public_methods(true).any? { |m| m.to_s == 'my_superclass_method' } + assert !klass.public_methods(false).any? { |m| m.to_s == 'my_superclass_method' } + assert_equal :original_return_value, instance.my_superclass_method + end + + def test_should_be_able_to_stub_method_if_ruby18_public_instance_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy + ruby18_klass = Class.new do + class << self + def public_instance_methods(include_superclass = true) + ['my_instance_method'] + end + end + end + test_result = run_as_test do + ruby18_klass.any_instance.stubs(:my_instance_method).returns(:new_return_value) + assert_equal :new_return_value, ruby18_klass.new.my_instance_method + end + assert_passed(test_result) + end + + def test_should_be_able_to_stub_method_if_ruby19_public_instance_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy + ruby19_klass = Class.new do + class << self + def public_instance_methods(include_superclass = true) + [:my_instance_method] + end + end + end + test_result = run_as_test do + ruby19_klass.any_instance.stubs(:my_instance_method).returns(:new_return_value) + assert_equal :new_return_value, ruby19_klass.new.my_instance_method + end + assert_passed(test_result) + end + + def test_should_be_able_to_stub_method_if_ruby18_protected_instance_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy + ruby18_klass = Class.new do + class << self + def protected_instance_methods(include_superclass = true) + ['my_instance_method'] + end + end + end + test_result = run_as_test do + ruby18_klass.any_instance.stubs(:my_instance_method).returns(:new_return_value) + assert_equal :new_return_value, ruby18_klass.new.my_instance_method + end + assert_passed(test_result) + end + + def test_should_be_able_to_stub_method_if_ruby19_protected_instance_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy + ruby19_klass = Class.new do + class << self + def protected_instance_methods(include_superclass = true) + [:my_instance_method] + end + end + end + test_result = run_as_test do + ruby19_klass.any_instance.stubs(:my_instance_method).returns(:new_return_value) + assert_equal :new_return_value, ruby19_klass.new.my_instance_method + end + assert_passed(test_result) + end + + def test_should_be_able_to_stub_method_if_ruby18_private_instance_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy + ruby18_klass = Class.new do + class << self + def private_instance_methods(include_superclass = true) + ['my_instance_method'] + end + end + end + test_result = run_as_test do + ruby18_klass.any_instance.stubs(:my_instance_method).returns(:new_return_value) + assert_equal :new_return_value, ruby18_klass.new.my_instance_method + end + assert_passed(test_result) + end + + def test_should_be_able_to_stub_method_if_ruby19_private_instance_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy + ruby19_klass = Class.new do + class << self + def private_instance_methods(include_superclass = true) + [:my_instance_method] + end + end + end + test_result = run_as_test do + ruby19_klass.any_instance.stubs(:my_instance_method).returns(:new_return_value) + assert_equal :new_return_value, ruby19_klass.new.my_instance_method + end + assert_passed(test_result) + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stub_class_method_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stub_class_method_test.rb new file mode 100644 index 0000000..e64d6d8 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stub_class_method_test.rb @@ -0,0 +1,203 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' + +class StubClassMethodTest < Test::Unit::TestCase + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_stub_method_within_test + klass = Class.new do + class << self + def my_class_method + :original_return_value + end + end + end + test_result = run_as_test do + klass.stubs(:my_class_method).returns(:new_return_value) + assert_equal :new_return_value, klass.my_class_method + end + assert_passed(test_result) + end + + def test_should_leave_stubbed_public_method_unchanged_after_test + klass = Class.new do + class << self + def my_class_method + :original_return_value + end + end + end + run_as_test do + klass.stubs(:my_class_method).returns(:new_return_value) + end + assert klass.public_methods(false).any? { |m| m.to_s == 'my_class_method' } + assert_equal :original_return_value, klass.my_class_method + end + + def test_should_leave_stubbed_protected_method_unchanged_after_test + klass = Class.new do + class << self + def my_class_method + :original_return_value + end + protected :my_class_method + end + end + run_as_test do + klass.stubs(:my_class_method).returns(:new_return_value) + end + assert klass.protected_methods(false).any? { |m| m.to_s == 'my_class_method' } + assert_equal :original_return_value, klass.send(:my_class_method) + end + + def test_should_leave_stubbed_private_method_unchanged_after_test + klass = Class.new do + class << self + def my_class_method + :original_return_value + end + private :my_class_method + end + end + run_as_test do + klass.stubs(:my_class_method).returns(:new_return_value) + end + assert klass.private_methods(false).any? { |m| m.to_s == 'my_class_method' } + assert_equal :original_return_value, klass.send(:my_class_method) + end + + def test_should_reset_class_expectations_after_test + klass = Class.new do + class << self + def my_class_method + :original_return_value + end + end + end + run_as_test do + klass.stubs(:my_class_method) + end + assert_equal 0, klass.mocha.expectations.length + end + + def test_should_be_able_to_stub_a_superclass_method + superklass = Class.new do + class << self + def my_superclass_method + :original_return_value + end + end + end + klass = Class.new(superklass) + test_result = run_as_test do + klass.stubs(:my_superclass_method).returns(:new_return_value) + assert_equal :new_return_value, klass.my_superclass_method + end + assert_passed(test_result) + superklass_public_methods = superklass.public_methods - superklass.superclass.public_methods + assert superklass_public_methods.any? { |m| m.to_s == 'my_superclass_method' } + klass_public_methods = klass.public_methods - klass.superclass.public_methods + assert !klass_public_methods.any? { |m| m.to_s == 'my_superclass_method' } + assert_equal :original_return_value, superklass.my_superclass_method + end + + def test_should_be_able_to_stub_method_if_ruby18_public_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy + ruby18_klass = Class.new do + class << self + def public_methods(include_superclass = true) + ['my_class_method'] + end + end + end + test_result = run_as_test do + ruby18_klass.stubs(:my_class_method).returns(:new_return_value) + assert_equal :new_return_value, ruby18_klass.my_class_method + end + assert_passed(test_result) + end + + def test_should_be_able_to_stub_method_if_ruby19_public_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy + ruby19_klass = Class.new do + class << self + def public_methods(include_superclass = true) + [:my_class_method] + end + end + end + test_result = run_as_test do + ruby19_klass.stubs(:my_class_method).returns(:new_return_value) + assert_equal :new_return_value, ruby19_klass.my_class_method + end + assert_passed(test_result) + end + + def test_should_be_able_to_stub_method_if_ruby18_protected_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy + ruby18_klass = Class.new do + class << self + def protected_methods(include_superclass = true) + ['my_class_method'] + end + end + end + test_result = run_as_test do + ruby18_klass.stubs(:my_class_method).returns(:new_return_value) + assert_equal :new_return_value, ruby18_klass.my_class_method + end + assert_passed(test_result) + end + + def test_should_be_able_to_stub_method_if_ruby19_protected_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy + ruby19_klass = Class.new do + class << self + def protected_methods(include_superclass = true) + [:my_class_method] + end + end + end + test_result = run_as_test do + ruby19_klass.stubs(:my_class_method).returns(:new_return_value) + assert_equal :new_return_value, ruby19_klass.my_class_method + end + assert_passed(test_result) + end + + def test_should_be_able_to_stub_method_if_ruby18_private_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy + ruby18_klass = Class.new do + class << self + def private_methods(include_superclass = true) + ['my_class_method'] + end + end + end + test_result = run_as_test do + ruby18_klass.stubs(:my_class_method).returns(:new_return_value) + assert_equal :new_return_value, ruby18_klass.my_class_method + end + assert_passed(test_result) + end + + def test_should_be_able_to_stub_method_if_ruby19_private_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy + ruby19_klass = Class.new do + class << self + def private_methods(include_superclass = true) + [:my_class_method] + end + end + end + test_result = run_as_test do + ruby19_klass.stubs(:my_class_method).returns(:new_return_value) + assert_equal :new_return_value, ruby19_klass.my_class_method + end + assert_passed(test_result) + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stub_everything_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stub_everything_test.rb new file mode 100644 index 0000000..18d28f7 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stub_everything_test.rb @@ -0,0 +1,56 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' + +class StubEverythingTest < Test::Unit::TestCase + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_build_stub_and_explicitly_add_an_expectation + test_result = run_as_test do + foo = stub_everything() + foo.stubs(:bar) + foo.bar + foo.unexpected_invocation + end + assert_passed(test_result) + end + + def test_should_build_named_stub_and_explicitly_add_an_expectation + test_result = run_as_test do + foo = stub_everything('foo') + foo.stubs(:bar) + foo.bar + foo.unexpected_invocation + end + assert_passed(test_result) + end + + def test_should_build_stub_incorporating_two_expectations + test_result = run_as_test do + foo = stub_everything(:bar => 'bar', :baz => 'baz') + foo.bar + foo.baz + foo.unexpected_invocation + end + assert_passed(test_result) + end + + def test_should_build_named_stub_incorporating_two_expectations + test_result = run_as_test do + foo = stub_everything('foo', :bar => 'bar', :baz => 'baz') + foo.bar + foo.baz + foo.unexpected_invocation + end + assert_passed(test_result) + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stub_instance_method_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stub_instance_method_test.rb new file mode 100644 index 0000000..f69d7a3 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stub_instance_method_test.rb @@ -0,0 +1,203 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' + +class StubInstanceMethodTest < Test::Unit::TestCase + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_leave_stubbed_public_method_unchanged_after_test + instance = Class.new do + def my_instance_method + :original_return_value + end + end.new + run_as_test do + instance.stubs(:my_instance_method).returns(:new_return_value) + end + assert instance.public_methods(false).any? { |m| m.to_s == 'my_instance_method' } + assert_equal :original_return_value, instance.my_instance_method + end + + def test_should_leave_stubbed_protected_method_unchanged_after_test + instance = Class.new do + def my_instance_method + :original_return_value + end + protected :my_instance_method + end.new + run_as_test do + instance.stubs(:my_instance_method).returns(:new_return_value) + end + assert instance.protected_methods(false).any? { |m| m.to_s == 'my_instance_method' } + assert_equal :original_return_value, instance.send(:my_instance_method) + end + + def test_should_leave_stubbed_private_method_unchanged_after_test + instance = Class.new do + def my_instance_method + :original_return_value + end + private :my_instance_method + end.new + run_as_test do + instance.stubs(:my_instance_method).returns(:new_return_value) + end + assert instance.private_methods(false).any? { |m| m.to_s == 'my_instance_method' } + assert_equal :original_return_value, instance.send(:my_instance_method) + end + + def test_should_reset_expectations_after_test + instance = Class.new do + def my_instance_method + :original_return_value + end + end.new + run_as_test do + instance.stubs(:my_instance_method).returns(:new_return_value) + end + assert_equal 0, instance.mocha.expectations.length + end + + def test_should_be_able_to_stub_a_superclass_method + superklass = Class.new do + def my_superclass_method + :original_return_value + end + end + klass = Class.new(superklass) + instance = klass.new + test_result = run_as_test do + instance.stubs(:my_superclass_method).returns(:new_return_value) + assert_equal :new_return_value, instance.my_superclass_method + end + assert_passed(test_result) + assert instance.public_methods(true).any? { |m| m.to_s == 'my_superclass_method' } + assert !instance.public_methods(false).any? { |m| m.to_s == 'my_superclass_method' } + assert_equal :original_return_value, instance.my_superclass_method + end + + def test_should_be_able_to_stub_method_if_ruby18_public_methods_include_method_but_method_does_not_exist_like_active_record_association_proxy + ruby18_instance = Class.new do + def public_methods(include_superclass = true) + ['my_instance_method'] + end + end.new + test_result = run_as_test do + ruby18_instance.stubs(:my_instance_method).returns(:new_return_value) + assert_equal :new_return_value, ruby18_instance.my_instance_method + end + assert_passed(test_result) + end + + def test_should_be_able_to_stub_method_if_ruby19_public_methods_include_method_but_method_does_not_exist_like_active_record_association_proxy + ruby19_instance = Class.new do + def public_methods(include_superclass = true) + [:my_instance_method] + end + end.new + test_result = run_as_test do + ruby19_instance.stubs(:my_instance_method).returns(:new_return_value) + assert_equal :new_return_value, ruby19_instance.my_instance_method + end + assert_passed(test_result) + end + + def test_should_be_able_to_stub_method_if_ruby18_protected_methods_include_method_but_method_does_not_exist_like_active_record_association_proxy + ruby18_instance = Class.new do + def protected_methods(include_superclass = true) + ['my_instance_method'] + end + end.new + test_result = run_as_test do + ruby18_instance.stubs(:my_instance_method).returns(:new_return_value) + assert_equal :new_return_value, ruby18_instance.my_instance_method + end + assert_passed(test_result) + end + + def test_should_be_able_to_stub_method_if_ruby19_protected_methods_include_method_but_method_does_not_exist_like_active_record_association_proxy + ruby19_instance = Class.new do + def protected_methods(include_superclass = true) + [:my_instance_method] + end + end.new + test_result = run_as_test do + ruby19_instance.stubs(:my_instance_method).returns(:new_return_value) + assert_equal :new_return_value, ruby19_instance.my_instance_method + end + assert_passed(test_result) + end + + def test_should_be_able_to_stub_method_if_ruby18_private_methods_include_method_but_method_does_not_exist_like_active_record_association_proxy + ruby18_instance = Class.new do + def private_methods(include_superclass = true) + ['my_instance_method'] + end + end.new + test_result = run_as_test do + ruby18_instance.stubs(:my_instance_method).returns(:new_return_value) + assert_equal :new_return_value, ruby18_instance.my_instance_method + end + assert_passed(test_result) + end + + def test_should_be_able_to_stub_method_if_ruby19_private_methods_include_method_but_method_does_not_exist_like_active_record_association_proxy + ruby19_instance = Class.new do + def private_methods(include_superclass = true) + [:my_instance_method] + end + end.new + test_result = run_as_test do + ruby19_instance.stubs(:my_instance_method).returns(:new_return_value) + assert_equal :new_return_value, ruby19_instance.my_instance_method + end + assert_passed(test_result) + end + + def test_should_be_able_to_specify_expectations_on_multiple_methods_in_a_single_call_to_expects + instance = Class.new do + def my_instance_method_1 + :original_return_value_1 + end + def my_instance_method_2 + :original_return_value_2 + end + end.new + run_as_test do + instance.expects( + :my_instance_method_1 => :new_return_value_1, + :my_instance_method_2 => :new_return_value_2 + ) + assert_equal :new_return_value_1, instance.my_instance_method_1 + assert_equal :new_return_value_2, instance.my_instance_method_2 + end + end + + def test_should_be_able_to_specify_expectations_on_multiple_methods_in_a_single_call_to_stubs + instance = Class.new do + def my_instance_method_1 + :original_return_value_1 + end + def my_instance_method_2 + :original_return_value_2 + end + end.new + run_as_test do + instance.stubs( + :my_instance_method_1 => :new_return_value_1, + :my_instance_method_2 => :new_return_value_2 + ) + assert_equal :new_return_value_1, instance.my_instance_method_1 + assert_equal :new_return_value_2, instance.my_instance_method_2 + end + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stub_module_method_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stub_module_method_test.rb new file mode 100644 index 0000000..a71a497 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stub_module_method_test.rb @@ -0,0 +1,163 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' + +class StubModuleMethodTest < Test::Unit::TestCase + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_stub_method_within_test + mod = Module.new { def self.my_module_method; :original_return_value; end } + test_result = run_as_test do + mod.stubs(:my_module_method).returns(:new_return_value) + assert_equal :new_return_value, mod.my_module_method + end + assert_passed(test_result) + end + + def test_should_leave_stubbed_public_method_unchanged_after_test + mod = Module.new { class << self; def my_module_method; :original_return_value; end; public :my_module_method; end } + run_as_test do + mod.stubs(:my_module_method).returns(:new_return_value) + end + assert mod.public_methods(false).any? { |m| m.to_s == 'my_module_method' } + assert_equal :original_return_value, mod.my_module_method + end + + def test_should_leave_stubbed_protected_method_unchanged_after_test + mod = Module.new { class << self; def my_module_method; :original_return_value; end; protected :my_module_method; end } + run_as_test do + mod.stubs(:my_module_method).returns(:new_return_value) + end + assert mod.protected_methods(false).any? { |m| m.to_s == 'my_module_method' } + assert_equal :original_return_value, mod.send(:my_module_method) + end + + def test_should_leave_stubbed_private_method_unchanged_after_test + mod = Module.new { class << self; def my_module_method; :original_return_value; end; private :my_module_method; end } + run_as_test do + mod.stubs(:my_module_method).returns(:new_return_value) + end + assert mod.private_methods(false).any? { |m| m.to_s == 'my_module_method' } + assert_equal :original_return_value, mod.send(:my_module_method) + end + + def test_should_reset_expectations_after_test + mod = Module.new { def self.my_module_method; :original_return_value; end } + run_as_test do + mod.stubs(:my_module_method) + end + assert_equal 0, mod.mocha.expectations.length + end + + def test_should_be_able_to_stub_a_superclass_method + supermod = Module.new { def self.my_superclass_method; :original_return_value; end } + mod = Module.new { include supermod } + test_result = run_as_test do + mod.stubs(:my_superclass_method).returns(:new_return_value) + assert_equal :new_return_value, mod.my_superclass_method + end + assert_passed(test_result) + assert supermod.public_methods.any? { |m| m.to_s == 'my_superclass_method' } + assert !mod.public_methods(false).any? { |m| m.to_s == 'my_superclass_method' } + assert_equal :original_return_value, supermod.my_superclass_method + end + + def test_should_be_able_to_stub_method_if_ruby18_public_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy + ruby18_mod = Module.new do + class << self + def public_methods(include_superclass = true) + ['my_module_method'] + end + end + end + test_result = run_as_test do + ruby18_mod.stubs(:my_module_method).returns(:new_return_value) + assert_equal :new_return_value, ruby18_mod.my_module_method + end + assert_passed(test_result) + end + + def test_should_be_able_to_stub_method_if_ruby19_public_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy + ruby19_mod = Module.new do + class << self + def public_methods(include_superclass = true) + [:my_module_method] + end + end + end + test_result = run_as_test do + ruby19_mod.stubs(:my_module_method).returns(:new_return_value) + assert_equal :new_return_value, ruby19_mod.my_module_method + end + assert_passed(test_result) + end + + def test_should_be_able_to_stub_method_if_ruby_18_protected_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy + ruby18_mod = Module.new do + class << self + def protected_methods(include_superclass = true) + ['my_module_method'] + end + end + end + test_result = run_as_test do + ruby18_mod.stubs(:my_module_method).returns(:new_return_value) + assert_equal :new_return_value, ruby18_mod.my_module_method + end + assert_passed(test_result) + end + + def test_should_be_able_to_stub_method_if_ruby19_protected_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy + ruby19_mod = Module.new do + class << self + def protected_methods(include_superclass = true) + [:my_module_method] + end + end + end + test_result = run_as_test do + ruby19_mod.stubs(:my_module_method).returns(:new_return_value) + assert_equal :new_return_value, ruby19_mod.my_module_method + end + assert_passed(test_result) + end + + def test_should_be_able_to_stub_method_if_ruby18_private_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy + ruby18_mod = Module.new do + class << self + def private_methods(include_superclass = true) + ['my_module_method'] + end + end + end + test_result = run_as_test do + ruby18_mod.stubs(:my_module_method).returns(:new_return_value) + assert_equal :new_return_value, ruby18_mod.my_module_method + end + assert_passed(test_result) + end + + def test_should_be_able_to_stub_method_if_ruby19_private_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy + ruby19_mod = Module.new do + class << self + def private_methods(include_superclass = true) + [:my_module_method] + end + end + end + test_result = run_as_test do + ruby19_mod.stubs(:my_module_method).returns(:new_return_value) + assert_equal :new_return_value, ruby19_mod.my_module_method + end + assert_passed(test_result) + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stub_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stub_test.rb new file mode 100644 index 0000000..92859c1 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stub_test.rb @@ -0,0 +1,52 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' + +class StubTest < Test::Unit::TestCase + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_build_stub_and_explicitly_add_an_expectation + test_result = run_as_test do + foo = stub() + foo.stubs(:bar) + foo.bar + end + assert_passed(test_result) + end + + def test_should_build_named_stub_and_explicitly_add_an_expectation + test_result = run_as_test do + foo = stub('foo') + foo.stubs(:bar) + foo.bar + end + assert_passed(test_result) + end + + def test_should_build_stub_incorporating_two_expectations + test_result = run_as_test do + foo = stub(:bar => 'bar', :baz => 'baz') + foo.bar + foo.baz + end + assert_passed(test_result) + end + + def test_should_build_named_stub_incorporating_two_expectations + test_result = run_as_test do + foo = stub('foo', :bar => 'bar', :baz => 'baz') + foo.bar + foo.baz + end + assert_passed(test_result) + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stubba_example_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stubba_example_test.rb new file mode 100644 index 0000000..bd5a84d --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stubba_example_test.rb @@ -0,0 +1,102 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") +require 'mocha' + +class Widget + + def model + 'original_model' + end + + class << self + + def find(options) + [] + end + + def create(attributes) + Widget.new + end + + end + +end + +module Thingy + + def self.wotsit + :hoojamaflip + end + +end + +class StubbaExampleTest < Test::Unit::TestCase + + def test_should_stub_instance_method + widget = Widget.new + widget.expects(:model).returns('different_model') + assert_equal 'different_model', widget.model + end + + def test_should_stub_module_method + should_stub_module_method + end + + def test_should_stub_module_method_again + should_stub_module_method + end + + def test_should_stub_class_method + should_stub_class_method + end + + def test_should_stub_class_method_again + should_stub_class_method + end + + def test_should_stub_instance_method_on_any_instance_of_a_class + should_stub_instance_method_on_any_instance_of_a_class + end + + def test_should_stub_instance_method_on_any_instance_of_a_class_again + should_stub_instance_method_on_any_instance_of_a_class + end + + def test_should_stub_two_different_class_methods + should_stub_two_different_class_methods + end + + def test_should_stub_two_different_class_methods_again + should_stub_two_different_class_methods + end + + private + + def should_stub_module_method + Thingy.expects(:wotsit).returns(:dooda) + assert_equal :dooda, Thingy.wotsit + end + + def should_stub_class_method + widgets = [Widget.new] + Widget.expects(:find).with(:all).returns(widgets) + assert_equal widgets, Widget.find(:all) + end + + def should_stub_two_different_class_methods + found_widgets = [Widget.new] + created_widget = Widget.new + Widget.expects(:find).with(:all).returns(found_widgets) + Widget.expects(:create).with(:model => 'wombat').returns(created_widget) + assert_equal found_widgets, Widget.find(:all) + assert_equal created_widget, Widget.create(:model => 'wombat') + end + + def should_stub_instance_method_on_any_instance_of_a_class + Widget.any_instance.expects(:model).at_least_once.returns('another_model') + widget_1 = Widget.new + widget_2 = Widget.new + assert_equal 'another_model', widget_1.model + assert_equal 'another_model', widget_2.model + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stubba_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stubba_test.rb new file mode 100644 index 0000000..1155ac5 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stubba_test.rb @@ -0,0 +1,15 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") +require 'deprecation_disabler' + +class StubbaTest < Test::Unit::TestCase + + include DeprecationDisabler + + def test_should_report_deprecation_of_stubba_which_will_be_removed_in_a_future_release + disable_deprecations do + load 'stubba.rb' + end + assert Mocha::Deprecation.messages.include?("require 'stubba' is no longer needed and stubba.rb will soon be removed") + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stubba_test_result_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stubba_test_result_test.rb new file mode 100644 index 0000000..df7a342 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stubba_test_result_test.rb @@ -0,0 +1,66 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' +require 'execution_point' + +class StubbaTestResultTest < Test::Unit::TestCase + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_include_expectation_verification_in_assertion_count + test_result = run_as_test do + object = Class.new { def message; end }.new + object.expects(:message) + object.message + end + assert_equal 1, test_result.assertion_count + end + + def test_should_include_assertions_in_assertion_count + test_result = run_as_test do + assert true + end + assert_equal 1, test_result.assertion_count + end + + def test_should_not_include_stubbing_expectation_verification_in_assertion_count + test_result = run_as_test do + object = Class.new { def message; end }.new + object.stubs(:message) + object.message + end + assert_equal 0, test_result.assertion_count + end + + def test_should_include_expectation_verification_failure_in_failure_count + test_result = run_as_test do + object = Class.new { def message; end }.new + object.expects(:message) + end + assert_equal 1, test_result.failure_count + end + + def test_should_include_assertion_failure_in_failure_count + test_result = run_as_test do + flunk + end + assert_equal 1, test_result.failure_count + end + + def test_should_display_backtrace_indicating_line_number_where_failing_assertion_was_called + execution_point = nil + test_result = run_as_test do + execution_point = ExecutionPoint.current; flunk + end + assert_equal 1, test_result.failure_count + assert_equal execution_point, ExecutionPoint.new(test_result.failures[0].location) + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stubbing_error_backtrace_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stubbing_error_backtrace_test.rb new file mode 100644 index 0000000..6e7a757 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stubbing_error_backtrace_test.rb @@ -0,0 +1,64 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' +require 'execution_point' + +class StubbingErrorBacktraceTest < Test::Unit::TestCase + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_display_backtrace_indicating_line_number_where_attempt_to_stub_non_existent_method_was_made + execution_point = nil + object = Object.new + Mocha::Configuration.prevent(:stubbing_non_existent_method) + test_result = run_as_test do + execution_point = ExecutionPoint.current; object.stubs(:non_existent_method) + end + assert_equal 1, test_result.error_count + assert_equal execution_point, ExecutionPoint.new(test_result.errors[0].exception.backtrace) + end + + def test_should_display_backtrace_indicating_line_number_where_attempt_to_stub_non_public_method_was_made + execution_point = nil + object = Class.new do + def non_public_method; end + private :non_public_method + end.new + Mocha::Configuration.prevent(:stubbing_non_public_method) + test_result = run_as_test do + execution_point = ExecutionPoint.current; object.stubs(:non_public_method) + end + assert_equal 1, test_result.error_count + assert_equal execution_point, ExecutionPoint.new(test_result.errors[0].exception.backtrace) + end + + def test_should_display_backtrace_indicating_line_number_where_attempt_to_stub_method_on_non_mock_object_was_made + execution_point = nil + object = Object.new + Mocha::Configuration.prevent(:stubbing_method_on_non_mock_object) + test_result = run_as_test do + execution_point = ExecutionPoint.current; object.stubs(:any_method) + end + assert_equal 1, test_result.error_count + assert_equal execution_point, ExecutionPoint.new(test_result.errors[0].exception.backtrace) + end + + def test_should_display_backtrace_indicating_line_number_where_method_was_unnecessarily_stubbed + execution_point = nil + object = Object.new + Mocha::Configuration.prevent(:stubbing_method_unnecessarily) + test_result = run_as_test do + execution_point = ExecutionPoint.current; object.stubs(:unused_method) + end + assert_equal 1, test_result.error_count + assert_equal execution_point, ExecutionPoint.new(test_result.errors[0].exception.backtrace) + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stubbing_method_unnecessarily_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stubbing_method_unnecessarily_test.rb new file mode 100644 index 0000000..dfc8155 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stubbing_method_unnecessarily_test.rb @@ -0,0 +1,65 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' + +class StubbingMethodUnnecessarilyTest < Test::Unit::TestCase + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_allow_stubbing_method_unnecessarily + Mocha::Configuration.allow(:stubbing_method_unnecessarily) + test_result = run_as_test do + mock = mock('mock') + mock.stubs(:public_method) + end + assert_passed(test_result) + assert !@logger.warnings.include?('stubbing method unnecessarily: #.public_method(any_parameters)') + end + + def test_should_warn_when_stubbing_method_unnecessarily + Mocha::Configuration.warn_when(:stubbing_method_unnecessarily) + test_result = run_as_test do + mock = mock('mock') + mock.stubs(:public_method) + end + assert_passed(test_result) + assert @logger.warnings.include?('stubbing method unnecessarily: #.public_method(any_parameters)') + end + + def test_should_prevent_stubbing_method_unnecessarily + Mocha::Configuration.prevent(:stubbing_method_unnecessarily) + test_result = run_as_test do + mock = mock('mock') + mock.stubs(:public_method) + end + assert_failed(test_result) + assert test_result.error_messages.include?('Mocha::StubbingError: stubbing method unnecessarily: #.public_method(any_parameters)') + end + + def test_should_default_to_allow_stubbing_method_unnecessarily + test_result = run_as_test do + mock = mock('mock') + mock.stubs(:public_method) + end + assert_passed(test_result) + assert !@logger.warnings.include?('stubbing method unnecessarily: #.public_method(any_parameters)') + end + + def test_should_allow_stubbing_method_when_stubbed_method_is_invoked + Mocha::Configuration.prevent(:stubbing_method_unnecessarily) + test_result = run_as_test do + mock = mock('mock') + mock.stubs(:public_method) + mock.public_method + end + assert_passed(test_result) + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stubbing_non_existent_any_instance_method_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stubbing_non_existent_any_instance_method_test.rb new file mode 100644 index 0000000..c987553 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stubbing_non_existent_any_instance_method_test.rb @@ -0,0 +1,130 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' + +class StubbingNonExistentAnyInstanceMethodTest < Test::Unit::TestCase + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_allow_stubbing_non_existent_any_instance_method + Mocha::Configuration.allow(:stubbing_non_existent_method) + klass = Class.new + test_result = run_as_test do + klass.any_instance.stubs(:non_existent_method) + end + assert !@logger.warnings.include?("stubbing non-existent method: #{klass.any_instance}.non_existent_method") + assert_passed(test_result) + end + + def test_should_warn_when_stubbing_non_existent_any_instance_method + Mocha::Configuration.warn_when(:stubbing_non_existent_method) + klass = Class.new + test_result = run_as_test do + klass.any_instance.stubs(:non_existent_method) + end + assert_passed(test_result) + assert @logger.warnings.include?("stubbing non-existent method: #{klass.any_instance}.non_existent_method") + end + + def test_should_prevent_stubbing_non_existent_any_instance_method + Mocha::Configuration.prevent(:stubbing_non_existent_method) + klass = Class.new + test_result = run_as_test do + klass.any_instance.stubs(:non_existent_method) + end + assert_failed(test_result) + assert test_result.error_messages.include?("Mocha::StubbingError: stubbing non-existent method: #{klass.any_instance}.non_existent_method") + end + + def test_should_default_to_allow_stubbing_non_existent_any_instance_method + klass = Class.new + test_result = run_as_test do + klass.any_instance.stubs(:non_existent_method) + end + assert !@logger.warnings.include?("stubbing non-existent method: #{klass.any_instance}.non_existent_method") + assert_passed(test_result) + end + + def test_should_allow_stubbing_existing_public_any_instance_method + Mocha::Configuration.prevent(:stubbing_non_existent_method) + klass = Class.new do + def existing_public_method; end + public :existing_public_method + end + test_result = run_as_test do + klass.any_instance.stubs(:existing_public_method) + end + assert_passed(test_result) + end + + def test_should_allow_stubbing_existing_protected_any_instance_method + Mocha::Configuration.prevent(:stubbing_non_existent_method) + klass = Class.new do + def existing_protected_method; end + protected :existing_protected_method + end + test_result = run_as_test do + klass.any_instance.stubs(:existing_protected_method) + end + assert_passed(test_result) + end + + def test_should_allow_stubbing_existing_private_any_instance_method + Mocha::Configuration.prevent(:stubbing_non_existent_method) + klass = Class.new do + def existing_private_method; end + private :existing_private_method + end + test_result = run_as_test do + klass.any_instance.stubs(:existing_private_method) + end + assert_passed(test_result) + end + + def test_should_allow_stubbing_existing_public_any_instance_superclass_method + Mocha::Configuration.prevent(:stubbing_non_existent_method) + superklass = Class.new do + def existing_public_method; end + public :existing_public_method + end + klass = Class.new(superklass) + test_result = run_as_test do + klass.any_instance.stubs(:existing_public_method) + end + assert_passed(test_result) + end + + def test_should_allow_stubbing_existing_protected_any_instance_superclass_method + Mocha::Configuration.prevent(:stubbing_non_existent_method) + superklass = Class.new do + def existing_protected_method; end + protected :existing_protected_method + end + klass = Class.new(superklass) + test_result = run_as_test do + klass.any_instance.stubs(:existing_protected_method) + end + assert_passed(test_result) + end + + def test_should_allow_stubbing_existing_private_any_instance_superclass_method + Mocha::Configuration.prevent(:stubbing_non_existent_method) + superklass = Class.new do + def existing_private_method; end + private :existing_private_method + end + klass = Class.new(superklass) + test_result = run_as_test do + klass.any_instance.stubs(:existing_private_method) + end + assert_passed(test_result) + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stubbing_non_existent_class_method_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stubbing_non_existent_class_method_test.rb new file mode 100644 index 0000000..55947b6 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stubbing_non_existent_class_method_test.rb @@ -0,0 +1,157 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' + +class StubbingNonExistentClassMethodTest < Test::Unit::TestCase + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_allow_stubbing_non_existent_class_method + Mocha::Configuration.allow(:stubbing_non_existent_method) + klass = Class.new + test_result = run_as_test do + klass.stubs(:non_existent_method) + end + assert !@logger.warnings.include?("stubbing non-existent method: #{klass}.non_existent_method") + assert_passed(test_result) + end + + def test_should_warn_when_stubbing_non_existent_class_method + Mocha::Configuration.warn_when(:stubbing_non_existent_method) + klass = Class.new + test_result = run_as_test do + klass.stubs(:non_existent_method) + end + assert_passed(test_result) + assert @logger.warnings.include?("stubbing non-existent method: #{klass}.non_existent_method") + end + + def test_should_prevent_stubbing_non_existent_class_method + Mocha::Configuration.prevent(:stubbing_non_existent_method) + klass = Class.new + test_result = run_as_test do + klass.stubs(:non_existent_method) + end + assert_failed(test_result) + assert test_result.error_messages.include?("Mocha::StubbingError: stubbing non-existent method: #{klass}.non_existent_method") + end + + def test_should_default_to_allow_stubbing_non_existent_class_method + klass = Class.new + test_result = run_as_test do + klass.stubs(:non_existent_method) + end + assert !@logger.warnings.include?("stubbing non-existent method: #{klass}.non_existent_method") + assert_passed(test_result) + end + + def test_should_allow_stubbing_existing_public_class_method + Mocha::Configuration.prevent(:stubbing_non_existent_method) + klass = Class.new do + class << self + def existing_public_method; end + public :existing_public_method + end + end + test_result = run_as_test do + klass.stubs(:existing_public_method) + end + assert_passed(test_result) + end + + def test_should_allow_stubbing_method_to_which_class_responds + Mocha::Configuration.prevent(:stubbing_non_existent_method) + klass = Class.new do + class << self + def respond_to?(method, include_private = false) + (method == :method_to_which_class_responds) + end + end + end + test_result = run_as_test do + klass.stubs(:method_to_which_class_responds) + end + assert_passed(test_result) + end + + def test_should_allow_stubbing_existing_protected_class_method + Mocha::Configuration.prevent(:stubbing_non_existent_method) + klass = Class.new do + class << self + def existing_protected_method; end + protected :existing_protected_method + end + end + test_result = run_as_test do + klass.stubs(:existing_protected_method) + end + assert_passed(test_result) + end + + def test_should_allow_stubbing_existing_private_class_method + Mocha::Configuration.prevent(:stubbing_non_existent_method) + klass = Class.new do + class << self + def existing_private_method; end + private :existing_private_method + end + end + test_result = run_as_test do + klass.stubs(:existing_private_method) + end + assert_passed(test_result) + end + + def test_should_allow_stubbing_existing_public_superclass_method + Mocha::Configuration.prevent(:stubbing_non_existent_method) + superklass = Class.new do + class << self + def existing_public_method; end + public :existing_public_method + end + end + klass = Class.new(superklass) + test_result = run_as_test do + klass.stubs(:existing_public_method) + end + assert_passed(test_result) + end + + def test_should_allow_stubbing_existing_protected_superclass_method + Mocha::Configuration.prevent(:stubbing_non_existent_method) + superklass = Class.new do + class << self + def existing_protected_method; end + protected :existing_protected_method + end + end + klass = Class.new(superklass) + test_result = run_as_test do + klass.stubs(:existing_protected_method) + end + assert_passed(test_result) + end + + def test_should_allow_stubbing_existing_private_superclass_method + Mocha::Configuration.prevent(:stubbing_non_existent_method) + superklass = Class.new do + class << self + def existing_private_method; end + protected :existing_private_method + end + end + klass = Class.new(superklass) + test_result = run_as_test do + klass.stubs(:existing_private_method) + end + assert_passed(test_result) + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stubbing_non_existent_instance_method_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stubbing_non_existent_instance_method_test.rb new file mode 100644 index 0000000..5aaf370 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stubbing_non_existent_instance_method_test.rb @@ -0,0 +1,147 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' + +class StubbingNonExistentInstanceMethodTest < Test::Unit::TestCase + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_allow_stubbing_non_existent_instance_method + Mocha::Configuration.allow(:stubbing_non_existent_method) + instance = Class.new.new + test_result = run_as_test do + instance.stubs(:non_existent_method) + end + assert !@logger.warnings.include?("stubbing non-existent method: #{instance}.non_existent_method") + assert_passed(test_result) + end + + def test_should_warn_when_stubbing_non_existent_instance_method + Mocha::Configuration.warn_when(:stubbing_non_existent_method) + instance = Class.new.new + test_result = run_as_test do + instance.stubs(:non_existent_method) + end + assert_passed(test_result) + assert @logger.warnings.include?("stubbing non-existent method: #{instance}.non_existent_method") + end + + def test_should_prevent_stubbing_non_existent_instance_method + Mocha::Configuration.prevent(:stubbing_non_existent_method) + instance = Class.new.new + test_result = run_as_test do + instance.stubs(:non_existent_method) + end + assert_failed(test_result) + assert test_result.error_messages.include?("Mocha::StubbingError: stubbing non-existent method: #{instance}.non_existent_method") + end + + def test_should_default_to_allow_stubbing_non_existent_instance_method + instance = Class.new.new + test_result = run_as_test do + instance.stubs(:non_existent_method) + end + assert !@logger.warnings.include?("stubbing non-existent method: #{instance}.non_existent_method") + assert_passed(test_result) + end + + def test_should_allow_stubbing_existing_public_instance_method + Mocha::Configuration.prevent(:stubbing_non_existent_method) + klass = Class.new do + def existing_public_method; end + public :existing_public_method + end + instance = klass.new + test_result = run_as_test do + instance.stubs(:existing_public_method) + end + assert_passed(test_result) + end + + def test_should_allow_stubbing_method_to_which_instance_responds + Mocha::Configuration.prevent(:stubbing_non_existent_method) + klass = Class.new do + def respond_to?(method, include_private = false) + (method == :method_to_which_instance_responds) + end + end + instance = klass.new + test_result = run_as_test do + instance.stubs(:method_to_which_instance_responds) + end + assert_passed(test_result) + end + + def test_should_allow_stubbing_existing_protected_instance_method + Mocha::Configuration.prevent(:stubbing_non_existent_method) + klass = Class.new do + def existing_protected_method; end + protected :existing_protected_method + end + instance = klass.new + test_result = run_as_test do + instance.stubs(:existing_protected_method) + end + assert_passed(test_result) + end + + def test_should_allow_stubbing_existing_private_instance_method + Mocha::Configuration.prevent(:stubbing_non_existent_method) + klass = Class.new do + def existing_private_method; end + private :existing_private_method + end + instance = klass.new + test_result = run_as_test do + instance.stubs(:existing_private_method) + end + assert_passed(test_result) + end + + def test_should_allow_stubbing_existing_public_instance_superclass_method + Mocha::Configuration.prevent(:stubbing_non_existent_method) + superklass = Class.new do + def existing_public_method; end + public :existing_public_method + end + instance = Class.new(superklass).new + test_result = run_as_test do + instance.stubs(:existing_public_method) + end + assert_passed(test_result) + end + + def test_should_allow_stubbing_existing_protected_instance_superclass_method + Mocha::Configuration.prevent(:stubbing_non_existent_method) + superklass = Class.new do + def existing_protected_method; end + protected :existing_protected_method + end + instance = Class.new(superklass).new + test_result = run_as_test do + instance.stubs(:existing_protected_method) + end + assert_passed(test_result) + end + + def test_should_allow_stubbing_existing_private_instance_superclass_method + Mocha::Configuration.prevent(:stubbing_non_existent_method) + superklass = Class.new do + def existing_private_method; end + private :existing_private_method + end + instance = Class.new(superklass).new + test_result = run_as_test do + instance.stubs(:existing_private_method) + end + assert_passed(test_result) + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stubbing_non_public_any_instance_method_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stubbing_non_public_any_instance_method_test.rb new file mode 100644 index 0000000..6fc5a98 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stubbing_non_public_any_instance_method_test.rb @@ -0,0 +1,130 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' + +class StubbingNonPublicAnyInstanceMethodTest < Test::Unit::TestCase + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_allow_stubbing_private_any_instance_method + Mocha::Configuration.allow(:stubbing_non_public_method) + klass = Class.new do + def private_method; end + private :private_method + end + test_result = run_as_test do + klass.any_instance.stubs(:private_method) + end + assert_passed(test_result) + assert !@logger.warnings.include?("stubbing non-public method: #{klass.any_instance}.private_method") + end + + def test_should_allow_stubbing_protected_any_instance_method + Mocha::Configuration.allow(:stubbing_non_public_method) + klass = Class.new do + def protected_method; end + protected :protected_method + end + test_result = run_as_test do + klass.any_instance.stubs(:protected_method) + end + assert_passed(test_result) + assert !@logger.warnings.include?("stubbing non-public method: #{klass.any_instance}.protected_method") + end + + def test_should_warn_when_stubbing_private_any_instance_method + Mocha::Configuration.warn_when(:stubbing_non_public_method) + klass = Class.new do + def private_method; end + private :private_method + end + test_result = run_as_test do + klass.any_instance.stubs(:private_method) + end + assert_passed(test_result) + assert @logger.warnings.include?("stubbing non-public method: #{klass.any_instance}.private_method") + end + + def test_should_warn_when_stubbing_protected_any_instance_method + Mocha::Configuration.warn_when(:stubbing_non_public_method) + klass = Class.new do + def protected_method; end + protected :protected_method + end + test_result = run_as_test do + klass.any_instance.stubs(:protected_method) + end + assert_passed(test_result) + assert @logger.warnings.include?("stubbing non-public method: #{klass.any_instance}.protected_method") + end + + def test_should_prevent_stubbing_private_any_instance_method + Mocha::Configuration.prevent(:stubbing_non_public_method) + klass = Class.new do + def private_method; end + private :private_method + end + test_result = run_as_test do + klass.any_instance.stubs(:private_method) + end + assert_failed(test_result) + assert test_result.error_messages.include?("Mocha::StubbingError: stubbing non-public method: #{klass.any_instance}.private_method") + end + + def test_should_prevent_stubbing_protected_any_instance_method + Mocha::Configuration.prevent(:stubbing_non_public_method) + klass = Class.new do + def protected_method; end + protected :protected_method + end + test_result = run_as_test do + klass.any_instance.stubs(:protected_method) + end + assert_failed(test_result) + assert test_result.error_messages.include?("Mocha::StubbingError: stubbing non-public method: #{klass.any_instance}.protected_method") + end + + def test_should_default_to_allow_stubbing_private_any_instance_method + klass = Class.new do + def private_method; end + private :private_method + end + test_result = run_as_test do + klass.any_instance.stubs(:private_method) + end + assert_passed(test_result) + assert !@logger.warnings.include?("stubbing non-public method: #{klass.any_instance}.private_method") + end + + def test_should_default_to_allow_stubbing_protected_any_instance_method + klass = Class.new do + def protected_method; end + protected :protected_method + end + test_result = run_as_test do + klass.any_instance.stubs(:protected_method) + end + assert_passed(test_result) + assert !@logger.warnings.include?("stubbing non-public method: #{klass.any_instance}.protected_method") + end + + def test_should_allow_stubbing_public_any_instance_method + Mocha::Configuration.prevent(:stubbing_non_public_method) + klass = Class.new do + def public_method; end + public :public_method + end + test_result = run_as_test do + klass.any_instance.stubs(:public_method) + end + assert_passed(test_result) + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stubbing_non_public_class_method_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stubbing_non_public_class_method_test.rb new file mode 100644 index 0000000..923f930 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stubbing_non_public_class_method_test.rb @@ -0,0 +1,163 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' + +class StubbingNonPublicClassMethodTest < Test::Unit::TestCase + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_allow_stubbing_private_class_method + Mocha::Configuration.allow(:stubbing_non_public_method) + klass = Class.new do + class << self + def private_method; end + private :private_method + end + end + test_result = run_as_test do + klass.stubs(:private_method) + end + assert_passed(test_result) + assert !@logger.warnings.include?("stubbing non-public method: #{klass}.private_method") + end + + def test_should_allow_stubbing_protected_class_method + Mocha::Configuration.allow(:stubbing_non_public_method) + klass = Class.new do + class << self + def protected_method; end + protected :protected_method + end + end + test_result = run_as_test do + klass.stubs(:protected_method) + end + assert_passed(test_result) + assert !@logger.warnings.include?("stubbing non-public method: #{klass}.protected_method") + end + + def test_should_warn_when_stubbing_private_class_method + Mocha::Configuration.warn_when(:stubbing_non_public_method) + klass = Class.new do + class << self + def private_method; end + private :private_method + end + end + test_result = run_as_test do + klass.stubs(:private_method) + end + assert_passed(test_result) + assert @logger.warnings.include?("stubbing non-public method: #{klass}.private_method") + end + + def test_should_warn_when_stubbing_protected_class_method + Mocha::Configuration.warn_when(:stubbing_non_public_method) + klass = Class.new do + class << self + def protected_method; end + protected :protected_method + end + end + test_result = run_as_test do + klass.stubs(:protected_method) + end + assert_passed(test_result) + assert @logger.warnings.include?("stubbing non-public method: #{klass}.protected_method") + end + + def test_should_prevent_stubbing_private_class_method + Mocha::Configuration.prevent(:stubbing_non_public_method) + klass = Class.new do + class << self + def private_method; end + private :private_method + end + end + test_result = run_as_test do + klass.stubs(:private_method) + end + assert_failed(test_result) + assert test_result.error_messages.include?("Mocha::StubbingError: stubbing non-public method: #{klass}.private_method") + end + + def test_should_prevent_stubbing_protected_class_method + Mocha::Configuration.prevent(:stubbing_non_public_method) + klass = Class.new do + class << self + def protected_method; end + protected :protected_method + end + end + test_result = run_as_test do + klass.stubs(:protected_method) + end + assert_failed(test_result) + assert test_result.error_messages.include?("Mocha::StubbingError: stubbing non-public method: #{klass}.protected_method") + end + + def test_should_default_to_allow_stubbing_private_class_method + klass = Class.new do + class << self + def private_method; end + private :private_method + end + end + test_result = run_as_test do + klass.stubs(:private_method) + end + assert_passed(test_result) + assert !@logger.warnings.include?("stubbing non-public method: #{klass}.private_method") + end + + def test_should_default_to_allow_stubbing_protected_class_method + klass = Class.new do + class << self + def protected_method; end + protected :protected_method + end + end + test_result = run_as_test do + klass.stubs(:protected_method) + end + assert_passed(test_result) + assert !@logger.warnings.include?("stubbing non-public method: #{klass}.protected_method") + end + + def test_should_allow_stubbing_public_class_method + Mocha::Configuration.prevent(:stubbing_non_public_method) + klass = Class.new do + class << self + def public_method; end + public :public_method + end + end + test_result = run_as_test do + klass.stubs(:public_method) + end + assert_passed(test_result) + end + + def test_should_allow_stubbing_method_to_which_class_responds + Mocha::Configuration.prevent(:stubbing_non_public_method) + klass = Class.new do + class << self + def respond_to?(method, include_private_methods = false) + (method == :method_to_which_class_responds) + end + end + end + test_result = run_as_test do + klass.stubs(:method_to_which_class_responds) + end + assert_passed(test_result) + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stubbing_non_public_instance_method_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stubbing_non_public_instance_method_test.rb new file mode 100644 index 0000000..823c9a0 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stubbing_non_public_instance_method_test.rb @@ -0,0 +1,143 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' + +class StubbingNonPublicInstanceMethodTest < Test::Unit::TestCase + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_allow_stubbing_private_instance_method + Mocha::Configuration.allow(:stubbing_non_public_method) + instance = Class.new do + def private_method; end + private :private_method + end.new + test_result = run_as_test do + instance.stubs(:private_method) + end + assert_passed(test_result) + assert !@logger.warnings.include?("stubbing non-public method: #{instance}.private_method") + end + + def test_should_allow_stubbing_protected_instance_method + Mocha::Configuration.allow(:stubbing_non_public_method) + instance = Class.new do + def protected_method; end + protected :protected_method + end.new + test_result = run_as_test do + instance.stubs(:protected_method) + end + assert_passed(test_result) + assert !@logger.warnings.include?("stubbing non-public method: #{instance}.protected_method") + end + + def test_should_warn_when_stubbing_private_instance_method + Mocha::Configuration.warn_when(:stubbing_non_public_method) + instance = Class.new do + def private_method; end + private :private_method + end.new + test_result = run_as_test do + instance.stubs(:private_method) + end + assert_passed(test_result) + assert @logger.warnings.include?("stubbing non-public method: #{instance}.private_method") + end + + def test_should_warn_when_stubbing_protected_instance_method + Mocha::Configuration.warn_when(:stubbing_non_public_method) + instance = Class.new do + def protected_method; end + protected :protected_method + end.new + test_result = run_as_test do + instance.stubs(:protected_method) + end + assert_passed(test_result) + assert @logger.warnings.include?("stubbing non-public method: #{instance}.protected_method") + end + + def test_should_prevent_stubbing_private_instance_method + Mocha::Configuration.prevent(:stubbing_non_public_method) + instance = Class.new do + def private_method; end + private :private_method + end.new + test_result = run_as_test do + instance.stubs(:private_method) + end + assert_failed(test_result) + assert test_result.error_messages.include?("Mocha::StubbingError: stubbing non-public method: #{instance}.private_method") + end + + def test_should_prevent_stubbing_protected_instance_method + Mocha::Configuration.prevent(:stubbing_non_public_method) + instance = Class.new do + def protected_method; end + protected :protected_method + end.new + test_result = run_as_test do + instance.stubs(:protected_method) + end + assert_failed(test_result) + assert test_result.error_messages.include?("Mocha::StubbingError: stubbing non-public method: #{instance}.protected_method") + end + + def test_should_default_to_allow_stubbing_private_instance_method + instance = Class.new do + def private_method; end + private :private_method + end.new + test_result = run_as_test do + instance.stubs(:private_method) + end + assert_passed(test_result) + assert !@logger.warnings.include?("stubbing non-public method: #{instance}.private_method") + end + + def test_should_default_to_allow_stubbing_protected_instance_method + instance = Class.new do + def protected_method; end + protected :protected_method + end.new + test_result = run_as_test do + instance.stubs(:protected_method) + end + assert_passed(test_result) + assert !@logger.warnings.include?("stubbing non-public method: #{instance}.protected_method") + end + + def test_should_allow_stubbing_public_instance_method + Mocha::Configuration.prevent(:stubbing_non_public_method) + instance = Class.new do + def public_method; end + public :public_method + end.new + test_result = run_as_test do + instance.stubs(:public_method) + end + assert_passed(test_result) + end + + def test_should_allow_stubbing_method_to_which_instance_responds + Mocha::Configuration.prevent(:stubbing_non_public_method) + instance = Class.new do + def respond_to?(method, include_private_methods = false) + (method == :method_to_which_instance_responds) + end + end.new + test_result = run_as_test do + instance.stubs(:method_to_which_instance_responds) + end + assert_passed(test_result) + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stubbing_on_non_mock_object_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stubbing_on_non_mock_object_test.rb new file mode 100644 index 0000000..216f539 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/stubbing_on_non_mock_object_test.rb @@ -0,0 +1,64 @@ +require File.join(File.dirname(__FILE__), "acceptance_test_helper") +require 'mocha' + +class StubbingOnNonMockObjectTest < Test::Unit::TestCase + + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_should_allow_stubbing_method_on_non_mock_object + Mocha::Configuration.allow(:stubbing_method_on_non_mock_object) + non_mock_object = Class.new { def existing_method; end } + test_result = run_as_test do + non_mock_object.stubs(:existing_method) + end + assert_passed(test_result) + assert !@logger.warnings.include?("stubbing method on non-mock object: #{non_mock_object}.existing_method") + end + + def test_should_warn_on_stubbing_method_on_non_mock_object + Mocha::Configuration.warn_when(:stubbing_method_on_non_mock_object) + non_mock_object = Class.new { def existing_method; end } + test_result = run_as_test do + non_mock_object.stubs(:existing_method) + end + assert_passed(test_result) + assert @logger.warnings.include?("stubbing method on non-mock object: #{non_mock_object}.existing_method") + end + + def test_should_prevent_stubbing_method_on_non_mock_object + Mocha::Configuration.prevent(:stubbing_method_on_non_mock_object) + non_mock_object = Class.new { def existing_method; end } + test_result = run_as_test do + non_mock_object.stubs(:existing_method) + end + assert_failed(test_result) + assert test_result.error_messages.include?("Mocha::StubbingError: stubbing method on non-mock object: #{non_mock_object}.existing_method") + end + + def test_should_default_to_allow_stubbing_method_on_non_mock_object + non_mock_object = Class.new { def existing_method; end } + test_result = run_as_test do + non_mock_object.stubs(:existing_method) + end + assert_passed(test_result) + assert !@logger.warnings.include?("stubbing method on non-mock object: #{non_mock_object}.existing_method") + end + + def test_should_allow_stubbing_method_on_mock_object + Mocha::Configuration.prevent(:stubbing_method_on_non_mock_object) + test_result = run_as_test do + mock = mock('mock') + mock.stubs(:any_method) + end + assert_passed(test_result) + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/deprecation_disabler.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/deprecation_disabler.rb new file mode 100644 index 0000000..c57fb3c --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/deprecation_disabler.rb @@ -0,0 +1,15 @@ +require 'mocha/deprecation' + +module DeprecationDisabler + + def disable_deprecations + original_mode = Mocha::Deprecation.mode + Mocha::Deprecation.mode = :disabled + begin + yield + ensure + Mocha::Deprecation.mode = original_mode + end + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/execution_point.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/execution_point.rb new file mode 100644 index 0000000..5824d2a --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/execution_point.rb @@ -0,0 +1,36 @@ +class ExecutionPoint + + attr_reader :backtrace + + def self.current + new(caller) + end + + def initialize(backtrace) + @backtrace = backtrace + end + + def file_name + return "unknown" unless @backtrace && @backtrace.first + /\A(.*?):\d+/.match(@backtrace.first)[1] + end + + def line_number + return "unknown" unless @backtrace && @backtrace.first + Integer(/\A.*?:(\d+)/.match(@backtrace.first)[1]) + end + + def ==(other) + return false unless other.is_a?(ExecutionPoint) + (file_name == other.file_name) and (line_number == other.line_number) + end + + def to_s + "file: #{file_name}; line: #{line_number}" + end + + def inspect + to_s + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/matcher_helpers.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/matcher_helpers.rb new file mode 100644 index 0000000..b9b12a0 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/matcher_helpers.rb @@ -0,0 +1,5 @@ +class Test::Unit::TestCase + def assert_matcher_accepts(matcher, instance) + assert matcher.matches?(instance), matcher.failure_message + end +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/method_definer.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/method_definer.rb new file mode 100644 index 0000000..816aa49 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/method_definer.rb @@ -0,0 +1,24 @@ +require 'mocha/metaclass' + +module Mocha + + module ObjectMethods + def define_instance_method(method_symbol, &block) + __metaclass__.send(:define_method, method_symbol, block) + end + + def replace_instance_method(method_symbol, &block) + raise "Cannot replace #{method_symbol} as #{self} does not respond to it." unless self.respond_to?(method_symbol) + define_instance_method(method_symbol, &block) + end + + def define_instance_accessor(*symbols) + symbols.each { |symbol| __metaclass__.send(:attr_accessor, symbol) } + end + end + +end + +class Object + include Mocha::ObjectMethods +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/simple_counter.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/simple_counter.rb new file mode 100644 index 0000000..a7b5b37 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/simple_counter.rb @@ -0,0 +1,13 @@ +class SimpleCounter + + attr_reader :count + + def initialize + @count = 0 + end + + def increment + @count += 1 + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/test_helper.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/test_helper.rb new file mode 100644 index 0000000..bbfd258 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/test_helper.rb @@ -0,0 +1,16 @@ +unless defined?(STANDARD_OBJECT_PUBLIC_INSTANCE_METHODS) + STANDARD_OBJECT_PUBLIC_INSTANCE_METHODS = Object.public_instance_methods +end + +$:.unshift File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")) +$:.unshift File.expand_path(File.join(File.dirname(__FILE__))) +$:.unshift File.expand_path(File.join(File.dirname(__FILE__), 'unit')) +$:.unshift File.expand_path(File.join(File.dirname(__FILE__), 'unit', 'parameter_matchers')) +$:.unshift File.expand_path(File.join(File.dirname(__FILE__), 'acceptance')) + +if ENV['MOCHA_OPTIONS'] == 'use_test_unit_gem' + gem 'test-unit' +end + +require 'test/unit' + diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/test_runner.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/test_runner.rb new file mode 100644 index 0000000..a818cda --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/test_runner.rb @@ -0,0 +1,33 @@ +require 'test/unit/testresult' +require 'test/unit/testcase' + +module TestRunner + + def run_as_test(test_result = Test::Unit::TestResult.new, &block) + test_class = Class.new(Test::Unit::TestCase) do + define_method(:test_me, &block) + end + test = test_class.new(:test_me) + test.run(test_result) {} + class << test_result + attr_reader :failures, :errors + def failure_messages + failures.map { |failure| failure.message } + end + def error_messages + errors.map { |error| error.message } + end + end + test_result + end + + def assert_passed(test_result) + flunk "Test failed unexpectedly with message: #{test_result.failures}" if test_result.failure_count > 0 + flunk "Test failed unexpectedly with message: #{test_result.errors}" if test_result.error_count > 0 + end + + def assert_failed(test_result) + flunk "Test passed unexpectedly" if test_result.passed? + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/any_instance_method_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/any_instance_method_test.rb new file mode 100644 index 0000000..1bf4d2a --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/any_instance_method_test.rb @@ -0,0 +1,126 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") +require 'method_definer' +require 'mocha/mock' +require 'mocha/any_instance_method' + +class AnyInstanceMethodTest < Test::Unit::TestCase + + include Mocha + + def test_should_hide_original_method + klass = Class.new { def method_x; end } + method = AnyInstanceMethod.new(klass, :method_x) + hidden_method_x = method.hidden_method.to_sym + + method.hide_original_method + + assert klass.method_defined?(hidden_method_x) + end + + def test_should_not_hide_original_method_if_it_is_not_defined + klass = Class.new + method = AnyInstanceMethod.new(klass, :method_x) + hidden_method_x = method.hidden_method.to_sym + + method.hide_original_method + + assert_equal false, klass.method_defined?(hidden_method_x) + end + + def test_should_define_a_new_method + klass = Class.new { def method_x; end } + method = AnyInstanceMethod.new(klass, :method_x) + mocha = Mock.new + mocha.expects(:method_x).with(:param1, :param2).returns(:result) + any_instance = Object.new + any_instance.define_instance_method(:mocha) { mocha } + klass.define_instance_method(:any_instance) { any_instance } + + method.hide_original_method + method.define_new_method + + instance = klass.new + result = instance.method_x(:param1, :param2) + + assert_equal :result, result + assert mocha.__verified__? + end + + def test_should_restore_original_method + klass = Class.new { def method_x; end } + method = AnyInstanceMethod.new(klass, :method_x) + hidden_method_x = method.hidden_method.to_sym + klass.send(:define_method, hidden_method_x, Proc.new { :original_result }) + + method.remove_new_method + method.restore_original_method + + instance = klass.new + assert_equal :original_result, instance.method_x + assert !klass.method_defined?(hidden_method_x) + end + + def test_should_not_restore_original_method_if_hidden_method_not_defined + klass = Class.new { def method_x; :new_result; end } + method = AnyInstanceMethod.new(klass, :method_x) + + method.restore_original_method + + instance = klass.new + assert_equal :new_result, instance.method_x + end + + def test_should_call_remove_new_method + klass = Class.new { def method_x; end } + any_instance = Mock.new + any_instance.stubs(:reset_mocha) + klass.define_instance_method(:any_instance) { any_instance } + method = AnyInstanceMethod.new(klass, :method_x) + method.replace_instance_method(:restore_original_method) { } + method.define_instance_accessor(:remove_called) + method.replace_instance_method(:remove_new_method) { self.remove_called = true } + + method.unstub + + assert method.remove_called + end + + def test_should_call_restore_original_method + klass = Class.new { def method_x; end } + any_instance = Mock.new + any_instance.stubs(:reset_mocha) + klass.define_instance_method(:any_instance) { any_instance } + method = AnyInstanceMethod.new(klass, :method_x) + method.replace_instance_method(:remove_new_method) { } + method.define_instance_accessor(:restore_called) + method.replace_instance_method(:restore_original_method) { self.restore_called = true } + + method.unstub + + assert method.restore_called + end + + def test_should_call_reset_mocha + klass = Class.new { def method_x; end } + any_instance = Class.new { attr_accessor :mocha_was_reset; def reset_mocha; self.mocha_was_reset = true; end }.new + klass.define_instance_method(:any_instance) { any_instance } + method = AnyInstanceMethod.new(klass, :method_x) + method.replace_instance_method(:remove_new_method) { } + method.replace_instance_method(:restore_original_method) { } + + method.unstub + + assert any_instance.mocha_was_reset + end + + def test_should_return_any_instance_mocha_for_stubbee + mocha = Object.new + any_instance = Object.new + any_instance.define_instance_method(:mocha) { mocha } + stubbee = Class.new + stubbee.define_instance_method(:any_instance) { any_instance } + method = AnyInstanceMethod.new(stubbee, :method_name) + assert_equal stubbee.any_instance.mocha, method.mock + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/array_inspect_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/array_inspect_test.rb new file mode 100644 index 0000000..8e555cd --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/array_inspect_test.rb @@ -0,0 +1,16 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") +require 'mocha/inspect' + +class ArrayInspectTest < Test::Unit::TestCase + + def test_should_use_inspect + array = [1, 2] + assert_equal array.inspect, array.mocha_inspect + end + + def test_should_use_mocha_inspect_on_each_item + array = [1, 2, "chris"] + assert_equal "[1, 2, 'chris']", array.mocha_inspect + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/assert_received_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/assert_received_test.rb new file mode 100644 index 0000000..167bb8c --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/assert_received_test.rb @@ -0,0 +1,145 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") +require 'test_runner' +require 'mocha/api' +require 'mocha/mockery' +require 'mocha/object' + +class AssertReceivedTest < Test::Unit::TestCase + + include Mocha + include TestRunner + include Mocha::API + + def teardown + Mockery.reset_instance + end + + class FakeMock + def initialize(name) + @name = name + end + + def inspect + @name + end + + def mocha + self + end + end + + def test_passes_if_invocation_exists + method = :a_method + mock = FakeMock.new('a mock') + Mockery.instance.invocation(mock, method, []) + assert_passes do + assert_received(mock, method) + end + end + + def test_fails_if_invocation_doesnt_exist + method = :a_method + mock = FakeMock.new('a mock') + assert_fails do + assert_received(mock, method) + end + end + + def test_fails_if_invocation_exists_with_different_arguments + method = :a_method + mock = FakeMock.new('a mock') + Mockery.instance.invocation(mock, method, [2, 1]) + assert_fails do + assert_received(mock, method) {|expect| expect.with(1, 2) } + end + end + + def test_passes_if_invocation_exists_with_wildcard_arguments + method = :a_method + mock = FakeMock.new('a mock') + Mockery.instance.invocation(mock, method, ['hello']) + assert_passes do + assert_received(mock, method) {|expect| expect.with(is_a(String)) } + end + end + + def test_passes_if_invocation_exists_with_exact_arguments + method = :a_method + mock = FakeMock.new('a mock') + Mockery.instance.invocation(mock, method, ['hello']) + assert_passes do + assert_received(mock, method) {|expect| expect.with('hello') } + end + end + + def test_fails_if_invocation_exists_only_on_other_mock + method = :a_method + mock = FakeMock.new('a mock') + other = 'another mock' + Mockery.instance.invocation(other, method, ['hello']) + assert_fails do + assert_received(mock, method) + end + end + + def test_passes_if_invocation_exists_for_impersonating_mock + method = :a_method + object = Object.new + mock = FakeMock.new('a mock') + + class << object + attr_accessor :mocha + end + object.mocha = mock + + Mockery.instance.invocation(mock, method, ['hello']) + assert_passes do + assert_received(object, method) {|expect| expect.with('hello') } + end + end + + def test_passes_if_invocation_count_correct + method = :a_method + mock = FakeMock.new('a mock') + 2.times { Mockery.instance.invocation(mock, method, []) } + assert_passes do + assert_received(mock, method) {|expect| expect.twice } + end + end + + def test_fails_if_invocation_count_too_low + method = :a_method + mock = FakeMock.new('a mock') + Mockery.instance.invocation(mock, method, []) + assert_fails do + assert_received(mock, method) {|expect| expect.twice } + end + end + + def test_fails_if_invocation_count_too_high + method = :a_method + mock = FakeMock.new('a mock') + 2.times { Mockery.instance.invocation(mock, method, []) } + assert_fails do + assert_received(mock, method) {|expect| expect.once } + end + end + + def assert_passes(&block) + assert ! fails?(&block) + end + + def assert_fails(&block) + assert fails?(&block) + end + + def fails? + begin + yield + false + rescue Test::Unit::AssertionFailedError + true + end + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/backtrace_filter_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/backtrace_filter_test.rb new file mode 100644 index 0000000..6d9379f --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/backtrace_filter_test.rb @@ -0,0 +1,19 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") +require 'mocha/backtrace_filter' + +class BacktraceFilterTest < Test::Unit::TestCase + + include Mocha + + def test_should_exclude_mocha_locations_from_backtrace + mocha_lib = "/username/workspace/mocha_wibble/lib/" + backtrace = [ mocha_lib + 'exclude/me/1', mocha_lib + 'exclude/me/2', '/keep/me', mocha_lib + 'exclude/me/3'] + filter = BacktraceFilter.new(mocha_lib) + assert_equal ['/keep/me'], filter.filtered(backtrace) + end + + def test_should_determine_path_for_mocha_lib_directory + assert_match Regexp.new("/lib/$"), BacktraceFilter::LIB_DIRECTORY + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/cardinality_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/cardinality_test.rb new file mode 100644 index 0000000..2a5ef9b --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/cardinality_test.rb @@ -0,0 +1,56 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") +require 'mocha/cardinality' + +class CardinalityTest < Test::Unit::TestCase + + include Mocha + + def test_should_allow_invocations_if_invocation_count_has_not_yet_reached_maximum + cardinality = Cardinality.new(2, 3) + assert cardinality.invocations_allowed?(0) + assert cardinality.invocations_allowed?(1) + assert cardinality.invocations_allowed?(2) + assert !cardinality.invocations_allowed?(3) + end + + def test_should_be_satisfied_if_invocations_so_far_have_reached_required_threshold + cardinality = Cardinality.new(2, 3) + assert !cardinality.satisfied?(0) + assert !cardinality.satisfied?(1) + assert cardinality.satisfied?(2) + assert cardinality.satisfied?(3) + end + + def test_should_describe_cardinality + assert_equal 'allowed any number of times', Cardinality.at_least(0).mocha_inspect + + assert_equal 'expected at most once', Cardinality.at_most(1).mocha_inspect + assert_equal 'expected at most twice', Cardinality.at_most(2).mocha_inspect + assert_equal 'expected at most 3 times', Cardinality.at_most(3).mocha_inspect + + assert_equal 'expected at least once', Cardinality.at_least(1).mocha_inspect + assert_equal 'expected at least twice', Cardinality.at_least(2).mocha_inspect + assert_equal 'expected at least 3 times', Cardinality.at_least(3).mocha_inspect + + assert_equal 'expected never', Cardinality.exactly(0).mocha_inspect + assert_equal 'expected exactly once', Cardinality.exactly(1).mocha_inspect + assert_equal 'expected exactly twice', Cardinality.exactly(2).mocha_inspect + assert_equal 'expected exactly 3 times', Cardinality.times(3).mocha_inspect + + assert_equal 'expected between 2 and 4 times', Cardinality.times(2..4).mocha_inspect + assert_equal 'expected between 1 and 3 times', Cardinality.times(1..3).mocha_inspect + end + + def test_should_need_verifying + assert Cardinality.exactly(2).needs_verifying? + assert Cardinality.at_least(3).needs_verifying? + assert Cardinality.at_most(2).needs_verifying? + assert Cardinality.times(4).needs_verifying? + assert Cardinality.times(2..4).needs_verifying? + end + + def test_should_not_need_verifying + assert_equal false, Cardinality.at_least(0).needs_verifying? + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/central_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/central_test.rb new file mode 100644 index 0000000..03bff91 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/central_test.rb @@ -0,0 +1,65 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") + +require 'mocha/central' +require 'mocha/mock' +require 'method_definer' + +class CentralTest < Test::Unit::TestCase + + include Mocha + + def test_should_start_with_empty_stubba_methods + stubba = Central.new + + assert_equal [], stubba.stubba_methods + end + + def test_should_stub_method_if_not_already_stubbed + method = Mock.new + method.expects(:stub) + stubba = Central.new + + stubba.stub(method) + + assert method.__verified__? + end + + def test_should_not_stub_method_if_already_stubbed + method = Mock.new + method.expects(:stub).times(0) + stubba = Central.new + stubba_methods = Mock.new + stubba_methods.stubs(:include?).with(method).returns(true) + stubba.stubba_methods = stubba_methods + + stubba.stub(method) + + assert method.__verified__? + end + + def test_should_record_method + method = Mock.new + method.expects(:stub) + stubba = Central.new + + stubba.stub(method) + + assert_equal [method], stubba.stubba_methods + end + + def test_should_unstub_all_methods + stubba = Central.new + method_1 = Mock.new + method_1.expects(:unstub) + method_2 = Mock.new + method_2.expects(:unstub) + stubba.stubba_methods = [method_1, method_2] + + stubba.unstub_all + + assert_equal [], stubba.stubba_methods + assert method_1.__verified__? + assert method_2.__verified__? + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/change_state_side_effect_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/change_state_side_effect_test.rb new file mode 100644 index 0000000..b48beaa --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/change_state_side_effect_test.rb @@ -0,0 +1,41 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") + +require 'mocha/change_state_side_effect' + +class ChangeStateSideEffectTest < Test::Unit::TestCase + + include Mocha + + class FakeState + + attr_reader :active + attr_writer :description + + def activate + @active = true + end + + def mocha_inspect + @description + end + + end + + def test_should_activate_the_given_state + state = FakeState.new + side_effect = ChangeStateSideEffect.new(state) + + side_effect.perform + + assert state.active + end + + def test_should_describe_itself_in_terms_of_the_activated_state + state = FakeState.new + state.description = 'the-new-state' + side_effect = ChangeStateSideEffect.new(state) + + assert_equal 'then the-new-state', side_effect.mocha_inspect + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/class_method_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/class_method_test.rb new file mode 100644 index 0000000..47c5999 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/class_method_test.rb @@ -0,0 +1,237 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") +require 'method_definer' +require 'mocha/mock' + +require 'mocha/class_method' + +class ClassMethodTest < Test::Unit::TestCase + + include Mocha + + def test_should_provide_hidden_version_of_method_name_starting_with_prefix + method = ClassMethod.new(nil, :original_method_name) + assert_match(/^__stubba__/, method.hidden_method.to_s) + end + + def test_should_provide_hidden_version_of_method_name_ending_with_suffix + method = ClassMethod.new(nil, :original_method_name) + assert_match(/__stubba__$/, method.hidden_method.to_s) + end + + def test_should_provide_hidden_version_of_method_name_including_original_method_name + method = ClassMethod.new(nil, :original_method_name) + assert_match(/original_method_name/, method.hidden_method.to_s) + end + + def test_should_provide_hidden_version_of_method_name_substituting_question_mark + method = ClassMethod.new(nil, :question_mark?) + assert_no_match(/\?/, method.hidden_method.to_s) + assert_match(/question_mark_substituted_character_63/, method.hidden_method.to_s) + end + + def test_should_provide_hidden_version_of_method_name_substituting_exclamation_mark + method = ClassMethod.new(nil, :exclamation_mark!) + assert_no_match(/!/, method.hidden_method.to_s) + assert_match(/exclamation_mark_substituted_character_33/, method.hidden_method.to_s) + end + + def test_should_provide_hidden_version_of_method_name_substituting_equals_sign + method = ClassMethod.new(nil, :equals_sign=) + assert_no_match(/\=/, method.hidden_method.to_s) + assert_match(/equals_sign_substituted_character_61/, method.hidden_method.to_s) + end + + def test_should_provide_hidden_version_of_method_name_substituting_brackets + method = ClassMethod.new(nil, :[]) + assert_no_match(/\[\]/, method.hidden_method.to_s) + assert_match(/substituted_character_91__substituted_character_93/, method.hidden_method.to_s) + end + + def test_should_provide_hidden_version_of_method_name_substituting_plus_sign + method = ClassMethod.new(nil, :+) + assert_no_match(/\+/, method.hidden_method.to_s) + assert_match(/substituted_character_43/, method.hidden_method.to_s) + end + + def test_should_hide_original_method + klass = Class.new { def self.method_x; end } + method = ClassMethod.new(klass, :method_x) + hidden_method_x = method.hidden_method + + method.hide_original_method + + assert klass.respond_to?(hidden_method_x) + end + + def test_should_respond_to_original_method_name_after_original_method_has_been_hidden + klass = Class.new { def self.original_method_name; end } + method = ClassMethod.new(klass, :original_method_name) + hidden_method_x = method.hidden_method + + method.hide_original_method + + assert klass.respond_to?(:original_method_name) + end + + def test_should_not_hide_original_method_if_method_not_defined + klass = Class.new + method = ClassMethod.new(klass, :method_x) + hidden_method_x = method.hidden_method + + method.hide_original_method + + assert_equal false, klass.respond_to?(hidden_method_x) + end + + def test_should_define_a_new_method_which_should_call_mocha_method_missing + klass = Class.new { def self.method_x; end } + mocha = Mocha::Mock.new + klass.define_instance_method(:mocha) { mocha } + mocha.expects(:method_x).with(:param1, :param2).returns(:result) + method = ClassMethod.new(klass, :method_x) + + method.hide_original_method + method.define_new_method + result = klass.method_x(:param1, :param2) + + assert_equal :result, result + assert mocha.__verified__? + end + + def test_should_remove_new_method + klass = Class.new { def self.method_x; end } + method = ClassMethod.new(klass, :method_x) + + method.remove_new_method + + assert_equal false, klass.respond_to?(:method_x) + end + + def test_should_restore_original_method + klass = Class.new { def self.method_x; end } + method = ClassMethod.new(klass, :method_x) + hidden_method_x = method.hidden_method.to_sym + klass.define_instance_method(hidden_method_x) { :original_result } + + method.remove_new_method + method.restore_original_method + + assert_equal :original_result, klass.method_x + assert_equal false, klass.respond_to?(hidden_method_x) + end + + def test_should_not_restore_original_method_if_hidden_method_is_not_defined + klass = Class.new { def self.method_x; :new_result; end } + method = ClassMethod.new(klass, :method_x) + + method.restore_original_method + + assert_equal :new_result, klass.method_x + end + + def test_should_call_hide_original_method + klass = Class.new { def self.method_x; end } + method = ClassMethod.new(klass, :method_x) + method.hide_original_method + method.define_instance_accessor(:hide_called) + method.replace_instance_method(:hide_original_method) { self.hide_called = true } + + method.stub + + assert method.hide_called + end + + def test_should_call_define_new_method + klass = Class.new { def self.method_x; end } + method = ClassMethod.new(klass, :method_x) + method.define_instance_accessor(:define_called) + method.replace_instance_method(:define_new_method) { self.define_called = true } + + method.stub + + assert method.define_called + end + + def test_should_call_remove_new_method + klass = Class.new { def self.method_x; end } + klass.define_instance_method(:reset_mocha) { } + method = ClassMethod.new(klass, :method_x) + method.define_instance_accessor(:remove_called) + method.replace_instance_method(:remove_new_method) { self.remove_called = true } + + method.unstub + + assert method.remove_called + end + + def test_should_call_restore_original_method + klass = Class.new { def self.method_x; end } + klass.define_instance_method(:reset_mocha) { } + method = ClassMethod.new(klass, :method_x) + method.define_instance_accessor(:restore_called) + method.replace_instance_method(:restore_original_method) { self.restore_called = true } + + method.unstub + + assert method.restore_called + end + + def test_should_call_reset_mocha + klass = Class.new { def self.method_x; end } + klass.define_instance_accessor(:reset_called) + klass.define_instance_method(:reset_mocha) { self.reset_called = true } + method = ClassMethod.new(klass, :method_x) + method.replace_instance_method(:restore_original_method) { } + + method.unstub + + assert klass.reset_called + end + + def test_should_return_mock_for_stubbee + mocha = Object.new + stubbee = Object.new + stubbee.define_instance_accessor(:mocha) { mocha } + stubbee.mocha = nil + method = ClassMethod.new(stubbee, :method_name) + assert_equal stubbee.mocha, method.mock + end + + def test_should_not_be_equal_if_other_object_has_a_different_class + class_method = ClassMethod.new(Object.new, :method) + other_object = Object.new + assert class_method != other_object + end + + def test_should_not_be_equal_if_other_class_method_has_different_stubbee + stubbee_1 = Object.new + stubbee_2 = Object.new + class_method_1 = ClassMethod.new(stubbee_1, :method) + class_method_2 = ClassMethod.new(stubbee_2, :method) + assert class_method_1 != class_method_2 + end + + def test_should_not_be_equal_if_other_class_method_has_different_method + stubbee = Object.new + class_method_1 = ClassMethod.new(stubbee, :method_1) + class_method_2 = ClassMethod.new(stubbee, :method_2) + assert class_method_1 != class_method_2 + end + + def test_should_be_equal_if_other_class_method_has_same_stubbee_and_same_method_so_no_attempt_is_made_to_stub_a_method_twice + stubbee = Object.new + class_method_1 = ClassMethod.new(stubbee, :method) + class_method_2 = ClassMethod.new(stubbee, :method) + assert class_method_1 == class_method_2 + end + + def test_should_be_equal_if_other_class_method_has_same_stubbee_and_same_method_but_stubbee_equal_method_lies_like_active_record_association_proxy + stubbee = Class.new do + def equal?(other); false; end + end.new + class_method_1 = ClassMethod.new(stubbee, :method) + class_method_2 = ClassMethod.new(stubbee, :method) + assert class_method_1 == class_method_2 + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/date_time_inspect_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/date_time_inspect_test.rb new file mode 100644 index 0000000..8557365 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/date_time_inspect_test.rb @@ -0,0 +1,21 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") +require 'mocha/inspect' + +class DateTimeInspectTest < Test::Unit::TestCase + + def test_should_use_include_date_in_seconds + time = Time.now + assert_equal "#{time.inspect} (#{time.to_f} secs)", time.mocha_inspect + end + + def test_should_use_to_s_for_date + date = Date.new(2006, 1, 1) + assert_equal date.to_s, date.mocha_inspect + end + + def test_should_use_to_s_for_datetime + datetime = DateTime.new(2006, 1, 1) + assert_equal datetime.to_s, datetime.mocha_inspect + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/exception_raiser_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/exception_raiser_test.rb new file mode 100644 index 0000000..942300a --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/exception_raiser_test.rb @@ -0,0 +1,42 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") + +require 'mocha/exception_raiser' +require 'timeout' + +class ExceptionRaiserTest < Test::Unit::TestCase + + include Mocha + + def test_should_raise_exception_with_specified_class_and_default_message + exception_class = Class.new(StandardError) + raiser = ExceptionRaiser.new(exception_class, nil) + exception = assert_raises(exception_class) { raiser.evaluate } + assert_equal exception_class.to_s, exception.message + end + + def test_should_raise_exception_with_specified_class_and_message + exception_class = Class.new(StandardError) + raiser = ExceptionRaiser.new(exception_class, 'message') + exception = assert_raises(exception_class) { raiser.evaluate } + assert_equal 'message', exception.message + end + + def test_should_raise_exception_instance + exception_class = Class.new(StandardError) + raiser = ExceptionRaiser.new(exception_class.new('message'), nil) + exception = assert_raises(exception_class) { raiser.evaluate } + assert_equal 'message', exception.message + end + + def test_should_raise_interrupt_exception_with_default_message_so_it_works_in_ruby_1_8_6 + raiser = ExceptionRaiser.new(Interrupt, nil) + assert_raises(Interrupt) { raiser.evaluate } + end + + def test_should_raise_subclass_of_interrupt_exception_with_default_message_so_it_works_in_ruby_1_8_6 + exception_class = Class.new(Interrupt) + raiser = ExceptionRaiser.new(exception_class, nil) + assert_raises(exception_class) { raiser.evaluate } + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/expectation_list_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/expectation_list_test.rb new file mode 100644 index 0000000..bc641c5 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/expectation_list_test.rb @@ -0,0 +1,57 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") +require 'mocha/expectation_list' +require 'mocha/expectation' +require 'set' +require 'method_definer' + +class ExpectationListTest < Test::Unit::TestCase + + include Mocha + + def test_should_return_added_expectation + expectation_list = ExpectationList.new + expectation = Expectation.new(nil, :my_method) + assert_same expectation, expectation_list.add(expectation) + end + + def test_should_find_matching_expectation + expectation_list = ExpectationList.new + expectation1 = Expectation.new(nil, :my_method).with(:argument1, :argument2) + expectation2 = Expectation.new(nil, :my_method).with(:argument3, :argument4) + expectation_list.add(expectation1) + expectation_list.add(expectation2) + assert_same expectation1, expectation_list.match(:my_method, :argument1, :argument2) + end + + def test_should_find_most_recent_matching_expectation + expectation_list = ExpectationList.new + expectation1 = Expectation.new(nil, :my_method).with(:argument1, :argument2) + expectation2 = Expectation.new(nil, :my_method).with(:argument1, :argument2) + expectation_list.add(expectation1) + expectation_list.add(expectation2) + assert_same expectation2, expectation_list.match(:my_method, :argument1, :argument2) + end + + def test_should_find_matching_expectation_allowing_invocation + expectation_list = ExpectationList.new + expectation1 = Expectation.new(nil, :my_method).with(:argument1, :argument2) + expectation2 = Expectation.new(nil, :my_method).with(:argument3, :argument4) + expectation1.define_instance_method(:invocations_allowed?) { true } + expectation2.define_instance_method(:invocations_allowed?) { true } + expectation_list.add(expectation1) + expectation_list.add(expectation2) + assert_same expectation1, expectation_list.match_allowing_invocation(:my_method, :argument1, :argument2) + end + + def test_should_find_most_recent_matching_expectation_allowing_invocation + expectation_list = ExpectationList.new + expectation1 = Expectation.new(nil, :my_method) + expectation2 = Expectation.new(nil, :my_method) + expectation1.define_instance_method(:invocations_allowed?) { true } + expectation2.define_instance_method(:invocations_allowed?) { false } + expectation_list.add(expectation1) + expectation_list.add(expectation2) + assert_same expectation1, expectation_list.match_allowing_invocation(:my_method) + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/expectation_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/expectation_test.rb new file mode 100644 index 0000000..560e00d --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/expectation_test.rb @@ -0,0 +1,526 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") +require 'method_definer' +require 'mocha/expectation' +require 'mocha/sequence' +require 'mocha/mockery' +require 'execution_point' +require 'simple_counter' + +class ExpectationTest < Test::Unit::TestCase + + include Mocha + + class FakeMockery + attr_reader :invocations + + def initialize + @invocations = [] + end + + def invocation(mock, method_name, args) + @invocations << { :mock => mock, :method_name => method_name, :args => args } + end + end + + def setup + Mockery.instance_variable_set('@instance', FakeMockery.new) + end + + def teardown + Mockery.reset_instance + end + + def new_expectation + Expectation.new(nil, :expected_method) + end + + def test_should_match_calls_to_same_method_with_any_parameters + assert new_expectation.match?(:expected_method, 1, 2, 3) + end + + def test_should_match_calls_to_same_method_with_exactly_zero_parameters + expectation = new_expectation.with() + assert expectation.match?(:expected_method) + end + + def test_should_not_match_calls_to_same_method_with_more_than_zero_parameters + expectation = new_expectation.with() + assert !expectation.match?(:expected_method, 1, 2, 3) + end + + def test_should_match_calls_to_same_method_with_expected_parameter_values + expectation = new_expectation.with(1, 2, 3) + assert expectation.match?(:expected_method, 1, 2, 3) + end + + def test_should_match_calls_to_same_method_with_parameters_constrained_as_expected + expectation = new_expectation.with() {|x, y, z| x + y == z} + assert expectation.match?(:expected_method, 1, 2, 3) + end + + def test_should_not_match_calls_to_different_method_with_parameters_constrained_as_expected + expectation = new_expectation.with() {|x, y, z| x + y == z} + assert !expectation.match?(:different_method, 1, 2, 3) + end + + def test_should_not_match_calls_to_different_methods_with_no_parameters + assert !new_expectation.match?(:unexpected_method) + end + + def test_should_not_match_calls_to_same_method_with_too_few_parameters + expectation = new_expectation.with(1, 2, 3) + assert !expectation.match?(:unexpected_method, 1, 2) + end + + def test_should_not_match_calls_to_same_method_with_too_many_parameters + expectation = new_expectation.with(1, 2) + assert !expectation.match?(:unexpected_method, 1, 2, 3) + end + + def test_should_not_match_calls_to_same_method_with_unexpected_parameter_values + expectation = new_expectation.with(1, 2, 3) + assert !expectation.match?(:unexpected_method, 1, 0, 3) + end + + def test_should_not_match_calls_to_same_method_with_parameters_not_constrained_as_expected + expectation = new_expectation.with() {|x, y, z| x + y == z} + assert !expectation.match?(:expected_method, 1, 0, 3) + end + + def test_should_allow_invocations_until_expected_invocation_count_is_one_and_actual_invocation_count_would_be_two + expectation = new_expectation.times(1) + assert expectation.invocations_allowed? + expectation.invoke([]) + assert !expectation.invocations_allowed? + end + + def test_should_allow_invocations_until_expected_invocation_count_is_two_and_actual_invocation_count_would_be_three + expectation = new_expectation.times(2) + assert expectation.invocations_allowed? + expectation.invoke([]) + assert expectation.invocations_allowed? + expectation.invoke([]) + assert !expectation.invocations_allowed? + end + + def test_should_allow_invocations_until_expected_invocation_count_is_a_range_from_two_to_three_and_actual_invocation_count_would_be_four + expectation = new_expectation.times(2..3) + assert expectation.invocations_allowed? + expectation.invoke([]) + assert expectation.invocations_allowed? + expectation.invoke([]) + assert expectation.invocations_allowed? + expectation.invoke([]) + assert !expectation.invocations_allowed? + end + + def test_should_store_provided_backtrace + backtrace = Object.new + expectation = Expectation.new(nil, :expected_method, backtrace) + assert_equal backtrace, expectation.backtrace + end + + def test_should_default_backtrace_to_caller + execution_point = ExecutionPoint.current; expectation = Expectation.new(nil, :expected_method) + assert_equal execution_point, ExecutionPoint.new(expectation.backtrace) + end + + def test_should_not_yield + yielded = false + new_expectation.invoke([]) { yielded = true } + assert_equal false, yielded + end + + def test_should_yield_no_parameters + expectation = new_expectation().yields() + yielded_parameters = nil + expectation.invoke([]) { |*parameters| yielded_parameters = parameters } + assert_equal Array.new, yielded_parameters + end + + def test_should_yield_with_specified_parameters + expectation = new_expectation().yields(1, 2, 3) + yielded_parameters = nil + expectation.invoke([]) { |*parameters| yielded_parameters = parameters } + assert_equal [1, 2, 3], yielded_parameters + end + + def test_should_yield_different_parameters_on_consecutive_invocations + expectation = new_expectation().yields(1, 2, 3).yields(4, 5) + yielded_parameters = [] + expectation.invoke([]) { |*parameters| yielded_parameters << parameters } + expectation.invoke([]) { |*parameters| yielded_parameters << parameters } + assert_equal [[1, 2, 3], [4, 5]], yielded_parameters + end + + def test_should_yield_multiple_times_for_single_invocation + expectation = new_expectation().multiple_yields([1, 2, 3], [4, 5]) + yielded_parameters = [] + expectation.invoke([]) { |*parameters| yielded_parameters << parameters } + assert_equal [[1, 2, 3], [4, 5]], yielded_parameters + end + + def test_should_yield_multiple_times_for_first_invocation_and_once_for_second_invocation + expectation = new_expectation().multiple_yields([1, 2, 3], [4, 5]).then.yields(6, 7) + yielded_parameters = [] + expectation.invoke([]) { |*parameters| yielded_parameters << parameters } + expectation.invoke([]) { |*parameters| yielded_parameters << parameters } + assert_equal [[1, 2, 3], [4, 5], [6, 7]], yielded_parameters + end + + def test_should_return_specified_value + expectation = new_expectation.returns(99) + assert_equal 99, expectation.invoke([]) + end + + def test_should_return_same_specified_value_multiple_times + expectation = new_expectation.returns(99) + assert_equal 99, expectation.invoke([]) + assert_equal 99, expectation.invoke([]) + end + + def test_should_return_specified_values_on_consecutive_calls + expectation = new_expectation.returns(99, 100, 101) + assert_equal 99, expectation.invoke([]) + assert_equal 100, expectation.invoke([]) + assert_equal 101, expectation.invoke([]) + end + + def test_should_return_specified_values_on_consecutive_calls_even_if_values_are_modified + values = [99, 100, 101] + expectation = new_expectation.returns(*values) + values.shift + assert_equal 99, expectation.invoke([]) + assert_equal 100, expectation.invoke([]) + assert_equal 101, expectation.invoke([]) + end + + def test_should_return_nil_by_default + assert_nil new_expectation.invoke([]) + end + + def test_should_return_nil_if_no_value_specified + expectation = new_expectation.returns() + assert_nil expectation.invoke([]) + end + + def test_should_raise_runtime_exception + expectation = new_expectation.raises + assert_raise(RuntimeError) { expectation.invoke([]) } + end + + def test_should_raise_custom_exception + exception = Class.new(Exception) + expectation = new_expectation.raises(exception) + assert_raise(exception) { expectation.invoke([]) } + end + + def test_should_raise_same_instance_of_custom_exception + exception_klass = Class.new(StandardError) + expected_exception = exception_klass.new + expectation = new_expectation.raises(expected_exception) + actual_exception = assert_raise(exception_klass) { expectation.invoke([]) } + assert_same expected_exception, actual_exception + end + + def test_should_use_the_default_exception_message + expectation = new_expectation.raises(Exception) + exception = assert_raise(Exception) { expectation.invoke([]) } + assert_equal Exception.new.message, exception.message + end + + def test_should_raise_custom_exception_with_message + exception_msg = "exception message" + expectation = new_expectation.raises(Exception, exception_msg) + exception = assert_raise(Exception) { expectation.invoke([]) } + assert_equal exception_msg, exception.message + end + + def test_should_return_values_then_raise_exception + expectation = new_expectation.returns(1, 2).then.raises() + assert_equal 1, expectation.invoke([]) + assert_equal 2, expectation.invoke([]) + assert_raise(RuntimeError) { expectation.invoke([]) } + end + + def test_should_raise_exception_then_return_values + expectation = new_expectation.raises().then.returns(1, 2) + assert_raise(RuntimeError) { expectation.invoke([]) } + assert_equal 1, expectation.invoke([]) + assert_equal 2, expectation.invoke([]) + end + + def test_should_verify_successfully_if_expected_call_was_made + expectation = new_expectation + expectation.invoke([]) + assert expectation.verified? + end + + def test_should_not_verify_successfully_if_call_expected_once_but_invoked_twice + expectation = new_expectation.once + expectation.invoke([]) + expectation.invoke([]) + assert !expectation.verified? + end + + def test_should_not_verify_successfully_if_call_expected_once_but_not_invoked + expectation = new_expectation.once + assert !expectation.verified? + end + + def test_should_verify_successfully_if_call_expected_once_and_invoked_once + expectation = new_expectation.once + expectation.invoke([]) + assert expectation.verified? + end + + def test_should_not_verify_successfully_if_call_expected_twice_and_invoked_three_times + expectation = new_expectation.twice + expectation.invoke([]) + expectation.invoke([]) + expectation.invoke([]) + assert !expectation.verified? + end + + def test_should_not_verify_successfully_if_call_expected_twice_but_invoked_once + expectation = new_expectation.twice + expectation.invoke([]) + assert !expectation.verified? + end + + def test_should_verify_successfully_if_call_expected_twice_and_invoked_twice + expectation = new_expectation.twice + expectation.invoke([]) + expectation.invoke([]) + assert expectation.verified? + end + + def test_should_verify_successfully_if_expected_call_was_made_at_least_once + expectation = new_expectation.at_least_once + 3.times {expectation.invoke([])} + assert expectation.verified? + end + + def test_should_not_verify_successfully_if_expected_call_was_not_made_at_least_once + expectation = new_expectation.with(1, 2, 3).at_least_once + assert !expectation.verified? + assert_match(/expected at least once, not yet invoked/i, expectation.mocha_inspect) + end + + def test_should_verify_successfully_if_expected_call_was_made_expected_number_of_times + expectation = new_expectation.times(2) + 2.times {expectation.invoke([])} + assert expectation.verified? + end + + def test_should_not_verify_successfully_if_expected_call_was_made_too_few_times + expectation = new_expectation.times(2) + 1.times {expectation.invoke([])} + assert !expectation.verified? + assert_match(/expected exactly twice, already invoked once/i, expectation.mocha_inspect) + end + + def test_should_not_verify_successfully_if_expected_call_was_made_too_many_times + expectation = new_expectation.times(2) + 3.times {expectation.invoke([])} + assert !expectation.verified? + end + + def test_should_increment_assertion_counter_for_expectation_because_it_does_need_verifyng + expectation = new_expectation + expectation.invoke([]) + assertion_counter = SimpleCounter.new + expectation.verified?(assertion_counter) + assert_equal 1, assertion_counter.count + end + + def test_should_not_increment_assertion_counter_for_stub_because_it_does_not_need_verifying + stub = Expectation.new(nil, :expected_method).at_least(0) + assertion_counter = SimpleCounter.new + stub.verified?(assertion_counter) + assert_equal 0, assertion_counter.count + end + + def test_should_store_backtrace_from_point_where_expectation_was_created + execution_point = ExecutionPoint.current; expectation = Expectation.new(nil, :expected_method) + assert_equal execution_point, ExecutionPoint.new(expectation.backtrace) + end + + class FakeMock + + def initialize(name) + @name = name + end + + def mocha_inspect + @name + end + + end + + def test_should_raise_error_with_message_indicating_which_method_was_expected_to_be_called_on_which_mock_object_with_which_parameters_and_in_what_sequences + mock = FakeMock.new('mock') + sequence_one = Sequence.new('one') + sequence_two = Sequence.new('two') + expectation = Expectation.new(mock, :expected_method).with(1, 2, {'a' => true}, {:b => false}, [1, 2, 3]).in_sequence(sequence_one, sequence_two) + assert !expectation.verified? + assert_match "mock.expected_method(1, 2, {'a' => true}, {:b => false}, [1, 2, 3]); in sequence 'one'; in sequence 'two'", expectation.mocha_inspect + end + + class FakeConstraint + + def initialize(allows_invocation_now) + @allows_invocation_now = allows_invocation_now + end + + def allows_invocation_now? + @allows_invocation_now + end + + end + + def test_should_be_in_correct_order_if_all_ordering_constraints_allow_invocation_now + constraint_one = FakeConstraint.new(allows_invocation_now = true) + constraint_two = FakeConstraint.new(allows_invocation_now = true) + expectation = Expectation.new(nil, :method_one) + expectation.add_ordering_constraint(constraint_one) + expectation.add_ordering_constraint(constraint_two) + assert expectation.in_correct_order? + end + + def test_should_not_be_in_correct_order_if_one_ordering_constraint_does_not_allow_invocation_now + constraint_one = FakeConstraint.new(allows_invocation_now = true) + constraint_two = FakeConstraint.new(allows_invocation_now = false) + expectation = Expectation.new(nil, :method_one) + expectation.add_ordering_constraint(constraint_one) + expectation.add_ordering_constraint(constraint_two) + assert !expectation.in_correct_order? + end + + def test_should_match_if_all_ordering_constraints_allow_invocation_now + constraint_one = FakeConstraint.new(allows_invocation_now = true) + constraint_two = FakeConstraint.new(allows_invocation_now = true) + expectation = Expectation.new(nil, :method_one) + expectation.add_ordering_constraint(constraint_one) + expectation.add_ordering_constraint(constraint_two) + assert expectation.match?(:method_one) + end + + def test_should_not_match_if_one_ordering_constraints_does_not_allow_invocation_now + constraint_one = FakeConstraint.new(allows_invocation_now = true) + constraint_two = FakeConstraint.new(allows_invocation_now = false) + expectation = Expectation.new(nil, :method_one) + expectation.add_ordering_constraint(constraint_one) + expectation.add_ordering_constraint(constraint_two) + assert !expectation.match?(:method_one) + end + + def test_should_not_be_satisfied_when_required_invocation_has_not_been_made + expectation = Expectation.new(nil, :method_one).times(1) + assert !expectation.satisfied? + end + + def test_should_be_satisfied_when_required_invocation_has_been_made + expectation = Expectation.new(nil, :method_one).times(1) + expectation.invoke([]) + assert expectation.satisfied? + end + + def test_should_not_be_satisfied_when_minimum_number_of_invocations_has_not_been_made + expectation = Expectation.new(nil, :method_one).at_least(2) + expectation.invoke([]) + assert !expectation.satisfied? + end + + def test_should_be_satisfied_when_minimum_number_of_invocations_has_been_made + expectation = Expectation.new(nil, :method_one).at_least(2) + 2.times { expectation.invoke([]) } + assert expectation.satisfied? + end + + class FakeSequence + + attr_reader :expectations + + def initialize + @expectations = [] + end + + def constrain_as_next_in_sequence(expectation) + @expectations << expectation + end + + end + + def test_should_tell_sequences_to_constrain_expectation_as_next_in_sequence + sequence_one = FakeSequence.new + sequence_two = FakeSequence.new + expectation = Expectation.new(nil, :method_one) + assert_equal expectation, expectation.in_sequence(sequence_one, sequence_two) + assert_equal [expectation], sequence_one.expectations + assert_equal [expectation], sequence_two.expectations + end + + class FakeState + + def initialize + @active = false + end + + def activate + @active = true + end + + def active? + @active + end + + end + + def test_should_change_state_when_expectation_is_invoked + state = FakeState.new + expectation = Expectation.new(nil, :method_one) + + expectation.then(state) + + expectation.invoke([]) + assert state.active? + end + + def test_should_match_when_state_is_active + state = FakeState.new + expectation = Expectation.new(nil, :method_one) + + expectation.when(state) + assert !expectation.match?(:method_one) + + state.activate + assert expectation.match?(:method_one) + end + + def test_should_record_invocation + Mockery.instance.invocations.clear + + mock = 'a mock' + method = :call_me + args = [1, 2, 3] + expectation = Expectation.new(mock, method) + + expectation.invoke(args) + assert_equal 1, Mockery.instance.invocations.size + invocation = Mockery.instance.invocations.first + assert_equal method, invocation[:method_name], "Got: #{invocation.inspect}" + assert_equal args, invocation[:args], "Got: #{invocation.inspect}" + assert_equal mock, invocation[:mock], "Got: #{invocation.inspect}" + end + + def test_should_expose_invocation_count + expectation = Expectation.new(nil, :a_method) + assert_equal 0, expectation.invocation_count + expectation.invoke(1) + assert_equal 1, expectation.invocation_count + expectation.invocation_count = 3 + assert_equal 3, expectation.invocation_count + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/hash_inspect_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/hash_inspect_test.rb new file mode 100644 index 0000000..15ad415 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/hash_inspect_test.rb @@ -0,0 +1,16 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") +require 'mocha/inspect' + +class HashInspectTest < Test::Unit::TestCase + + def test_should_keep_spacing_between_key_value + hash = {:a => true} + assert_equal '{:a => true}', hash.mocha_inspect + end + + def test_should_use_mocha_inspect_on_each_item + hash = {:a => 'mocha'} + assert_equal "{:a => 'mocha'}", hash.mocha_inspect + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/have_received_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/have_received_test.rb new file mode 100644 index 0000000..bbfe20a --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/have_received_test.rb @@ -0,0 +1,192 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") +require 'test_runner' +require 'mocha/api' +require 'mocha/mockery' +require 'mocha/object' +require 'matcher_helpers' + +module HaveReceivedTestMethods + + include Mocha + + def teardown + Mockery.reset_instance + end + + def test_passes_if_invocation_exists + method = :a_method + mock = new_mock('a mock') + Mockery.instance.invocation(mock, method, []) + assert_passes do + assert_matcher_accepts have_received(method), mock + end + end + + def test_fails_if_invocation_doesnt_exist + method = :a_method + mock = new_mock('a mock') + assert_fails do + assert_matcher_accepts have_received(method), mock + end + end + + def test_fails_if_invocation_exists_with_different_arguments + method = :a_method + mock = new_mock('a mock') + Mockery.instance.invocation(mock, method, [2, 1]) + assert_fails do + assert_matcher_accepts have_received(method).with(1, 2), mock + end + end + + def test_passes_if_invocation_exists_with_wildcard_arguments + method = :a_method + mock = new_mock('a mock') + Mockery.instance.invocation(mock, method, ['hello']) + assert_passes do + assert_matcher_accepts have_received(method).with(is_a(String)), mock + end + end + + def test_passes_if_invocation_exists_with_exact_arguments + method = :a_method + mock = new_mock('a mock') + Mockery.instance.invocation(mock, method, ['hello']) + assert_passes do + assert_matcher_accepts have_received(method).with('hello'), mock + end + end + + def test_fails_if_invocation_exists_only_on_other_mock + method = :a_method + mock = new_mock('a mock') + other = 'another mock' + Mockery.instance.invocation(other, method, ['hello']) + assert_fails do + assert_matcher_accepts have_received(method), mock + end + end + + def test_passes_if_invocation_exists_for_impersonating_mock + method = :a_method + object = Object.new + mock = new_mock('a mock') + + class << object + attr_accessor :mocha + end + object.mocha = mock + + Mockery.instance.invocation(mock, method, ['hello']) + assert_passes do + assert_matcher_accepts have_received(method).with('hello'), object + end + end + + def test_passes_if_invocation_count_correct + method = :a_method + mock = new_mock('a mock') + 2.times { Mockery.instance.invocation(mock, method, []) } + assert_passes do + assert_matcher_accepts have_received(method).twice, mock + end + end + + def test_fails_if_invocation_count_incorrect + method = :a_method + mock = new_mock('a mock') + Mockery.instance.invocation(mock, method, []) + assert_fails do + assert_matcher_accepts have_received(method).twice, mock + end + end + + def test_fails_if_invocation_count_too_low + method = :a_method + mock = new_mock('a mock') + Mockery.instance.invocation(mock, method, []) + assert_fails do + assert_matcher_accepts have_received(method).twice, mock + end + end + + def test_fails_if_invocation_count_too_high + method = :a_method + mock = new_mock('a mock') + 2.times { Mockery.instance.invocation(mock, method, []) } + assert_fails do + assert_matcher_accepts have_received(method).once, mock + end + end + + def assert_passes(&block) + assert ! fails?(&block) + end + + def assert_fails(&block) + assert fails?(&block) + end + + def fails? + begin + yield + false + rescue Test::Unit::AssertionFailedError + true + end + end + +end + +class PartialHaveReceivedTest < Test::Unit::TestCase + + include TestRunner + include Mocha::API + include HaveReceivedTestMethods + + class FakeMock + def initialize(name) + @name = name + end + + def inspect + @name + end + + def mocha + self + end + end + + def new_mock(*args) + FakeMock.new(*args) + end + +end + + +class PureHaveReceivedTest < Test::Unit::TestCase + + include TestRunner + include Mocha::API + include HaveReceivedTestMethods + + class FakeMock + def initialize(name) + @name = name + end + + def inspect + @name + end + + def mocha + self + end + end + + def new_mock(*args) + Mocha::Mock.new(*args) + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/in_state_ordering_constraint_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/in_state_ordering_constraint_test.rb new file mode 100644 index 0000000..96e20c5 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/in_state_ordering_constraint_test.rb @@ -0,0 +1,43 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") + +require 'mocha/in_state_ordering_constraint' + +class InStateOrderingConstraintTest < Test::Unit::TestCase + + include Mocha + + class FakeStatePredicate + + attr_writer :active, :description + + def active? + @active + end + + def mocha_inspect + @description + end + + end + + def test_should_allow_invocation_when_state_is_active + state_predicate = FakeStatePredicate.new + ordering_constraint = InStateOrderingConstraint.new(state_predicate) + + state_predicate.active = true + assert ordering_constraint.allows_invocation_now? + + state_predicate.active = false + assert !ordering_constraint.allows_invocation_now? + end + + def test_should_describe_itself_in_terms_of_the_state_predicates_description + state_predicate = FakeStatePredicate.new + ordering_constraint = InStateOrderingConstraint.new(state_predicate) + + state_predicate.description = 'the-state-predicate' + + assert_equal 'when the-state-predicate', ordering_constraint.mocha_inspect + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/invocation_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/invocation_test.rb new file mode 100644 index 0000000..cc3f1c2 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/invocation_test.rb @@ -0,0 +1,17 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") +require 'mocha/invocation' + +class InvocationTest < Test::Unit::TestCase + + include Mocha + + def test_has_mock_method_name_and_args + mock = 'a mock' + method = :call_me + args = [1, 2] + invocation = Invocation.new(mock, method, args) + assert_equal mock, invocation.mock + assert_equal method, invocation.method_name + assert_equal args, invocation.arguments + end +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/metaclass_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/metaclass_test.rb new file mode 100644 index 0000000..956bcb4 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/metaclass_test.rb @@ -0,0 +1,22 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") +require 'mocha/metaclass' + +class MetaclassTest < Test::Unit::TestCase + + def test_should_return_objects_singleton_class + object = Object.new + assert_raises(NoMethodError) { object.success? } + + object = Object.new + assert object.__metaclass__.ancestors.include?(Object) + assert object.__metaclass__.ancestors.include?(Kernel) + assert object.__metaclass__.is_a?(Class) + + object.__metaclass__.class_eval { def success?; true; end } + assert object.success? + + object = Object.new + assert_raises(NoMethodError) { object.success? } + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/method_matcher_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/method_matcher_test.rb new file mode 100644 index 0000000..0167433 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/method_matcher_test.rb @@ -0,0 +1,23 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") +require 'mocha/method_matcher' + +class MethodMatcherTest < Test::Unit::TestCase + + include Mocha + + def test_should_match_if_actual_method_name_is_same_as_expected_method_name + method_matcher = MethodMatcher.new(:method_name) + assert method_matcher.match?(:method_name) + end + + def test_should_not_match_if_actual_method_name_is_not_same_as_expected_method_name + method_matcher = MethodMatcher.new(:method_name) + assert !method_matcher.match?(:different_method_name) + end + + def test_should_describe_what_method_is_expected + method_matcher = MethodMatcher.new(:method_name) + assert_equal "method_name", method_matcher.mocha_inspect + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/mock_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/mock_test.rb new file mode 100644 index 0000000..e9e1d92 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/mock_test.rb @@ -0,0 +1,329 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") +require 'mocha/mock' +require 'mocha/expectation_error' +require 'set' +require 'simple_counter' + +class MockTest < Test::Unit::TestCase + + include Mocha + + def test_should_set_single_expectation + mock = Mock.new + mock.expects(:method1).returns(1) + assert_nothing_raised(ExpectationError) do + assert_equal 1, mock.method1 + end + end + + def test_should_build_and_store_expectations + mock = Mock.new + expectation = mock.expects(:method1) + assert_not_nil expectation + assert_equal [expectation], mock.expectations.to_a + end + + def test_should_not_stub_everything_by_default + mock = Mock.new + assert_equal false, mock.everything_stubbed + end + + def test_should_stub_everything + mock = Mock.new + mock.stub_everything + assert_equal true, mock.everything_stubbed + end + + def test_should_be_able_to_extend_mock_object_with_module + mock = Mock.new + assert_nothing_raised(ExpectationError) { mock.extend(Module.new) } + end + + def test_should_be_equal + mock = Mock.new + assert_equal true, mock.eql?(mock) + end + + if RUBY_VERSION < '1.9' + OBJECT_METHODS = STANDARD_OBJECT_PUBLIC_INSTANCE_METHODS.reject { |m| m =~ /^__.*__$/ } + else + OBJECT_METHODS = STANDARD_OBJECT_PUBLIC_INSTANCE_METHODS.reject { |m| m =~ /^__.*__$/ || m == :object_id } + end + + def test_should_be_able_to_mock_standard_object_methods + mock = Mock.new + OBJECT_METHODS.each { |method| mock.__expects__(method.to_sym).returns(method) } + OBJECT_METHODS.each { |method| assert_equal method, mock.__send__(method.to_sym) } + assert mock.__verified__? + end + + def test_should_be_able_to_stub_standard_object_methods + mock = Mock.new + OBJECT_METHODS.each { |method| mock.__stubs__(method.to_sym).returns(method) } + OBJECT_METHODS.each { |method| assert_equal method, mock.__send__(method.to_sym) } + end + + def test_should_create_and_add_expectations + mock = Mock.new + expectation1 = mock.expects(:method1) + expectation2 = mock.expects(:method2) + assert_equal [expectation1, expectation2].to_set, mock.expectations.to_set + end + + def test_should_pass_backtrace_into_expectation + mock = Mock.new + backtrace = Object.new + expectation = mock.expects(:method1, backtrace) + assert_equal backtrace, expectation.backtrace + end + + def test_should_pass_backtrace_into_stub + mock = Mock.new + backtrace = Object.new + stub = mock.stubs(:method1, backtrace) + assert_equal backtrace, stub.backtrace + end + + def test_should_create_and_add_stubs + mock = Mock.new + stub1 = mock.stubs(:method1) + stub2 = mock.stubs(:method2) + assert_equal [stub1, stub2].to_set, mock.expectations.to_set + end + + def test_should_invoke_expectation_and_return_result + mock = Mock.new + mock.expects(:my_method).returns(:result) + result = mock.my_method + assert_equal :result, result + end + + def test_should_not_raise_error_if_stubbing_everything + mock = Mock.new + mock.stub_everything + result = nil + assert_nothing_raised(ExpectationError) do + result = mock.unexpected_method + end + assert_nil result + end + + def test_should_raise_assertion_error_for_unexpected_method_call + mock = Mock.new + error = assert_raise(ExpectationError) do + mock.unexpected_method_called(:my_method, :argument1, :argument2) + end + assert_match(/unexpected invocation/, error.message) + assert_match(/my_method/, error.message) + assert_match(/argument1/, error.message) + assert_match(/argument2/, error.message) + end + + def test_should_not_verify_successfully_because_not_all_expectations_have_been_satisfied + mock = Mock.new + mock.expects(:method1) + mock.expects(:method2) + mock.method1 + assert !mock.__verified__? + end + + def test_should_increment_assertion_counter_for_every_verified_expectation + mock = Mock.new + + mock.expects(:method1) + mock.method1 + + mock.expects(:method2) + mock.method2 + + assertion_counter = SimpleCounter.new + + mock.__verified__?(assertion_counter) + + assert_equal 2, assertion_counter.count + end + + def test_should_yield_supplied_parameters_to_block + mock = Mock.new + parameters_for_yield = [1, 2, 3] + mock.expects(:method1).yields(*parameters_for_yield) + yielded_parameters = nil + mock.method1() { |*parameters| yielded_parameters = parameters } + assert_equal parameters_for_yield, yielded_parameters + end + + def test_should_set_up_multiple_expectations_with_return_values + mock = Mock.new + mock.expects(:method1 => :result1, :method2 => :result2) + assert_equal :result1, mock.method1 + assert_equal :result2, mock.method2 + end + + def test_should_set_up_multiple_stubs_with_return_values + mock = Mock.new + mock.stubs(:method1 => :result1, :method2 => :result2) + assert_equal :result1, mock.method1 + assert_equal :result2, mock.method2 + end + + def test_should_keep_returning_specified_value_for_stubs + mock = Mock.new + mock.stubs(:method1).returns(1) + assert_equal 1, mock.method1 + assert_equal 1, mock.method1 + end + + def test_should_keep_returning_specified_value_for_expects + mock = Mock.new + mock.expects(:method1).times(2).returns(1) + assert_equal 1, mock.method1 + assert_equal 1, mock.method1 + end + + def test_should_match_most_recent_call_to_expects + mock = Mock.new + mock.expects(:method1).returns(0) + mock.expects(:method1).returns(1) + assert_equal 1, mock.method1 + end + + def test_should_match_most_recent_call_to_stubs + mock = Mock.new + mock.stubs(:method1).returns(0) + mock.stubs(:method1).returns(1) + assert_equal 1, mock.method1 + end + + def test_should_match_most_recent_call_to_stubs_or_expects + mock = Mock.new + mock.stubs(:method1).returns(0) + mock.expects(:method1).returns(1) + assert_equal 1, mock.method1 + end + + def test_should_match_most_recent_call_to_expects_or_stubs + mock = Mock.new + mock.expects(:method1).returns(0) + mock.stubs(:method1).returns(1) + assert_equal 1, mock.method1 + end + + def test_should_respond_to_expected_method + mock = Mock.new + mock.expects(:method1) + assert_equal true, mock.respond_to?(:method1) + end + + def test_should_not_respond_to_unexpected_method + mock = Mock.new + assert_equal false, mock.respond_to?(:method1) + end + + def test_should_respond_to_methods_which_the_responder_does_responds_to + instance = Class.new do + define_method(:respond_to?) { |symbol| true } + end.new + mock = Mock.new + mock.responds_like(instance) + assert_equal true, mock.respond_to?(:invoked_method) + end + + def test_should_not_respond_to_methods_which_the_responder_does_not_responds_to + instance = Class.new do + define_method(:respond_to?) { |symbol| false } + end.new + mock = Mock.new + mock.responds_like(instance) + assert_equal false, mock.respond_to?(:invoked_method) + end + + def test_should_return_itself_to_allow_method_chaining + mock = Mock.new + assert_same mock.responds_like(Object.new), mock + end + + def test_should_not_raise_no_method_error_if_mock_is_not_restricted_to_respond_like_a_responder + instance = Class.new do + define_method(:respond_to?) { true } + end.new + mock = Mock.new + mock.stubs(:invoked_method) + assert_nothing_raised(NoMethodError) { mock.invoked_method } + end + + def test_should_not_raise_no_method_error_if_responder_does_respond_to_invoked_method + instance = Class.new do + define_method(:respond_to?) { |symbol| true } + end.new + mock = Mock.new + mock.responds_like(instance) + mock.stubs(:invoked_method) + assert_nothing_raised(NoMethodError) { mock.invoked_method } + end + + def test_should_raise_no_method_error_if_responder_does_not_respond_to_invoked_method + instance = Class.new do + define_method(:respond_to?) { |symbol| false } + define_method(:mocha_inspect) { 'mocha_inspect' } + end.new + mock = Mock.new + mock.responds_like(instance) + mock.stubs(:invoked_method) + assert_raises(NoMethodError) { mock.invoked_method } + end + + def test_should_raise_no_method_error_with_message_indicating_that_mock_is_constrained_to_respond_like_responder + instance = Class.new do + define_method(:respond_to?) { |symbol| false } + define_method(:mocha_inspect) { 'mocha_inspect' } + end.new + mock = Mock.new + mock.responds_like(instance) + mock.stubs(:invoked_method) + begin + mock.invoked_method + rescue NoMethodError => e + assert_match(/which responds like mocha_inspect/, e.message) + end + end + + def test_should_handle_respond_to_with_private_methods_param_without_error + mock = Mock.new + assert_nothing_raised{ mock.respond_to?(:object_id, false) } + end + + def test_should_respond_to_any_method_if_stubbing_everything + mock = Mock.new + mock.stub_everything + assert mock.respond_to?(:abc) + assert mock.respond_to?(:xyz) + end + + class FakeExpectation + attr_reader :args + + def invoke(args) + @args = args + end + + def match?(*args) + true + end + + def invocations_allowed? + true + end + end + + def test_should_record_invocations + method = :a_method + args = [1, 2] + mock = Mock.new(method) + expectation = FakeExpectation.new + mock.expectations.add expectation + mock.send(method, *args) + + assert_equal args, expectation.args + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/mockery_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/mockery_test.rb new file mode 100644 index 0000000..0165f06 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/mockery_test.rb @@ -0,0 +1,163 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") +require 'mocha/mockery' +require 'mocha/state_machine' +require 'mocha/invocation' + +class MockeryTest < Test::Unit::TestCase + + include Mocha + + def test_should_build_instance_of_mockery + mockery = Mockery.instance + assert_not_nil mockery + assert_kind_of Mockery, mockery + end + + def test_should_cache_instance_of_mockery + mockery_1 = Mockery.instance + mockery_2 = Mockery.instance + assert_same mockery_1, mockery_2 + end + + def test_should_expire_mockery_instance_cache + mockery_1 = Mockery.instance + Mockery.reset_instance + mockery_2 = Mockery.instance + assert_not_same mockery_1, mockery_2 + end + + def test_should_raise_expectation_error_because_not_all_expectations_are_satisfied + mockery = Mockery.new + mock_1 = mockery.named_mock('mock-1') { expects(:method_1) } + mock_2 = mockery.named_mock('mock-2') { expects(:method_2) } + 1.times { mock_1.method_1 } + 0.times { mock_2.method_2 } + assert_raises(ExpectationError) { mockery.verify } + end + + def test_should_reset_list_of_mocks_on_teardown + mockery = Mockery.new + mock = mockery.unnamed_mock { expects(:my_method) } + mockery.teardown + assert_nothing_raised(ExpectationError) { mockery.verify } + end + + def test_should_build_instance_of_stubba_on_instantiation + mockery = Mockery.new + assert_not_nil mockery.stubba + assert_kind_of Central, mockery.stubba + end + + def test_should_build_new_instance_of_stubba_on_teardown + mockery = Mockery.new + stubba_1 = mockery.stubba + mockery.teardown + stubba_2 = mockery.stubba + assert_not_same stubba_1, stubba_2 + end + + def test_should_build_and_store_new_state_machine + mockery = Mockery.new + mockery.new_state_machine('state-machine-name') + assert_equal 1, mockery.state_machines.length + assert_kind_of StateMachine, mockery.state_machines[0] + end + + def test_should_reset_list_of_state_machines_on_teardown + mockery = Mockery.new + mockery.new_state_machine('state-machine-name') + mockery.teardown + assert_equal 0, mockery.state_machines.length + end + + class FakeMethod + def stub; end + def unstub; end + end + + def test_should_unstub_all_methods_on_teardown + mockery = Mockery.new + stubba = mockery.stubba + stubba.stub(FakeMethod.new) + mockery.teardown + assert stubba.stubba_methods.empty? + end + + def test_should_display_object_id_for_mocha_inspect_if_mock_has_no_name + mockery = Mockery.new + mock = mockery.unnamed_mock + assert_match Regexp.new("^#$"), mock.mocha_inspect + end + + def test_should_display_object_id_for_inspect_if_mock_has_no_name + mockery = Mockery.new + mock = mockery.unnamed_mock + assert_match Regexp.new("^#$"), mock.inspect + end + + def test_should_display_name_for_mocha_inspect_if_mock_has_string_name + mockery = Mockery.new + mock = mockery.named_mock('named_mock') + assert_equal "#", mock.mocha_inspect + end + + def test_should_display_name_for_mocha_inspect_if_mock_has_symbol_name + mockery = Mockery.new + mock = mockery.named_mock(:named_mock) + assert_equal "#", mock.mocha_inspect + end + + def test_should_display_name_for_inspect_if_mock_has_string_name + mockery = Mockery.new + mock = mockery.named_mock('named_mock') + assert_equal "#", mock.inspect + end + + def test_should_display_name_for_inspect_if_mock_has_symbol_name + mockery = Mockery.new + mock = mockery.named_mock(:named_mock) + assert_equal "#", mock.inspect + end + + def test_should_display_impersonated_object_for_mocha_inspect + mockery = Mockery.new + instance = Object.new + mock = mockery.mock_impersonating(instance) + assert_equal "#{instance.mocha_inspect}", mock.mocha_inspect + end + + def test_should_display_impersonated_object_for_inspect + mockery = Mockery.new + instance = Object.new + mock = mockery.mock_impersonating(instance) + assert_equal "#{instance.mocha_inspect}", mock.inspect + end + + class FakeClass; end + + def test_should_display_any_instance_prefix_followed_by_class_whose_instances_are_being_impersonated_for_mocha_inspect + mockery = Mockery.new + mock = mockery.mock_impersonating_any_instance_of(FakeClass) + assert_equal "#", mock.mocha_inspect + end + + def test_should_display_any_instance_prefix_followed_by_class_whose_instances_are_being_impersonated_for_inspect + mockery = Mockery.new + mock = mockery.mock_impersonating_any_instance_of(FakeClass) + assert_equal "#", mock.inspect + end + + def test_should_record_invocation + mock = 'a mock' + method = :call_me + args = [1, 2] + mockery = Mockery.new + mockery.invocation(mock, method, args) + assert_equal 1, mockery.invocations.size + invocation = mockery.invocations.first + assert_equal mock, invocation.mock + assert_equal method, invocation.method_name + assert_equal args, invocation.arguments + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/multiple_yields_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/multiple_yields_test.rb new file mode 100644 index 0000000..65724a8 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/multiple_yields_test.rb @@ -0,0 +1,18 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") + +require 'mocha/multiple_yields' + +class MultipleYieldsTest < Test::Unit::TestCase + + include Mocha + + def test_should_provide_parameters_for_multiple_yields_in_single_invocation + parameter_group = MultipleYields.new([1, 2, 3], [4, 5]) + parameter_groups = [] + parameter_group.each do |parameters| + parameter_groups << parameters + end + assert_equal [[1, 2, 3], [4, 5]], parameter_groups + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/no_yields_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/no_yields_test.rb new file mode 100644 index 0000000..544d1ef --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/no_yields_test.rb @@ -0,0 +1,18 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") + +require 'mocha/no_yields' + +class NoYieldsTest < Test::Unit::TestCase + + include Mocha + + def test_should_provide_parameters_for_no_yields_in_single_invocation + parameter_group = NoYields.new + parameter_groups = [] + parameter_group.each do |parameters| + parameter_groups << parameters + end + assert_equal [], parameter_groups + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/object_inspect_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/object_inspect_test.rb new file mode 100644 index 0000000..56d84a9 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/object_inspect_test.rb @@ -0,0 +1,37 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") +require 'mocha/inspect' +require 'method_definer' + +class ObjectInspectTest < Test::Unit::TestCase + + def test_should_return_default_string_representation_of_object_not_including_instance_variables + object = Object.new + class << object + attr_accessor :attribute + end + object.attribute = 'instance_variable' + assert_match Regexp.new("^#$"), object.mocha_inspect + assert_no_match(/instance_variable/, object.mocha_inspect) + end + + def test_should_return_customized_string_representation_of_object + object = Object.new + class << object + define_method(:inspect) { 'custom_inspect' } + end + assert_equal 'custom_inspect', object.mocha_inspect + end + + def test_should_use_underscored_id_instead_of_object_id_or_id_so_that_they_can_be_stubbed + object = Object.new + object.define_instance_accessor(:called) + object.called = false + object.replace_instance_method(:object_id) { self.called = true; 1 } + if RUBY_VERSION < '1.9' + object.replace_instance_method(:id) { self.called = true; 1 } + end + object.mocha_inspect + assert_equal false, object.called + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/object_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/object_test.rb new file mode 100644 index 0000000..57262e4 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/object_test.rb @@ -0,0 +1,82 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") +require 'mocha/object' +require 'mocha/mockery' +require 'mocha/mock' +require 'method_definer' + +class ObjectTest < Test::Unit::TestCase + + include Mocha + + def test_should_build_mocha_referring_to_self + instance = Object.new + mocha = instance.mocha + assert_not_nil mocha + assert mocha.is_a?(Mock) + assert_equal instance.mocha_inspect, mocha.mocha_inspect + end + + def test_should_reuse_existing_mocha + instance = Object.new + mocha_1 = instance.mocha + mocha_2 = instance.mocha + assert_equal mocha_1, mocha_2 + end + + def test_should_reset_mocha + instance = Object.new + assert_nil instance.reset_mocha + end + + def test_should_build_any_instance_object + klass = Class.new + any_instance = klass.any_instance + assert_not_nil any_instance + assert any_instance.is_a?(Class::AnyInstance) + end + + def test_should_return_same_any_instance_object + klass = Class.new + any_instance_1 = klass.any_instance + any_instance_2 = klass.any_instance + assert_equal any_instance_1, any_instance_2 + end + + def test_should_use_stubba_instance_method_for_object + assert_equal Mocha::InstanceMethod, Object.new.stubba_method + end + + def test_should_use_stubba_module_method_for_module + assert_equal Mocha::ModuleMethod, Module.new.stubba_method + end + + def test_should_use_stubba_class_method_for_class + assert_equal Mocha::ClassMethod, Class.new.stubba_method + end + + def test_should_use_stubba_class_method_for_any_instance + assert_equal Mocha::AnyInstanceMethod, Class::AnyInstance.new(nil).stubba_method + end + + def test_should_stub_self_for_object + object = Object.new + assert_equal object, object.stubba_object + end + + def test_should_stub_self_for_module + mod = Module.new + assert_equal mod, mod.stubba_object + end + + def test_should_stub_self_for_class + klass = Class.new + assert_equal klass, klass.stubba_object + end + + def test_should_stub_relevant_class_for_any_instance + klass = Class.new + any_instance = Class::AnyInstance.new(klass) + assert_equal klass, any_instance.stubba_object + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/all_of_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/all_of_test.rb new file mode 100644 index 0000000..14028f5 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/all_of_test.rb @@ -0,0 +1,26 @@ +require File.join(File.dirname(__FILE__), "..", "..", "test_helper") + +require 'mocha/parameter_matchers/all_of' +require 'mocha/inspect' +require 'stub_matcher' + +class AllOfTest < Test::Unit::TestCase + + include Mocha::ParameterMatchers + + def test_should_match_if_all_matchers_match + matcher = all_of(Stub::Matcher.new(true), Stub::Matcher.new(true), Stub::Matcher.new(true)) + assert matcher.matches?(['any_old_value']) + end + + def test_should_not_match_if_any_matcher_does_not_match + matcher = all_of(Stub::Matcher.new(true), Stub::Matcher.new(false), Stub::Matcher.new(true)) + assert !matcher.matches?(['any_old_value']) + end + + def test_should_describe_matcher + matcher = all_of(Stub::Matcher.new(true), Stub::Matcher.new(false), Stub::Matcher.new(true)) + assert_equal 'all_of(matcher(true), matcher(false), matcher(true))', matcher.mocha_inspect + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/any_of_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/any_of_test.rb new file mode 100644 index 0000000..503d6dc --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/any_of_test.rb @@ -0,0 +1,26 @@ +require File.join(File.dirname(__FILE__), "..", "..", "test_helper") + +require 'mocha/parameter_matchers/any_of' +require 'mocha/inspect' +require 'stub_matcher' + +class AnyOfTest < Test::Unit::TestCase + + include Mocha::ParameterMatchers + + def test_should_match_if_any_matchers_match + matcher = any_of(Stub::Matcher.new(false), Stub::Matcher.new(true), Stub::Matcher.new(false)) + assert matcher.matches?(['any_old_value']) + end + + def test_should_not_match_if_no_matchers_match + matcher = any_of(Stub::Matcher.new(false), Stub::Matcher.new(false), Stub::Matcher.new(false)) + assert !matcher.matches?(['any_old_value']) + end + + def test_should_describe_matcher + matcher = any_of(Stub::Matcher.new(false), Stub::Matcher.new(true), Stub::Matcher.new(false)) + assert_equal 'any_of(matcher(false), matcher(true), matcher(false))', matcher.mocha_inspect + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/anything_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/anything_test.rb new file mode 100644 index 0000000..42a88a1 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/anything_test.rb @@ -0,0 +1,21 @@ +require File.join(File.dirname(__FILE__), "..", "..", "test_helper") + +require 'mocha/parameter_matchers/anything' +require 'mocha/inspect' + +class AnythingTest < Test::Unit::TestCase + + include Mocha::ParameterMatchers + + def test_should_match_anything + matcher = anything + assert matcher.matches?([:something]) + assert matcher.matches?([{'x' => 'y'}]) + end + + def test_should_describe_matcher + matcher = anything + assert_equal "anything", matcher.mocha_inspect + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/equals_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/equals_test.rb new file mode 100644 index 0000000..df1eb6e --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/equals_test.rb @@ -0,0 +1,25 @@ +require File.join(File.dirname(__FILE__), "..", "..", "test_helper") + +require 'mocha/parameter_matchers/equals' +require 'mocha/inspect' + +class EqualsTest < Test::Unit::TestCase + + include Mocha::ParameterMatchers + + def test_should_match_object_that_equals_value + matcher = equals('x') + assert matcher.matches?(['x']) + end + + def test_should_not_match_object_that_does_not_equal_value + matcher = equals('x') + assert !matcher.matches?(['y']) + end + + def test_should_describe_matcher + matcher = equals('x') + assert_equal "'x'", matcher.mocha_inspect + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/has_entries_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/has_entries_test.rb new file mode 100644 index 0000000..181c9b2 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/has_entries_test.rb @@ -0,0 +1,51 @@ +require File.join(File.dirname(__FILE__), "..", "..", "test_helper") + +require 'mocha/parameter_matchers/has_entries' +require 'mocha/parameter_matchers/object' +require 'mocha/inspect' + +class HasEntriesTest < Test::Unit::TestCase + + include Mocha::ParameterMatchers + + def test_should_match_hash_including_specified_entries + matcher = has_entries(:key_1 => 'value_1', :key_2 => 'value_2') + assert matcher.matches?([{ :key_1 => 'value_1', :key_2 => 'value_2', :key_3 => 'value_3' }]) + end + + def test_should_not_match_hash_not_including_specified_entries + matcher = has_entries(:key_1 => 'value_2', :key_2 => 'value_2', :key_3 => 'value_3') + assert !matcher.matches?([{ :key_1 => 'value_1', :key_2 => 'value_2' }]) + end + + def test_should_describe_matcher + matcher = has_entries(:key_1 => 'value_1', :key_2 => 'value_2') + description = matcher.mocha_inspect + matches = /has_entries\((.*)\)/.match(description) + assert_not_nil matches[0] + entries = eval(matches[1], binding, __FILE__, __LINE__) + assert_equal 'value_1', entries[:key_1] + assert_equal 'value_2', entries[:key_2] + end + + def test_should_match_hash_including_specified_entries_with_nested_key_matchers + matcher = has_entries(equals(:key_1) => 'value_1', equals(:key_2) => 'value_2') + assert matcher.matches?([{ :key_1 => 'value_1', :key_2 => 'value_2', :key_3 => 'value_3' }]) + end + + def test_should_not_match_hash_not_including_specified_entries_with_nested_key_matchers + matcher = has_entries(equals(:key_1) => 'value_2', equals(:key_2) => 'value_2', equals(:key_3) => 'value_3') + assert !matcher.matches?([{ :key_1 => 'value_1', :key_2 => 'value_2' }]) + end + + def test_should_match_hash_including_specified_entries_with_nested_value_matchers + matcher = has_entries(:key_1 => equals('value_1'), :key_2 => equals('value_2')) + assert matcher.matches?([{ :key_1 => 'value_1', :key_2 => 'value_2', :key_3 => 'value_3' }]) + end + + def test_should_not_match_hash_not_including_specified_entries_with_nested_value_matchers + matcher = has_entries(:key_1 => equals('value_2'), :key_2 => equals('value_2'), :key_3 => equals('value_3')) + assert !matcher.matches?([{ :key_1 => 'value_1', :key_2 => 'value_2' }]) + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/has_entry_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/has_entry_test.rb new file mode 100644 index 0000000..5d30ee1 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/has_entry_test.rb @@ -0,0 +1,82 @@ +require File.join(File.dirname(__FILE__), "..", "..", "test_helper") + +require 'mocha/parameter_matchers/has_entry' +require 'mocha/parameter_matchers/object' +require 'mocha/parameter_matchers/equals' +require 'mocha/inspect' + +class HasEntryTest < Test::Unit::TestCase + + include Mocha::ParameterMatchers + + def test_should_match_hash_including_specified_key_value_pair + matcher = has_entry(:key_1, 'value_1') + assert matcher.matches?([{ :key_1 => 'value_1', :key_2 => 'value_2' }]) + end + + def test_should_not_match_hash_not_including_specified_key_value_pair + matcher = has_entry(:key_1, 'value_2') + assert !matcher.matches?([{ :key_1 => 'value_1', :key_2 => 'value_2' }]) + end + + def test_should_match_hash_including_specified_entry + matcher = has_entry(:key_1 => 'value_1') + assert matcher.matches?([{ :key_1 => 'value_1', :key_2 => 'value_2' }]) + end + + def test_should_not_match_hash_not_including_specified_entry + matcher = has_entry(:key_1 => 'value_2') + assert !matcher.matches?([{ :key_1 => 'value_1', :key_2 => 'value_2' }]) + end + + def test_should_describe_matcher_with_key_value_pair + matcher = has_entry(:key_1, 'value_1') + assert_equal "has_entry(:key_1 => 'value_1')", matcher.mocha_inspect + end + + def test_should_describe_matcher_with_entry + matcher = has_entry(:key_1 => 'value_1') + assert_equal "has_entry(:key_1 => 'value_1')", matcher.mocha_inspect + end + + def test_should_match_hash_including_specified_entry_with_nested_key_matcher + matcher = has_entry(equals(:key_1) => 'value_1') + assert matcher.matches?([{ :key_1 => 'value_1', :key_2 => 'value_2' }]) + end + + def test_should_match_hash_including_specified_entry_with_nested_value_matcher + matcher = has_entry(:key_1 => equals('value_1')) + assert matcher.matches?([{ :key_1 => 'value_1', :key_2 => 'value_2' }]) + end + + def test_should_not_match_hash_not_including_specified_entry_with_nested_key_matcher + matcher = has_entry(equals(:key_1) => 'value_2') + assert !matcher.matches?([{ :key_1 => 'value_1', :key_2 => 'value_2' }]) + end + + def test_should_not_match_hash_not_including_specified_entry_with_nested_value_matcher + matcher = has_entry(:key_1 => equals('value_2')) + assert !matcher.matches?([{ :key_1 => 'value_1', :key_2 => 'value_2' }]) + end + + def test_should_not_match_object_that_doesnt_respond_to_keys + matcher = has_entry(:key_1 => equals('value_2')) + object = Class.new do + def [](key) + 'value_2' + end + end.new + assert !matcher.matches?([object]) + end + + def test_should_not_match_object_that_doesnt_respond_to_square_bracket + matcher = has_entry(:key_1 => equals('value_2')) + object = Class.new do + def keys + [:key_1] + end + end.new + assert !matcher.matches?([object]) + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/has_key_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/has_key_test.rb new file mode 100644 index 0000000..ad8362e --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/has_key_test.rb @@ -0,0 +1,36 @@ +require File.join(File.dirname(__FILE__), "..", "..", "test_helper") + +require 'mocha/parameter_matchers/has_key' +require 'mocha/parameter_matchers/object' +require 'mocha/inspect' + +class HasKeyTest < Test::Unit::TestCase + + include Mocha::ParameterMatchers + + def test_should_match_hash_including_specified_key + matcher = has_key(:key_1) + assert matcher.matches?([{ :key_1 => 1, :key_2 => 2 }]) + end + + def test_should_not_match_hash_not_including_specified_key + matcher = has_key(:key_1) + assert !matcher.matches?([{ :key_2 => 2 }]) + end + + def test_should_describe_matcher + matcher = has_key(:key) + assert_equal 'has_key(:key)', matcher.mocha_inspect + end + + def test_should_match_hash_including_specified_key_with_nested_key_matcher + matcher = has_key(equals(:key_1)) + assert matcher.matches?([{ :key_1 => 1, :key_2 => 2 }]) + end + + def test_should_not_match_hash_not_including_specified_key_with_nested_key_matcher + matcher = has_key(equals(:key_1)) + assert !matcher.matches?([{ :key_2 => 2 }]) + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/has_value_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/has_value_test.rb new file mode 100644 index 0000000..0219f6a --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/has_value_test.rb @@ -0,0 +1,37 @@ +require File.join(File.dirname(__FILE__), "..", "..", "test_helper") + +require 'mocha/parameter_matchers/has_value' +require 'mocha/parameter_matchers/object' +require 'mocha/parameter_matchers/equals' +require 'mocha/inspect' + +class HasValueTest < Test::Unit::TestCase + + include Mocha::ParameterMatchers + + def test_should_match_hash_including_specified_value + matcher = has_value('value_1') + assert matcher.matches?([{ :key_1 => 'value_1', :key_2 => 'value_2' }]) + end + + def test_should_not_match_hash_not_including_specified_value + matcher = has_value('value_1') + assert !matcher.matches?([{ :key_2 => 'value_2' }]) + end + + def test_should_describe_matcher + matcher = has_value('value_1') + assert_equal "has_value('value_1')", matcher.mocha_inspect + end + + def test_should_match_hash_including_specified_value_with_nested_value_matcher + matcher = has_value(equals('value_1')) + assert matcher.matches?([{ :key_1 => 'value_1', :key_2 => 'value_2' }]) + end + + def test_should_not_match_hash_not_including_specified_value_with_nested_value_matcher + matcher = has_value(equals('value_1')) + assert !matcher.matches?([{ :key_2 => 'value_2' }]) + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/includes_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/includes_test.rb new file mode 100644 index 0000000..70fb649 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/includes_test.rb @@ -0,0 +1,25 @@ +require File.join(File.dirname(__FILE__), "..", "..", "test_helper") + +require 'mocha/parameter_matchers/includes' +require 'mocha/inspect' + +class IncludesTest < Test::Unit::TestCase + + include Mocha::ParameterMatchers + + def test_should_match_object_including_value + matcher = includes(:x) + assert matcher.matches?([[:x, :y, :z]]) + end + + def test_should_not_match_object_that_does_not_include_value + matcher = includes(:not_included) + assert !matcher.matches?([[:x, :y, :z]]) + end + + def test_should_describe_matcher + matcher = includes(:x) + assert_equal "includes(:x)", matcher.mocha_inspect + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/instance_of_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/instance_of_test.rb new file mode 100644 index 0000000..415b79a --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/instance_of_test.rb @@ -0,0 +1,25 @@ +require File.join(File.dirname(__FILE__), "..", "..", "test_helper") + +require 'mocha/parameter_matchers/instance_of' +require 'mocha/inspect' + +class InstanceOfTest < Test::Unit::TestCase + + include Mocha::ParameterMatchers + + def test_should_match_object_that_is_an_instance_of_specified_class + matcher = instance_of(String) + assert matcher.matches?(['string']) + end + + def test_should_not_match_object_that_is_not_an_instance_of_specified_class + matcher = instance_of(String) + assert !matcher.matches?([99]) + end + + def test_should_describe_matcher + matcher = instance_of(String) + assert_equal "instance_of(String)", matcher.mocha_inspect + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/is_a_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/is_a_test.rb new file mode 100644 index 0000000..c9ef919 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/is_a_test.rb @@ -0,0 +1,25 @@ +require File.join(File.dirname(__FILE__), "..", "..", "test_helper") + +require 'mocha/parameter_matchers/is_a' +require 'mocha/inspect' + +class IsATest < Test::Unit::TestCase + + include Mocha::ParameterMatchers + + def test_should_match_object_that_is_a_specified_class + matcher = is_a(Integer) + assert matcher.matches?([99]) + end + + def test_should_not_match_object_that_is_not_a_specified_class + matcher = is_a(Integer) + assert !matcher.matches?(['string']) + end + + def test_should_describe_matcher + matcher = is_a(Integer) + assert_equal "is_a(Integer)", matcher.mocha_inspect + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/kind_of_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/kind_of_test.rb new file mode 100644 index 0000000..1167e5c --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/kind_of_test.rb @@ -0,0 +1,25 @@ +require File.join(File.dirname(__FILE__), "..", "..", "test_helper") + +require 'mocha/parameter_matchers/kind_of' +require 'mocha/inspect' + +class KindOfTest < Test::Unit::TestCase + + include Mocha::ParameterMatchers + + def test_should_match_object_that_is_a_kind_of_specified_class + matcher = kind_of(Integer) + assert matcher.matches?([99]) + end + + def test_should_not_match_object_that_is_not_a_kind_of_specified_class + matcher = kind_of(Integer) + assert !matcher.matches?(['string']) + end + + def test_should_describe_matcher + matcher = kind_of(Integer) + assert_equal "kind_of(Integer)", matcher.mocha_inspect + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/not_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/not_test.rb new file mode 100644 index 0000000..4cb6790 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/not_test.rb @@ -0,0 +1,26 @@ +require File.join(File.dirname(__FILE__), "..", "..", "test_helper") + +require 'mocha/parameter_matchers/not' +require 'mocha/inspect' +require 'stub_matcher' + +class NotTest < Test::Unit::TestCase + + include Mocha::ParameterMatchers + + def test_should_match_if_matcher_does_not_match + matcher = Not(Stub::Matcher.new(false)) + assert matcher.matches?(['any_old_value']) + end + + def test_should_not_match_if_matcher_does_match + matcher = Not(Stub::Matcher.new(true)) + assert !matcher.matches?(['any_old_value']) + end + + def test_should_describe_matcher + matcher = Not(Stub::Matcher.new(true)) + assert_equal 'Not(matcher(true))', matcher.mocha_inspect + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/regexp_matches_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/regexp_matches_test.rb new file mode 100644 index 0000000..5aec002 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/regexp_matches_test.rb @@ -0,0 +1,25 @@ +require File.join(File.dirname(__FILE__), "..", "..", "test_helper") + +require 'mocha/parameter_matchers/regexp_matches' +require 'mocha/inspect' + +class RegexpMatchesTest < Test::Unit::TestCase + + include Mocha::ParameterMatchers + + def test_should_match_parameter_matching_regular_expression + matcher = regexp_matches(/oo/) + assert matcher.matches?(['foo']) + end + + def test_should_not_match_parameter_not_matching_regular_expression + matcher = regexp_matches(/oo/) + assert !matcher.matches?(['bar']) + end + + def test_should_describe_matcher + matcher = regexp_matches(/oo/) + assert_equal "regexp_matches(/oo/)", matcher.mocha_inspect + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/responds_with_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/responds_with_test.rb new file mode 100644 index 0000000..f32bf8b --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/responds_with_test.rb @@ -0,0 +1,25 @@ +require File.join(File.dirname(__FILE__), "..", "..", "test_helper") + +require 'mocha/parameter_matchers/responds_with' +require 'mocha/inspect' + +class RespondsWithTest < Test::Unit::TestCase + + include Mocha::ParameterMatchers + + def test_should_match_parameter_responding_with_expected_value + matcher = responds_with(:upcase, 'FOO') + assert matcher.matches?(['foo']) + end + + def test_should_not_match_parameter_responding_with_unexpected_value + matcher = responds_with(:upcase, 'FOO') + assert !matcher.matches?(['bar']) + end + + def test_should_describe_matcher + matcher = responds_with(:foo, :bar) + assert_equal 'responds_with(:foo, :bar)', matcher.mocha_inspect + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/stub_matcher.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/stub_matcher.rb new file mode 100644 index 0000000..8bb8172 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/stub_matcher.rb @@ -0,0 +1,27 @@ +module Stub + + class Matcher + + attr_accessor :value + + def initialize(matches) + @matches = matches + end + + def matches?(available_parameters) + value = available_parameters.shift + @value = value + @matches + end + + def mocha_inspect + "matcher(#{@matches})" + end + + def to_matcher + self + end + + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/yaml_equivalent_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/yaml_equivalent_test.rb new file mode 100644 index 0000000..b163f30 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameter_matchers/yaml_equivalent_test.rb @@ -0,0 +1,25 @@ +require File.join(File.dirname(__FILE__), "..", "..", "test_helper") + +require 'mocha/parameter_matchers/yaml_equivalent' +require 'mocha/inspect' + +class YamlEquivalentTest < Test::Unit::TestCase + + include Mocha::ParameterMatchers + + def test_should_match_parameter_matching_yaml_representation_of_object + matcher = yaml_equivalent([1, 2, 3]) + assert matcher.matches?(["--- \n- 1\n- 2\n- 3\n"]) + end + + def test_should_not_match_parameter_matching_yaml_representation_of_object + matcher = yaml_equivalent([1, 2, 3]) + assert !matcher.matches?(["--- \n- 4\n- 5\n"]) + end + + def test_should_describe_matcher + matcher = yaml_equivalent([1, 2, 3]) + assert_equal "yaml_equivalent([1, 2, 3])", matcher.mocha_inspect + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameters_matcher_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameters_matcher_test.rb new file mode 100644 index 0000000..612805e --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/parameters_matcher_test.rb @@ -0,0 +1,121 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") +require 'mocha/parameters_matcher' + +class ParametersMatcherTest < Test::Unit::TestCase + + include Mocha + + def test_should_match_any_actual_parameters_if_no_expected_parameters_specified + parameters_matcher = ParametersMatcher.new + assert parameters_matcher.match?(actual_parameters = [1, 2, 3]) + end + + def test_should_match_if_actual_parameters_are_same_as_expected_parameters + parameters_matcher = ParametersMatcher.new(expected_parameters = [4, 5, 6]) + assert parameters_matcher.match?(actual_parameters = [4, 5, 6]) + end + + def test_should_not_match_if_actual_parameters_are_different_from_expected_parameters + parameters_matcher = ParametersMatcher.new(expected_parameters = [4, 5, 6]) + assert !parameters_matcher.match?(actual_parameters = [1, 2, 3]) + end + + def test_should_not_match_if_there_are_less_actual_parameters_than_expected_parameters + parameters_matcher = ParametersMatcher.new(expected_parameters = [4, 5, 6]) + assert !parameters_matcher.match?(actual_parameters = [4, 5]) + end + + def test_should_not_match_if_there_are_more_actual_parameters_than_expected_parameters + parameters_matcher = ParametersMatcher.new(expected_parameters = [4, 5]) + assert !parameters_matcher.match?(actual_parameters = [4, 5, 6]) + end + + def test_should_not_match_if_not_all_required_parameters_are_supplied + optionals = ParameterMatchers::Optionally.new(6, 7) + parameters_matcher = ParametersMatcher.new(expected_parameters = [4, 5, optionals]) + assert !parameters_matcher.match?(actual_parameters = [4]) + end + + def test_should_match_if_all_required_parameters_match_and_no_optional_parameters_are_supplied + optionals = ParameterMatchers::Optionally.new(6, 7) + parameters_matcher = ParametersMatcher.new(expected_parameters = [4, 5, optionals]) + assert parameters_matcher.match?(actual_parameters = [4, 5]) + end + + def test_should_match_if_all_required_and_optional_parameters_match_and_some_optional_parameters_are_supplied + optionals = ParameterMatchers::Optionally.new(6, 7) + parameters_matcher = ParametersMatcher.new(expected_parameters = [4, 5, optionals]) + assert parameters_matcher.match?(actual_parameters = [4, 5, 6]) + end + + def test_should_match_if_all_required_and_optional_parameters_match_and_all_optional_parameters_are_supplied + optionals = ParameterMatchers::Optionally.new(6, 7) + parameters_matcher = ParametersMatcher.new(expected_parameters = [4, 5, optionals]) + assert parameters_matcher.match?(actual_parameters = [4, 5, 6, 7]) + end + + def test_should_not_match_if_all_required_and_optional_parameters_match_but_too_many_optional_parameters_are_supplied + optionals = ParameterMatchers::Optionally.new(6, 7) + parameters_matcher = ParametersMatcher.new(expected_parameters = [4, 5, optionals]) + assert !parameters_matcher.match?(actual_parameters = [4, 5, 6, 7, 8]) + end + + def test_should_not_match_if_all_required_parameters_match_but_some_optional_parameters_do_not_match + optionals = ParameterMatchers::Optionally.new(6, 7) + parameters_matcher = ParametersMatcher.new(expected_parameters = [4, 5, optionals]) + assert !parameters_matcher.match?(actual_parameters = [4, 5, 6, 0]) + end + + def test_should_not_match_if_some_required_parameters_do_not_match_although_all_optional_parameters_do_match + optionals = ParameterMatchers::Optionally.new(6, 7) + parameters_matcher = ParametersMatcher.new(expected_parameters = [4, 5, optionals]) + assert !parameters_matcher.match?(actual_parameters = [4, 0, 6]) + end + + def test_should_not_match_if_all_required_parameters_match_but_no_optional_parameters_match + optionals = ParameterMatchers::Optionally.new(6, 7) + parameters_matcher = ParametersMatcher.new(expected_parameters = [4, 5, optionals]) + assert !parameters_matcher.match?(actual_parameters = [4, 5, 0, 0]) + end + + def test_should_match_if_actual_parameters_satisfy_matching_block + parameters_matcher = ParametersMatcher.new { |x, y| x + y == 3 } + assert parameters_matcher.match?(actual_parameters = [1, 2]) + end + + def test_should_not_match_if_actual_parameters_do_not_satisfy_matching_block + parameters_matcher = ParametersMatcher.new { |x, y| x + y == 3 } + assert !parameters_matcher.match?(actual_parameters = [2, 3]) + end + + def test_should_remove_outer_array_braces + params = [1, 2, [3, 4]] + parameters_matcher = ParametersMatcher.new(params) + assert_equal '(1, 2, [3, 4])', parameters_matcher.mocha_inspect + end + + def test_should_display_numeric_arguments_as_is + params = [1, 2, 3] + parameters_matcher = ParametersMatcher.new(params) + assert_equal '(1, 2, 3)', parameters_matcher.mocha_inspect + end + + def test_should_remove_curly_braces_if_hash_is_only_argument + params = [{:a => 1, :z => 2}] + parameters_matcher = ParametersMatcher.new(params) + assert_nil parameters_matcher.mocha_inspect.index('{') + assert_nil parameters_matcher.mocha_inspect.index('}') + end + + def test_should_not_remove_curly_braces_if_hash_is_not_the_only_argument + params = [1, {:a => 1}] + parameters_matcher = ParametersMatcher.new(params) + assert_equal '(1, {:a => 1})', parameters_matcher.mocha_inspect + end + + def test_should_indicate_that_matcher_will_match_any_actual_parameters + parameters_matcher = ParametersMatcher.new + assert_equal '(any_parameters)', parameters_matcher.mocha_inspect + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/return_values_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/return_values_test.rb new file mode 100644 index 0000000..01ddfbc --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/return_values_test.rb @@ -0,0 +1,63 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") + +require 'mocha/return_values' + +class ReturnValuesTest < Test::Unit::TestCase + + include Mocha + + def test_should_return_nil + values = ReturnValues.new + assert_nil values.next + end + + def test_should_keep_returning_nil + values = ReturnValues.new + values.next + assert_nil values.next + assert_nil values.next + end + + def test_should_return_evaluated_single_return_value + values = ReturnValues.new(SingleReturnValue.new('value')) + assert_equal 'value', values.next + end + + def test_should_keep_returning_evaluated_single_return_value + values = ReturnValues.new(SingleReturnValue.new('value')) + values.next + assert_equal 'value', values.next + assert_equal 'value', values.next + end + + def test_should_return_consecutive_evaluated_single_return_values + values = ReturnValues.new(SingleReturnValue.new('value_1'), SingleReturnValue.new('value_2')) + assert_equal 'value_1', values.next + assert_equal 'value_2', values.next + end + + def test_should_keep_returning_last_of_consecutive_evaluated_single_return_values + values = ReturnValues.new(SingleReturnValue.new('value_1'), SingleReturnValue.new('value_2')) + values.next + values.next + assert_equal 'value_2', values.next + assert_equal 'value_2', values.next + end + + def test_should_build_single_return_values_for_each_values + values = ReturnValues.build('value_1', 'value_2', 'value_3').values + assert_equal 'value_1', values[0].evaluate + assert_equal 'value_2', values[1].evaluate + assert_equal 'value_3', values[2].evaluate + end + + def test_should_combine_two_sets_of_return_values + values_1 = ReturnValues.build('value_1') + values_2 = ReturnValues.build('value_2a', 'value_2b') + values = (values_1 + values_2).values + assert_equal 'value_1', values[0].evaluate + assert_equal 'value_2a', values[1].evaluate + assert_equal 'value_2b', values[2].evaluate + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/sequence_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/sequence_test.rb new file mode 100644 index 0000000..544b3fe --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/sequence_test.rb @@ -0,0 +1,104 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") +require 'mocha/sequence' +require 'mocha/expectation' + +class SequenceTest < Test::Unit::TestCase + + include Mocha + + class FakeExpectation + + attr_reader :ordering_constraints + + def initialize(satisfied = false) + @satisfied = satisfied + @ordering_constraints = [] + end + + def add_ordering_constraint(ordering_constraint) + @ordering_constraints << ordering_constraint + end + + def satisfied? + @satisfied + end + + end + + def test_should_be_satisfied_if_no_expectations_added + sequence = Sequence.new('name') + assert sequence.satisfied_to_index?(0) + end + + def test_should_be_satisfied_if_one_unsatisfied_expectations_added_but_it_is_not_included_by_index + sequence = Sequence.new('name') + expectation = FakeExpectation.new(satisfied = false) + sequence.constrain_as_next_in_sequence(expectation) + assert sequence.satisfied_to_index?(0) + end + + def test_should_not_be_satisfied_if_one_unsatisfied_expectations_added_and_it_is_included_by_index + sequence = Sequence.new('name') + expectation = FakeExpectation.new(satisfied = false) + sequence.constrain_as_next_in_sequence(expectation) + assert !sequence.satisfied_to_index?(1) + end + + def test_should_be_satisfied_if_one_satisfied_expectations_added_and_it_is_included_by_index + sequence = Sequence.new('name') + expectation = FakeExpectation.new(satisfied = true) + sequence.constrain_as_next_in_sequence(expectation) + assert sequence.satisfied_to_index?(1) + end + + def test_should_not_be_satisfied_if_one_satisfied_and_one_unsatisfied_expectation_added_and_both_are_included_by_index + sequence = Sequence.new('name') + expectation_one = FakeExpectation.new(satisfied = true) + expectation_two = FakeExpectation.new(satisfied = false) + sequence.constrain_as_next_in_sequence(expectation_one) + sequence.constrain_as_next_in_sequence(expectation_two) + assert !sequence.satisfied_to_index?(2) + end + + def test_should_be_satisfied_if_two_satisfied_expectations_added_and_both_are_included_by_index + sequence = Sequence.new('name') + expectation_one = FakeExpectation.new(satisfied = true) + expectation_two = FakeExpectation.new(satisfied = true) + sequence.constrain_as_next_in_sequence(expectation_one) + sequence.constrain_as_next_in_sequence(expectation_two) + assert sequence.satisfied_to_index?(2) + end + + def test_should_add_ordering_constraint_to_expectation + sequence = Sequence.new('name') + expectation = FakeExpectation.new + sequence.constrain_as_next_in_sequence(expectation) + assert_equal 1, expectation.ordering_constraints.length + end + + def test_should_not_allow_invocation_of_second_method_when_first_n_sequence_has_not_been_invoked + sequence = Sequence.new('name') + expectation_one = FakeExpectation.new(satisfied = false) + expectation_two = FakeExpectation.new(satisfied = false) + sequence.constrain_as_next_in_sequence(expectation_one) + sequence.constrain_as_next_in_sequence(expectation_two) + assert !expectation_two.ordering_constraints[0].allows_invocation_now? + end + + def test_should_allow_invocation_of_second_method_when_first_in_sequence_has_been_invoked + sequence = Sequence.new('name') + expectation_one = FakeExpectation.new(satisfied = true) + expectation_two = FakeExpectation.new(satisfied = false) + sequence.constrain_as_next_in_sequence(expectation_one) + sequence.constrain_as_next_in_sequence(expectation_two) + assert expectation_two.ordering_constraints[0].allows_invocation_now? + end + + def test_should_describe_ordering_constraint_as_being_part_of_named_sequence + sequence = Sequence.new('wibble') + expectation = FakeExpectation.new + sequence.constrain_as_next_in_sequence(expectation) + assert_equal "in sequence 'wibble'", expectation.ordering_constraints[0].mocha_inspect + end + +end \ No newline at end of file diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/single_return_value_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/single_return_value_test.rb new file mode 100644 index 0000000..9a94e09 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/single_return_value_test.rb @@ -0,0 +1,14 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") + +require 'mocha/single_return_value' + +class SingleReturnValueTest < Test::Unit::TestCase + + include Mocha + + def test_should_return_value + value = SingleReturnValue.new('value') + assert_equal 'value', value.evaluate + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/single_yield_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/single_yield_test.rb new file mode 100644 index 0000000..12bd0a2 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/single_yield_test.rb @@ -0,0 +1,18 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") + +require 'mocha/single_yield' + +class SingleYieldTest < Test::Unit::TestCase + + include Mocha + + def test_should_provide_parameters_for_single_yield_in_single_invocation + parameter_group = SingleYield.new(1, 2, 3) + parameter_groups = [] + parameter_group.each do |parameters| + parameter_groups << parameters + end + assert_equal [[1, 2, 3]], parameter_groups + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/state_machine_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/state_machine_test.rb new file mode 100644 index 0000000..4ccb229 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/state_machine_test.rb @@ -0,0 +1,98 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") + +require 'mocha/state_machine' + +class StateMachineTest < Test::Unit::TestCase + + include Mocha + + def test_should_initially_be_in_no_state + state_machine = StateMachine.new('name') + any_state.each do |state| + assert !state_machine.is(state).active? + assert state_machine.is_not(state).active? + end + end + + def test_should_be_able_to_enter_a_state + state_machine = StateMachine.new('name') + state = 'A' + other_states = any_state.reject { |s| s == state } + + state_machine.is(state).activate + + assert state_machine.is(state).active? + assert !state_machine.is_not(state).active? + other_states.each do |s| + assert !state_machine.is(s).active? + assert state_machine.is_not(s).active? + end + end + + def test_should_be_able_to_change_state + state_machine = StateMachine.new('name') + state = 'B' + other_states = any_state.reject { |s| s == state } + + state_machine.is('A').activate + state_machine.is(state).activate + + assert state_machine.is(state).active? + assert !state_machine.is_not(state).active? + other_states.each do |s| + assert !state_machine.is(s).active? + assert state_machine.is_not(s).active? + end + end + + def test_should_be_put_into_an_initial_state + state_machine = StateMachine.new('name') + initial_state = 'A' + other_states = any_state.reject { |s| s == initial_state } + + state_machine.starts_as(initial_state) + + assert state_machine.is(initial_state).active? + assert !state_machine.is_not(initial_state).active? + other_states.each do |state| + assert !state_machine.is(state).active? + assert state_machine.is_not(state).active? + end + end + + def test_should_be_put_into_a_new_state + next_state = 'B' + + other_states = any_state.reject { |s| s == next_state } + state_machine = StateMachine.new('name').starts_as('A') + + state_machine.become(next_state) + + assert state_machine.is(next_state).active? + assert !state_machine.is_not(next_state).active? + other_states.each do |state| + assert !state_machine.is(state).active? + assert state_machine.is_not(state).active? + end + end + + def test_should_describe_itself_as_name_and_current_state + state_machine = StateMachine.new('state_machine_name') + assert_equal 'state_machine_name has no current state', state_machine.mocha_inspect + inspectable_state = Class.new { define_method(:mocha_inspect) { "'inspectable_state'" } }.new + state_machine.is(inspectable_state).activate + assert_equal "state_machine_name is 'inspectable_state'", state_machine.mocha_inspect + end + + def test_should_have_self_describing_states + state_machine = StateMachine.new('state_machine_name') + inspectable_state = Class.new { define_method(:mocha_inspect) { "'inspectable_state'" } }.new + assert_equal "state_machine_name is 'inspectable_state'", state_machine.is(inspectable_state).mocha_inspect + assert_equal "state_machine_name is not 'inspectable_state'", state_machine.is_not(inspectable_state).mocha_inspect + end + + def any_state + %w(A B C D) + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/string_inspect_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/string_inspect_test.rb new file mode 100644 index 0000000..43b9c4e --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/string_inspect_test.rb @@ -0,0 +1,11 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") +require 'mocha/inspect' + +class StringInspectTest < Test::Unit::TestCase + + def test_should_replace_escaped_quotes_with_single_quote + string = "my_string" + assert_equal "'my_string'", string.mocha_inspect + end + +end diff --git a/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/yield_parameters_test.rb b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/yield_parameters_test.rb new file mode 100644 index 0000000..4e93f13 --- /dev/null +++ b/vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/unit/yield_parameters_test.rb @@ -0,0 +1,93 @@ +require File.join(File.dirname(__FILE__), "..", "test_helper") + +require 'mocha/yield_parameters' +require 'mocha/no_yields' +require 'mocha/single_yield' +require 'mocha/multiple_yields' + +class YieldParametersTest < Test::Unit::TestCase + + include Mocha + + def test_should_return_null_yield_parameter_group_by_default + yield_parameters = YieldParameters.new + assert yield_parameters.next_invocation.is_a?(NoYields) + end + + def test_should_return_single_yield_parameter_group + yield_parameters = YieldParameters.new + yield_parameters.add(1, 2, 3) + parameter_group = yield_parameters.next_invocation + assert parameter_group.is_a?(SingleYield) + assert_equal [1, 2, 3], parameter_group.parameters + end + + def test_should_keep_returning_single_yield_parameter_group + yield_parameters = YieldParameters.new + yield_parameters.add(1, 2, 3) + yield_parameters.next_invocation + parameter_group = yield_parameters.next_invocation + assert parameter_group.is_a?(SingleYield) + assert_equal [1, 2, 3], parameter_group.parameters + parameter_group = yield_parameters.next_invocation + assert parameter_group.is_a?(SingleYield) + assert_equal [1, 2, 3], parameter_group.parameters + end + + def test_should_return_consecutive_single_yield_parameter_groups + yield_parameters = YieldParameters.new + yield_parameters.add(1, 2, 3) + yield_parameters.add(4, 5) + parameter_group = yield_parameters.next_invocation + assert parameter_group.is_a?(SingleYield) + assert_equal [1, 2, 3], parameter_group.parameters + parameter_group = yield_parameters.next_invocation + assert parameter_group.is_a?(SingleYield) + assert_equal [4, 5], parameter_group.parameters + end + + def test_should_return_multiple_yield_parameter_group + yield_parameters = YieldParameters.new + yield_parameters.multiple_add([1, 2, 3], [4, 5]) + parameter_group = yield_parameters.next_invocation + assert parameter_group.is_a?(MultipleYields) + assert_equal [[1, 2, 3], [4, 5]], parameter_group.parameter_groups + end + + def test_should_keep_returning_multiple_yield_parameter_group + yield_parameters = YieldParameters.new + yield_parameters.multiple_add([1, 2, 3], [4, 5]) + yield_parameters.next_invocation + parameter_group = yield_parameters.next_invocation + assert parameter_group.is_a?(MultipleYields) + assert_equal [[1, 2, 3], [4, 5]], parameter_group.parameter_groups + parameter_group = yield_parameters.next_invocation + assert parameter_group.is_a?(MultipleYields) + assert_equal [[1, 2, 3], [4, 5]], parameter_group.parameter_groups + end + + def test_should_return_consecutive_multiple_yield_parameter_groups + yield_parameters = YieldParameters.new + yield_parameters.multiple_add([1, 2, 3], [4, 5]) + yield_parameters.multiple_add([6, 7], [8, 9, 0]) + parameter_group = yield_parameters.next_invocation + assert parameter_group.is_a?(MultipleYields) + assert_equal [[1, 2, 3], [4, 5]], parameter_group.parameter_groups + parameter_group = yield_parameters.next_invocation + assert parameter_group.is_a?(MultipleYields) + assert_equal [[6, 7], [8, 9, 0]], parameter_group.parameter_groups + end + + def test_should_return_consecutive_single_and_multiple_yield_parameter_groups + yield_parameters = YieldParameters.new + yield_parameters.add(1, 2, 3) + yield_parameters.multiple_add([4, 5, 6], [7, 8]) + parameter_group = yield_parameters.next_invocation + assert parameter_group.is_a?(SingleYield) + assert_equal [1, 2, 3], parameter_group.parameters + parameter_group = yield_parameters.next_invocation + assert parameter_group.is_a?(MultipleYields) + assert_equal [[4, 5, 6], [7, 8]], parameter_group.parameter_groups + end + +end \ No newline at end of file diff --git a/vendor/gems/thoughtbot-factory_girl-1.2.1/CONTRIBUTION_GUIDELINES.rdoc b/vendor/gems/thoughtbot-factory_girl-1.2.1/CONTRIBUTION_GUIDELINES.rdoc new file mode 100644 index 0000000..a1778f2 --- /dev/null +++ b/vendor/gems/thoughtbot-factory_girl-1.2.1/CONTRIBUTION_GUIDELINES.rdoc @@ -0,0 +1,10 @@ +We're using GitHub[http://github.com/thoughtbot/factory_girl/tree/master] and Lighthouse[http://thoughtbot.lighthouseapp.com/projects/14354], and we've been getting any combination of github pull requests, Lighthouse tickets, patches, emails, etc. We need to normalize this workflow to make sure we don't miss any fixes. + +* Make sure you're accessing the source from the {official repository}[http://github.com/thoughtbot/factory_girl/tree/master]. +* We prefer git branches over patches, but we can take either. +* If you're using git, please make a branch for each separate contribution. We can cherry pick your commits, but pulling from a branch is easier. +* If you're submitting patches, please cut each fix or feature into a separate patch. +* There should be a Lighthouse[http://thoughtbot.lighthouseapp.com/projects/14354] ticket for any submission. If you've found a bug and want to fix it, open a new ticket at the same time. +* Please don't send pull requests Just update the lighthouse ticket with the url for your fix (or attach the patch) when it's ready. The github pull requests pretty much get dropped on the floor until someone with commit rights notices them in the mailbox. +* Contributions without tests won't be accepted. +* Please don't submit patches or branches that update the Gem version. diff --git a/vendor/gems/thoughtbot-factory_girl-1.2.1/Changelog b/vendor/gems/thoughtbot-factory_girl-1.2.1/Changelog new file mode 100644 index 0000000..d775959 --- /dev/null +++ b/vendor/gems/thoughtbot-factory_girl-1.2.1/Changelog @@ -0,0 +1,29 @@ +1.1.4 (November 28, 2008) + Factory.build now uses Factory.create for associations of the built object + Factory definitions are now detected in subdirectories, such as + factories/person_factory.rb (thanks to Josh Nichols) + Factory definitions are now loaded after the environment in a Rails project + (fixes some issues with dependencies being loaded too early) (thanks to + Josh Nichols) + Factory names ending in 's' no longer cause problems (thanks to Alex Sharp + and Josh Owens) + +1.1.3 (September 12, 2008) + Automatically pull in definitions from factories.rb, test/factories.rb, or + spec/factories.rb +1.1.2 (July 30, 2008) + Improved error handling for invalid and undefined factories/attributes + Improved handling of strings vs symbols vs classes + Added a prettier syntax for handling associations + Updated documentation and fixed compatibility with Rails 2.1 + +1.1.1 (June 23, 2008) + The attribute "name" no longer requires using #add_attribute + +1.1.0 (June 3, 2008) + Added support for dependent attributes + Fixed the attributes_for build strategy to not build associations + Added support for sequences + +1.0.0 (May 31, 208) + First version diff --git a/vendor/gems/thoughtbot-factory_girl-1.2.1/LICENSE b/vendor/gems/thoughtbot-factory_girl-1.2.1/LICENSE new file mode 100644 index 0000000..182911b --- /dev/null +++ b/vendor/gems/thoughtbot-factory_girl-1.2.1/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2008 Joe Ferris and thoughtbot, inc. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/vendor/gems/thoughtbot-factory_girl-1.2.1/README.rdoc b/vendor/gems/thoughtbot-factory_girl-1.2.1/README.rdoc new file mode 100644 index 0000000..ee8af32 --- /dev/null +++ b/vendor/gems/thoughtbot-factory_girl-1.2.1/README.rdoc @@ -0,0 +1,228 @@ += factory_girl + +factory_girl is a fixtures replacement with a straightforward definition syntax, support for multiple build strategies (saved instances, unsaved instances, attribute hashes, and stubbed objects), and support for multiple factories for the same class (user, admin_user, and so on), including factory inheritence. + +== Download + +Github: http://github.com/thoughtbot/factory_girl/tree/master + +Gem: + gem install thoughtbot-factory_girl --source http://gems.github.com + +Note: if you install factory_girl using the gem from Github, you'll need this +in your environment.rb if you want to use Rails 2.1+'s dependency manager: + + config.gem "thoughtbot-factory_girl", + :lib => "factory_girl", + :source => "http://gems.github.com" + +== Defining factories + +Each factory has a name and a set of attributes. The name is used to guess the class of the object by default, but it's possible to excplicitly specify it: + + # This will guess the User class + Factory.define :user do |u| + u.first_name 'John' + u.last_name 'Doe' + u.admin false + end + + # This will use the User class (Admin would have been guessed) + Factory.define :admin, :class => User do |u| + u.first_name 'Admin' + u.last_name 'User' + u.admin true + end + + # The same, but using a string instead of class constant + Factory.define :admin, :class => 'user' do |u| + u.first_name 'Admin' + u.last_name 'User' + u.admin true + end + +It is highly recommended that you have one factory for each class that provides the simplest set of attributes necessary to create an instance of that class. If you're creating ActiveRecord objects, that means that you should only provide attributes that are required through validations and that do not have defaults. Other factories can be created through inheritence to cover common scenarios for each class. + +Factories can either be defined anywhere, but will automatically be loaded if they are defined in files at the following locations: + + test/factories.rb + spec/factories.rb + test/factories/*.rb + spec/factories/*.rb + +== Using factories + +factory_girl supports several different build strategies: build, create, attributes_for and stub: + + # Returns a User instance that's not saved + user = Factory.build(:user) + + # Returns a saved User instance + user = Factory.create(:user) + + # Returns a hash of attributes that can be used to build a User instance: + attrs = Factory.attributes_for(:user) + + # Returns an object with all defined attributes stubbed out: + stub = Factory.stub(:user) + +You can use the Factory method as a shortcut for the default build strategy: + + # Same as Factory.create :user: + user = Factory(:user) + +The default strategy can be overriden: + + # Now same as Factory.build(:user) + Factory.define :user, :default_strategy => :build do |u| + ... + end + + user = Factory(:user) + +No matter which startegy is used, it's possible to override the defined attributes by passing a hash: + + # Build a User instance and override the first_name property + user = Factory.build(:user, :first_name => 'Joe') + user.first_name + # => "Joe" + +== Lazy Attributes + +Most factory attributes can be added using static values that are evaluated when the factory is defined, but some attributes (such as associations and other attributes that must be dynamically generated) will need values assigned each time an instance is generated. These "lazy" attributes can be added by passing a block instead of a parameter: + + Factory.define :user do |u| + # ... + u.activation_code { User.generate_activation_code } + end + +== Dependent Attributes + +Attributes can be based on the values of other attributes using the proxy that is yieled to lazy attribute blocks: + + Factory.define :user do |u| + u.first_name 'Joe' + u.last_name 'Blow' + u.email {|a| "#{a.first_name}.#{a.last_name}@example.com".downcase } + end + + Factory(:user, :last_name => 'Doe').email + # => "joe.doe@example.com" + +== Associations + +Associated instances can be generated by using the association method when +defining a lazy attribute: + + Factory.define :post do |p| + # ... + p.author {|author| author.association(:user, :last_name => 'Writely') } + end + +The behavior of the association method varies depending on the build strategy used for the parent object. + + # Builds and saves a User and a Post + post = Factory(:post) + post.new_record? # => false + post.author.new_record # => false + + # Builds and saves a User, and then builds but does not save a Post + Factory.build(:post) + post.new_record? # => true + post.author.new_record # => false + +Because this pattern is so common, a prettier syntax is available for defining +associations: + + # The following definitions are equivilent: + Factory.define :post do |p| + p.author {|a| a.association(:user) } + end + + Factory.define :post do |p| + p.association :author, :factory => :user + end + +If the factory name is the same as the association name, the factory name can +be left out. + +== Inheritance + +You can easily create multiple factories for the same class without repeating common attributes by using inheritence: + + Factory.define :post do |p| + # the 'title' attribute is required for all posts + p.title 'A title' + end + + Factory.define :approved_post, :parent => :post do |p| + p.approved true + # the 'approver' association is required for an approved post + p.association :approver, :factory => :user + end + +== Sequences + +Unique values in a specific format (for example, e-mail addresses) can be +generated using sequences. Sequences are defined by calling Factory.sequence, +and values in a sequence are generated by calling Factory.next: + + # Defines a new sequence + Factory.sequence :email do |n| + "person#{n}@example.com" + end + + Factory.next :email + # => "person1@example.com" + + Factory.next :email + # => "person2@example.com" + +Sequences can be used in lazy attributes: + + Factory.define :user do |f| + f.email { Factory.next(:email) } + end + +And it's also possible to define an in-line sequence that is only used in +a particular factory: + + Factory.define :user do |f| + f.sequence(:email) {|n| "person#{n}@example.com" } + end + +== Alternate Syntaxes + +Users' tastes for syntax vary dramatically, but most users are looking for a common feature set. Because of this, factory_girl supports "syntax layers" which provide alternate interfaces. See Factory::Syntax for information about the various layers available. + +== More Information + +Our blog: http://giantrobots.thoughtbot.com + +factory_girl rdoc: http://dev.thoughtbot.com/factory_girl + +Mailing list: http://groups.google.com/group/factory_girl + +factory_girl tickets: http://thoughtbot.lighthouseapp.com/projects/14354-factory_girl + +== Contributing + +Please read the contribution guidelines before submitting patches or pull requests. + +== Author + +factory_girl was written by Joe Ferris with contributions from several authors, including: +* Alex Sharp +* Eugene Bolshakov +* Jon Yurek +* Josh Nichols +* Josh Owens + +The syntax layers are derived from software written by the following authors: +* Pete Yandell +* Rick Bradley +* Yossef Mendelssohn + +Thanks to all members of thoughtbot for inspiration, ideas, and funding. + +Copyright 2008-2009 Joe Ferris and thoughtbot[http://www.thoughtbot.com], inc. diff --git a/vendor/gems/thoughtbot-factory_girl-1.2.1/Rakefile b/vendor/gems/thoughtbot-factory_girl-1.2.1/Rakefile new file mode 100644 index 0000000..00135cf --- /dev/null +++ b/vendor/gems/thoughtbot-factory_girl-1.2.1/Rakefile @@ -0,0 +1,78 @@ +require 'rubygems' +require 'rake' +require 'rake/testtask' +require 'rake/rdoctask' +require 'rake/gempackagetask' +require 'rcov/rcovtask' +require 'date' + +desc 'Default: run unit tests.' +task :default => :test + +desc 'Test the factory_girl plugin.' +Rake::TestTask.new(:test) do |t| + t.libs << 'lib' + t.libs << 'test' + t.pattern = 'test/**/*_test.rb' + t.verbose = true +end + +desc 'Performs code coverage on the factory_girl plugin.' +Rcov::RcovTask.new do |t| + t.libs << "test" + t.test_files = FileList['test/*_test.rb'] + t.verbose = true +end + +desc 'Generate documentation for the factory_girl plugin.' +Rake::RDocTask.new(:rdoc) do |rdoc| + rdoc.rdoc_dir = 'rdoc' + rdoc.title = 'Factory Girl' + rdoc.options << '--line-numbers' << "--main" << "README.rdoc" + rdoc.rdoc_files.include('README.rdoc') + rdoc.rdoc_files.include('CONTRIBUTION_GUIDELINES.rdoc') + rdoc.rdoc_files.include('lib/**/*.rb') +end + +desc 'Update documentation on website' +task :sync_docs => 'rdoc' do + `rsync -ave ssh rdoc/ dev@dev.thoughtbot.com:/home/dev/www/dev.thoughtbot.com/factory_girl` +end + +spec = Gem::Specification.new do |s| + s.name = %q{factory_girl} + s.version = "1.2.0" + s.summary = %q{factory_girl provides a framework and DSL for defining and + using model instance factories.} + s.description = %q{factory_girl provides a framework and DSL for defining and + using factories - less error-prone, more explicit, and + all-around easier to work with than fixtures.} + + s.files = FileList['[A-Z]*', 'lib/**/*.rb', 'test/**/*.rb'] + s.require_path = 'lib' + s.test_files = Dir[*['test/**/*_test.rb']] + + s.has_rdoc = true + s.extra_rdoc_files = ["README.rdoc"] + s.rdoc_options = ['--line-numbers', "--main", "README.rdoc"] + + s.authors = ["Joe Ferris"] + s.email = %q{jferris@thoughtbot.com} + + s.platform = Gem::Platform::RUBY +end + +Rake::GemPackageTask.new spec do |pkg| + pkg.need_tar = true + pkg.need_zip = true +end + +desc "Clean files generated by rake tasks" +task :clobber => [:clobber_rdoc, :clobber_package] + +desc "Generate a gemspec file" +task :gemspec do + File.open("#{spec.name}.gemspec", 'w') do |f| + f.write spec.to_ruby + end +end diff --git a/vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl.rb b/vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl.rb new file mode 100644 index 0000000..a730775 --- /dev/null +++ b/vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl.rb @@ -0,0 +1,34 @@ +require 'active_support' +require 'factory_girl/proxy' +require 'factory_girl/proxy/build' +require 'factory_girl/proxy/create' +require 'factory_girl/proxy/attributes_for' +require 'factory_girl/proxy/stub' +require 'factory_girl/factory' +require 'factory_girl/attribute' +require 'factory_girl/attribute/static' +require 'factory_girl/attribute/dynamic' +require 'factory_girl/attribute/association' +require 'factory_girl/sequence' +require 'factory_girl/aliases' + +# Shortcut for Factory.default_strategy. +# +# Example: +# Factory(:user, :name => 'Joe') +def Factory (name, attrs = {}) + Factory.default_strategy(name, attrs) +end + +if defined? Rails.configuration + Rails.configuration.after_initialize do + Factory.definition_file_paths = [ + File.join(RAILS_ROOT, 'test', 'factories'), + File.join(RAILS_ROOT, 'spec', 'factories') + ] + Factory.find_definitions + end +else + Factory.find_definitions +end + diff --git a/vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/aliases.rb b/vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/aliases.rb new file mode 100644 index 0000000..8ed9a1d --- /dev/null +++ b/vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/aliases.rb @@ -0,0 +1,50 @@ +class Factory + + class << self + attr_accessor :aliases #:nodoc: + end + self.aliases = [ + [/(.*)_id/, '\1'], + [/(.*)/, '\1_id'] + ] + + # Defines a new alias for attributes. + # + # Arguments: + # * pattern: +Regexp+ + # A pattern that will be matched against attributes when looking for + # aliases. Contents captured in the pattern can be used in the alias. + # * replace: +String+ + # The alias that results from the matched pattern. Captured strings can + # be substituded like with +String#sub+. + # + # Example: + # + # Factory.alias /(.*)_confirmation/, '\1' + # + # factory_girl starts with aliases for foreign keys, so that a :user + # association can be overridden by a :user_id parameter: + # + # Factory.define :post do |p| + # p.association :user + # end + # + # # The user association will not be built in this example. The user_id + # # will be used instead. + # Factory(:post, :user_id => 1) + def self.alias (pattern, replace) + self.aliases << [pattern, replace] + end + + def self.aliases_for (attribute) #:nodoc: + aliases.collect do |params| + pattern, replace = *params + if pattern.match(attribute.to_s) + attribute.to_s.sub(pattern, replace).to_sym + else + nil + end + end.compact << attribute + end + +end diff --git a/vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/attribute.rb b/vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/attribute.rb new file mode 100644 index 0000000..d0a29cd --- /dev/null +++ b/vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/attribute.rb @@ -0,0 +1,28 @@ +class Factory + + # Raised when defining an invalid attribute: + # * Defining an attribute which has a name ending in "=" + # * Defining an attribute with both a static and lazy value + # * Defining an attribute twice in the same factory + class AttributeDefinitionError < RuntimeError + end + + class Attribute #:nodoc: + + attr_reader :name + + def initialize(name) + @name = name.to_sym + + if @name.to_s =~ /=$/ + raise AttributeDefinitionError, + "factory_girl uses 'f.#{@name.to_s.chop} value' syntax " + + "rather than 'f.#{@name} = value'" + end + end + + def add_to(proxy) + end + end + +end diff --git a/vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/attribute/association.rb b/vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/attribute/association.rb new file mode 100644 index 0000000..d6b8a04 --- /dev/null +++ b/vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/attribute/association.rb @@ -0,0 +1,18 @@ +class Factory + class Attribute #:nodoc: + + class Association < Attribute #:nodoc: + + def initialize(name, factory, overrides) + super(name) + @factory = factory + @overrides = overrides + end + + def add_to(proxy) + proxy.associate(name, @factory, @overrides) + end + end + + end +end diff --git a/vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/attribute/dynamic.rb b/vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/attribute/dynamic.rb new file mode 100644 index 0000000..2429576 --- /dev/null +++ b/vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/attribute/dynamic.rb @@ -0,0 +1,17 @@ +class Factory + class Attribute #:nodoc: + + class Dynamic < Attribute #:nodoc: + + def initialize(name, block) + super(name) + @block = block + end + + def add_to(proxy) + proxy.set(name, @block.call(proxy)) + end + end + + end +end diff --git a/vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/attribute/static.rb b/vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/attribute/static.rb new file mode 100644 index 0000000..a319268 --- /dev/null +++ b/vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/attribute/static.rb @@ -0,0 +1,17 @@ +class Factory + class Attribute #:nodoc: + + class Static < Attribute #:nodoc: + + def initialize(name, value) + super(name) + @value = value + end + + def add_to(proxy) + proxy.set(name, @value) + end + end + + end +end diff --git a/vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/factory.rb b/vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/factory.rb new file mode 100644 index 0000000..060e0be --- /dev/null +++ b/vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/factory.rb @@ -0,0 +1,360 @@ +class Factory + + # Raised when a factory is defined that attempts to instantiate itself. + class AssociationDefinitionError < RuntimeError + end + + class << self + attr_accessor :factories #:nodoc: + + # An Array of strings specifying locations that should be searched for + # factory definitions. By default, factory_girl will attempt to require + # "factories," "test/factories," and "spec/factories." Only the first + # existing file will be loaded. + attr_accessor :definition_file_paths + end + + self.factories = {} + self.definition_file_paths = %w(factories test/factories spec/factories) + + attr_reader :factory_name #:nodoc: + attr_reader :attributes #:nodoc: + + # Defines a new factory that can be used by the build strategies (create and + # build) to build new objects. + # + # Arguments: + # * name: +Symbol+ or +String+ + # A unique name used to identify this factory. + # * options: +Hash+ + # + # Options: + # * class: +Symbol+, +Class+, or +String+ + # The class that will be used when generating instances for this factory. If not specified, the class will be guessed from the factory name. + # * parent: +Symbol+ + # The parent factory. If specified, the attributes from the parent + # factory will be copied to the current one with an ability to override + # them. + # * default_strategy: +Symbol+ + # The strategy that will be used by the Factory shortcut method. + # Defaults to :create. + # + # Yields: +Factory+ + # The newly created factory. + def self.define (name, options = {}) + instance = Factory.new(name, options) + yield(instance) + if parent = options.delete(:parent) + instance.inherit_from(Factory.factory_by_name(parent)) + end + self.factories[instance.factory_name] = instance + end + + def class_name #:nodoc: + @options[:class] || factory_name + end + + def build_class #:nodoc: + @build_class ||= class_for(class_name) + end + + def default_strategy #:nodoc: + @options[:default_strategy] || :create + end + + def initialize (name, options = {}) #:nodoc: + assert_valid_options(options) + @factory_name = factory_name_for(name) + @options = options + @attributes = [] + end + + def inherit_from(parent) #:nodoc: + @options[:class] ||= parent.class_name + parent.attributes.each do |attribute| + unless attribute_defined?(attribute.name) + @attributes << attribute.clone + end + end + end + + # Adds an attribute that should be assigned on generated instances for this + # factory. + # + # This method should be called with either a value or block, but not both. If + # called with a block, the attribute will be generated "lazily," whenever an + # instance is generated. Lazy attribute blocks will not be called if that + # attribute is overriden for a specific instance. + # + # When defining lazy attributes, an instance of Factory::Proxy will + # be yielded, allowing associations to be built using the correct build + # strategy. + # + # Arguments: + # * name: +Symbol+ or +String+ + # The name of this attribute. This will be assigned using :"#{name}=" for + # generated instances. + # * value: +Object+ + # If no block is given, this value will be used for this attribute. + def add_attribute (name, value = nil, &block) + if block_given? + if value + raise AttributeDefinitionError, "Both value and block given" + else + attribute = Attribute::Dynamic.new(name, block) + end + else + attribute = Attribute::Static.new(name, value) + end + + if attribute_defined?(attribute.name) + raise AttributeDefinitionError, "Attribute already defined: #{name}" + end + + @attributes << attribute + end + + # Calls add_attribute using the missing method name as the name of the + # attribute, so that: + # + # Factory.define :user do |f| + # f.name 'Billy Idol' + # end + # + # and: + # + # Factory.define :user do |f| + # f.add_attribute :name, 'Billy Idol' + # end + # + # are equivilent. + def method_missing (name, *args, &block) + add_attribute(name, *args, &block) + end + + # Adds an attribute that builds an association. The associated instance will + # be built using the same build strategy as the parent instance. + # + # Example: + # Factory.define :user do |f| + # f.name 'Joey' + # end + # + # Factory.define :post do |f| + # f.association :author, :factory => :user + # end + # + # Arguments: + # * name: +Symbol+ + # The name of this attribute. + # * options: +Hash+ + # + # Options: + # * factory: +Symbol+ or +String+ + # The name of the factory to use when building the associated instance. + # If no name is given, the name of the attribute is assumed to be the + # name of the factory. For example, a "user" association will by + # default use the "user" factory. + def association (name, options = {}) + factory_name = options.delete(:factory) || name + if factory_name_for(factory_name) == self.factory_name + raise AssociationDefinitionError, "Self-referencing association '#{name}' in factory '#{self.factory_name}'" + end + @attributes << Attribute::Association.new(name, factory_name, options) + end + + # Adds an attribute that will have unique values generated by a sequence with + # a specified format. + # + # The result of: + # Factory.define :user do |f| + # f.sequence(:email) { |n| "person#{n}@example.com" } + # end + # + # Is equal to: + # Factory.sequence(:email) { |n| "person#{n}@example.com" } + # + # Factory.define :user do |f| + # f.email { Factory.next(:email) } + # end + # + # Except that no globally available sequence will be defined. + def sequence (name, &block) + s = Sequence.new(&block) + add_attribute(name) { s.next } + end + + # Generates and returns a Hash of attributes from this factory. Attributes + # can be individually overridden by passing in a Hash of attribute => value + # pairs. + # + # Arguments: + # * name: +Symbol+ or +String+ + # The name of the factory that should be used. + # * overrides: +Hash+ + # Attributes to overwrite for this set. + # + # Returns: +Hash+ + # A set of attributes that can be used to build an instance of the class + # this factory generates. + def self.attributes_for (name, overrides = {}) + factory_by_name(name).run(Proxy::AttributesFor, overrides) + end + + # Generates and returns an instance from this factory. Attributes can be + # individually overridden by passing in a Hash of attribute => value pairs. + # + # Arguments: + # * name: +Symbol+ or +String+ + # The name of the factory that should be used. + # * overrides: +Hash+ + # Attributes to overwrite for this instance. + # + # Returns: +Object+ + # An instance of the class this factory generates, with generated attributes + # assigned. + def self.build (name, overrides = {}) + factory_by_name(name).run(Proxy::Build, overrides) + end + + # Generates, saves, and returns an instance from this factory. Attributes can + # be individually overridden by passing in a Hash of attribute => value + # pairs. + # + # Instances are saved using the +save!+ method, so ActiveRecord models will + # raise ActiveRecord::RecordInvalid exceptions for invalid attribute sets. + # + # Arguments: + # * name: +Symbol+ or +String+ + # The name of the factory that should be used. + # * overrides: +Hash+ + # Attributes to overwrite for this instance. + # + # Returns: +Object+ + # A saved instance of the class this factory generates, with generated + # attributes assigned. + def self.create (name, overrides = {}) + factory_by_name(name).run(Proxy::Create, overrides) + end + + # Generates and returns an object with all attributes from this factory + # stubbed out. Attributes can be individually overridden by passing in a Hash + # of attribute => value pairs. + # + # Arguments: + # * name: +Symbol+ or +String+ + # The name of the factory that should be used. + # * overrides: +Hash+ + # Attributes to overwrite for this instance. + # + # Returns: +Object+ + # An object with generated attributes stubbed out. + def self.stub (name, overrides = {}) + factory_by_name(name).run(Proxy::Stub, overrides) + end + + # Executes the default strategy for the given factory. This is usually create, + # but it can be overridden for each factory. + # + # Arguments: + # * name: +Symbol+ or +String+ + # The name of the factory that should be used. + # * overrides: +Hash+ + # Attributes to overwrite for this instance. + # + # Returns: +Object+ + # The result of the default strategy. + def self.default_strategy (name, overrides = {}) + self.send(factory_by_name(name).default_strategy, name, overrides) + end + + def self.find_definitions #:nodoc: + definition_file_paths.each do |path| + require("#{path}.rb") if File.exists?("#{path}.rb") + + if File.directory? path + Dir[File.join(path, '*.rb')].each do |file| + require file + end + end + end + end + + def run (proxy_class, overrides) #:nodoc: + proxy = proxy_class.new(build_class) + overrides = symbolize_keys(overrides) + overrides.each {|attr, val| proxy.set(attr, val) } + passed_keys = overrides.keys.collect {|k| Factory.aliases_for(k) }.flatten + @attributes.each do |attribute| + unless passed_keys.include?(attribute.name) + attribute.add_to(proxy) + end + end + proxy.result + end + + private + + def self.factory_by_name (name) + factories[name.to_sym] or raise ArgumentError.new("No such factory: #{name.to_s}") + end + + def class_for (class_or_to_s) + if class_or_to_s.respond_to?(:to_sym) + Object.const_get(variable_name_to_class_name(class_or_to_s)) + else + class_or_to_s + end + end + + def factory_name_for (class_or_to_s) + if class_or_to_s.respond_to?(:to_sym) + class_or_to_s.to_sym + else + class_name_to_variable_name(class_or_to_s).to_sym + end + end + + def attribute_defined? (name) + !@attributes.detect {|attr| attr.name == name }.nil? + end + + def assert_valid_options(options) + invalid_keys = options.keys - [:class, :parent, :default_strategy] + unless invalid_keys == [] + raise ArgumentError, "Unknown arguments: #{invalid_keys.inspect}" + end + assert_valid_strategy(options[:default_strategy]) if options[:default_strategy] + end + + def assert_valid_strategy(strategy) + unless Factory::Proxy.const_defined? variable_name_to_class_name(strategy) + raise ArgumentError, "Unknown strategy: #{strategy}" + end + end + + # Based on ActiveSupport's underscore inflector + def class_name_to_variable_name(name) + name.to_s.gsub(/::/, '/'). + gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). + gsub(/([a-z\d])([A-Z])/,'\1_\2'). + tr("-", "_"). + downcase + end + + # Based on ActiveSupport's camelize inflector + def variable_name_to_class_name(name) + name.to_s. + gsub(/\/(.?)/) { "::#{$1.upcase}" }. + gsub(/(?:^|_)(.)/) { $1.upcase } + end + + # From ActiveSupport + def symbolize_keys(hash) + hash.inject({}) do |options, (key, value)| + options[(key.to_sym rescue key) || key] = value + options + end + end + +end diff --git a/vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/proxy.rb b/vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/proxy.rb new file mode 100644 index 0000000..be06fc1 --- /dev/null +++ b/vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/proxy.rb @@ -0,0 +1,62 @@ +class Factory + + class Proxy #:nodoc: + def initialize(klass) + end + + def get(attribute) + nil + end + + def set(attribute, value) + end + + def associate(name, factory, attributes) + end + + # Generates an association using the current build strategy. + # + # Arguments: + # name: (Symbol) + # The name of the factory that should be used to generate this + # association. + # attributes: (Hash) + # A hash of attributes that should be overridden for this association. + # + # Returns: + # The generated association for the current build strategy. Note that + # assocaitions are not generated for the attributes_for strategy. Returns + # nil in this case. + # + # Example: + # + # Factory.define :user do |f| + # # ... + # end + # + # Factory.define :post do |f| + # # ... + # f.author {|a| a.association :user, :name => 'Joe' } + # end + # + # # Builds (but doesn't save) a Post and a User + # Factory.build(:post) + # + # # Builds and saves a User, builds a Post, assigns the User to the + # # author association, and saves the User. + # Factory.create(:post) + # + def association(name, overrides = {}) + nil + end + + def method_missing(method, *args, &block) + get(method) + end + + def result + raise NotImplementedError, "Strategies must return a result" + end + end + +end diff --git a/vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/proxy/attributes_for.rb b/vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/proxy/attributes_for.rb new file mode 100644 index 0000000..03bcb48 --- /dev/null +++ b/vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/proxy/attributes_for.rb @@ -0,0 +1,21 @@ +class Factory + class Proxy #:nodoc: + class AttributesFor < Proxy #:nodoc: + def initialize(klass) + @hash = {} + end + + def get(attribute) + @hash[attribute] + end + + def set(attribute, value) + @hash[attribute] = value + end + + def result + @hash + end + end + end +end diff --git a/vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/proxy/build.rb b/vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/proxy/build.rb new file mode 100644 index 0000000..ba81ee7 --- /dev/null +++ b/vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/proxy/build.rb @@ -0,0 +1,29 @@ +class Factory + class Proxy #:nodoc: + class Build < Proxy #:nodoc: + def initialize(klass) + @instance = klass.new + end + + def get(attribute) + @instance.send(attribute) + end + + def set(attribute, value) + @instance.send(:"#{attribute}=", value) + end + + def associate(name, factory, attributes) + set(name, Factory.create(factory, attributes)) + end + + def association(factory, overrides = {}) + Factory.create(factory, overrides) + end + + def result + @instance + end + end + end +end diff --git a/vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/proxy/create.rb b/vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/proxy/create.rb new file mode 100644 index 0000000..f50a8f2 --- /dev/null +++ b/vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/proxy/create.rb @@ -0,0 +1,10 @@ +class Factory + class Proxy #:nodoc: + class Create < Build #:nodoc: + def result + @instance.save! + @instance + end + end + end +end diff --git a/vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/proxy/stub.rb b/vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/proxy/stub.rb new file mode 100644 index 0000000..bd7f4de --- /dev/null +++ b/vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/proxy/stub.rb @@ -0,0 +1,28 @@ +class Factory + class Proxy + class Stub < Proxy #:nodoc: + def initialize(klass) + @mock = Object.new + end + + def get(attribute) + @mock.send(attribute) + end + + def set(attribute, value) + unless @mock.respond_to?("#{attribute}=") + class << @mock; self end.send(:attr_accessor, attribute) + end + @mock.send("#{attribute}=", value) + end + + def associate(name, factory, attributes) + set(name, nil) + end + + def result + @mock + end + end + end +end diff --git a/vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/sequence.rb b/vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/sequence.rb new file mode 100644 index 0000000..fc18fc4 --- /dev/null +++ b/vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/sequence.rb @@ -0,0 +1,60 @@ +class Factory + + # Sequences are defined using Factory.sequence. Sequence values are generated + # using next. + class Sequence + + def initialize (&proc) #:nodoc: + @proc = proc + @value = 0 + end + + # Returns the next value for this sequence + def next + @value += 1 + @proc.call(@value) + end + + end + + class << self + attr_accessor :sequences #:nodoc: + end + self.sequences = {} + + # Defines a new sequence that can be used to generate unique values in a specific format. + # + # Arguments: + # name: (Symbol) + # A unique name for this sequence. This name will be referenced when + # calling next to generate new values from this sequence. + # block: (Proc) + # The code to generate each value in the sequence. This block will be + # called with a unique number each time a value in the sequence is to be + # generated. The block should return the generated value for the + # sequence. + # + # Example: + # + # Factory.sequence(:email) {|n| "somebody_#{n}@example.com" } + def self.sequence (name, &block) + self.sequences[name] = Sequence.new(&block) + end + + # Generates and returns the next value in a sequence. + # + # Arguments: + # name: (Symbol) + # The name of the sequence that a value should be generated for. + # + # Returns: + # The next value in the sequence. (Object) + def self.next (sequence) + unless self.sequences.key?(sequence) + raise "No such sequence: #{sequence}" + end + + self.sequences[sequence].next + end + +end diff --git a/vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/syntax.rb b/vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/syntax.rb new file mode 100644 index 0000000..638405d --- /dev/null +++ b/vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/syntax.rb @@ -0,0 +1,12 @@ +class Factory + # Provides alternate syntaxes for factory_girl. If you don't like the default + # syntax for defining or using factories, look at one of the Factory::Syntax + # modules: + # + # * Factory::Syntax::Blueprint: definition syntax similar to Machinist + # * Factory::Syntax::Generate: usage syntax similar to Object Daddy + # * Factory::Syntax::Make: usage syntax similar to Machinist + # * Factory::Syntax::Sham: sequence syntax similar to Machinist + module Syntax + end +end diff --git a/vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/syntax/blueprint.rb b/vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/syntax/blueprint.rb new file mode 100644 index 0000000..940d821 --- /dev/null +++ b/vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/syntax/blueprint.rb @@ -0,0 +1,42 @@ +class Factory + module Syntax + + # Extends ActiveRecord::Base to provide a make class method, which is an + # alternate syntax for defining factories. + # + # Usage: + # + # require 'factory_girl/syntax/blueprint' + # + # User.blueprint do + # name { 'Billy Bob' } + # email { 'billy@bob.example.com' } + # end + # + # Factory(:user, :name => 'Johnny') + # + # This syntax was derived from Pete Yandell's machinist. + module Blueprint + module ActiveRecord #:nodoc: + + def self.included(base) # :nodoc: + base.extend ClassMethods + end + + module ClassMethods #:nodoc: + + def blueprint(&block) + instance = Factory.new(name.underscore, :class => self) + instance.instance_eval(&block) + Factory.factories[instance.factory_name] = instance + end + + end + + end + end + end +end + +ActiveRecord::Base.send(:include, Factory::Syntax::Blueprint::ActiveRecord) + diff --git a/vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/syntax/generate.rb b/vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/syntax/generate.rb new file mode 100644 index 0000000..1d257cf --- /dev/null +++ b/vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/syntax/generate.rb @@ -0,0 +1,68 @@ +class Factory + module Syntax + + # Extends ActiveRecord::Base to provide generation methods for factories. + # + # Usage: + # + # require 'factory_girl/syntax/generate' + # + # Factory.define :user do |factory| + # factory.name 'Billy Bob' + # factory.email 'billy@bob.example.com' + # end + # + # # Creates a saved instance without raising (same as saving the result + # # of Factory.build) + # User.generate(:name => 'Johnny') + # + # # Creates a saved instance and raises when invalid (same as + # # Factory.create) + # User.generate! + # + # # Creates an unsaved instance (same as Factory.build) + # User.spawn + # + # # Creates an instance and yields it to the passed block + # User.generate do |user| + # # ...do something with user... + # end + # + # This syntax was derived from Rick Bradley and Yossef Mendelssohn's + # object_daddy. + module Generate + module ActiveRecord #:nodoc: + + def self.included(base) # :nodoc: + base.extend ClassMethods + end + + module ClassMethods #:nodoc: + + def generate(overrides = {}, &block) + instance = Factory.build(name.underscore, overrides) + instance.save + yield(instance) if block_given? + instance + end + + def generate!(overrides = {}, &block) + instance = Factory.create(name.underscore, overrides) + yield(instance) if block_given? + instance + end + + def spawn(overrides = {}, &block) + instance = Factory.build(name.underscore, overrides) + yield(instance) if block_given? + instance + end + + end + + end + end + end +end + +ActiveRecord::Base.send(:include, Factory::Syntax::Generate::ActiveRecord) diff --git a/vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/syntax/make.rb b/vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/syntax/make.rb new file mode 100644 index 0000000..1aea973 --- /dev/null +++ b/vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/syntax/make.rb @@ -0,0 +1,39 @@ +class Factory + module Syntax + + # Extends ActiveRecord::Base to provide a make class method, which is a + # shortcut for Factory.create. + # + # Usage: + # + # require 'factory_girl/syntax/make' + # + # Factory.define :user do |factory| + # factory.name 'Billy Bob' + # factory.email 'billy@bob.example.com' + # end + # + # User.make(:name => 'Johnny') + # + # This syntax was derived from Pete Yandell's machinist. + module Make + module ActiveRecord #:nodoc: + + def self.included(base) # :nodoc: + base.extend ClassMethods + end + + module ClassMethods #:nodoc: + + def make(overrides = {}) + Factory.create(name.underscore, overrides) + end + + end + + end + end + end +end + +ActiveRecord::Base.send(:include, Factory::Syntax::Make::ActiveRecord) diff --git a/vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/syntax/sham.rb b/vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/syntax/sham.rb new file mode 100644 index 0000000..69dd47b --- /dev/null +++ b/vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/syntax/sham.rb @@ -0,0 +1,42 @@ +class Factory + module Syntax + + # Adds a Sham module, which provides an alternate interface to + # Factory::Sequence. + # + # Usage: + # + # require 'factory_girl/syntax/sham' + # + # Sham.email {|n| "somebody#{n}@example.com" } + # + # Factory.define :user do |factory| + # factory.email { Sham.email } + # end + # + # Note that you can also use Faker, but it is recommended that you simply + # use a sequence as in the above example, as factory_girl does not provide + # protection against duplication in randomized sequences, and a randomized + # value does not provide any tangible benefits over an ascending sequence. + # + # This syntax was derived from Pete Yandell's machinist. + module Sham + module Sham #:nodoc: + def self.method_missing(name, &block) + if block_given? + Factory.sequence(name, &block) + else + Factory.next(name) + end + end + + # overrides name on Module + def self.name(&block) + method_missing('name', &block) + end + end + end + end +end + +include Factory::Syntax::Sham diff --git a/vendor/gems/thoughtbot-factory_girl-1.2.1/test/aliases_test.rb b/vendor/gems/thoughtbot-factory_girl-1.2.1/test/aliases_test.rb new file mode 100644 index 0000000..7ca951a --- /dev/null +++ b/vendor/gems/thoughtbot-factory_girl-1.2.1/test/aliases_test.rb @@ -0,0 +1,29 @@ +require 'test_helper' + +class AliasesTest < Test::Unit::TestCase + + should "include an attribute as an alias for itself by default" do + assert Factory.aliases_for(:test).include?(:test) + end + + should "include the root of a foreign key as an alias by default" do + assert Factory.aliases_for(:test_id).include?(:test) + end + + should "include an attribute's foreign key as an alias by default" do + assert Factory.aliases_for(:test).include?(:test_id) + end + + context "after adding an alias" do + + setup do + Factory.alias(/(.*)_suffix/, '\1') + end + + should "return the alias in the aliases list" do + assert Factory.aliases_for(:test_suffix).include?(:test) + end + + end + +end diff --git a/vendor/gems/thoughtbot-factory_girl-1.2.1/test/association_attribute_test.rb b/vendor/gems/thoughtbot-factory_girl-1.2.1/test/association_attribute_test.rb new file mode 100644 index 0000000..0a00efb --- /dev/null +++ b/vendor/gems/thoughtbot-factory_girl-1.2.1/test/association_attribute_test.rb @@ -0,0 +1,31 @@ +require 'test_helper' + +class AssociationAttributeTest < Test::Unit::TestCase + + context "an association" do + setup do + @name = :author + @factory = :user + @overrides = { :first_name => 'John' } + @attr = Factory::Attribute::Association.new(@name, + @factory, + @overrides) + end + + should "have a name" do + assert_equal @name, @attr.name + end + + should "tell the proxy to associate when being added to a proxy" do + proxy = mock('proxy') + proxy.expects(:associate).with(@name, @factory, @overrides) + @attr.add_to(proxy) + end + end + + should "convert names to symbols" do + assert_equal :name, + Factory::Attribute::Association.new('name', :user, {}).name + end + +end diff --git a/vendor/gems/thoughtbot-factory_girl-1.2.1/test/attribute_test.rb b/vendor/gems/thoughtbot-factory_girl-1.2.1/test/attribute_test.rb new file mode 100644 index 0000000..ef9d900 --- /dev/null +++ b/vendor/gems/thoughtbot-factory_girl-1.2.1/test/attribute_test.rb @@ -0,0 +1,32 @@ +require 'test_helper' + +class AttributeTest < Test::Unit::TestCase + + context "an attribute" do + setup do + @name = :user + @attr = Factory::Attribute.new(@name) + end + + should "have a name" do + assert_equal @name, @attr.name + end + + should "do nothing when being added to a proxy" do + @proxy = mock('proxy') + @proxy.expects(:set).never + @attr.add_to(@proxy) + end + end + + should "raise an error when defining an attribute writer" do + assert_raise Factory::AttributeDefinitionError do + Factory::Attribute.new('test=') + end + end + + should "convert names to symbols" do + assert_equal :name, Factory::Attribute.new('name').name + end + +end diff --git a/vendor/gems/thoughtbot-factory_girl-1.2.1/test/attributes_for_strategy_test.rb b/vendor/gems/thoughtbot-factory_girl-1.2.1/test/attributes_for_strategy_test.rb new file mode 100644 index 0000000..60794fd --- /dev/null +++ b/vendor/gems/thoughtbot-factory_girl-1.2.1/test/attributes_for_strategy_test.rb @@ -0,0 +1,55 @@ +require 'test_helper' + +class AttributesForProxyTest < Test::Unit::TestCase + + context "the attributes_for proxy" do + setup do + @proxy = Factory::Proxy::AttributesFor.new(@class) + end + + context "when asked to associate with another factory" do + setup do + Factory.stubs(:create) + @proxy.associate(:owner, :user, {}) + end + + should "not set a value for the association" do + assert !@proxy.result.key?(:owner) + end + end + + should "return nil when building an association" do + assert_nil @proxy.association(:user) + end + + should "not call Factory.create when building an association" do + Factory.expects(:create).never + assert_nil @proxy.association(:user) + end + + should "always return nil when building an association" do + @proxy.set(:association, 'x') + assert_nil @proxy.association(:user) + end + + should "return a hash when asked for the result" do + assert_kind_of Hash, @proxy.result + end + + context "after setting an attribute" do + setup do + @proxy.set(:attribute, 'value') + end + + should "set that value in the resulting hash" do + assert_equal 'value', @proxy.result[:attribute] + end + + should "return that value when asked for that attribute" do + assert_equal 'value', @proxy.get(:attribute) + end + end + end + +end + diff --git a/vendor/gems/thoughtbot-factory_girl-1.2.1/test/build_strategy_test.rb b/vendor/gems/thoughtbot-factory_girl-1.2.1/test/build_strategy_test.rb new file mode 100644 index 0000000..e8114a4 --- /dev/null +++ b/vendor/gems/thoughtbot-factory_girl-1.2.1/test/build_strategy_test.rb @@ -0,0 +1,79 @@ +require 'test_helper' + +class BuildProxyTest < Test::Unit::TestCase + + context "with a class to build" do + setup do + @class = Class.new + @instance = mock('built-instance') + @association = mock('associated-instance') + + @class. stubs(:new). returns(@instance) + @instance.stubs(:attribute).returns('value') + Factory. stubs(:create). returns(@association) + @instance.stubs(:attribute=) + @instance.stubs(:owner=) + end + + context "the build proxy" do + setup do + @proxy = Factory::Proxy::Build.new(@class) + end + + before_should "instantiate the class" do + @class.expects(:new).with().returns(@instance) + end + + context "when asked to associate with another factory" do + setup do + @proxy.associate(:owner, :user, {}) + end + + before_should "create the associated instance" do + Factory.expects(:create).with(:user, {}).returns(@association) + end + + before_should "set the associated instance" do + @instance.expects(:owner=).with(@association) + end + end + + should "call Factory.create when building an association" do + association = 'association' + attribs = { :first_name => 'Billy' } + Factory.expects(:create).with(:user, attribs).returns(association) + assert_equal association, @proxy.association(:user, attribs) + end + + should "return the built instance when asked for the result" do + assert_equal @instance, @proxy.result + end + + context "when setting an attribute" do + setup do + @proxy.set(:attribute, 'value') + end + + before_should "set that value" do + @instance.expects(:attribute=).with('value') + end + end + + context "when getting an attribute" do + setup do + @result = @proxy.get(:attribute) + end + + before_should "ask the built class for the value" do + @instance.expects(:attribute).with().returns('value') + end + + should "return the value for that attribute" do + assert_equal 'value', @result + end + end + end + end + +end + diff --git a/vendor/gems/thoughtbot-factory_girl-1.2.1/test/create_strategy_test.rb b/vendor/gems/thoughtbot-factory_girl-1.2.1/test/create_strategy_test.rb new file mode 100644 index 0000000..c67517f --- /dev/null +++ b/vendor/gems/thoughtbot-factory_girl-1.2.1/test/create_strategy_test.rb @@ -0,0 +1,90 @@ +require 'test_helper' + +class CreateProxyTest < Test::Unit::TestCase + + context "with a class to build" do + setup do + @class = Class.new + @instance = mock('built-instance') + @association = mock('associated-instance') + + @class. stubs(:new). returns(@instance) + Factory. stubs(:create). returns(@association) + @instance.stubs(:attribute).returns('value') + @instance.stubs(:attribute=) + @instance.stubs(:owner=) + @instance.stubs(:save!) + end + + context "the create proxy" do + setup do + @proxy = Factory::Proxy::Create.new(@class) + end + + before_should "instantiate the class" do + @class.expects(:new).with().returns(@instance) + end + + context "when asked to associate with another factory" do + setup do + @proxy.associate(:owner, :user, {}) + end + + before_should "create the associated instance" do + Factory.expects(:create).with(:user, {}).returns(@association) + end + + before_should "set the associated instance" do + @instance.expects(:owner=).with(@association) + end + end + + should "call Factory.create when building an association" do + association = 'association' + attribs = { :first_name => 'Billy' } + Factory.expects(:create).with(:user, attribs).returns(association) + assert_equal association, @proxy.association(:user, attribs) + end + + context "when asked for the result" do + setup do + @result = @proxy.result + end + + before_should "save the instance" do + @instance.expects(:save!).with() + end + + should "return the built instance" do + assert_equal @instance, @result + end + end + + context "when setting an attribute" do + setup do + @proxy.set(:attribute, 'value') + end + + before_should "set that value" do + @instance.expects(:attribute=).with('value') + end + end + + context "when getting an attribute" do + setup do + @result = @proxy.get(:attribute) + end + + before_should "ask the built class for the value" do + @instance.expects(:attribute).with().returns('value') + end + + should "return the value for that attribute" do + assert_equal 'value', @result + end + end + end + end + +end + diff --git a/vendor/gems/thoughtbot-factory_girl-1.2.1/test/dynamic_attribute_test.rb b/vendor/gems/thoughtbot-factory_girl-1.2.1/test/dynamic_attribute_test.rb new file mode 100644 index 0000000..e69bdbd --- /dev/null +++ b/vendor/gems/thoughtbot-factory_girl-1.2.1/test/dynamic_attribute_test.rb @@ -0,0 +1,41 @@ +require 'test_helper' + +class DynamicAttributeTest < Test::Unit::TestCase + + context "a static attribute" do + setup do + @name = :first_name + @block = lambda { 'value' } + @attr = Factory::Attribute::Dynamic.new(@name, @block) + end + + should "have a name" do + assert_equal @name, @attr.name + end + + should "call the block to set a value" do + @proxy = mock('proxy') + @proxy.expects(:set).with(@name, 'value') + @attr.add_to(@proxy) + end + + should "yield the proxy to the block when adding its value to a proxy" do + @block = lambda {|a| a } + @attr = Factory::Attribute::Dynamic.new(:user, @block) + @proxy = mock('proxy') + @proxy.expects(:set).with(:user, @proxy) + @attr.add_to(@proxy) + end + end + + should "raise an error when defining an attribute writer" do + assert_raise Factory::AttributeDefinitionError do + Factory::Attribute::Dynamic.new('test=', nil) + end + end + + should "convert names to symbols" do + assert_equal :name, Factory::Attribute::Dynamic.new('name', nil).name + end + +end diff --git a/vendor/gems/thoughtbot-factory_girl-1.2.1/test/factory_test.rb b/vendor/gems/thoughtbot-factory_girl-1.2.1/test/factory_test.rb new file mode 100644 index 0000000..0c73ff6 --- /dev/null +++ b/vendor/gems/thoughtbot-factory_girl-1.2.1/test/factory_test.rb @@ -0,0 +1,513 @@ +require 'test_helper' + +class FactoryTest < Test::Unit::TestCase +factory = Factory.new(:post) + context "defining a factory" do + setup do + @name = :user + @factory = mock('factory') + @factory.stubs(:factory_name).returns(@name) + @options = { :class => 'magic' } + Factory.stubs(:new).returns(@factory) + end + + should "create a new factory using the specified name and options" do + Factory.expects(:new).with(@name, @options).returns(@factory) + Factory.define(@name, @options) {|f| } + end + + should "pass the factory do the block" do + yielded = nil + Factory.define(@name) do |y| + yielded = y + end + assert_equal @factory, yielded + end + + should "add the factory to the list of factories" do + Factory.define(@name) {|f| } + assert_equal Factory.factories[@name], + @factory, + "Factories: #{Factory.factories.inspect}" + end + end + + context "a factory" do + setup do + @name = :user + @class = User + @factory = Factory.new(@name) + end + + should "have a factory name" do + assert_equal @name, @factory.factory_name + end + + should "have a build class" do + assert_equal @class, @factory.build_class + end + + should "have a default strategy" do + assert_equal :create, @factory.default_strategy + end + + should "not allow the same attribute to be added twice" do + assert_raise(Factory::AttributeDefinitionError) do + 2.times { @factory.add_attribute :first_name } + end + end + + should "add a static attribute when an attribute is defined with a value" do + attribute = mock('attribute', :name => :name) + Factory::Attribute::Static. + expects(:new). + with(:name, 'value'). + returns(attribute) + @factory.add_attribute(:name, 'value') + end + + should "add a dynamic attribute when an attribute is defined with a block" do + attribute = mock('attribute', :name => :name) + block = lambda {} + Factory::Attribute::Dynamic. + expects(:new). + with(:name, block). + returns(attribute) + @factory.add_attribute(:name, &block) + end + + should "raise for an attribute with a value and a block" do + assert_raise(Factory::AttributeDefinitionError) do + @factory.add_attribute(:name, 'value') {} + end + end + + context "adding an attribute using a in-line sequence" do + should 'create the sequence' do + Factory::Sequence. + expects(:new) + @factory.sequence(:name) {} + end + + should 'add a dynamic attribute' do + attr = mock('attribute', :name => :name) + Factory::Attribute::Dynamic. + expects(:new). + with(:name, instance_of(Proc)). + returns(attr) + @factory.sequence(:name) {} + assert @factory.attributes.include?(attr) + end + end + + context "after adding an attribute" do + setup do + @attribute = mock('attribute') + @proxy = mock('proxy') + + @attribute. stubs(:name). returns(:name) + @attribute. stubs(:add_to) + @proxy. stubs(:set) + @proxy. stubs(:result).returns('result') + Factory::Attribute::Static.stubs(:new). returns(@attribute) + Factory::Proxy::Build. stubs(:new). returns(@proxy) + + @factory.add_attribute(:name, 'value') + end + + should "create the right proxy using the build class when running" do + Factory::Proxy::Build. + expects(:new). + with(@factory.build_class). + returns(@proxy) + @factory.run(Factory::Proxy::Build, {}) + end + + should "add the attribute to the proxy when running" do + @attribute.expects(:add_to).with(@proxy) + @factory.run(Factory::Proxy::Build, {}) + end + + should "return the result from the proxy when running" do + @proxy.expects(:result).with().returns('result') + assert_equal 'result', + @factory.run(Factory::Proxy::Build, {}) + end + end + + should "add an association without a factory name or overrides" do + factory = Factory.new(:post) + name = :user + attr = 'attribute' + Factory::Attribute::Association. + expects(:new). + with(name, name, {}). + returns(attr) + factory.association(name) + assert factory.attributes.include?(attr) + end + + should "add an association with overrides" do + factory = Factory.new(:post) + name = :user + attr = 'attribute' + overrides = { :first_name => 'Ben' } + Factory::Attribute::Association. + expects(:new). + with(name, name, overrides). + returns(attr) + factory.association(name, overrides) + assert factory.attributes.include?(attr) + end + + should "add an association with a factory name" do + factory = Factory.new(:post) + attr = 'attribute' + Factory::Attribute::Association. + expects(:new). + with(:author, :user, {}). + returns(attr) + factory.association(:author, :factory => :user) + assert factory.attributes.include?(attr) + end + + should "add an association with a factory name and overrides" do + factory = Factory.new(:post) + attr = 'attribute' + Factory::Attribute::Association. + expects(:new). + with(:author, :user, :first_name => 'Ben'). + returns(attr) + factory.association(:author, :factory => :user, :first_name => 'Ben') + assert factory.attributes.include?(attr) + end + + should "raise for a self referencing association" do + factory = Factory.new(:post) + assert_raise(Factory::AssociationDefinitionError) do + factory.association(:parent, :factory => :post) + end + end + + should "add an attribute using the method name when passed an undefined method" do + attr = mock('attribute', :name => :name) + block = lambda {} + Factory::Attribute::Static. + expects(:new). + with(:name, 'value'). + returns(attr) + @factory.send(:name, 'value') + assert @factory.attributes.include?(attr) + end + + context "when overriding generated attributes with a hash" do + setup do + @attr = :name + @value = 'The price is right!' + @hash = { @attr => @value } + end + + should "return the overridden value in the generated attributes" do + @factory.add_attribute(@attr, 'The price is wrong, Bob!') + result = @factory.run(Factory::Proxy::AttributesFor, @hash) + assert_equal @value, result[@attr] + end + + should "not call a lazy attribute block for an overridden attribute" do + @factory.add_attribute(@attr) { flunk } + result = @factory.run(Factory::Proxy::AttributesFor, @hash) + end + + should "override a symbol parameter with a string parameter" do + @factory.add_attribute(@attr, 'The price is wrong, Bob!') + @hash = { @attr.to_s => @value } + result = @factory.run(Factory::Proxy::AttributesFor, @hash) + assert_equal @value, result[@attr] + end + end + + context "overriding an attribute with an alias" do + setup do + @factory.add_attribute(:test, 'original') + Factory.alias(/(.*)_alias/, '\1') + @result = @factory.run(Factory::Proxy::AttributesFor, + :test_alias => 'new') + end + + should "use the passed in value for the alias" do + assert_equal 'new', @result[:test_alias] + end + + should "discard the predefined value for the attribute" do + assert_nil @result[:test] + end + end + + should "guess the build class from the factory name" do + assert_equal User, @factory.build_class + end + + context "when defined with a custom class" do + setup do + @class = User + @factory = Factory.new(:author, :class => @class) + end + + should "use the specified class as the build class" do + assert_equal @class, @factory.build_class + end + end + + context "when defined with a class instead of a name" do + setup do + @class = ArgumentError + @name = :argument_error + @factory = Factory.new(@class) + end + + should "guess the name from the class" do + assert_equal @name, @factory.factory_name + end + + should "use the class as the build class" do + assert_equal @class, @factory.build_class + end + end + + context "when defined with a custom class name" do + setup do + @class = ArgumentError + @factory = Factory.new(:author, :class => :argument_error) + end + + should "use the specified class as the build class" do + assert_equal @class, @factory.build_class + end + end + end + + context "a factory with a name ending in s" do + setup do + @name = :business + @class = Business + @factory = Factory.new(@name) + end + + should "have a factory name" do + assert_equal @name, @factory.factory_name + end + + should "have a build class" do + assert_equal @class, @factory.build_class + end + end + + context "a factory with a string for a name" do + setup do + @name = :user + @factory = Factory.new(@name.to_s) {} + end + + should "convert the string to a symbol" do + assert_equal @name, @factory.factory_name + end + end + + context "a factory defined with a string name" do + setup do + Factory.factories = {} + @name = :user + @factory = Factory.define(@name.to_s) {} + end + + should "store the factory using a symbol" do + assert_equal @factory, Factory.factories[@name] + end + end + + context "after defining a factory" do + setup do + @name = :user + @factory = mock('factory') + + Factory.factories[@name] = @factory + end + + teardown { Factory.factories.clear } + + should "use Proxy::AttributesFor for Factory.attributes_for" do + @factory. + expects(:run). + with(Factory::Proxy::AttributesFor, :attr => 'value'). + returns('result') + assert_equal 'result', Factory.attributes_for(@name, :attr => 'value') + end + + should "use Proxy::Build for Factory.build" do + @factory. + expects(:run). + with(Factory::Proxy::Build, :attr => 'value'). + returns('result') + assert_equal 'result', Factory.build(@name, :attr => 'value') + end + + should "use Proxy::Create for Factory.create" do + @factory. + expects(:run). + with(Factory::Proxy::Create, :attr => 'value'). + returns('result') + assert_equal 'result', Factory.create(@name, :attr => 'value') + end + + should "use Proxy::Stub for Factory.stub" do + @factory. + expects(:run). + with(Factory::Proxy::Stub, :attr => 'value'). + returns('result') + assert_equal 'result', Factory.stub(@name, :attr => 'value') + end + + should "use default strategy option as Factory.default_strategy" do + @factory.stubs(:default_strategy).returns(:create) + @factory. + expects(:run). + with(Factory::Proxy::Create, :attr => 'value'). + returns('result') + assert_equal 'result', Factory.default_strategy(@name, :attr => 'value') + end + + should "use the default strategy for the global Factory method" do + @factory.stubs(:default_strategy).returns(:create) + @factory. + expects(:run). + with(Factory::Proxy::Create, :attr => 'value'). + returns('result') + assert_equal 'result', Factory(@name, :attr => 'value') + end + + [:build, :create, :attributes_for, :stub].each do |method| + should "raise an ArgumentError on #{method} with a nonexistant factory" do + assert_raise(ArgumentError) { Factory.send(method, :bogus) } + end + + should "recognize either 'name' or :name for Factory.#{method}" do + @factory.stubs(:run) + assert_nothing_raised { Factory.send(method, @name.to_s) } + assert_nothing_raised { Factory.send(method, @name.to_sym) } + end + end + end + + context 'defining a factory with a parent parameter' do + setup do + @parent = Factory.define :object do |f| + f.name 'Name' + end + end + + should 'raise an ArgumentError when trying to use a non-existent factory as parent' do + assert_raise(ArgumentError) { Factory.define(:child, :parent => :nonexsitent) {} } + end + + should 'create a new factory using the class of the parent' do + child = Factory.define(:child, :parent => :object) {} + assert_equal @parent.build_class, child.build_class + end + + should 'create a new factory while overriding the parent class' do + class Other; end + + child = Factory.define(:child, :parent => :object, :class => Other) {} + assert_equal Other, child.build_class + end + + should 'create a new factory with attributes of the parent' do + child = Factory.define(:child, :parent => :object) {} + assert_equal 1, child.attributes.size + assert_equal :name, child.attributes.first.name + end + + should 'allow to define additional attributes' do + child = Factory.define(:child, :parent => :object) do |f| + f.email 'person@somebody.com' + end + assert_equal 2, child.attributes.size + end + + should 'allow to override parent attributes' do + child = Factory.define(:child, :parent => :object) do |f| + f.name { 'Child Name' } + end + assert_equal 1, child.attributes.size + assert_kind_of Factory::Attribute::Dynamic, child.attributes.first + end + end + + context 'defining a factory with a default strategy parameter' do + should 'raise an ArgumentError when trying to use a non-existent factory' do + assert_raise(ArgumentError) { Factory.define(:object, :default_strategy => :nonexistent) {} } + end + + should 'create a new factory with a specified default strategy' do + factory = Factory.define(:object, :default_strategy => :stub) {} + assert_equal :stub, factory.default_strategy + end + end + + def self.context_in_directory_with_files(*files) + context "in a directory with #{files.to_sentence}" do + setup do + @pwd = Dir.pwd + @tmp_dir = File.join(File.dirname(__FILE__), 'tmp') + FileUtils.mkdir_p @tmp_dir + Dir.chdir(@tmp_dir) + + files.each do |file| + FileUtils.mkdir_p File.dirname(file) + FileUtils.touch file + Factory.stubs(:require).with(file) + end + end + + teardown do + Dir.chdir(@pwd) + FileUtils.rm_rf(@tmp_dir) + end + + yield + end + end + + def self.should_require_definitions_from(file) + should "load definitions from #{file}" do + Factory.expects(:require).with(file) + Factory.find_definitions + end + end + + context_in_directory_with_files 'factories.rb' do + should_require_definitions_from 'factories.rb' + end + + %w(spec test).each do |dir| + context_in_directory_with_files File.join(dir, 'factories.rb') do + should_require_definitions_from "#{dir}/factories.rb" + end + + context_in_directory_with_files File.join(dir, 'factories', 'post_factory.rb') do + should_require_definitions_from "#{dir}/factories/post_factory.rb" + end + + context_in_directory_with_files File.join(dir, 'factories', 'post_factory.rb'), File.join(dir, 'factories', 'person_factory.rb') do + should_require_definitions_from "#{dir}/factories/post_factory.rb" + should_require_definitions_from "#{dir}/factories/person_factory.rb" + end + + context_in_directory_with_files File.join(dir, 'factories.rb'), File.join(dir, 'factories', 'post_factory.rb'), File.join(dir, 'factories', 'person_factory.rb') do + should_require_definitions_from "#{dir}/factories.rb" + should_require_definitions_from "#{dir}/factories/post_factory.rb" + should_require_definitions_from "#{dir}/factories/person_factory.rb" + end + end + +end diff --git a/vendor/gems/thoughtbot-factory_girl-1.2.1/test/integration_test.rb b/vendor/gems/thoughtbot-factory_girl-1.2.1/test/integration_test.rb new file mode 100644 index 0000000..559caad --- /dev/null +++ b/vendor/gems/thoughtbot-factory_girl-1.2.1/test/integration_test.rb @@ -0,0 +1,235 @@ +require 'test_helper' + +class IntegrationTest < Test::Unit::TestCase + + def setup + Factory.define :user, :class => 'user' do |f| + f.first_name 'Jimi' + f.last_name 'Hendrix' + f.admin false + f.email {|a| "#{a.first_name}.#{a.last_name}@example.com".downcase } + end + + Factory.define Post, :default_strategy => :attributes_for do |f| + f.name 'Test Post' + f.association :author, :factory => :user + end + + Factory.define :admin, :class => User do |f| + f.first_name 'Ben' + f.last_name 'Stein' + f.admin true + f.sequence(:username) { |n| "username#{n}" } + f.email { Factory.next(:email) } + end + + Factory.define :guest, :parent => :user do |f| + f.last_name 'Anonymous' + f.username 'GuestUser' + end + + Factory.sequence :email do |n| + "somebody#{n}@example.com" + end + end + + def teardown + Factory.factories.clear + end + + context "a generated attributes hash" do + + setup do + @attrs = Factory.attributes_for(:user, :first_name => 'Bill') + end + + should "assign all attributes" do + assert_equal [:admin, :email, :first_name, :last_name], + @attrs.keys.sort {|a, b| a.to_s <=> b.to_s } + end + + should "correctly assign lazy, dependent attributes" do + assert_equal "bill.hendrix@example.com", @attrs[:email] + end + + should "override attrbutes" do + assert_equal 'Bill', @attrs[:first_name] + end + + should "not assign associations" do + assert_nil Factory.attributes_for(:post)[:author] + end + + end + + context "a built instance" do + + setup do + @instance = Factory.build(:post) + end + + should "not be saved" do + assert @instance.new_record? + end + + should "assign associations" do + assert_kind_of User, @instance.author + end + + should "save associations" do + assert !@instance.author.new_record? + end + + should "not assign both an association and its foreign key" do + assert_equal 1, Factory.build(:post, :author_id => 1).author_id + end + + end + + context "a created instance" do + + setup do + @instance = Factory.create('post') + end + + should "be saved" do + assert !@instance.new_record? + end + + should "assign associations" do + assert_kind_of User, @instance.author + end + + should "save associations" do + assert !@instance.author.new_record? + end + + end + + context "a generated mock instance" do + + setup do + @stub = Factory.stub(:user, :first_name => 'Bill') + end + + should "assign all attributes" do + [:admin, :email, :first_name, :last_name].each do |attr| + assert_not_nil @stub.send(attr) + end + end + + should "correctly assign lazy, dependent attributes" do + assert_equal "bill.hendrix@example.com", @stub.email + end + + should "override attrbutes" do + assert_equal 'Bill', @stub.first_name + end + + should "not assign associations" do + assert_nil Factory.stub(:post).author + end + + end + + context "an instance generated by a factory with a custom class name" do + + setup do + @instance = Factory.create(:admin) + end + + should "use the correct class name" do + assert_kind_of User, @instance + end + + should "use the correct factory definition" do + assert @instance.admin? + end + + end + + context "an instance generated by a factory that inherits from another factory" do + setup do + @instance = Factory.create(:guest) + end + + should "use the class name of the parent factory" do + assert_kind_of User, @instance + end + + should "have attributes of the parent" do + assert_equal 'Jimi', @instance.first_name + end + + should "have attributes defined in the factory itself" do + assert_equal 'GuestUser', @instance.username + end + + should "have attributes that have been overriden" do + assert_equal 'Anonymous', @instance.last_name + end + end + + context "an attribute generated by a sequence" do + + setup do + @email = Factory.attributes_for(:admin)[:email] + end + + should "match the correct format" do + assert_match /^somebody\d+@example\.com$/, @email + end + + context "after the attribute has already been generated once" do + + setup do + @another_email = Factory.attributes_for(:admin)[:email] + end + + should "match the correct format" do + assert_match /^somebody\d+@example\.com$/, @email + end + + should "not be the same as the first generated value" do + assert_not_equal @email, @another_email + end + + end + + end + + context "an attribute generated by an in-line sequence" do + + setup do + @username = Factory.attributes_for(:admin)[:username] + end + + should "match the correct format" do + assert_match /^username\d+$/, @username + end + + context "after the attribute has already been generated once" do + + setup do + @another_username = Factory.attributes_for(:admin)[:username] + end + + should "match the correct format" do + assert_match /^username\d+$/, @username + end + + should "not be the same as the first generated value" do + assert_not_equal @username, @another_username + end + + end + + end + + context "a factory with a default strategy specified" do + should "generate instances according to the strategy" do + assert_kind_of Hash, Factory(:post) + end + end + +end diff --git a/vendor/gems/thoughtbot-factory_girl-1.2.1/test/models.rb b/vendor/gems/thoughtbot-factory_girl-1.2.1/test/models.rb new file mode 100644 index 0000000..9b23778 --- /dev/null +++ b/vendor/gems/thoughtbot-factory_girl-1.2.1/test/models.rb @@ -0,0 +1,43 @@ +ActiveRecord::Base.establish_connection( + :adapter => 'sqlite3', + :database => File.join(File.dirname(__FILE__), 'test.db') +) + +class CreateSchema < ActiveRecord::Migration + def self.up + create_table :users, :force => true do |t| + t.string :first_name + t.string :last_name + t.string :email + t.string :username + t.boolean :admin, :default => false + end + + create_table :posts, :force => true do |t| + t.string :name + t.integer :author_id + end + + create_table :business, :force => true do |t| + t.string :name + t.integer :owner_id + end + end +end + +CreateSchema.suppress_messages { CreateSchema.migrate(:up) } + +class User < ActiveRecord::Base + validates_presence_of :first_name, :last_name, :email + has_many :posts, :foreign_key => 'author_id' +end + +class Business < ActiveRecord::Base + validates_presence_of :name, :owner_id + belongs_to :owner, :class_name => 'User' +end + +class Post < ActiveRecord::Base + validates_presence_of :name, :author_id + belongs_to :author, :class_name => 'User' +end diff --git a/vendor/gems/thoughtbot-factory_girl-1.2.1/test/sequence_test.rb b/vendor/gems/thoughtbot-factory_girl-1.2.1/test/sequence_test.rb new file mode 100644 index 0000000..fd95740 --- /dev/null +++ b/vendor/gems/thoughtbot-factory_girl-1.2.1/test/sequence_test.rb @@ -0,0 +1,76 @@ +require 'test_helper' + +class SequenceTest < Test::Unit::TestCase + + context "a sequence" do + + setup do + @sequence = Factory::Sequence.new {|n| "=#{n}" } + end + + should "start with a value of 1" do + assert_equal "=1", @sequence.next + end + + context "after being called" do + + setup do + @sequence.next + end + + should "use the next value" do + assert_equal "=2", @sequence.next + end + + end + + end + + context "defining a sequence" do + + setup do + @sequence = mock('sequence') + @name = :count + Factory::Sequence.stubs(:new).returns(@sequence) + end + + should "create a new sequence" do + Factory::Sequence.expects(:new).with().returns(@sequence) + Factory.sequence(@name) + end + + should "use the supplied block as the sequence generator" do + Factory::Sequence.stubs(:new).yields(1) + yielded = false + Factory.sequence(@name) {|n| yielded = true } + assert yielded + end + + end + + context "after defining a sequence" do + + setup do + @sequence = mock('sequence') + @name = :test + @value = '1 2 5' + + @sequence. stubs(:next).returns(@value) + Factory::Sequence.stubs(:new). returns(@sequence) + + Factory.sequence(@name) {} + end + + should "call next on the sequence when sent next" do + @sequence.expects(:next) + + Factory.next(@name) + end + + should "return the value from the sequence" do + assert_equal @value, Factory.next(@name) + end + + end + +end diff --git a/vendor/gems/thoughtbot-factory_girl-1.2.1/test/static_attribute_test.rb b/vendor/gems/thoughtbot-factory_girl-1.2.1/test/static_attribute_test.rb new file mode 100644 index 0000000..4d49e37 --- /dev/null +++ b/vendor/gems/thoughtbot-factory_girl-1.2.1/test/static_attribute_test.rb @@ -0,0 +1,33 @@ +require 'test_helper' + +class StaticAttributeTest < Test::Unit::TestCase + + context "a static attribute" do + setup do + @name = :first_name + @value = 'John' + @attr = Factory::Attribute::Static.new(@name, @value) + end + + should "have a name" do + assert_equal @name, @attr.name + end + + should "set its static value on a proxy" do + @proxy = mock('proxy') + @proxy.expects(:set).with(@name, @value) + @attr.add_to(@proxy) + end + end + + should "raise an error when defining an attribute writer" do + assert_raise Factory::AttributeDefinitionError do + Factory::Attribute::Static.new('test=', nil) + end + end + + should "convert names to symbols" do + assert_equal :name, Factory::Attribute::Static.new('name', nil).name + end + +end diff --git a/vendor/gems/thoughtbot-factory_girl-1.2.1/test/strategy_test.rb b/vendor/gems/thoughtbot-factory_girl-1.2.1/test/strategy_test.rb new file mode 100644 index 0000000..33ec4c2 --- /dev/null +++ b/vendor/gems/thoughtbot-factory_girl-1.2.1/test/strategy_test.rb @@ -0,0 +1,33 @@ +require 'test_helper' + +class Proxy < Test::Unit::TestCase + + context "a proxy" do + setup do + @proxy = Factory::Proxy.new(Class.new) + end + + should "do nothing when asked to set an attribute to a value" do + assert_nothing_raised { @proxy.set(:name, 'a name') } + end + + should "return nil when asked for an attribute" do + assert_nil @proxy.get(:name) + end + + should "call get for a missing method" do + @proxy.expects(:get).with(:name).returns("it's a name") + assert_equal "it's a name", @proxy.name + end + + should "do nothing when asked to associate with another factory" do + assert_nothing_raised { @proxy.associate(:owner, :user, {}) } + end + + should "raise an error when asked for the result" do + assert_raise(NotImplementedError) { @proxy.result } + end + end + +end + diff --git a/vendor/gems/thoughtbot-factory_girl-1.2.1/test/stub_strategy_test.rb b/vendor/gems/thoughtbot-factory_girl-1.2.1/test/stub_strategy_test.rb new file mode 100644 index 0000000..589534f --- /dev/null +++ b/vendor/gems/thoughtbot-factory_girl-1.2.1/test/stub_strategy_test.rb @@ -0,0 +1,61 @@ +require 'test_helper' + +class StubProxyTest < Test::Unit::TestCase + context "the stub proxy" do + setup do + @proxy = Factory::Proxy::Stub.new(@class) + end + + context "when asked to associate with another factory" do + setup do + Factory.stubs(:create) + @proxy.associate(:owner, :user, {}) + end + + should "not set a value for the association" do + assert_nil @proxy.result.owner + end + end + + should "return nil when building an association" do + assert_nil @proxy.association(:user) + end + + should "not call Factory.create when building an association" do + Factory.expects(:create).never + assert_nil @proxy.association(:user) + end + + should "always return nil when building an association" do + @proxy.set(:association, 'x') + assert_nil @proxy.association(:user) + end + + should "return a mock object when asked for the result" do + assert_kind_of Object, @proxy.result + end + + context "setting an attribute" do + should "define attributes even if attribute= is defined" do + @proxy.set('attribute', nil) + assert_nothing_raised do + @proxy.set('age', 18) + end + end + end + + context "after setting an attribute" do + setup do + @proxy.set(:attribute, 'value') + end + + should "add a stub to the resulting object" do + assert_equal 'value', @proxy.attribute + end + + should "return that value when asked for that attribute" do + assert_equal 'value', @proxy.get(:attribute) + end + end + end +end diff --git a/vendor/gems/thoughtbot-factory_girl-1.2.1/test/syntax/blueprint_test.rb b/vendor/gems/thoughtbot-factory_girl-1.2.1/test/syntax/blueprint_test.rb new file mode 100644 index 0000000..9a2aa87 --- /dev/null +++ b/vendor/gems/thoughtbot-factory_girl-1.2.1/test/syntax/blueprint_test.rb @@ -0,0 +1,39 @@ +require 'test_helper' + +require 'factory_girl/syntax/blueprint' + +class BlueprintSyntaxTest < Test::Unit::TestCase + + context "a blueprint" do + setup do + Factory.sequence(:email) { |n| "somebody#{n}@example.com" } + User.blueprint do + first_name { 'Bill' } + last_name { 'Nye' } + email { Factory.next(:email) } + end + end + + teardown do + Factory.factories.clear + Factory.sequences.clear + end + + context "after making an instance" do + setup do + @instance = Factory(:user, :last_name => 'Rye') + end + + should "use attributes from the blueprint" do + assert_equal 'Bill', @instance.first_name + end + + should "evaluate attribute blocks for each instance" do + assert_match /somebody\d+@example.com/, @instance.email + assert_not_equal @instance.email, Factory(:user).email + end + end + end + +end + diff --git a/vendor/gems/thoughtbot-factory_girl-1.2.1/test/syntax/generate_test.rb b/vendor/gems/thoughtbot-factory_girl-1.2.1/test/syntax/generate_test.rb new file mode 100644 index 0000000..c12b3b8 --- /dev/null +++ b/vendor/gems/thoughtbot-factory_girl-1.2.1/test/syntax/generate_test.rb @@ -0,0 +1,63 @@ +require 'test_helper' + +require 'factory_girl/syntax/generate' + +class GenerateSyntaxTest < Test::Unit::TestCase + + context "a factory" do + setup do + Factory.define :user do |factory| + factory.first_name 'Bill' + factory.last_name 'Nye' + factory.email 'science@guys.net' + end + end + + teardown do + Factory.factories.clear + end + + should "not raise an error when generating an invalid instance" do + assert_nothing_raised { User.generate(:first_name => nil) } + end + + should "raise an error when forcefully generating an invalid instance" do + assert_raise ActiveRecord::RecordInvalid do + User.generate!(:first_name => nil) + end + end + + %w(generate generate! spawn).each do |method| + should "yield a generated instance when using #{method} with a block" do + instance = nil + User.send(method) {|instance| } + assert_kind_of User, instance + end + + context "after generating an instance using #{method}" do + setup do + @instance = User.send(method, :last_name => 'Rye') + end + + should "use attributes from the factory" do + assert_equal 'Bill', @instance.first_name + end + + should "use attributes passed to generate" do + assert_equal 'Rye', @instance.last_name + end + + if method == 'spawn' + should "not save the record" do + assert @instance.new_record? + end + else + should "save the record" do + assert !@instance.new_record? + end + end + end + end + end + +end diff --git a/vendor/gems/thoughtbot-factory_girl-1.2.1/test/syntax/make_test.rb b/vendor/gems/thoughtbot-factory_girl-1.2.1/test/syntax/make_test.rb new file mode 100644 index 0000000..bb9a375 --- /dev/null +++ b/vendor/gems/thoughtbot-factory_girl-1.2.1/test/syntax/make_test.rb @@ -0,0 +1,39 @@ +require 'test_helper' + +require 'factory_girl/syntax/make' + +class MakeSyntaxTest < Test::Unit::TestCase + + context "a factory" do + setup do + Factory.define :user do |factory| + factory.first_name 'Bill' + factory.last_name 'Nye' + factory.email 'science@guys.net' + end + end + + teardown do + Factory.factories.clear + end + + context "after making an instance" do + setup do + @instance = User.make(:last_name => 'Rye') + end + + should "use attributes from the factory" do + assert_equal 'Bill', @instance.first_name + end + + should "use attributes passed to make" do + assert_equal 'Rye', @instance.last_name + end + + should "save the record" do + assert !@instance.new_record? + end + end + end + +end diff --git a/vendor/gems/thoughtbot-factory_girl-1.2.1/test/syntax/sham_test.rb b/vendor/gems/thoughtbot-factory_girl-1.2.1/test/syntax/sham_test.rb new file mode 100644 index 0000000..d8a646a --- /dev/null +++ b/vendor/gems/thoughtbot-factory_girl-1.2.1/test/syntax/sham_test.rb @@ -0,0 +1,40 @@ +require 'test_helper' + +require 'factory_girl/syntax/sham' + +class ShamSyntaxTest < Test::Unit::TestCase + + context "a factory" do + setup do + Sham.name { "Name" } + Sham.email { "somebody#{rand(5)}@example.com" } + + Factory.define :user do |factory| + factory.first_name { Sham.name } + factory.last_name { Sham.name } + factory.email { Sham.email } + end + end + + teardown do + Factory.factories.clear + Factory.sequences.clear + end + + context "after making an instance" do + setup do + @instance = Factory(:user, :last_name => 'Rye') + end + + should "support a sham called 'name'" do + assert_equal 'Name', @instance.first_name + end + + should "use the sham for the email" do + assert_match /somebody\d@example.com/, @instance.email + end + end + end + +end + diff --git a/vendor/gems/thoughtbot-factory_girl-1.2.1/test/test_helper.rb b/vendor/gems/thoughtbot-factory_girl-1.2.1/test/test_helper.rb new file mode 100644 index 0000000..577051a --- /dev/null +++ b/vendor/gems/thoughtbot-factory_girl-1.2.1/test/test_helper.rb @@ -0,0 +1,11 @@ +$: << File.join(File.dirname(__FILE__), '..', 'lib') +$: << File.join(File.dirname(__FILE__)) + +require 'rubygems' +require 'test/unit' +require 'activerecord' +require 'factory_girl' +gem 'thoughtbot-shoulda', ">= 2.0.0" +require 'shoulda' +require 'mocha' +require 'models' diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/CONTRIBUTION_GUIDELINES.rdoc b/vendor/gems/thoughtbot-shoulda-2.10.1/CONTRIBUTION_GUIDELINES.rdoc new file mode 100644 index 0000000..ac1794f --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/CONTRIBUTION_GUIDELINES.rdoc @@ -0,0 +1,12 @@ +We're using GitHub[http://github.com/thoughtbot/shoulda/tree/master] and Lighthouse[http://thoughtbot.lighthouseapp.com/projects/5807], and we've been getting any combination of github pull requests, Lighthouse tickets, patches, emails, etc. We need to normalize this workflow to make sure we don't miss any fixes. + +* Make sure you're accessing the source from the {official repository}[http://github.com/thoughtbot/shoulda/tree/master]. +* We prefer git branches over patches, but we can take either. +* If you're using git, please make a branch for each separate contribution. We can cherry pick your commits, but pulling from a branch is easier. +* If you're submitting patches, please cut each fix or feature into a separate patch. +* There should be a Lighthouse[http://thoughtbot.lighthouseapp.com/projects/5807] ticket for any submission. If you've found a bug and want to fix it, open a new ticket at the same time. +* We've got github/lighthouse integration going, so you can update tickets when you commit. {This blog post}[http://hoth.entp.com/2008/4/11/github-and-lighthouse-sitting-in-a-tree] explains the commit options pretty well. +* Please don't send pull requests Just update the lighthouse ticket with the url for your fix (or attach the patch) when it's ready. The github pull requests pretty much get dropped on the floor until someone with commit rights notices them in the mailbox. +* Contributions without tests won't be accepted. The file /test/README explains the testing system pretty thoroughly. + + diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/MIT-LICENSE b/vendor/gems/thoughtbot-shoulda-2.10.1/MIT-LICENSE new file mode 100644 index 0000000..f8e9154 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/MIT-LICENSE @@ -0,0 +1,22 @@ +Copyright (c) 2007, Tammer Saleh, Thoughtbot, Inc. + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the "Software"), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/README.rdoc b/vendor/gems/thoughtbot-shoulda-2.10.1/README.rdoc new file mode 100644 index 0000000..4c61ad4 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/README.rdoc @@ -0,0 +1,169 @@ += Shoulda - Making tests easy on the fingers and eyes + +Shoulda makes it easy to write elegant, understandable, and maintainable tests. Shoulda consists of test macros, assertions, and helpers added on to the Test::Unit framework. It's fully compatible with your existing tests, and requires no retooling to use. + +Helpers:: #context and #should give you RSpec like test blocks. + In addition, you get nested contexts and a much more readable syntax. +Macros:: Generate hundreds of lines of Controller and ActiveRecord tests with these powerful macros. + They get you started quickly, and can help you ensure that your application is conforming to best practices. +Assertions:: Many common rails testing idioms have been distilled into a set of useful assertions. +Matchers:: Rspec-compatible matchers providing the same tests as Shoulda macros. + += Usage + +=== Context Helpers (Shoulda::Context) + +Stop killing your fingers with all of those underscores... Name your tests with plain sentences! + + class UserTest < Test::Unit::TestCase + context "A User instance" do + setup do + @user = User.find(:first) + end + + should "return its full name" do + assert_equal 'John Doe', @user.full_name + end + + context "with a profile" do + setup do + @user.profile = Profile.find(:first) + end + + should "return true when sent #has_profile?" do + assert @user.has_profile? + end + end + end + end + +Produces the following test methods: + + "test: A User instance should return its full name." + "test: A User instance with a profile should return true when sent #has_profile?." + +So readable! + +=== ActiveRecord Tests (Shoulda::ActiveRecord::Macros) + +Quick macro tests for your ActiveRecord associations and validations: + + class PostTest < Test::Unit::TestCase + fixtures :all + + should_belong_to :user + should_have_many :tags, :through => :taggings + + should_validate_uniqueness_of :title + should_validate_presence_of :body, :message => /wtf/ + should_validate_presence_of :title + should_validate_numericality_of :user_id + end + + class UserTest < Test::Unit::TestCase + should_have_many :posts + + should_not_allow_values_for :email, "blah", "b lah" + should_allow_values_for :email, "a@b.com", "asdf@asdf.com" + should_ensure_length_in_range :email, 1..100 + should_ensure_value_in_range :age, 1..100 + should_not_allow_mass_assignment_of :password + end + +Makes TDD so much easier. + +=== Controller Tests (Shoulda::Controller::Macros) + +Macros to test the most common controller patterns... + + context "on GET to :show for first record" do + setup do + get :show, :id => 1 + end + + should_assign_to :user + should_respond_with :success + should_render_template :show + should_not_set_the_flash + + should "do something else really cool" do + assert_equal 1, assigns(:user).id + end + end + +=== Helpful Assertions (Shoulda::Assertions) + +More to come here, but have fun with what's there. + + assert_same_elements([:a, :b, :c], [:c, :a, :b]) + assert_contains(['a', '1'], /\d/) + assert_contains(['a', '1'], 'a') + +=== 3rd Party and Application Specific Macros + +Any *.rb file under RAILS_ROOT/test/shoulda_macros/ or vendor/(plugins|gems)/gem_name/shoulda_macros/ will be automatically required when you run your tests. This allows you to distribute macros with your plugins, or to organize the macros inside your application. Remember to add your macro to Test::Unit::TestCase in the macro file: + + # test/shoulda_macros/security.rb + class Test::Unit::TestCase + def self.should_be_denied(opts = {}) + should_set_the_flash_to(opts[:flash] || /Please log in/i) + should_redirect_to(opts[:redirect] || 'login_url') + end + end + += Rails Installation (Test::Unit) + +=== As a Gem + +Use this if you prefer to use versioned releases of shoulda. Specify the gem dependency in your config/environment.rb file: + + Rails::Initializer.run do |config| + config.gem "thoughtbot-shoulda", :lib => "shoulda", :source => "http://gems.github.com" + end + +Then: + + $ rake gems:install + $ rake gems:unpack + +=== As a Plugin + +Use this if you prefer to use the edge version of shoulda: + + $ script/plugin install git://github.com/thoughtbot/shoulda.git + +=== As a Plugin (using git submodules) + +Use this if you prefer the idea of being able to easily switch between using edge or a tagged version of shoulda: + + $ git submodule add git://github.com/thoughtbot/shoulda.git vendor/plugins/shoulda + += Rails Installation (RSpec) + +If you're using Shoulda with RSpec, we recommend that you add config.gem lines +for RSpec and Shoulda in your config/environment/test.rb file, but do not ask +Rails to load the RSpec and Shoulda libraries: + + config.gem 'rspec', :lib => false + config.gem 'rspec-rails', :lib => false + config.gem 'thoughtbot-shoulda', + :lib => false, + :source => 'http://gems.github.com' + +Then require shoulda from your spec/spec_helper.rb file, before Spec::Runner is +configured: + + # requires for RSpec + require 'shoulda' + Spec::Runner.configure do |config| + # ... + +You should not need to require anything besides the top-level shoulda library. + += Credits + +Shoulda is maintained by {Tammer Saleh}[mailto:tsaleh@thoughtbot.com], and is funded by Thoughtbot[http://www.thoughtbot.com], inc. + += License + +Shoulda is Copyright © 2006-2008 Tammer Saleh, Thoughtbot. It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file. diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/Rakefile b/vendor/gems/thoughtbot-shoulda-2.10.1/Rakefile new file mode 100644 index 0000000..7c04641 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/Rakefile @@ -0,0 +1,72 @@ +require 'rake' +require 'rake/testtask' +require 'rake/rdoctask' +require 'rake/gempackagetask' + +$LOAD_PATH.unshift("lib") +require 'shoulda' +load 'tasks/shoulda.rake' + +# Test::Unit::UI::VERBOSE +test_files_pattern = 'test/{unit,functional,other,matchers}/**/*_test.rb' +Rake::TestTask.new do |t| + t.libs << 'lib' + t.pattern = test_files_pattern + t.verbose = false +end + +Rake::RDocTask.new { |rdoc| + rdoc.rdoc_dir = 'doc' + rdoc.title = "Shoulda -- Making tests easy on the fingers and eyes" + rdoc.options << '--line-numbers' + rdoc.template = "#{ENV['template']}.rb" if ENV['template'] + rdoc.rdoc_files.include('README.rdoc', 'CONTRIBUTION_GUIDELINES.rdoc', 'lib/**/*.rb') +} + +desc "Run code-coverage analysis using rcov" +task :coverage do + rm_rf "coverage" + files = Dir[test_files_pattern] + system "rcov --rails --sort coverage -Ilib #{files.join(' ')}" +end + +desc 'Update documentation on website' +task :sync_docs => 'rdoc' do + `rsync -ave ssh doc/ dev@dev.thoughtbot.com:/home/dev/www/dev.thoughtbot.com/shoulda` +end + +desc 'Default: run tests.' +task :default => ['test'] + +spec = Gem::Specification.new do |s| + s.name = "shoulda" + s.version = Shoulda::VERSION + s.summary = "Making tests easy on the fingers and eyes" + s.homepage = "http://thoughtbot.com/projects/shoulda" + s.rubyforge_project = "shoulda" + + s.files = FileList["[A-Z]*", "{bin,lib,rails,test}/**/*"] + s.executables = s.files.grep(/^bin/) { |f| File.basename(f) } + + s.has_rdoc = true + s.extra_rdoc_files = ["README.rdoc", "CONTRIBUTION_GUIDELINES.rdoc"] + s.rdoc_options = ["--line-numbers", "--main", "README.rdoc"] + + s.authors = ["Tammer Saleh"] + s.email = "tsaleh@thoughtbot.com" +end + +Rake::GemPackageTask.new spec do |pkg| + pkg.need_tar = true + pkg.need_zip = true +end + +desc "Clean files generated by rake tasks" +task :clobber => [:clobber_rdoc, :clobber_package] + +desc "Generate a gemspec file for GitHub" +task :gemspec do + File.open("#{spec.name}.gemspec", 'w') do |f| + f.write spec.to_ruby + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/bin/convert_to_should_syntax b/vendor/gems/thoughtbot-shoulda-2.10.1/bin/convert_to_should_syntax new file mode 100755 index 0000000..d1264d0 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/bin/convert_to_should_syntax @@ -0,0 +1,42 @@ +#!/usr/bin/env ruby +require 'fileutils' +require 'tmpdir' + +TMP = Dir::tmpdir + +def usage(msg = nil) + puts "Error: #{msg}" if msg + puts if msg + puts "Usage: #{File.basename(__FILE__)} normal_test_file.rb" + puts + puts "Will convert an existing test file with names like " + puts + puts " def test_should_do_stuff" + puts " ..." + puts " end" + puts + puts "to one using the new syntax: " + puts + puts " should \"be super cool\" do" + puts " ..." + puts " end" + puts + puts "A copy of the old file will be left under #{TMP} in case\nthis script just seriously screws up" + puts + exit (msg ? 2 : 0) +end + +usage("Wrong number of arguments.") unless ARGV.size == 1 +usage("Temp directory '#{TMP}' is not valid. Set TMPDIR environment variable to a writeable directory.") unless File.directory?(TMP) && File.writable?(TMP) + +file = ARGV.shift +tmpfile = File.join(TMP, File.basename(file)) +usage("File '#{file}' doesn't exist") unless File.exists?(file) + +FileUtils.cp(file, tmpfile) +contents = File.read(tmpfile) +contents.gsub!(/def test_should_(\S+)/) {|line| "should \"#{$1.tr('_', ' ')}\" do"} +contents.gsub!(/def test_(\S+)/) {|line| "should \"RENAME ME: test #{$1.tr('_', ' ')}\" do"} +File.open(file, 'w') { |f| f.write(contents) } + +puts "File '#{file}' has been converted to 'should' syntax. Old version has been stored in '#{tmpfile}'" diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda.rb new file mode 100644 index 0000000..4b46206 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda.rb @@ -0,0 +1,9 @@ +module Shoulda + VERSION = "2.10.1" +end + +if defined? Spec + require 'shoulda/rspec' +else + require 'shoulda/test_unit' +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller.rb new file mode 100644 index 0000000..4719851 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller.rb @@ -0,0 +1,28 @@ +require 'shoulda' +require 'shoulda/action_controller/helpers' +require 'shoulda/action_controller/matchers' +require 'shoulda/action_controller/macros' + +module Test # :nodoc: all + module Unit + class TestCase + include Shoulda::ActionController::Matchers + include Shoulda::ActionController::Helpers + extend Shoulda::ActionController::Macros + end + end +end + +require 'shoulda/active_record/assertions' +require 'shoulda/action_mailer/assertions' + +module ActionController #:nodoc: all + module Integration + class Session + include Shoulda::Assertions + include Shoulda::Helpers + include Shoulda::ActiveRecord::Assertions + include Shoulda::ActionMailer::Assertions + end + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller/helpers.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller/helpers.rb new file mode 100644 index 0000000..654bf7b --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller/helpers.rb @@ -0,0 +1,47 @@ +module Shoulda # :nodoc: + module ActionController # :nodoc: + module Helpers # :nodoc: + private # :enddoc: + + SPECIAL_INSTANCE_VARIABLES = %w{ + _cookies + _flash + _headers + _params + _request + _response + _session + action_name + before_filter_chain_aborted + cookies + flash + headers + ignore_missing_templates + logger + params + request + request_origin + response + session + template + template_class + template_root + url + variables_added + }.map(&:to_s) + + def instantiate_variables_from_assigns(*names, &blk) + old = {} + names = (@response.template.assigns.keys - SPECIAL_INSTANCE_VARIABLES) if names.empty? + names.each do |name| + old[name] = instance_variable_get("@#{name}") + instance_variable_set("@#{name}", assigns(name.to_sym)) + end + blk.call + names.each do |name| + instance_variable_set("@#{name}", old[name]) + end + end + end + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller/macros.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller/macros.rb new file mode 100644 index 0000000..c9d5f75 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller/macros.rb @@ -0,0 +1,277 @@ +module Shoulda # :nodoc: + module ActionController # :nodoc: + # = Macro test helpers for your controllers + # + # By using the macro helpers you can quickly and easily create concise and easy to read test suites. + # + # This code segment: + # context "on GET to :show for first record" do + # setup do + # get :show, :id => 1 + # end + # + # should_assign_to :user + # should_respond_with :success + # should_render_template :show + # should_not_set_the_flash + # + # should "do something else really cool" do + # assert_equal 1, assigns(:user).id + # end + # end + # + # Would produce 5 tests for the +show+ action + module Macros + include Matchers + + # Macro that creates a test asserting that the flash contains the given value. + # val can be a String, a Regex, or nil (indicating that the flash should not be set) + # + # Example: + # + # should_set_the_flash_to "Thank you for placing this order." + # should_set_the_flash_to /created/i + # should_set_the_flash_to nil + def should_set_the_flash_to(val) + matcher = set_the_flash.to(val) + if val + should matcher.description do + assert_accepts matcher, @controller + end + else + should "not #{matcher.description}" do + assert_rejects matcher, @controller + end + end + end + + # Macro that creates a test asserting that the flash is empty. Same as + # @should_set_the_flash_to nil@ + def should_not_set_the_flash + should_set_the_flash_to nil + end + + # Macro that creates a test asserting that filter_parameter_logging + # is set for the specified keys + # + # Example: + # + # should_filter_params :password, :ssn + def should_filter_params(*keys) + keys.each do |key| + matcher = filter_param(key) + should matcher.description do + assert_accepts matcher, @controller + end + end + end + + # Macro that creates a test asserting that the controller assigned to + # each of the named instance variable(s). + # + # Options: + # * :class - The expected class of the instance variable being checked. + # * :equals - A string which is evaluated and compared for equality with + # the instance variable being checked. + # + # Example: + # + # should_assign_to :user, :posts + # should_assign_to :user, :class => User + # should_assign_to(:user) { @user } + def should_assign_to(*names, &block) + opts = names.extract_options! + if opts[:equals] + warn "[DEPRECATION] should_assign_to :var, :equals => 'val' " << + "is deprecated. Use should_assign_to(:var) { 'val' } instead." + end + names.each do |name| + matcher = assign_to(name).with_kind_of(opts[:class]) + test_name = matcher.description + test_name << " which is equal to #{opts[:equals]}" if opts[:equals] + should test_name do + if opts[:equals] + instantiate_variables_from_assigns do + expected_value = eval(opts[:equals], + self.send(:binding), + __FILE__, + __LINE__) + matcher = matcher.with(expected_value) + end + elsif block + expected_value = instance_eval(&block) + matcher = matcher.with(expected_value) + end + + assert_accepts matcher, @controller + end + end + end + + # Macro that creates a test asserting that the controller did not assign to + # any of the named instance variable(s). + # + # Example: + # + # should_not_assign_to :user, :posts + def should_not_assign_to(*names) + names.each do |name| + matcher = assign_to(name) + should "not #{matcher.description}" do + assert_rejects matcher, @controller + end + end + end + + # Macro that creates a test asserting that the controller responded with a 'response' status code. + # Example: + # + # should_respond_with :success + def should_respond_with(response) + should "respond with #{response}" do + matcher = respond_with(response) + assert_accepts matcher, @controller + end + end + + # Macro that creates a test asserting that the response content type was 'content_type'. + # Example: + # + # should_respond_with_content_type 'application/rss+xml' + # should_respond_with_content_type :rss + # should_respond_with_content_type /rss/ + def should_respond_with_content_type(content_type) + should "respond with content type of #{content_type}" do + matcher = respond_with_content_type(content_type) + assert_accepts matcher, @controller + end + end + + # Macro that creates a test asserting that a value returned from the session is correct. + # The given string is evaled to produce the resulting redirect path. All of the instance variables + # set by the controller are available to the evaled string. + # Example: + # + # should_set_session(:user_id) { '@user.id' } + # should_set_session(:message) { "Free stuff" } + def should_set_session(key, expected = nil, &block) + matcher = set_session(key) + if expected + warn "[DEPRECATION] should_set_session :key, 'val' is deprecated. " << + "Use should_set_session(:key) { 'val' } instead." + end + should matcher.description do + if expected + instantiate_variables_from_assigns do + expected_value = eval(expected, + self.send(:binding), + __FILE__, + __LINE__) + matcher = matcher.to(expected_value) + end + else + expected_value = instance_eval(&block) + matcher = matcher.to(expected_value) + end + assert_accepts matcher, @controller + end + end + + # Deprecated. See should_set_session + def should_return_from_session(key, expected) + warn "[DEPRECATION] should_require_attributes is deprecated. " << + "Use should_set_session instead." + should_set_session(key, expected) + end + + # Macro that creates a test asserting that the controller rendered the given template. + # Example: + # + # should_render_template :new + def should_render_template(template) + should "render template #{template.inspect}" do + assert_template template.to_s + end + end + + # Macro that creates a test asserting that the controller rendered with the given layout. + # Example: + # + # should_render_with_layout 'special' + def should_render_with_layout(expected_layout = 'application') + matcher = render_with_layout(expected_layout) + if expected_layout + should matcher.description do + assert_accepts matcher, @controller + end + else + should "render without layout" do + assert_rejects matcher, @controller + end + end + end + + # Macro that creates a test asserting that the controller rendered without a layout. + # Same as @should_render_with_layout false@ + def should_render_without_layout + should_render_with_layout nil + end + + # Macro that creates a test asserting that the controller returned a redirect to the given path. + # The given string is evaled to produce the resulting redirect path. All of the instance variables + # set by the controller are available to the evaled string. + # Example: + # + # should_redirect_to("the user's profile") { user_url(@user) } + def should_redirect_to(description, &block) + unless block + warn "[DEPRECATION] should_redirect_to without a block is " << + "deprecated. Use should_redirect_to('somewhere') { } instead." + end + should "redirect to #{description}" do + if block + url = instance_eval(&block) + else + instantiate_variables_from_assigns do + url = eval(description, self.send(:binding), __FILE__, __LINE__) + end + end + assert_redirected_to url + end + end + + # Macro that creates a routing test. It tries to use the given HTTP + # +method+ on the given +path+, and asserts that it routes to the + # given +options+. + # + # If you don't specify a :controller, it will try to guess the controller + # based on the current test. + # + # +to_param+ is called on the +options+ given. + # + # Examples: + # + # should_route :get, "/posts", :controller => :posts, :action => :index + # should_route :get, "/posts/new", :action => :new + # should_route :post, "/posts", :action => :create + # should_route :get, "/posts/1", :action => :show, :id => 1 + # should_route :edit, "/posts/1", :action => :show, :id => 1 + # should_route :put, "/posts/1", :action => :update, :id => 1 + # should_route :delete, "/posts/1", :action => :destroy, :id => 1 + # should_route :get, "/users/1/posts/1", + # :action => :show, :id => 1, :user_id => 1 + # + def should_route(method, path, options) + unless options[:controller] + options[:controller] = self.name.gsub(/ControllerTest$/, '').tableize + end + + matcher = route(method, path).to(options) + + should matcher.description do + assert_accepts matcher.in_context(self), self + end + end + end + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller/matchers.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller/matchers.rb new file mode 100644 index 0000000..c12f729 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller/matchers.rb @@ -0,0 +1,37 @@ +require 'shoulda/action_controller/matchers/assign_to_matcher' +require 'shoulda/action_controller/matchers/filter_param_matcher' +require 'shoulda/action_controller/matchers/set_the_flash_matcher' +require 'shoulda/action_controller/matchers/render_with_layout_matcher' +require 'shoulda/action_controller/matchers/respond_with_matcher' +require 'shoulda/action_controller/matchers/respond_with_content_type_matcher' +require 'shoulda/action_controller/matchers/set_session_matcher' +require 'shoulda/action_controller/matchers/route_matcher' + +module Shoulda # :nodoc: + module ActionController # :nodoc: + + # By using the macro helpers you can quickly and easily create concise and + # easy to read test suites. + # + # This code segment: + # + # describe UsersController, "on GET to show with a valid id" do + # before(:each) do + # get :show, :id => User.first.to_param + # end + # + # it { should assign_to(:user) } + # it { should respond_with(:success) } + # it { should render_template(:show) } + # it { should not_set_the_flash) } + # + # it "should do something else really cool" do + # assigns[:user].id.should == 1 + # end + # end + # + # Would produce 5 tests for the show action + module Matchers + end + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller/matchers/assign_to_matcher.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller/matchers/assign_to_matcher.rb new file mode 100644 index 0000000..dde864b --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller/matchers/assign_to_matcher.rb @@ -0,0 +1,109 @@ +module Shoulda # :nodoc: + module ActionController # :nodoc: + module Matchers + + # Ensures that the controller assigned to the named instance variable. + # + # Options: + # * with_kind_of - The expected class of the instance variable + # being checked. + # * with - The value that should be assigned. + # + # Example: + # + # it { should assign_to(:user) } + # it { should_not assign_to(:user) } + # it { should assign_to(:user).with_kind_of(User) } + # it { should assign_to(:user).with(@user) } + def assign_to(variable) + AssignToMatcher.new(variable) + end + + class AssignToMatcher # :nodoc: + + def initialize(variable) + @variable = variable.to_s + end + + def with_kind_of(expected_class) + @expected_class = expected_class + self + end + + def with(expected_value) + @expected_value = expected_value + self + end + + def matches?(controller) + @controller = controller + assigned_value? && kind_of_expected_class? && equal_to_expected_value? + end + + attr_reader :failure_message, :negative_failure_message + + def description + description = "assign @#{@variable}" + description << " with a kind of #{@expected_class}" if @expected_class + description + end + + private + + def assigned_value? + if assigned_value.nil? + @failure_message = + "Expected action to assign a value for @#{@variable}" + false + else + @negative_failure_message = + "Didn't expect action to assign a value for @#{@variable}, " << + "but it was assigned to #{assigned_value.inspect}" + true + end + end + + def kind_of_expected_class? + return true unless @expected_class + if assigned_value.kind_of?(@expected_class) + @negative_failure_message = + "Didn't expect action to assign a kind of #{@expected_class} " << + "for #{@variable}, but got one anyway" + true + else + @failure_message = + "Expected action to assign a kind of #{@expected_class} " << + "for #{@variable}, but got #{@variable.inspect} " << + "(#{@variable.class.name})" + false + end + end + + def equal_to_expected_value? + return true unless @expected_value + if @expected_value == assigned_value + @negative_failure_message = + "Didn't expect action to assign #{@expected_value.inspect} " << + "for #{@variable}, but got it anyway" + true + else + @failure_message = + "Expected action to assign #{@expected_value.inspect} " << + "for #{@variable}, but got #{assigned_value.inspect}" + false + end + end + + def assigned_value + assigns[@variable] + end + + def assigns + @controller.response.template.assigns + end + + end + + end + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller/matchers/filter_param_matcher.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller/matchers/filter_param_matcher.rb new file mode 100644 index 0000000..1e46896 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller/matchers/filter_param_matcher.rb @@ -0,0 +1,57 @@ +module Shoulda # :nodoc: + module ActionController # :nodoc: + module Matchers + + # Ensures that filter_parameter_logging is set for the specified key. + # + # Example: + # + # it { should filter_param(:password) } + def filter_param(key) + FilterParamMatcher.new(key) + end + + class FilterParamMatcher # :nodoc: + + def initialize(key) + @key = key.to_s + end + + def matches?(controller) + @controller = controller + filters_params? && filters_key? + end + + def failure_message + "Expected #{@key} to be filtered" + end + + def negative_failure_message + "Did not expect #{@key} to be filtered" + end + + def description + "filter #{@key}" + end + + private + + def filters_params? + @controller.respond_to?(:filter_parameters) + end + + def filters_key? + filtered_value == '[FILTERED]' + end + + def filtered_value + filtered = @controller.send(:filter_parameters, + @key.to_s => @key.to_s) + filtered[@key.to_s] + end + + end + + end + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller/matchers/render_with_layout_matcher.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller/matchers/render_with_layout_matcher.rb new file mode 100644 index 0000000..9ceb4e8 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller/matchers/render_with_layout_matcher.rb @@ -0,0 +1,81 @@ +module Shoulda # :nodoc: + module ActionController # :nodoc: + module Matchers + + # Ensures that the controller rendered with the given layout. + # + # Example: + # + # it { should render_with_layout } + # it { should render_with_layout(:special) } + # it { should_not render_with_layout } + def render_with_layout(layout = nil) + RenderWithLayout.new(layout) + end + + class RenderWithLayout # :nodoc: + + def initialize(layout) + @layout = layout.to_s unless layout.nil? + end + + def matches?(controller) + @controller = controller + rendered_with_layout? && rendered_with_expected_layout? + end + + def failure_message + "Expected #{expectation}, but #{result}" + end + + def negative_failure_message + "Did not expect #{expectation}, but #{result}" + end + + def description + description = "render with " + if @layout.nil? + description << "a layout" + else + description << "the #{@layout.inspect} layout" + end + description + end + + private + + def rendered_with_layout? + !layout.blank? + end + + def rendered_with_expected_layout? + return true if @layout.nil? + layout == @layout + end + + def layout + layout = @controller.response.layout + if layout.nil? + nil + else + layout.split('/').last + end + end + + def expectation + "to #{description}" + end + + def result + if rendered_with_layout? + "rendered with the #{layout.inspect} layout" + else + "rendered without a layout" + end + end + + end + + end + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller/matchers/respond_with_content_type_matcher.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller/matchers/respond_with_content_type_matcher.rb new file mode 100644 index 0000000..c47dba3 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller/matchers/respond_with_content_type_matcher.rb @@ -0,0 +1,70 @@ +module Shoulda # :nodoc: + module ActionController # :nodoc: + module Matchers + + # Ensures a controller responded with expected 'response' content type. + # + # You can pass an explicit content type such as 'application/rss+xml' + # or its symbolic equivalent :rss + # or a regular expression such as /rss/ + # + # Example: + # + # it { should respond_with_content_type(:xml) } + # it { should respond_with_content_type(:csv) } + # it { should respond_with_content_type(:atom) } + # it { should respond_with_content_type(:yaml) } + # it { should respond_with_content_type(:text) } + # it { should respond_with_content_type('application/rss+xml') } + # it { should respond_with_content_type(/json/) } + def respond_with_content_type(content_type) + RespondWithContentTypeMatcher.new(content_type) + end + + class RespondWithContentTypeMatcher # :nodoc: + + def initialize(content_type) + @content_type = if content_type.is_a?(Symbol) + lookup_by_extension(content_type) + else + content_type + end + end + + def matches?(controller) + @controller = controller + if @content_type.is_a?(Regexp) + response_content_type =~ @content_type + else + response_content_type == @content_type + end + end + + def failure_message + "Expected #{expectation}" + end + + def negative_failure_message + "Did not expect #{expectation}" + end + + protected + + def response_content_type + @controller.response.content_type + end + + def lookup_by_extension(extension) + Mime::Type.lookup_by_extension(extension.to_s).to_s + end + + def expectation + "content type to be #{@content_type}, " << + "but was #{response_content_type}" + end + + end + + end + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller/matchers/respond_with_matcher.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller/matchers/respond_with_matcher.rb new file mode 100644 index 0000000..8c61384 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller/matchers/respond_with_matcher.rb @@ -0,0 +1,81 @@ +module Shoulda # :nodoc: + module ActionController # :nodoc: + module Matchers + + # Ensures a controller responded with expected 'response' status code. + # + # You can pass an explicit status number like 200, 301, 404, 500 + # or its symbolic equivalent :success, :redirect, :missing, :error. + # See ActionController::StatusCodes for a full list. + # + # Example: + # + # it { should respond_with(:success) } + # it { should respond_with(:redirect) } + # it { should respond_with(:missing) } + # it { should respond_with(:error) } + # it { should respond_with(501) } + def respond_with(status) + RespondWithMatcher.new(status) + end + + class RespondWithMatcher # :nodoc: + + def initialize(status) + @status = symbol_to_status_code(status) + end + + def matches?(controller) + @controller = controller + correct_status_code? || correct_status_code_range? + end + + def failure_message + "Expected #{expectation}" + end + + def negative_failure_message + "Did not expect #{expectation}" + end + + def description + "respond with #{@status}" + end + + protected + + def correct_status_code? + response_code == @status + end + + def correct_status_code_range? + @status.is_a?(Range) && + @status.include?(response_code) + end + + def response_code + @controller.response.response_code + end + + def symbol_to_status_code(potential_symbol) + case potential_symbol + when :success then 200 + when :redirect then 300..399 + when :missing then 404 + when :error then 500..599 + when Symbol + ::ActionController::StatusCodes::SYMBOL_TO_STATUS_CODE[potential_symbol] + else + potential_symbol + end + end + + def expectation + "response to be a #{@status}, but was #{response_code}" + end + + end + + end + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller/matchers/route_matcher.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller/matchers/route_matcher.rb new file mode 100644 index 0000000..fe8e2b6 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller/matchers/route_matcher.rb @@ -0,0 +1,93 @@ +module Shoulda # :nodoc: + module ActionController # :nodoc: + module Matchers + + # Ensures that requesting +path+ using +method+ routes to +options+. + # + # If you don't specify a controller, it will use the controller from the + # example group. + # + # +to_param+ is called on the +options+ given. + # + # Examples: + # + # it { should route(:get, "/posts"). + # to(:controller => :posts, :action => :index) } + # it { should route(:get, "/posts/new").to(:action => :new) } + # it { should route(:post, "/posts").to(:action => :create) } + # it { should route(:get, "/posts/1").to(:action => :show, :id => 1) } + # it { should route(:edit, "/posts/1").to(:action => :show, :id => 1) } + # it { should route(:put, "/posts/1").to(:action => :update, :id => 1) } + # it { should route(:delete, "/posts/1"). + # to(:action => :destroy, :id => 1) } + # it { should route(:get, "/users/1/posts/1"). + # to(:action => :show, :id => 1, :user_id => 1) } + def route(method, path) + RouteMatcher.new(method, path, self) + end + + class RouteMatcher # :nodoc: + + def initialize(method, path, context) + @method = method + @path = path + @context = context + end + + def to(params) + @params = params + self + end + + def in_context(context) + @context = context + self + end + + def matches?(controller) + @controller = controller + guess_controller! + stringify_params! + route_recognized? + end + + attr_reader :failure_message, :negative_failure_message + + def description + "route #{@method.to_s.upcase} #{@path} to/from #{@params.inspect}" + end + + private + + def guess_controller! + @params[:controller] ||= @controller.controller_path + end + + def stringify_params! + @params.each do |key, value| + @params[key] = value.to_param + end + end + + def route_recognized? + begin + @context.send(:assert_routing, + { :method => @method, :path => @path }, + @params) + + @negative_failure_message = "Didn't expect to #{description}" + true + rescue ::ActionController::RoutingError => error + @failure_message = error.message + false + rescue Test::Unit::AssertionFailedError => error + @failure_message = error.message + false + end + end + + end + + end + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller/matchers/set_session_matcher.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller/matchers/set_session_matcher.rb new file mode 100644 index 0000000..c1a823b --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller/matchers/set_session_matcher.rb @@ -0,0 +1,87 @@ +module Shoulda # :nodoc: + module ActionController # :nodoc: + module Matchers + + # Ensures that a session key was set to the expected value. + # + # Example: + # + # it { should set_session(:message) } + # it { should set_session(:user_id).to(@user.id) } + # it { should_not set_session(:user_id) } + def set_session(key) + SetSessionMatcher.new(key) + end + + class SetSessionMatcher # :nodoc: + + def initialize(key) + @key = key.to_s + end + + def to(value) + @value = value + self + end + + def matches?(controller) + @controller = controller + (assigned_value? && assigned_correct_value?) || cleared_value? + end + + def failure_message + "Expected #{expectation}, but #{result}" + end + + def negative_failure_message + "Didn't expect #{expectation}, but #{result}" + end + + def description + description = "set session variable #{@key.inspect}" + description << " to #{@value.inspect}" if defined?(@value) + description + end + + private + + def assigned_value? + !assigned_value.blank? + end + + def cleared_value? + defined?(@value) && @value.nil? && assigned_value.nil? + end + + def assigned_correct_value? + return true if @value.nil? + assigned_value == @value + end + + def assigned_value + session[@key] + end + + def session + @controller.response.session.data + end + + def expectation + expectation = "session variable #{@key} to be set" + expectation << " to #{@value.inspect}" if @value + expectation + end + + def result + if session.empty? + "no session variables were set" + else + "the session was #{session.inspect}" + end + end + + end + + end + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller/matchers/set_the_flash_matcher.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller/matchers/set_the_flash_matcher.rb new file mode 100644 index 0000000..0964cc7 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_controller/matchers/set_the_flash_matcher.rb @@ -0,0 +1,85 @@ +module Shoulda # :nodoc: + module ActionController # :nodoc: + module Matchers + + # Ensures that the flash contains the given value. Can be a String, a + # Regexp, or nil (indicating that the flash should not be set). + # + # Example: + # + # it { should set_the_flash } + # it { should set_the_flash.to("Thank you for placing this order.") } + # it { should set_the_flash.to(/created/i) } + # it { should_not set_the_flash } + def set_the_flash + SetTheFlashMatcher.new + end + + class SetTheFlashMatcher # :nodoc: + + def to(value) + @value = value + self + end + + def matches?(controller) + @controller = controller + sets_the_flash? && string_value_matches? && regexp_value_matches? + end + + attr_reader :failure_message, :negative_failure_message + + def description + description = "set the flash" + description << " to #{@value.inspect}" unless @value.nil? + description + end + + def failure_message + "Expected #{expectation}" + end + + def negative_failure_message + "Did not expect #{expectation}" + end + + private + + def sets_the_flash? + !flash.blank? + end + + def string_value_matches? + return true unless String === @value + flash.values.any? {|value| value == @value } + end + + def regexp_value_matches? + return true unless Regexp === @value + flash.values.any? {|value| value =~ @value } + end + + def flash + @controller.response.session['flash'] + end + + def expectation + expectation = "the flash to be set" + expectation << " to #{@value.inspect}" unless @value.nil? + expectation << ", but #{flash_description}" + expectation + end + + def flash_description + if flash.blank? + "no flash was set" + else + "was #{flash.inspect}" + end + end + + end + + end + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_mailer.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_mailer.rb new file mode 100644 index 0000000..f6195f2 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_mailer.rb @@ -0,0 +1,10 @@ +require 'shoulda' +require 'shoulda/action_mailer/assertions' + +module Test # :nodoc: all + module Unit + class TestCase + include Shoulda::ActionMailer::Assertions + end + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_mailer/assertions.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_mailer/assertions.rb new file mode 100644 index 0000000..153d079 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_mailer/assertions.rb @@ -0,0 +1,38 @@ +module Shoulda # :nodoc: + module ActionMailer # :nodoc: + module Assertions + # Asserts that an email was delivered. Can take a block that can further + # narrow down the types of emails you're expecting. + # + # assert_sent_email + # + # Passes if ActionMailer::Base.deliveries has an email + # + # assert_sent_email do |email| + # email.subject =~ /hi there/ && email.to.include?('none@none.com') + # end + # + # Passes if there is an email with subject containing 'hi there' and + # 'none@none.com' as one of the recipients. + # + def assert_sent_email + emails = ::ActionMailer::Base.deliveries + assert !emails.empty?, "No emails were sent" + if block_given? + matching_emails = emails.select {|email| yield email } + assert !matching_emails.empty?, "None of the emails matched." + end + end + + # Asserts that no ActionMailer mails were delivered + # + # assert_did_not_send_email + def assert_did_not_send_email + msg = "Sent #{::ActionMailer::Base.deliveries.size} emails.\n" + ::ActionMailer::Base.deliveries.each { |m| msg << " '#{m.subject}' sent to #{m.to.to_sentence}\n" } + assert ::ActionMailer::Base.deliveries.empty?, msg + end + end + end +end + diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_view.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_view.rb new file mode 100644 index 0000000..2615b63 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_view.rb @@ -0,0 +1,10 @@ +require 'shoulda' +require 'shoulda/action_view/macros' + +module Test # :nodoc: all + module Unit + class TestCase + extend Shoulda::ActionView::Macros + end + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_view/macros.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_view/macros.rb new file mode 100644 index 0000000..7157bd0 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/action_view/macros.rb @@ -0,0 +1,56 @@ +module Shoulda # :nodoc: + module ActionView # :nodoc: + # = Macro test helpers for your view + # + # By using the macro helpers you can quickly and easily create concise and + # easy to read test suites. + # + # This code segment: + # context "on GET to :new" do + # setup do + # get :new + # end + # + # should_render_a_form + # should_render_page_with_metadata :title => /index/ + # + # should "do something else really cool" do + # assert_select '#really_cool' + # end + # end + # + # Would produce 3 tests for the +show+ action + module Macros + + # Macro that creates a test asserting that the rendered view contains a
element. + def should_render_a_form + should "display a form" do + assert_select "form", true, "The template doesn't contain a element" + end + end + + # Macro that creates a test asserting that the rendered view contains the selected metatags. + # Values can be string or Regexps. + # Example: + # + # should_render_page_with_metadata :description => "Description of this page", :keywords => /post/ + # + # You can also use this method to test the rendered views title. + # + # Example: + # should_render_page_with_metadata :title => /index/ + def should_render_page_with_metadata(options) + options.each do |key, value| + should "have metatag #{key}" do + if key.to_sym == :title + assert_select "title", value + else + assert_select "meta[name=?][content#{"*" if value.is_a?(Regexp)}=?]", key, value + end + end + end + end + end + end +end + diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record.rb new file mode 100644 index 0000000..c379282 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record.rb @@ -0,0 +1,16 @@ +require 'shoulda' +require 'shoulda/active_record/helpers' +require 'shoulda/active_record/matchers' +require 'shoulda/active_record/assertions' +require 'shoulda/active_record/macros' + +module Test # :nodoc: all + module Unit + class TestCase + include Shoulda::ActiveRecord::Helpers + include Shoulda::ActiveRecord::Matchers + include Shoulda::ActiveRecord::Assertions + extend Shoulda::ActiveRecord::Macros + end + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/assertions.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/assertions.rb new file mode 100644 index 0000000..9730fe1 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/assertions.rb @@ -0,0 +1,69 @@ +module Shoulda # :nodoc: + module ActiveRecord # :nodoc: + module Assertions + # Asserts that the given object can be saved + # + # assert_save User.new(params) + def assert_save(obj) + assert obj.save, "Errors: #{pretty_error_messages obj}" + obj.reload + end + + # Asserts that the given object is valid + # + # assert_valid User.new(params) + def assert_valid(obj) + assert obj.valid?, "Errors: #{pretty_error_messages obj}" + end + + # Asserts that an Active Record model validates with the passed + # value by making sure the error_message_to_avoid is not + # contained within the list of errors for that attribute. + # + # assert_good_value(User.new, :email, "user@example.com") + # assert_good_value(User.new, :ssn, "123456789", /length/) + # + # If a class is passed as the first argument, a new object will be + # instantiated before the assertion. If an instance variable exists with + # the same name as the class (underscored), that object will be used + # instead. + # + # assert_good_value(User, :email, "user@example.com") + # + # @product = Product.new(:tangible => false) + # assert_good_value(Product, :price, "0") + def assert_good_value(object_or_klass, attribute, value, error_message_to_avoid = nil) + object = get_instance_of(object_or_klass) + matcher = allow_value(value). + for(attribute). + with_message(error_message_to_avoid) + assert_accepts(matcher, object) + end + + # Asserts that an Active Record model invalidates the passed + # value by making sure the error_message_to_expect is + # contained within the list of errors for that attribute. + # + # assert_bad_value(User.new, :email, "invalid") + # assert_bad_value(User.new, :ssn, "123", /length/) + # + # If a class is passed as the first argument, a new object will be + # instantiated before the assertion. If an instance variable exists with + # the same name as the class (underscored), that object will be used + # instead. + # + # assert_bad_value(User, :email, "invalid") + # + # @product = Product.new(:tangible => true) + # assert_bad_value(Product, :price, "0") + def assert_bad_value(object_or_klass, attribute, value, + error_message_to_expect = nil) + object = get_instance_of(object_or_klass) + matcher = allow_value(value). + for(attribute). + with_message(error_message_to_expect) + assert_rejects(matcher, object) + end + end + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/helpers.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/helpers.rb new file mode 100644 index 0000000..26799c1 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/helpers.rb @@ -0,0 +1,40 @@ +module Shoulda # :nodoc: + module ActiveRecord # :nodoc: + module Helpers + def pretty_error_messages(obj) # :nodoc: + obj.errors.map do |a, m| + msg = "#{a} #{m}" + msg << " (#{obj.send(a).inspect})" unless a.to_sym == :base + end + end + + def get_instance_of(object_or_klass) + if object_or_klass.is_a?(Class) + klass = object_or_klass + instance_variable_get("@#{instance_variable_name_for(klass)}") || klass.new + else + object_or_klass + end + end + + def instance_variable_name_for(klass) + klass.to_s.split('::').last.underscore + end + + # Helper method that determines the default error message used by Active + # Record. Works for both existing Rails 2.1 and Rails 2.2 with the newly + # introduced I18n module used for localization. + # + # default_error_message(:blank) + # default_error_message(:too_short, :count => 5) + # default_error_message(:too_long, :count => 60) + def default_error_message(key, values = {}) + if Object.const_defined?(:I18n) # Rails >= 2.2 + I18n.translate("activerecord.errors.messages.#{key}", values) + else # Rails <= 2.1.x + ::ActiveRecord::Errors.default_error_messages[key] % values[:count] + end + end + end + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/macros.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/macros.rb new file mode 100644 index 0000000..231ca20 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/macros.rb @@ -0,0 +1,589 @@ +module Shoulda # :nodoc: + module ActiveRecord # :nodoc: + # = Macro test helpers for your active record models + # + # These helpers will test most of the validations and associations for your ActiveRecord models. + # + # class UserTest < Test::Unit::TestCase + # should_validate_presence_of :name, :phone_number + # should_not_allow_values_for :phone_number, "abcd", "1234" + # should_allow_values_for :phone_number, "(123) 456-7890" + # + # should_not_allow_mass_assignment_of :password + # + # should_have_one :profile + # should_have_many :dogs + # should_have_many :messes, :through => :dogs + # should_belong_to :lover + # end + # + # For all of these helpers, the last parameter may be a hash of options. + # + module Macros + include Helpers + include Matchers + + # Ensures that the model cannot be saved if one of the attributes listed is not present. + # + # If an instance variable has been created in the setup named after the + # model being tested, then this method will use that. Otherwise, it will + # create a new instance to test against. + # + # Options: + # * :message - value the test expects to find in errors.on(:attribute). + # Regexp or string. Default = I18n.translate('activerecord.errors.messages.blank') + # + # Example: + # should_validate_presence_of :name, :phone_number + # + def should_validate_presence_of(*attributes) + message = get_options!(attributes, :message) + klass = model_class + + attributes.each do |attribute| + matcher = validate_presence_of(attribute).with_message(message) + should matcher.description do + assert_accepts(matcher, get_instance_of(klass)) + end + end + end + + # Deprecated. See should_validate_presence_of + def should_require_attributes(*attributes) + warn "[DEPRECATION] should_require_attributes is deprecated. " << + "Use should_validate_presence_of instead." + should_validate_presence_of(*attributes) + end + + # Ensures that the model cannot be saved if one of the attributes listed is not unique. + # Requires an existing record + # + # Options: + + # * :message - value the test expects to find in errors.on(:attribute). + # Regexp or string. Default = I18n.translate('activerecord.errors.messages.taken') + # * :scoped_to - field(s) to scope the uniqueness to. + # * :case_sensitive - whether or not uniqueness is defined by an + # exact match. Ignored by non-text attributes. Default = true + # + # Examples: + # should_validate_uniqueness_of :keyword, :username + # should_validate_uniqueness_of :name, :message => "O NOES! SOMEONE STOELED YER NAME!" + # should_validate_uniqueness_of :email, :scoped_to => :name + # should_validate_uniqueness_of :address, :scoped_to => [:first_name, :last_name] + # should_validate_uniqueness_of :email, :case_sensitive => false + # + def should_validate_uniqueness_of(*attributes) + message, scope, case_sensitive = get_options!(attributes, :message, :scoped_to, :case_sensitive) + scope = [*scope].compact + case_sensitive = true if case_sensitive.nil? + + klass = model_class + + attributes.each do |attribute| + matcher = validate_uniqueness_of(attribute). + with_message(message).scoped_to(scope) + matcher = matcher.case_insensitive unless case_sensitive + should matcher.description do + assert_accepts(matcher, get_instance_of(klass)) + end + end + end + + # Deprecated. See should_validate_uniqueness_of + def should_require_unique_attributes(*attributes) + warn "[DEPRECATION] should_require_unique_attributes is deprecated. " << + "Use should_validate_uniqueness_of instead." + should_validate_uniqueness_of(*attributes) + end + + # Ensures that the attribute can be set on mass update. + # + # should_allow_mass_assignment_of :first_name, :last_name + # + def should_allow_mass_assignment_of(*attributes) + get_options!(attributes) + klass = model_class + + attributes.each do |attribute| + matcher = allow_mass_assignment_of(attribute) + should matcher.description do + assert_accepts matcher, klass.new + end + end + end + + # Ensures that the attribute cannot be set on mass update. + # + # should_not_allow_mass_assignment_of :password, :admin_flag + # + def should_not_allow_mass_assignment_of(*attributes) + get_options!(attributes) + klass = model_class + + attributes.each do |attribute| + matcher = allow_mass_assignment_of(attribute) + should "not #{matcher.description}" do + assert_rejects matcher, klass.new + end + end + end + + # Deprecated. See should_not_allow_mass_assignment_of + def should_protect_attributes(*attributes) + warn "[DEPRECATION] should_protect_attributes is deprecated. " << + "Use should_not_allow_mass_assignment_of instead." + should_not_allow_mass_assignment_of(*attributes) + end + + # Ensures that the attribute cannot be changed once the record has been created. + # + # should_have_readonly_attributes :password, :admin_flag + # + def should_have_readonly_attributes(*attributes) + get_options!(attributes) + klass = model_class + + attributes.each do |attribute| + matcher = have_readonly_attribute(attribute) + should matcher.description do + assert_accepts matcher, klass.new + end + end + end + + # Ensures that the attribute cannot be set to the given values + # + # If an instance variable has been created in the setup named after the + # model being tested, then this method will use that. Otherwise, it will + # create a new instance to test against. + # + # Options: + # * :message - value the test expects to find in errors.on(:attribute). + # Regexp or string. Default = I18n.translate('activerecord.errors.messages.invalid') + # + # Example: + # should_not_allow_values_for :isbn, "bad 1", "bad 2" + # + def should_not_allow_values_for(attribute, *bad_values) + message = get_options!(bad_values, :message) + klass = model_class + bad_values.each do |value| + matcher = allow_value(value).for(attribute).with_message(message) + should "not #{matcher.description}" do + assert_rejects matcher, get_instance_of(klass) + end + end + end + + # Ensures that the attribute can be set to the given values. + # + # If an instance variable has been created in the setup named after the + # model being tested, then this method will use that. Otherwise, it will + # create a new instance to test against. + # + # Example: + # should_allow_values_for :isbn, "isbn 1 2345 6789 0", "ISBN 1-2345-6789-0" + # + def should_allow_values_for(attribute, *good_values) + get_options!(good_values) + klass = model_class + klass = model_class + good_values.each do |value| + matcher = allow_value(value).for(attribute) + should matcher.description do + assert_accepts matcher, get_instance_of(klass) + end + end + end + + # Ensures that the length of the attribute is in the given range + # + # If an instance variable has been created in the setup named after the + # model being tested, then this method will use that. Otherwise, it will + # create a new instance to test against. + # + # Options: + # * :short_message - value the test expects to find in errors.on(:attribute). + # Regexp or string. Default = I18n.translate('activerecord.errors.messages.too_short') % range.first + # * :long_message - value the test expects to find in errors.on(:attribute). + # Regexp or string. Default = I18n.translate('activerecord.errors.messages.too_long') % range.last + # + # Example: + # should_ensure_length_in_range :password, (6..20) + # + def should_ensure_length_in_range(attribute, range, opts = {}) + short_message, long_message = get_options!([opts], + :short_message, + :long_message) + klass = model_class + + matcher = ensure_length_of(attribute). + is_at_least(range.first). + with_short_message(short_message). + is_at_most(range.last). + with_long_message(long_message) + + should matcher.description do + assert_accepts matcher, get_instance_of(klass) + end + end + + # Ensures that the length of the attribute is at least a certain length + # + # If an instance variable has been created in the setup named after the + # model being tested, then this method will use that. Otherwise, it will + # create a new instance to test against. + # + # Options: + # * :short_message - value the test expects to find in errors.on(:attribute). + # Regexp or string. Default = I18n.translate('activerecord.errors.messages.too_short') % min_length + # + # Example: + # should_ensure_length_at_least :name, 3 + # + def should_ensure_length_at_least(attribute, min_length, opts = {}) + short_message = get_options!([opts], :short_message) + klass = model_class + + matcher = ensure_length_of(attribute). + is_at_least(min_length). + with_short_message(short_message) + + should matcher.description do + assert_accepts matcher, get_instance_of(klass) + end + end + + # Ensures that the length of the attribute is exactly a certain length + # + # If an instance variable has been created in the setup named after the + # model being tested, then this method will use that. Otherwise, it will + # create a new instance to test against. + # + # Options: + # * :message - value the test expects to find in errors.on(:attribute). + # Regexp or string. Default = I18n.translate('activerecord.errors.messages.wrong_length') % length + # + # Example: + # should_ensure_length_is :ssn, 9 + # + def should_ensure_length_is(attribute, length, opts = {}) + message = get_options!([opts], :message) + klass = model_class + matcher = ensure_length_of(attribute). + is_equal_to(length). + with_message(message) + + should matcher.description do + assert_accepts matcher, get_instance_of(klass) + end + end + + # Ensure that the attribute is in the range specified + # + # If an instance variable has been created in the setup named after the + # model being tested, then this method will use that. Otherwise, it will + # create a new instance to test against. + # + # Options: + # * :low_message - value the test expects to find in errors.on(:attribute). + # Regexp or string. Default = I18n.translate('activerecord.errors.messages.inclusion') + # * :high_message - value the test expects to find in errors.on(:attribute). + # Regexp or string. Default = I18n.translate('activerecord.errors.messages.inclusion') + # + # Example: + # should_ensure_value_in_range :age, (0..100) + # + def should_ensure_value_in_range(attribute, range, opts = {}) + message, low_message, high_message = get_options!([opts], + :message, + :low_message, + :high_message) + klass = model_class + matcher = ensure_inclusion_of(attribute). + in_range(range). + with_message(message). + with_low_message(low_message). + with_high_message(high_message) + should matcher.description do + assert_accepts matcher, get_instance_of(klass) + end + end + + # Ensure that the attribute is numeric + # + # If an instance variable has been created in the setup named after the + # model being tested, then this method will use that. Otherwise, it will + # create a new instance to test against. + # + # Options: + # * :message - value the test expects to find in errors.on(:attribute). + # Regexp or string. Default = I18n.translate('activerecord.errors.messages.not_a_number') + # + # Example: + # should_validate_numericality_of :age + # + def should_validate_numericality_of(*attributes) + message = get_options!(attributes, :message) + klass = model_class + attributes.each do |attribute| + matcher = validate_numericality_of(attribute). + with_message(message) + should matcher.description do + assert_accepts matcher, get_instance_of(klass) + end + end + end + + # Deprecated. See should_validate_numericality_of + def should_only_allow_numeric_values_for(*attributes) + warn "[DEPRECATION] should_only_allow_numeric_values_for is " << + "deprecated. Use should_validate_numericality_of instead." + should_validate_numericality_of(*attributes) + end + + # Ensures that the has_many relationship exists. Will also test that the + # associated table has the required columns. Works with polymorphic + # associations. + # + # Options: + # * :through - association name for has_many :through + # * :dependent - tests that the association makes use of the dependent option. + # + # Example: + # should_have_many :friends + # should_have_many :enemies, :through => :friends + # should_have_many :enemies, :dependent => :destroy + # + def should_have_many(*associations) + through, dependent = get_options!(associations, :through, :dependent) + klass = model_class + associations.each do |association| + matcher = have_many(association).through(through).dependent(dependent) + should matcher.description do + assert_accepts(matcher, klass.new) + end + end + end + + # Ensure that the has_one relationship exists. Will also test that the + # associated table has the required columns. Works with polymorphic + # associations. + # + # Options: + # * :dependent - tests that the association makes use of the dependent option. + # + # Example: + # should_have_one :god # unless hindu + # + def should_have_one(*associations) + dependent = get_options!(associations, :dependent) + klass = model_class + associations.each do |association| + matcher = have_one(association).dependent(dependent) + should matcher.description do + assert_accepts(matcher, klass.new) + end + end + end + + # Ensures that the has_and_belongs_to_many relationship exists, and that the join + # table is in place. + # + # should_have_and_belong_to_many :posts, :cars + # + def should_have_and_belong_to_many(*associations) + get_options!(associations) + klass = model_class + + associations.each do |association| + matcher = have_and_belong_to_many(association) + should matcher.description do + assert_accepts(matcher, klass.new) + end + end + end + + # Ensure that the belongs_to relationship exists. + # + # should_belong_to :parent + # + def should_belong_to(*associations) + dependent = get_options!(associations, :dependent) + klass = model_class + associations.each do |association| + matcher = belong_to(association).dependent(dependent) + should matcher.description do + assert_accepts(matcher, klass.new) + end + end + end + + # Ensure that the given class methods are defined on the model. + # + # should_have_class_methods :find, :destroy + # + def should_have_class_methods(*methods) + get_options!(methods) + klass = model_class + methods.each do |method| + should "respond to class method ##{method}" do + assert_respond_to klass, method, "#{klass.name} does not have class method #{method}" + end + end + end + + # Ensure that the given instance methods are defined on the model. + # + # should_have_instance_methods :email, :name, :name= + # + def should_have_instance_methods(*methods) + get_options!(methods) + klass = model_class + methods.each do |method| + should "respond to instance method ##{method}" do + assert_respond_to klass.new, method, "#{klass.name} does not have instance method #{method}" + end + end + end + + # Ensure that the given columns are defined on the models backing SQL table. + # Also aliased to should_have_index for readability. + # Takes the same options available in migrations: + # :type, :precision, :limit, :default, :null, and :scale + # + # Examples: + # + # should_have_db_columns :id, :email, :name, :created_at + # + # should_have_db_column :email, :type => "string", :limit => 255 + # should_have_db_column :salary, :decimal, :precision => 15, :scale => 2 + # should_have_db_column :admin, :default => false, :null => false + # + def should_have_db_columns(*columns) + column_type, precision, limit, default, null, scale, sql_type = + get_options!(columns, :type, :precision, :limit, + :default, :null, :scale, :sql_type) + klass = model_class + columns.each do |name| + matcher = have_db_column(name). + of_type(column_type). + with_options(:precision => precision, :limit => limit, + :default => default, :null => null, + :scale => scale, :sql_type => sql_type) + should matcher.description do + assert_accepts(matcher, klass.new) + end + end + end + + alias_method :should_have_db_column, :should_have_db_columns + + # Ensures that there are DB indices on the given columns or tuples of columns. + # Also aliased to should_have_index for readability + # + # Options: + # * :unique - whether or not the index has a unique + # constraint. Use true to explicitly test for a unique + # constraint. Use false to explicitly test for a non-unique + # constraint. Use nil if you don't care whether the index is + # unique or not. Default = nil + # + # Examples: + # + # should_have_indices :email, :name, [:commentable_type, :commentable_id] + # should_have_index :age + # should_have_index :ssn, :unique => true + # + def should_have_indices(*columns) + unique = get_options!(columns, :unique) + klass = model_class + + columns.each do |column| + matcher = have_index(column).unique(unique) + should matcher.description do + assert_accepts(matcher, klass.new) + end + end + end + + alias_method :should_have_index, :should_have_indices + + # Ensures that the model cannot be saved if one of the attributes listed is not accepted. + # + # If an instance variable has been created in the setup named after the + # model being tested, then this method will use that. Otherwise, it will + # create a new instance to test against. + # + # Options: + # * :message - value the test expects to find in errors.on(:attribute). + # Regexp or string. Default = I18n.translate('activerecord.errors.messages.accepted') + # + # Example: + # should_validate_acceptance_of :eula + # + def should_validate_acceptance_of(*attributes) + message = get_options!(attributes, :message) + klass = model_class + + attributes.each do |attribute| + matcher = validate_acceptance_of(attribute).with_message(message) + should matcher.description do + assert_accepts matcher, get_instance_of(klass) + end + end + end + + # Deprecated. See should_validate_uniqueness_of + def should_require_acceptance_of(*attributes) + warn "[DEPRECATION] should_require_acceptance_of is deprecated. " << + "Use should_validate_acceptance_of instead." + should_validate_acceptance_of(*attributes) + end + + # Ensures that the model has a method named scope_name that returns a NamedScope object with the + # proxy options set to the options you supply. scope_name can be either a symbol, or a method + # call which will be evaled against the model. The eval'd method call has access to all the same + # instance variables that a should statement would. + # + # Options: Any of the options that the named scope would pass on to find. + # + # Example: + # + # should_have_named_scope :visible, :conditions => {:visible => true} + # + # Passes for + # + # named_scope :visible, :conditions => {:visible => true} + # + # Or for + # + # def self.visible + # scoped(:conditions => {:visible => true}) + # end + # + # You can test lambdas or methods that return ActiveRecord#scoped calls: + # + # should_have_named_scope 'recent(5)', :limit => 5 + # should_have_named_scope 'recent(1)', :limit => 1 + # + # Passes for + # named_scope :recent, lambda {|c| {:limit => c}} + # + # Or for + # + # def self.recent(c) + # scoped(:limit => c) + # end + # + def should_have_named_scope(scope_call, find_options = nil) + klass = model_class + matcher = have_named_scope(scope_call).finding(find_options) + should matcher.description do + assert_accepts matcher.in_context(self), klass.new + end + end + end + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers.rb new file mode 100644 index 0000000..69b35ba --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers.rb @@ -0,0 +1,42 @@ +require 'shoulda/active_record/helpers' +require 'shoulda/active_record/matchers/validation_matcher' +require 'shoulda/active_record/matchers/allow_value_matcher' +require 'shoulda/active_record/matchers/ensure_length_of_matcher' +require 'shoulda/active_record/matchers/ensure_inclusion_of_matcher' +require 'shoulda/active_record/matchers/validate_presence_of_matcher' +require 'shoulda/active_record/matchers/validate_uniqueness_of_matcher' +require 'shoulda/active_record/matchers/validate_acceptance_of_matcher' +require 'shoulda/active_record/matchers/validate_numericality_of_matcher' +require 'shoulda/active_record/matchers/association_matcher' +require 'shoulda/active_record/matchers/have_db_column_matcher' +require 'shoulda/active_record/matchers/have_index_matcher' +require 'shoulda/active_record/matchers/have_readonly_attribute_matcher' +require 'shoulda/active_record/matchers/allow_mass_assignment_of_matcher' +require 'shoulda/active_record/matchers/have_named_scope_matcher' + + +module Shoulda # :nodoc: + module ActiveRecord # :nodoc: + # = Matchers for your active record models + # + # These matchers will test most of the validations and associations for your + # ActiveRecord models. + # + # describe User do + # it { should validate_presence_of(:name) } + # it { should validate_presence_of(:phone_number) } + # %w(abcd 1234).each do |value| + # it { should_not allow_value(value).for(:phone_number) } + # end + # it { should allow_value("(123) 456-7890").for(:phone_number) } + # it { should_not allow_mass_assignment_of(:password) } + # it { should have_one(:profile) } + # it { should have_many(:dogs) } + # it { should have_many(:messes).through(:dogs) } + # it { should belong_to(:lover) } + # end + # + module Matchers + end + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/allow_mass_assignment_of_matcher.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/allow_mass_assignment_of_matcher.rb new file mode 100644 index 0000000..fab6b64 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/allow_mass_assignment_of_matcher.rb @@ -0,0 +1,83 @@ +module Shoulda # :nodoc: + module ActiveRecord # :nodoc: + module Matchers + + # Ensures that the attribute can be set on mass update. + # + # it { should_not allow_mass_assignment_of(:password) } + # it { should allow_mass_assignment_of(:first_name) } + # + def allow_mass_assignment_of(value) + AllowMassAssignmentOfMatcher.new(value) + end + + class AllowMassAssignmentOfMatcher # :nodoc: + + def initialize(attribute) + @attribute = attribute.to_s + end + + def matches?(subject) + @subject = subject + if attr_mass_assignable? + if whitelisting? + @failure_message = "#{@attribute} was made accessible" + else + if protected_attributes.empty? + @failure_message = "no attributes were protected" + else + @failure_message = "#{class_name} is protecting " << + "#{protected_attributes.to_a.to_sentence}, " << + "but not #{@attribute}." + end + end + true + else + if whitelisting? + @negative_failure_message = + "Expected #{@attribute} to be accessible" + else + @negative_failure_message = + "Did not expect #{@attribute} to be protected" + end + false + end + end + + attr_reader :failure_message, :negative_failure_message + + def description + "protect #{@attribute} from mass updates" + end + + private + + def protected_attributes + @protected_attributes ||= (@subject.class.protected_attributes || []) + end + + def accessible_attributes + @accessible_attributes ||= (@subject.class.accessible_attributes || []) + end + + def whitelisting? + !accessible_attributes.empty? + end + + def attr_mass_assignable? + if whitelisting? + accessible_attributes.include?(@attribute) + else + !protected_attributes.include?(@attribute) + end + end + + def class_name + @subject.class.name + end + + end + + end + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/allow_value_matcher.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/allow_value_matcher.rb new file mode 100644 index 0000000..3402602 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/allow_value_matcher.rb @@ -0,0 +1,102 @@ +module Shoulda # :nodoc: + module ActiveRecord # :nodoc: + module Matchers + + # Ensures that the attribute can be set to the given value. + # + # Options: + # * with_message - value the test expects to find in + # errors.on(:attribute). Regexp or string. Defaults to the + # translation for :invalid. + # + # Example: + # it { should_not allow_value('bad').for(:isbn) } + # it { should allow_value("isbn 1 2345 6789 0").for(:isbn) } + # + def allow_value(value) + AllowValueMatcher.new(value) + end + + class AllowValueMatcher # :nodoc: + include Helpers + + def initialize(value) + @value = value + end + + def for(attribute) + @attribute = attribute + self + end + + def with_message(message) + @expected_message = message if message + self + end + + def matches?(instance) + @instance = instance + @expected_message ||= :invalid + if Symbol === @expected_message + @expected_message = default_error_message(@expected_message) + end + @instance.send("#{@attribute}=", @value) + !errors_match? + end + + def failure_message + "Did not expect #{expectation}, got error: #{@matched_error}" + end + + def negative_failure_message + "Expected #{expectation}, got #{error_description}" + end + + def description + "allow #{@attribute} to be set to #{@value.inspect}" + end + + private + + def errors_match? + @instance.valid? + @errors = @instance.errors.on(@attribute) + @errors = [@errors] unless @errors.is_a?(Array) + errors_match_regexp? || errors_match_string? + end + + def errors_match_regexp? + if Regexp === @expected_message + @matched_error = @errors.detect { |e| e =~ @expected_message } + !@matched_error.nil? + else + false + end + end + + def errors_match_string? + if @errors.include?(@expected_message) + @matched_error = @expected_message + true + else + false + end + end + + def expectation + "errors to include #{@expected_message.inspect} " << + "when #{@attribute} is set to #{@value.inspect}" + end + + def error_description + if @instance.errors.empty? + "no errors" + else + "errors: #{pretty_error_messages(@instance)}" + end + end + end + + end + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/association_matcher.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/association_matcher.rb new file mode 100644 index 0000000..87e0176 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/association_matcher.rb @@ -0,0 +1,226 @@ +module Shoulda # :nodoc: + module ActiveRecord # :nodoc: + module Matchers + + # Ensure that the belongs_to relationship exists. + # + # it { should belong_to(:parent) } + # + def belong_to(name) + AssociationMatcher.new(:belongs_to, name) + end + + # Ensures that the has_many relationship exists. Will also test that the + # associated table has the required columns. Works with polymorphic + # associations. + # + # Options: + # * through - association name for has_many :through + # * dependent - tests that the association makes use of the + # dependent option. + # + # Example: + # it { should_have_many(:friends) } + # it { should_have_many(:enemies).through(:friends) } + # it { should_have_many(:enemies).dependent(:destroy) } + # + def have_many(name) + AssociationMatcher.new(:has_many, name) + end + + # Ensure that the has_one relationship exists. Will also test that the + # associated table has the required columns. Works with polymorphic + # associations. + # + # Options: + # * :dependent - tests that the association makes use of the + # dependent option. + # + # Example: + # it { should have_one(:god) } # unless hindu + # + def have_one(name) + AssociationMatcher.new(:has_one, name) + end + + # Ensures that the has_and_belongs_to_many relationship exists, and that + # the join table is in place. + # + # it { should have_and_belong_to_many(:posts) } + # + def have_and_belong_to_many(name) + AssociationMatcher.new(:has_and_belongs_to_many, name) + end + + class AssociationMatcher # :nodoc: + def initialize(macro, name) + @macro = macro + @name = name + end + + def through(through) + @through = through + self + end + + def dependent(dependent) + @dependent = dependent + self + end + + def matches?(subject) + @subject = subject + association_exists? && + macro_correct? && + foreign_key_exists? && + through_association_valid? && + dependent_correct? && + join_table_exists? + end + + def failure_message + "Expected #{expectation} (#{@missing})" + end + + def negative_failure_message + "Did not expect #{expectation}" + end + + def description + description = "#{macro_description} #{@name}" + description += " through #{@through}" if @through + description += " dependent => #{@dependent}" if @dependent + description + end + + protected + + def association_exists? + if reflection.nil? + @missing = "no association called #{@name}" + false + else + true + end + end + + def macro_correct? + if reflection.macro == @macro + true + else + @missing = "actual association type was #{reflection.macro}" + false + end + end + + def foreign_key_exists? + !(belongs_foreign_key_missing? || has_foreign_key_missing?) + end + + def belongs_foreign_key_missing? + @macro == :belongs_to && !class_has_foreign_key?(model_class) + end + + def has_foreign_key_missing? + [:has_many, :has_one].include?(@macro) && + !through? && + !class_has_foreign_key?(associated_class) + end + + def through_association_valid? + @through.nil? || (through_association_exists? && through_association_correct?) + end + + def through_association_exists? + if through_reflection.nil? + "#{model_class.name} does not have any relationship to #{@through}" + false + else + true + end + end + + def through_association_correct? + if @through == reflection.options[:through] + "Expected #{model_class.name} to have #{@name} through #{@through}, " << + " but got it through #{reflection.options[:through]}" + true + else + false + end + end + + def dependent_correct? + if @dependent.nil? || @dependent.to_s == reflection.options[:dependent].to_s + true + else + @missing = "#{@name} should have #{@dependent} dependency" + false + end + end + + def join_table_exists? + if @macro != :has_and_belongs_to_many || + ::ActiveRecord::Base.connection.tables.include?(join_table.to_s) + true + else + @missing = "join table #{join_table} doesn't exist" + false + end + end + + def class_has_foreign_key?(klass) + if klass.column_names.include?(foreign_key.to_s) + true + else + @missing = "#{klass} does not have a #{foreign_key} foreign key." + false + end + end + + def model_class + @subject.class + end + + def join_table + reflection.options[:join_table] + end + + def associated_class + reflection.klass + end + + def foreign_key + reflection.primary_key_name + end + + def through? + reflection.options[:through] + end + + def reflection + @reflection ||= model_class.reflect_on_association(@name) + end + + def through_reflection + @through_reflection ||= model_class.reflect_on_association(@through) + end + + def expectation + "#{model_class.name} to have a #{@macro} association called #{@name}" + end + + def macro_description + case @macro.to_s + when 'belongs_to' then 'belong to' + when 'has_many' then 'have many' + when 'has_one' then 'have one' + when 'has_and_belongs_to_many' then + 'have and belong to many' + end + end + end + + end + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/ensure_inclusion_of_matcher.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/ensure_inclusion_of_matcher.rb new file mode 100644 index 0000000..a20095a --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/ensure_inclusion_of_matcher.rb @@ -0,0 +1,87 @@ +module Shoulda # :nodoc: + module ActiveRecord # :nodoc: + module Matchers + + # Ensure that the attribute's value is in the range specified + # + # Options: + # * in_range - the range of allowed values for this attribute + # * with_low_message - value the test expects to find in + # errors.on(:attribute). Regexp or string. Defaults to the + # translation for :inclusion. + # * with_high_message - value the test expects to find in + # errors.on(:attribute). Regexp or string. Defaults to the + # translation for :inclusion. + # + # Example: + # it { should ensure_inclusion_of(:age).in_range(0..100) } + # + def ensure_inclusion_of(attr) + EnsureInclusionOfMatcher.new(attr) + end + + class EnsureInclusionOfMatcher < ValidationMatcher # :nodoc: + + def in_range(range) + @range = range + @minimum = range.first + @maximum = range.last + self + end + + def with_message(message) + if message + @low_message = message + @high_message = message + end + self + end + + def with_low_message(message) + @low_message = message if message + self + end + + def with_high_message(message) + @high_message = message if message + self + end + + def description + "ensure inclusion of #{@attribute} in #{@range.inspect}" + end + + def matches?(subject) + super(subject) + + @low_message ||= :inclusion + @high_message ||= :inclusion + + disallows_lower_value && + allows_minimum_value && + disallows_higher_value && + allows_maximum_value + end + + private + + def disallows_lower_value + @minimum == 0 || disallows_value_of(@minimum - 1, @low_message) + end + + def disallows_higher_value + disallows_value_of(@maximum + 1, @high_message) + end + + def allows_minimum_value + allows_value_of(@minimum, @low_message) + end + + def allows_maximum_value + allows_value_of(@maximum, @high_message) + end + end + + end + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/ensure_length_of_matcher.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/ensure_length_of_matcher.rb new file mode 100644 index 0000000..9c5cde1 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/ensure_length_of_matcher.rb @@ -0,0 +1,141 @@ +module Shoulda # :nodoc: + module ActiveRecord # :nodoc: + module Matchers + + # Ensures that the length of the attribute is validated. + # + # Options: + # * is_at_least - minimum length of this attribute + # * is_at_most - maximum length of this attribute + # * is_equal_to - exact requred length of this attribute + # * with_short_message - value the test expects to find in + # errors.on(:attribute). Regexp or string. Defaults to the + # translation for :too_short. + # * with_long_message - value the test expects to find in + # errors.on(:attribute). Regexp or string. Defaults to the + # translation for :too_long. + # * with_message - value the test expects to find in + # errors.on(:attribute). Regexp or string. Defaults to the + # translation for :wrong_length. Used in conjunction with + # is_equal_to. + # + # Examples: + # it { should ensure_length_of(:password). + # is_at_least(6). + # is_at_most(20) } + # it { should ensure_length_of(:name). + # is_at_least(3). + # with_short_message(/not long enough/) } + # it { should ensure_length_of(:ssn). + # is_equal_to(9). + # with_message(/is invalid/) } + def ensure_length_of(attr) + EnsureLengthOfMatcher.new(attr) + end + + class EnsureLengthOfMatcher < ValidationMatcher # :nodoc: + include Helpers + + def is_at_least(length) + @minimum = length + @short_message ||= :too_short + self + end + + def is_at_most(length) + @maximum = length + @long_message ||= :too_long + self + end + + def is_equal_to(length) + @minimum = length + @maximum = length + @short_message ||= :wrong_length + self + end + + def with_short_message(message) + @short_message = message if message + self + end + alias_method :with_message, :with_short_message + + def with_long_message(message) + @long_message = message if message + self + end + + def description + description = "ensure #{@attribute} has a length " + if @minimum && @maximum + if @minimum == @maximum + description << "of exactly #{@minimum}" + else + description << "between #{@minimum} and #{@maximum}" + end + else + description << "of at least #{@minimum}" if @minimum + description << "of at most #{@maximum}" if @maximum + end + description + end + + def matches?(subject) + super(subject) + translate_messages! + disallows_lower_length && + allows_minimum_length && + ((@minimum == @maximum) || + (disallows_higher_length && + allows_maximum_length)) + end + + private + + def translate_messages! + if Symbol === @short_message + @short_message = default_error_message(@short_message, + :count => @minimum) + end + + if Symbol === @long_message + @long_message = default_error_message(@long_message, + :count => @maximum) + end + end + + def disallows_lower_length + @minimum == 0 || + @minimum.nil? || + disallows_length_of(@minimum - 1, @short_message) + end + + def disallows_higher_length + @maximum.nil? || disallows_length_of(@maximum + 1, @long_message) + end + + def allows_minimum_length + allows_length_of(@minimum, @short_message) + end + + def allows_maximum_length + allows_length_of(@maximum, @long_message) + end + + def allows_length_of(length, message) + length.nil? || allows_value_of(string_of_length(length), message) + end + + def disallows_length_of(length, message) + length.nil? || disallows_value_of(string_of_length(length), message) + end + + def string_of_length(length) + 'x' * length + end + end + + end + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/have_db_column_matcher.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/have_db_column_matcher.rb new file mode 100644 index 0000000..86f5212 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/have_db_column_matcher.rb @@ -0,0 +1,169 @@ +module Shoulda # :nodoc: + module ActiveRecord # :nodoc: + module Matchers + + # Ensures the database column exists. + # + # Options: + # * of_type - db column type (:integer, :string, etc.) + # * with_options - same options available in migrations + # (:default, :null, :limit, :precision, :scale) + # + # Examples: + # it { should_not have_db_column(:admin).of_type(:boolean) } + # it { should have_db_column(:salary). + # of_type(:decimal). + # with_options(:precision => 10, :scale => 2) } + # + def have_db_column(column) + HaveDbColumnMatcher.new(:have_db_column, column) + end + + class HaveDbColumnMatcher # :nodoc: + def initialize(macro, column) + @macro = macro + @column = column + end + + def of_type(column_type) + @column_type = column_type + self + end + + def with_options(opts = {}) + @precision = opts[:precision] + @limit = opts[:limit] + @default = opts[:default] + @null = opts[:null] + @scale = opts[:scale] + self + end + + def matches?(subject) + @subject = subject + column_exists? && + correct_column_type? && + correct_precision? && + correct_limit? && + correct_default? && + correct_null? && + correct_scale? + end + + def failure_message + "Expected #{expectation} (#{@missing})" + end + + def negative_failure_message + "Did not expect #{expectation}" + end + + def description + desc = "have db column named #{@column}" + desc << " of type #{@column_type}" unless @column_type.nil? + desc << " of precision #{@precision}" unless @precision.nil? + desc << " of limit #{@limit}" unless @limit.nil? + desc << " of default #{@default}" unless @default.nil? + desc << " of null #{@null}" unless @null.nil? + desc << " of primary #{@primary}" unless @primary.nil? + desc << " of scale #{@scale}" unless @scale.nil? + desc + end + + protected + + def column_exists? + if model_class.column_names.include?(@column.to_s) + true + else + @missing = "#{model_class} does not have a db column named #{@column}." + false + end + end + + def correct_column_type? + return true if @column_type.nil? + if matched_column.type.to_s == @column_type.to_s + true + else + @missing = "#{model_class} has a db column named #{@column} " << + "of type #{matched_column.type}, not #{@column_type}." + false + end + end + + def correct_precision? + return true if @precision.nil? + if matched_column.precision.to_s == @precision.to_s + true + else + @missing = "#{model_class} has a db column named #{@column} " << + "of precision #{matched_column.precision}, " << + "not #{@precision}." + false + end + end + + def correct_limit? + return true if @limit.nil? + if matched_column.limit.to_s == @limit.to_s + true + else + @missing = "#{model_class} has a db column named #{@column} " << + "of limit #{matched_column.limit}, " << + "not #{@limit}." + false + end + end + + def correct_default? + return true if @default.nil? + if matched_column.default.to_s == @default.to_s + true + else + @missing = "#{model_class} has a db column named #{@column} " << + "of default #{matched_column.default}, " << + "not #{@default}." + false + end + end + + def correct_null? + return true if @null.nil? + if matched_column.null.to_s == @null.to_s + true + else + @missing = "#{model_class} has a db column named #{@column} " << + "of null #{matched_column.null}, " << + "not #{@null}." + false + end + end + + def correct_scale? + return true if @scale.nil? + if matched_column.scale.to_s == @scale.to_s + true + else + @missing = "#{model_class} has a db column named #{@column} " << + "of scale #{matched_column.scale}, not #{@scale}." + false + end + end + + def matched_column + model_class.columns.detect { |each| each.name == @column.to_s } + end + + def model_class + @subject.class + end + + def expectation + expected = "#{model_class.name} to #{description}" + end + end + + end + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/have_index_matcher.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/have_index_matcher.rb new file mode 100644 index 0000000..be4a8c4 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/have_index_matcher.rb @@ -0,0 +1,105 @@ +module Shoulda # :nodoc: + module ActiveRecord # :nodoc: + module Matchers + + # Ensures that there are DB indices on the given columns or tuples of + # columns. + # + # Options: + # * unique - whether or not the index has a unique + # constraint. Use true to explicitly test for a unique + # constraint. Use false to explicitly test for a non-unique + # constraint. Use nil if you don't care whether the index is + # unique or not. Default = nil + # + # Examples: + # + # it { should have_index(:age) } + # it { should have_index([:commentable_type, :commentable_id]) } + # it { should have_index(:ssn).unique(true) } + # + def have_index(columns) + HaveIndexMatcher.new(:have_index, columns) + end + + class HaveIndexMatcher # :nodoc: + def initialize(macro, columns) + @macro = macro + @columns = normalize_columns_to_array(columns) + end + + def unique(unique) + @unique = unique + self + end + + def matches?(subject) + @subject = subject + index_exists? && correct_unique? + end + + def failure_message + "Expected #{expectation} (#{@missing})" + end + + def negative_failure_message + "Did not expect #{expectation}" + end + + def description + "have a #{index_type} index on columns #{@columns}" + end + + protected + + def index_exists? + ! matched_index.nil? + end + + def correct_unique? + return true if @unique.nil? + if matched_index.unique == @unique + true + else + @missing = "#{table_name} has an index named #{matched_index.name} " << + "of unique #{matched_index.unique}, not #{@unique}." + false + end + end + + def matched_index + indexes.detect { |each| each.columns == @columns } + end + + def model_class + @subject.class + end + + def table_name + model_class.table_name + end + + def indexes + ::ActiveRecord::Base.connection.indexes(table_name) + end + + def expectation + expected = "#{model_class.name} to #{description}" + end + + def index_type + @unique ? "unique" : "non-unique" + end + + def normalize_columns_to_array(columns) + if columns.class == Array + columns.collect { |each| each.to_s } + else + [columns.to_s] + end + end + end + + end + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/have_named_scope_matcher.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/have_named_scope_matcher.rb new file mode 100644 index 0000000..576e8ce --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/have_named_scope_matcher.rb @@ -0,0 +1,125 @@ +module Shoulda # :nodoc: + module ActiveRecord # :nodoc: + module Matchers + + # Ensures that the model has a method named scope_call that returns a + # NamedScope object with the proxy options set to the options you supply. + # scope_call can be either a symbol, or a Ruby expression in a String + # which will be evaled. The eval'd method call has access to all the same + # instance variables that an example would. + # + # Options: + # + # * in_context - Any of the options that the named scope would + # pass on to find. + # + # Example: + # + # it { should have_named_scope(:visible). + # finding(:conditions => {:visible => true}) } + # + # Passes for + # + # named_scope :visible, :conditions => {:visible => true} + # + # Or for + # + # def self.visible + # scoped(:conditions => {:visible => true}) + # end + # + # You can test lambdas or methods that return ActiveRecord#scoped calls: + # + # it { should have_named_scope('recent(5)').finding(:limit => 5) } + # it { should have_named_scope('recent(1)').finding(:limit => 1) } + # + # Passes for + # named_scope :recent, lambda {|c| {:limit => c}} + # + # Or for + # + # def self.recent(c) + # scoped(:limit => c) + # end + # + def have_named_scope(scope_call) + HaveNamedScopeMatcher.new(scope_call).in_context(self) + end + + class HaveNamedScopeMatcher # :nodoc: + + def initialize(scope_call) + @scope_call = scope_call.to_s + end + + def finding(finding) + @finding = finding + self + end + + def in_context(context) + @context = context + self + end + + def matches?(subject) + @subject = subject + call_succeeds? && returns_scope? && finds_correct_scope? + end + + def failure_message + "Expected #{@missing_expectation}" + end + + def negative_failure_message + "Didn't expect a named scope for #{@scope_call}" + end + + def description + result = "have a named scope for #{@scope_call}" + result << " finding #{@finding.inspect}" unless @finding.nil? + result + end + + private + + def call_succeeds? + scope + true + rescue Exception => exception + @missing_expectation = "#{@subject.class.name} " << + "to respond to #{@scope_call} " << + "but raised error: #{exception.inspect}" + false + end + + def scope + @scope ||= @context.instance_eval("#{@subject.class.name}.#{@scope_call}") + end + + def returns_scope? + if ::ActiveRecord::NamedScope::Scope === scope + true + else + @missing_expectation = "#{@scope_call} to return a scope" + false + end + end + + def finds_correct_scope? + return true if @finding.nil? + if @finding == scope.proxy_options + true + else + @missing_expectation = "#{@scope_call} to return results scoped to " + @missing_expectation << "#{@finding.inspect} but was scoped to " + @missing_expectation << scope.proxy_options.inspect + false + end + end + + end + + end + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/have_readonly_attribute_matcher.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/have_readonly_attribute_matcher.rb new file mode 100644 index 0000000..de9a2c8 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/have_readonly_attribute_matcher.rb @@ -0,0 +1,59 @@ +module Shoulda # :nodoc: + module ActiveRecord # :nodoc: + module Matchers + + # Ensures that the attribute cannot be changed once the record has been + # created. + # + # it { should have_readonly_attributes(:password) } + # + def have_readonly_attribute(value) + HaveReadonlyAttributeMatcher.new(value) + end + + class HaveReadonlyAttributeMatcher # :nodoc: + + def initialize(attribute) + @attribute = attribute.to_s + end + + def matches?(subject) + @subject = subject + if readonly_attributes.include?(@attribute) + @negative_failure_message = + "Did not expect #{@attribute} to be read-only" + true + else + if readonly_attributes.empty? + @failure_message = "#{class_name} attribute #{@attribute} " << + "is not read-only" + else + @failure_message = "#{class_name} is making " << + "#{readonly_attributes.to_sentence} " << + "read-only, but not #{@attribute}." + end + false + end + end + + attr_reader :failure_message, :negative_failure_message + + def description + "make #{@attribute} read-only" + end + + private + + def readonly_attributes + @readonly_attributes ||= (@subject.class.readonly_attributes || []) + end + + def class_name + @subject.class.name + end + + end + + end + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/validate_acceptance_of_matcher.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/validate_acceptance_of_matcher.rb new file mode 100644 index 0000000..f77da83 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/validate_acceptance_of_matcher.rb @@ -0,0 +1,41 @@ +module Shoulda # :nodoc: + module ActiveRecord # :nodoc: + module Matchers + + # Ensures that the model cannot be saved the given attribute is not + # accepted. + # + # Options: + # * with_message - value the test expects to find in + # errors.on(:attribute). Regexp or string. Defaults to the + # translation for :accepted. + # + # Example: + # it { should validate_acceptance_of(:eula) } + # + def validate_acceptance_of(attr) + ValidateAcceptanceOfMatcher.new(attr) + end + + class ValidateAcceptanceOfMatcher < ValidationMatcher # :nodoc: + + def with_message(message) + @expected_message = message if message + self + end + + def matches?(subject) + super(subject) + @expected_message ||= :accepted + disallows_value_of(false, @expected_message) + end + + def description + "require #{@attribute} to be accepted" + end + + end + + end + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/validate_numericality_of_matcher.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/validate_numericality_of_matcher.rb new file mode 100644 index 0000000..0f6857c --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/validate_numericality_of_matcher.rb @@ -0,0 +1,39 @@ +module Shoulda # :nodoc: + module ActiveRecord # :nodoc: + module Matchers + + # Ensure that the attribute is numeric + # + # Options: + # * with_message - value the test expects to find in + # errors.on(:attribute). Regexp or string. Defaults to the + # translation for :not_a_number. + # + # Example: + # it { should validate_numericality_of(:age) } + # + def validate_numericality_of(attr) + ValidateNumericalityOfMatcher.new(attr) + end + + class ValidateNumericalityOfMatcher < ValidationMatcher # :nodoc: + + def with_message(message) + @expected_message = message if message + self + end + + def matches?(subject) + super(subject) + @expected_message ||= :not_a_number + disallows_value_of('abcd', @expected_message) + end + + def description + "only allow numeric values for #{@attribute}" + end + end + + end + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/validate_presence_of_matcher.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/validate_presence_of_matcher.rb new file mode 100644 index 0000000..ed460c4 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/validate_presence_of_matcher.rb @@ -0,0 +1,60 @@ +module Shoulda # :nodoc: + module ActiveRecord # :nodoc: + module Matchers + + # Ensures that the model is not valid if the given attribute is not + # present. + # + # Options: + # * with_message - value the test expects to find in + # errors.on(:attribute). Regexp or String. + # Defaults to the translation for :blank. + # + # Examples: + # it { should validate_presence_of(:name) } + # it { should validate_presence_of(:name). + # with_message(/is not optional/) } + # + def validate_presence_of(attr) + ValidatePresenceOfMatcher.new(attr) + end + + class ValidatePresenceOfMatcher < ValidationMatcher # :nodoc: + + def with_message(message) + @expected_message = message if message + self + end + + def matches?(subject) + super(subject) + @expected_message ||= :blank + disallows_value_of(blank_value, @expected_message) + end + + def description + "require #{@attribute} to be set" + end + + private + + def blank_value + if collection? + [] + else + nil + end + end + + def collection? + if reflection = @subject.class.reflect_on_association(@attribute) + [:has_many, :has_and_belongs_to_many].include?(reflection.macro) + else + false + end + end + end + + end + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/validate_uniqueness_of_matcher.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/validate_uniqueness_of_matcher.rb new file mode 100644 index 0000000..322c77c --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/validate_uniqueness_of_matcher.rb @@ -0,0 +1,148 @@ +module Shoulda # :nodoc: + module ActiveRecord # :nodoc: + module Matchers + + # Ensures that the model is invalid if the given attribute is not unique. + # + # Internally, this uses values from existing records to test validations, + # so this will always fail if you have not saved at least one record for + # the model being tested, like so: + # + # describe User do + # before(:each) { User.create!(:email => 'address@example.com') } + # it { should validate_uniqueness_of(:email) } + # end + # + # Options: + # + # * with_message - value the test expects to find in + # errors.on(:attribute). Regexp or String. + # Defaults to the translation for :taken. + # * scoped_to - field(s) to scope the uniqueness to. + # * case_insensitive - ensures that the validation does not + # check case. Off by default. Ignored by non-text attributes. + # + # Examples: + # it { should validate_uniqueness_of(:keyword) } + # it { should validate_uniqueness_of(:keyword).with_message(/dup/) } + # it { should validate_uniqueness_of(:email).scoped_to(:name) } + # it { should validate_uniqueness_of(:email). + # scoped_to(:first_name, :last_name) } + # it { should validate_uniqueness_of(:keyword).case_insensitive } + # + def validate_uniqueness_of(attr) + ValidateUniquenessOfMatcher.new(attr) + end + + class ValidateUniquenessOfMatcher < ValidationMatcher # :nodoc: + include Helpers + + def initialize(attribute) + @attribute = attribute + end + + def scoped_to(*scopes) + @scopes = [*scopes].flatten + self + end + + def with_message(message) + @expected_message = message + self + end + + def case_insensitive + @case_insensitive = true + self + end + + def description + result = "require " + result << "case sensitive " unless @case_insensitive + result << "unique value for #{@attribute}" + result << " scoped to #{@scopes.join(', ')}" unless @scopes.blank? + result + end + + def matches?(subject) + @subject = subject.class.new + @expected_message ||= :taken + find_existing && + set_scoped_attributes && + validate_attribute && + validate_after_scope_change + end + + private + + def find_existing + if @existing = @subject.class.find(:first) + true + else + @failure_message = "Can't find first #{class_name}" + false + end + end + + def set_scoped_attributes + unless @scopes.blank? + @scopes.each do |scope| + setter = :"#{scope}=" + unless @subject.respond_to?(setter) + @failure_message = + "#{class_name} doesn't seem to have a #{scope} attribute." + return false + end + @subject.send("#{scope}=", @existing.send(scope)) + end + end + true + end + + def validate_attribute + disallows_value_of(existing_value, @expected_message) + end + + # TODO: There is a chance that we could change the scoped field + # to a value that's already taken. An alternative implementation + # could actually find all values for scope and create a unique + def validate_after_scope_change + if @scopes.blank? + true + else + @scopes.all? do |scope| + previous_value = @existing.send(scope) + + # Assume the scope is a foreign key if the field is nil + previous_value ||= 0 + + next_value = previous_value.next + + @subject.send("#{scope}=", next_value) + + if allows_value_of(existing_value, @expected_message) + @negative_failure_message << + " (with different value of #{scope})" + true + else + @failure_message << " (with different value of #{scope})" + false + end + end + end + end + + def class_name + @subject.class.name + end + + def existing_value + value = @existing.send(@attribute) + value.swapcase! if @case_insensitive && value.respond_to?(:swapcase!) + value + end + end + + end + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/validation_matcher.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/validation_matcher.rb new file mode 100644 index 0000000..7faf50c --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/matchers/validation_matcher.rb @@ -0,0 +1,56 @@ +module Shoulda # :nodoc: + module ActiveRecord # :nodoc: + module Matchers + + class ValidationMatcher # :nodoc: + + attr_reader :failure_message + + def initialize(attribute) + @attribute = attribute + end + + def negative_failure_message + @negative_failure_message || @failure_message + end + + def matches?(subject) + @subject = subject + false + end + + private + + def allows_value_of(value, message = nil) + allow = AllowValueMatcher. + new(value). + for(@attribute). + with_message(message) + if allow.matches?(@subject) + @negative_failure_message = allow.failure_message + true + else + @failure_message = allow.negative_failure_message + false + end + end + + def disallows_value_of(value, message = nil) + disallow = AllowValueMatcher. + new(value). + for(@attribute). + with_message(message) + if disallow.matches?(@subject) + @failure_message = disallow.negative_failure_message + false + else + @negative_failure_message = disallow.failure_message + true + end + end + end + + end + end +end + diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/assertions.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/assertions.rb new file mode 100644 index 0000000..73f31ec --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/assertions.rb @@ -0,0 +1,59 @@ +module Shoulda # :nodoc: + module Assertions + # Asserts that two arrays contain the same elements, the same number of times. Essentially ==, but unordered. + # + # assert_same_elements([:a, :b, :c], [:c, :a, :b]) => passes + def assert_same_elements(a1, a2, msg = nil) + [:select, :inject, :size].each do |m| + [a1, a2].each {|a| assert_respond_to(a, m, "Are you sure that #{a.inspect} is an array? It doesn't respond to #{m}.") } + end + + assert a1h = a1.inject({}) { |h,e| h[e] = a1.select { |i| i == e }.size; h } + assert a2h = a2.inject({}) { |h,e| h[e] = a2.select { |i| i == e }.size; h } + + assert_equal(a1h, a2h, msg) + end + + # Asserts that the given collection contains item x. If x is a regular expression, ensure that + # at least one element from the collection matches x. +extra_msg+ is appended to the error message if the assertion fails. + # + # assert_contains(['a', '1'], /\d/) => passes + # assert_contains(['a', '1'], 'a') => passes + # assert_contains(['a', '1'], /not there/) => fails + def assert_contains(collection, x, extra_msg = "") + collection = [collection] unless collection.is_a?(Array) + msg = "#{x.inspect} not found in #{collection.to_a.inspect} #{extra_msg}" + case x + when Regexp + assert(collection.detect { |e| e =~ x }, msg) + else + assert(collection.include?(x), msg) + end + end + + # Asserts that the given collection does not contain item x. If x is a regular expression, ensure that + # none of the elements from the collection match x. + def assert_does_not_contain(collection, x, extra_msg = "") + collection = [collection] unless collection.is_a?(Array) + msg = "#{x.inspect} found in #{collection.to_a.inspect} " + extra_msg + case x + when Regexp + assert(!collection.detect { |e| e =~ x }, msg) + else + assert(!collection.include?(x), msg) + end + end + + # Asserts that the given matcher returns true when +target+ is passed to #matches? + def assert_accepts(matcher, target) + success = matcher.matches?(target) + assert_block(matcher.failure_message) { success } + end + + # Asserts that the given matcher returns false when +target+ is passed to #matches? + def assert_rejects(matcher, target) + success = !matcher.matches?(target) + assert_block(matcher.negative_failure_message) { success } + end + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/autoload_macros.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/autoload_macros.rb new file mode 100644 index 0000000..d815ee3 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/autoload_macros.rb @@ -0,0 +1,46 @@ +module Shoulda # :nodoc: + # Call autoload_macros when you want to load test macros automatically in a non-Rails + # project (it's done automatically for Rails projects). + # You don't need to specify ROOT/test/shoulda_macros explicitly. Your custom macros + # are loaded automatically when you call autoload_macros. + # + # The first argument is the path to you application's root directory. + # All following arguments are directories relative to your root, which contain + # shoulda_macros subdirectories. These directories support the same kinds of globs as the + # Dir class. + # + # Basic usage (from a test_helper): + # Shoulda.autoload_macros(File.dirname(__FILE__) + '/..') + # will load everything in + # - your_app/test/shoulda_macros + # + # To load vendored macros as well: + # Shoulda.autoload_macros(APP_ROOT, 'vendor/*') + # will load everything in + # - APP_ROOT/vendor/*/shoulda_macros + # - APP_ROOT/test/shoulda_macros + # + # To load macros in an app with a vendor directory laid out like Rails': + # Shoulda.autoload_macros(APP_ROOT, 'vendor/{plugins,gems}/*') + # or + # Shoulda.autoload_macros(APP_ROOT, 'vendor/plugins/*', 'vendor/gems/*') + # will load everything in + # - APP_ROOT/vendor/plugins/*/shoulda_macros + # - APP_ROOT/vendor/gems/*/shoulda_macros + # - APP_ROOT/test/shoulda_macros + # + # If you prefer to stick testing dependencies away from your production dependencies: + # Shoulda.autoload_macros(APP_ROOT, 'vendor/*', 'test/vendor/*') + # will load everything in + # - APP_ROOT/vendor/*/shoulda_macros + # - APP_ROOT/test/vendor/*/shoulda_macros + # - APP_ROOT/test/shoulda_macros + def self.autoload_macros(root, *dirs) + dirs << File.join('test') + complete_dirs = dirs.map{|d| File.join(root, d, 'shoulda_macros')} + all_files = complete_dirs.inject([]){ |files, dir| files + Dir[File.join(dir, '*.rb')] } + all_files.each do |file| + require file + end + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/context.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/context.rb new file mode 100644 index 0000000..2ee79b9 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/context.rb @@ -0,0 +1,304 @@ +module Shoulda + class << self + attr_accessor :contexts + def contexts # :nodoc: + @contexts ||= [] + end + + def current_context # :nodoc: + self.contexts.last + end + + def add_context(context) # :nodoc: + self.contexts.push(context) + end + + def remove_context # :nodoc: + self.contexts.pop + end + end + + module ClassMethods + # == Should statements + # + # Should statements are just syntactic sugar over normal Test::Unit test methods. A should block + # contains all the normal code and assertions you're used to seeing, with the added benefit that + # they can be wrapped inside context blocks (see below). + # + # === Example: + # + # class UserTest < Test::Unit::TestCase + # + # def setup + # @user = User.new("John", "Doe") + # end + # + # should "return its full name" + # assert_equal 'John Doe', @user.full_name + # end + # + # end + # + # ...will produce the following test: + # * "test: User should return its full name. " + # + # Note: The part before should in the test name is gleamed from the name of the Test::Unit class. + # + # Should statements can also take a Proc as a :before option. This proc runs after any + # parent context's setups but before the current context's setup. + # + # === Example: + # + # context "Some context" do + # setup { puts("I run after the :before proc") } + # + # should "run a :before proc", :before => lambda { puts("I run before the setup") } do + # assert true + # end + # end + + def should(name, options = {}, &blk) + if Shoulda.current_context + block_given? ? Shoulda.current_context.should(name, options, &blk) : Should.current_context.should_eventually(name) + else + context_name = self.name.gsub(/Test/, "") + context = Shoulda::Context.new(context_name, self) do + block_given? ? should(name, options, &blk) : should_eventually(name) + end + context.build + end + end + + # == Before statements + # + # Before statements are should statements that run before the current + # context's setup. These are especially useful when setting expectations. + # + # === Example: + # + # class UserControllerTest < Test::Unit::TestCase + # context "the index action" do + # setup do + # @users = [Factory(:user)] + # User.stubs(:find).returns(@users) + # end + # + # context "on GET" do + # setup { get :index } + # + # should_respond_with :success + # + # # runs before "get :index" + # before_should "find all users" do + # User.expects(:find).with(:all).returns(@users) + # end + # end + # end + # end + def before_should(name, &blk) + should(name, :before => blk) { assert true } + end + + # Just like should, but never runs, and instead prints an 'X' in the Test::Unit output. + def should_eventually(name, options = {}, &blk) + context_name = self.name.gsub(/Test/, "") + context = Shoulda::Context.new(context_name, self) do + should_eventually(name, &blk) + end + context.build + end + + # == Contexts + # + # A context block groups should statements under a common set of setup/teardown methods. + # Context blocks can be arbitrarily nested, and can do wonders for improving the maintainability + # and readability of your test code. + # + # A context block can contain setup, should, should_eventually, and teardown blocks. + # + # class UserTest < Test::Unit::TestCase + # context "A User instance" do + # setup do + # @user = User.find(:first) + # end + # + # should "return its full name" + # assert_equal 'John Doe', @user.full_name + # end + # end + # end + # + # This code will produce the method "test: A User instance should return its full name. ". + # + # Contexts may be nested. Nested contexts run their setup blocks from out to in before each + # should statement. They then run their teardown blocks from in to out after each should statement. + # + # class UserTest < Test::Unit::TestCase + # context "A User instance" do + # setup do + # @user = User.find(:first) + # end + # + # should "return its full name" + # assert_equal 'John Doe', @user.full_name + # end + # + # context "with a profile" do + # setup do + # @user.profile = Profile.find(:first) + # end + # + # should "return true when sent :has_profile?" + # assert @user.has_profile? + # end + # end + # end + # end + # + # This code will produce the following methods + # * "test: A User instance should return its full name. " + # * "test: A User instance with a profile should return true when sent :has_profile?. " + # + # Just like should statements, a context block can exist next to normal def test_the_old_way; end + # tests. This means you do not have to fully commit to the context/should syntax in a test file. + + def context(name, &blk) + if Shoulda.current_context + Shoulda.current_context.context(name, &blk) + else + context = Shoulda::Context.new(name, self, &blk) + context.build + end + end + end + + class Context # :nodoc: + + attr_accessor :name # my name + attr_accessor :parent # may be another context, or the original test::unit class. + attr_accessor :subcontexts # array of contexts nested under myself + attr_accessor :setup_blocks # blocks given via setup methods + attr_accessor :teardown_blocks # blocks given via teardown methods + attr_accessor :shoulds # array of hashes representing the should statements + attr_accessor :should_eventuallys # array of hashes representing the should eventually statements + + def initialize(name, parent, &blk) + Shoulda.add_context(self) + self.name = name + self.parent = parent + self.setup_blocks = [] + self.teardown_blocks = [] + self.shoulds = [] + self.should_eventuallys = [] + self.subcontexts = [] + + merge_block(&blk) + Shoulda.remove_context + end + + def merge_block(&blk) + blk.bind(self).call + end + + def context(name, &blk) + self.subcontexts << Context.new(name, self, &blk) + end + + def setup(&blk) + self.setup_blocks << blk + end + + def teardown(&blk) + self.teardown_blocks << blk + end + + def should(name, options = {}, &blk) + if block_given? + self.shoulds << { :name => name, :before => options[:before], :block => blk } + else + self.should_eventuallys << { :name => name } + end + end + + def should_eventually(name, &blk) + self.should_eventuallys << { :name => name, :block => blk } + end + + def full_name + parent_name = parent.full_name if am_subcontext? + return [parent_name, name].join(" ").strip + end + + def am_subcontext? + parent.is_a?(self.class) # my parent is the same class as myself. + end + + def test_unit_class + am_subcontext? ? parent.test_unit_class : parent + end + + def create_test_from_should_hash(should) + test_name = ["test:", full_name, "should", "#{should[:name]}. "].flatten.join(' ').to_sym + + if test_unit_class.instance_methods.include?(test_name.to_s) + warn " * WARNING: '#{test_name}' is already defined" + end + + context = self + test_unit_class.send(:define_method, test_name) do + begin + context.run_parent_setup_blocks(self) + should[:before].bind(self).call if should[:before] + context.run_current_setup_blocks(self) + should[:block].bind(self).call + ensure + context.run_all_teardown_blocks(self) + end + end + end + + def run_all_setup_blocks(binding) + run_parent_setup_blocks(binding) + run_current_setup_blocks(binding) + end + + def run_parent_setup_blocks(binding) + self.parent.run_all_setup_blocks(binding) if am_subcontext? + end + + def run_current_setup_blocks(binding) + setup_blocks.each do |setup_block| + setup_block.bind(binding).call + end + end + + def run_all_teardown_blocks(binding) + teardown_blocks.reverse.each do |teardown_block| + teardown_block.bind(binding).call + end + self.parent.run_all_teardown_blocks(binding) if am_subcontext? + end + + def print_should_eventuallys + should_eventuallys.each do |should| + test_name = [full_name, "should", "#{should[:name]}. "].flatten.join(' ') + puts " * DEFERRED: " + test_name + end + end + + def build + shoulds.each do |should| + create_test_from_should_hash(should) + end + + subcontexts.each { |context| context.build } + + print_should_eventuallys + end + + def method_missing(method, *args, &blk) + test_unit_class.send(method, *args, &blk) + end + + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/helpers.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/helpers.rb new file mode 100644 index 0000000..873e7c7 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/helpers.rb @@ -0,0 +1,8 @@ +module Shoulda # :nodoc: + module Helpers + # Prints a message to stdout, tagged with the name of the calling method. + def report!(msg = "") + puts("#{caller.first}: #{msg}") + end + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/macros.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/macros.rb new file mode 100644 index 0000000..7eefb13 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/macros.rb @@ -0,0 +1,73 @@ +require 'shoulda/private_helpers' + +module Shoulda # :nodoc: + module Macros + # Macro that creates a test asserting a change between the return value + # of an expression that is run before and after the current setup block + # is run. This is similar to Active Support's assert_difference + # assertion, but supports more than just numeric values. See also + # should_not_change. + # + # Example: + # + # context "Creating a post" do + # setup { Post.create } + # should_change "Post.count", :by => 1 + # end + # + # As shown in this example, the :by option expects a numeric + # difference between the before and after values of the expression. You + # may also specify :from and :to options: + # + # should_change "Post.count", :from => 0, :to => 1 + # should_change "@post.title", :from => "old", :to => "new" + # + # Combinations of :by, :from, and :to are allowed: + # + # should_change "@post.title" # => assert the value changed in some way + # should_change "@post.title", :from => "old" # => assert the value changed to anything other than "old" + # should_change "@post.title", :to => "new" # => assert the value changed from anything other than "new" + def should_change(expression, options = {}) + by, from, to = get_options!([options], :by, :from, :to) + stmt = "change #{expression.inspect}" + stmt << " from #{from.inspect}" if from + stmt << " to #{to.inspect}" if to + stmt << " by #{by.inspect}" if by + + expression_eval = lambda { eval(expression) } + before = lambda { @_before_should_change = expression_eval.bind(self).call } + should stmt, :before => before do + old_value = @_before_should_change + new_value = expression_eval.bind(self).call + assert_operator from, :===, old_value, "#{expression.inspect} did not originally match #{from.inspect}" if from + assert_not_equal old_value, new_value, "#{expression.inspect} did not change" unless by == 0 + assert_operator to, :===, new_value, "#{expression.inspect} was not changed to match #{to.inspect}" if to + assert_equal old_value + by, new_value if by + end + end + + # Macro that creates a test asserting no change between the return value + # of an expression that is run before and after the current setup block + # is run. This is the logical opposite of should_change. + # + # Example: + # + # context "Updating a post" do + # setup { @post.update_attributes(:title => "new") } + # should_not_change "Post.count" + # end + def should_not_change(expression) + expression_eval = lambda { eval(expression) } + before = lambda { @_before_should_not_change = expression_eval.bind(self).call } + should "not change #{expression.inspect}", :before => before do + new_value = expression_eval.bind(self).call + assert_equal @_before_should_not_change, new_value, "#{expression.inspect} changed" + end + end + + private + + include Shoulda::Private + end +end + diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/private_helpers.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/private_helpers.rb new file mode 100644 index 0000000..e579957 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/private_helpers.rb @@ -0,0 +1,20 @@ +module Shoulda # :nodoc: + module Private # :nodoc: + # Returns the values for the entries in the args hash who's keys are listed in the wanted array. + # Will raise if there are keys in the args hash that aren't listed. + def get_options!(args, *wanted) + ret = [] + opts = (args.last.is_a?(Hash) ? args.pop : {}) + wanted.each {|w| ret << opts.delete(w)} + raise ArgumentError, "Unsupported options given: #{opts.keys.join(', ')}" unless opts.keys.empty? + return *ret + end + + # Returns the model class constant, as determined by the test class name. + # + # class TestUser; model_class; end => User + def model_class + self.name.gsub(/Test$/, '').constantize + end + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/proc_extensions.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/proc_extensions.rb new file mode 100644 index 0000000..0d577df --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/proc_extensions.rb @@ -0,0 +1,14 @@ +# Stolen straight from ActiveSupport + +class Proc #:nodoc: + def bind(object) + block, time = self, Time.now + (class << object; self end).class_eval do + method_name = "__bind_#{time.to_i}_#{time.usec}" + define_method(method_name, &block) + method = instance_method(method_name) + remove_method(method_name) + method + end.bind(object) + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/rails.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/rails.rb new file mode 100644 index 0000000..ddb2fcc --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/rails.rb @@ -0,0 +1,13 @@ +require 'rubygems' +require 'active_support' +require 'shoulda' + +require 'shoulda/active_record' if defined? ActiveRecord::Base +require 'shoulda/action_controller' if defined? ActionController::Base +require 'shoulda/action_view' if defined? ActionView::Base +require 'shoulda/action_mailer' if defined? ActionMailer::Base + +if defined?(RAILS_ROOT) + # load in the 3rd party macros from vendorized plugins and gems + Shoulda.autoload_macros RAILS_ROOT, File.join("vendor", "{plugins,gems}", "*") +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/rspec.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/rspec.rb new file mode 100644 index 0000000..ef636ab --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/rspec.rb @@ -0,0 +1,11 @@ +require 'shoulda/active_record/matchers' +require 'shoulda/action_controller/matchers' +require 'active_support/test_case' + +# :enddoc: +module ActiveSupport + class TestCase + include Shoulda::ActiveRecord::Matchers + include Shoulda::ActionController::Matchers + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/tasks.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/tasks.rb new file mode 100644 index 0000000..b59c89e --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/tasks.rb @@ -0,0 +1,3 @@ +Dir[File.join(File.dirname(__FILE__), 'tasks', '*.rake')].each do |f| + load f +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/tasks/list_tests.rake b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/tasks/list_tests.rake new file mode 100644 index 0000000..521daf2 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/tasks/list_tests.rake @@ -0,0 +1,29 @@ +namespace :shoulda do + desc "List the names of the test methods in a specification like format" + task :list do + $LOAD_PATH.unshift("test") + + require 'test/unit' + require 'rubygems' + require 'active_support' + + # bug in test unit. Set to true to stop from running. + Test::Unit.run = true + + test_files = Dir.glob(File.join('test', '**', '*_test.rb')) + test_files.each do |file| + load file + klass = File.basename(file, '.rb').classify + unless Object.const_defined?(klass.to_s) + puts "Skipping #{klass} because it doesn't map to a Class" + next + end + klass = klass.constantize + + puts klass.name.gsub('Test', '') + + test_methods = klass.instance_methods.grep(/^test/).map {|s| s.gsub(/^test: /, '')}.sort + test_methods.each {|m| puts " " + m } + end + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/tasks/yaml_to_shoulda.rake b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/tasks/yaml_to_shoulda.rake new file mode 100644 index 0000000..8303011 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/tasks/yaml_to_shoulda.rake @@ -0,0 +1,28 @@ +namespace :shoulda do + # From http://blog.internautdesign.com/2007/11/2/a-yaml_to_shoulda-rake-task + # David.Lowenfels@gmail.com + desc "Converts a YAML file (FILE=./path/to/yaml) into a Shoulda skeleton" + task :from_yaml do + require 'yaml' + + def yaml_to_context(hash, indent = 0) + indent1 = ' ' * indent + indent2 = ' ' * (indent + 1) + hash.each_pair do |context, shoulds| + puts indent1 + "context \"#{context}\" do" + puts + shoulds.each do |should| + yaml_to_context( should, indent + 1 ) and next if should.is_a?( Hash ) + puts indent2 + "should_eventually \"" + should.gsub(/^should +/,'') + "\" do" + puts indent2 + "end" + puts + end + puts indent1 + "end" + end + end + + puts("Please pass in a FILE argument.") and exit unless ENV['FILE'] + + yaml_to_context( YAML.load_file( ENV['FILE'] ) ) + end +end \ No newline at end of file diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/test_unit.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/test_unit.rb new file mode 100644 index 0000000..1caa430 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/test_unit.rb @@ -0,0 +1,19 @@ +require 'shoulda/context' +require 'shoulda/proc_extensions' +require 'shoulda/assertions' +require 'shoulda/macros' +require 'shoulda/helpers' +require 'shoulda/autoload_macros' +require 'shoulda/rails' if defined? RAILS_ROOT + +module Test # :nodoc: all + module Unit + class TestCase + extend Shoulda::ClassMethods + include Shoulda::Assertions + extend Shoulda::Macros + include Shoulda::Helpers + end + end +end + diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/rails/init.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/rails/init.rb new file mode 100644 index 0000000..3f683d8 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/rails/init.rb @@ -0,0 +1,7 @@ +if RAILS_ENV == 'test' + if defined? Spec + require 'shoulda/rspec' + else + require 'shoulda/rails' + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/README b/vendor/gems/thoughtbot-shoulda-2.10.1/test/README new file mode 100644 index 0000000..12a996c --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/README @@ -0,0 +1,36 @@ +The Shoulda test suite (in particular - the tests that test shoulda) + +Quick overview: + +The test directory contains the following files and subdirectories: + +* rails_root - contains the stripped down rails application that the tests run against. The rails root contains: +** the models, controllers, and views defined under app/ +** the test.rb environment file +** a migration file for each model +** a shoulda initializer that simulates loading the plugin but without relying on vendor/plugins +* fixtures - contain the sample DB data for each model +* functional - controller tests for each of the controllers under rails_root/app +* unit - model tests for each of the models under rails_root/app +* other - tests for the shoulda contexts, should statements, and assertions +* test_helper.rb - responsible for initializing the test environment +** sets the rails_env to test +** sets the rails_root +** runs all the migrations against the in-memory sqlite3 db +** adds some magic to load the right fixture files + +In order to add a new model (or controller) to the test suite: + +* add that model to rails_root/app/models +* add a migration for that model +* add a fixture file +* add a test for that file under test/units + +Dependencies: + +* Rails gem installed in the host system +* A working sqlite3 installation. + +If you have problems running these tests, please notify the mailing list: shoulda@googlegroups.com + +- Tammer Saleh diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/fail_macros.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/fail_macros.rb new file mode 100644 index 0000000..408cdf1 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/fail_macros.rb @@ -0,0 +1,34 @@ +module Shoulda + class << self + attr_accessor :expected_exceptions + end + + module ClassMethods + # Enables the core shoulda test suite to test for failure scenarios. For + # example, to ensure that a set of test macros should fail, do this: + # + # should_fail do + # should_validate_presence_of :comments + # should_not_allow_mass_assignment_of :name + # end + def should_fail(&block) + context "should fail when trying to run:" do + Shoulda.expected_exceptions = [Test::Unit::AssertionFailedError] + yield block + Shoulda.expected_exceptions = nil + end + end + end + + class Context + # alias_method_chain hack to allow the should_fail macro to work + def should_with_failure_scenario(name, options = {}, &block) + if Shoulda.expected_exceptions + expected_exceptions = Shoulda.expected_exceptions + failure_block = lambda { assert_raise(*expected_exceptions, &block.bind(self)) } + end + should_without_failure_scenario(name, options, &(failure_block || block)) + end + alias_method_chain :should, :failure_scenario + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/fixtures/addresses.yml b/vendor/gems/thoughtbot-shoulda-2.10.1/test/fixtures/addresses.yml new file mode 100644 index 0000000..3b468e5 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/fixtures/addresses.yml @@ -0,0 +1,3 @@ +first: + title: Home + addressable: first (User) diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/fixtures/friendships.yml b/vendor/gems/thoughtbot-shoulda-2.10.1/test/fixtures/friendships.yml new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/fixtures/friendships.yml diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/fixtures/posts.yml b/vendor/gems/thoughtbot-shoulda-2.10.1/test/fixtures/posts.yml new file mode 100644 index 0000000..f5cd7b6 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/fixtures/posts.yml @@ -0,0 +1,5 @@ +first: + id: 1 + title: My Cute Kitten! + body: This is totally a cute kitten + user_id: 1 diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/fixtures/products.yml b/vendor/gems/thoughtbot-shoulda-2.10.1/test/fixtures/products.yml new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/fixtures/products.yml diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/fixtures/taggings.yml b/vendor/gems/thoughtbot-shoulda-2.10.1/test/fixtures/taggings.yml new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/fixtures/taggings.yml diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/fixtures/tags.yml b/vendor/gems/thoughtbot-shoulda-2.10.1/test/fixtures/tags.yml new file mode 100644 index 0000000..3ef6292 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/fixtures/tags.yml @@ -0,0 +1,9 @@ +first: + id: 1 + name: Stuff +second: + id: 2 + name: Rails +third: + id: 3 + name: Nothing \ No newline at end of file diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/fixtures/users.yml b/vendor/gems/thoughtbot-shoulda-2.10.1/test/fixtures/users.yml new file mode 100644 index 0000000..6242a63 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/fixtures/users.yml @@ -0,0 +1,6 @@ +first: + id: 1 + name: Some dude + age: 2 + email: none@none.com + ssn: 123456789 diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/functional/posts_controller_test.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/functional/posts_controller_test.rb new file mode 100644 index 0000000..796492b --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/functional/posts_controller_test.rb @@ -0,0 +1,125 @@ +require File.dirname(__FILE__) + '/../test_helper' +require 'posts_controller' + +# Re-raise errors caught by the controller. +class PostsController; def rescue_action(e) raise e end; end + +class PostsControllerTest < Test::Unit::TestCase + fixtures :all + + def setup + @controller = PostsController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + @post = Post.find(:first) + end + + # autodetects the :controller + should_route :get, '/posts', :action => :index + # explicitly specify :controller + should_route :post, '/posts', :controller => :posts, :action => :create + # non-string parameter + should_route :get, '/posts/1', :action => :show, :id => 1 + # string-parameter + should_route :put, '/posts/1', :action => :update, :id => "1" + should_route :delete, '/posts/1', :action => :destroy, :id => 1 + should_route :get, '/posts/new', :action => :new + + # Test the nested routes + should_route :get, '/users/5/posts', :action => :index, :user_id => 5 + should_route :post, '/users/5/posts', :action => :create, :user_id => 5 + should_route :get, '/users/5/posts/1', :action => :show, :id => 1, :user_id => 5 + should_route :delete, '/users/5/posts/1', :action => :destroy, :id => 1, :user_id => 5 + should_route :get, '/users/5/posts/new', :action => :new, :user_id => 5 + should_route :put, '/users/5/posts/1', :action => :update, :id => 1, :user_id => 5 + + context "Logged in" do + setup do + @request.session[:logged_in] = true + end + + context "viewing posts for a user" do + setup do + get :index, :user_id => users(:first) + end + should_respond_with :success + should_assign_to :user, :class => User, :equals => 'users(:first)' + should_assign_to(:user) { users(:first) } + should_fail do + should_assign_to :user, :class => Post + end + should_fail do + should_assign_to :user, :equals => 'posts(:first)' + end + should_fail do + should_assign_to(:user) { posts(:first) } + end + should_assign_to :posts + should_not_assign_to :foo, :bar + should_render_page_with_metadata :description => /Posts/, :title => /index/ + should_render_page_with_metadata :keywords => "posts" + end + + context "viewing posts for a user with rss format" do + setup do + get :index, :user_id => users(:first), :format => 'rss' + @user = users(:first) + end + should_respond_with :success + should_respond_with_content_type 'application/rss+xml' + should_respond_with_content_type :rss + should_respond_with_content_type /rss/ + context "deprecated" do # to avoid redefining a test + should_return_from_session :special, "'$2 off your next purchase'" + end + should_fail do + should_return_from_session :special, "'not special'" + end + should_set_session(:mischief) { nil } + should_return_from_session :malarky, "nil" + should_set_session :special, "'$2 off your next purchase'" + should_set_session :special_user_id, '@user.id' + context "with a block" do + should_set_session(:special_user_id) { @user.id } + end + should_fail do # to avoid redefining a test + should_set_session(:special_user_id) { 'value' } + end + should_assign_to :user, :posts + should_not_assign_to :foo, :bar + end + + context "viewing a post on GET to #show" do + setup { get :show, :user_id => users(:first), :id => posts(:first) } + should_render_with_layout 'wide' + context "with a symbol" do # to avoid redefining a test + should_render_with_layout :wide + end + should_assign_to :false_flag + end + + context "on GET to #new" do + setup { get :new, :user_id => users(:first) } + should_render_without_layout + end + + context "on POST to #create" do + setup do + post :create, :user_id => users(:first), + :post => { :title => "first post", + :body => 'blah blah blah' } + end + + should_redirect_to 'user_post_url(@post.user, @post)' + should_redirect_to('the created post') { user_post_url(users(:first), + assigns(:post)) } + should_fail do + should_redirect_to 'user_posts_url(@post.user)' + end + should_fail do + should_redirect_to('elsewhere') { user_posts_url(users(:first)) } + end + end + end + +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/functional/users_controller_test.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/functional/users_controller_test.rb new file mode 100644 index 0000000..cd0205f --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/functional/users_controller_test.rb @@ -0,0 +1,19 @@ +require File.dirname(__FILE__) + '/../test_helper' +require 'users_controller' + +# Re-raise errors caught by the controller. +class UsersController; def rescue_action(e) raise e end; end + +class UsersControllerTest < Test::Unit::TestCase + fixtures :all + + def setup + @controller = UsersController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + @user = User.find(:first) + end + + should_filter_params :ssn + +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/allow_mass_assignment_of_matcher_test.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/allow_mass_assignment_of_matcher_test.rb new file mode 100644 index 0000000..5b12726 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/allow_mass_assignment_of_matcher_test.rb @@ -0,0 +1,68 @@ +require File.join(File.dirname(__FILE__), '..', '..', 'test_helper') + +class AllowMassAssignmentOfMatcherTest < Test::Unit::TestCase # :nodoc: + + context "an attribute that is blacklisted from mass-assignment" do + setup do + define_model :example, :attr => :string do + attr_protected :attr + end + @model = Example.new + end + + should "reject being mass-assignable" do + assert_rejects allow_mass_assignment_of(:attr), @model + end + end + + context "an attribute that is not whitelisted for mass-assignment" do + setup do + define_model :example, :attr => :string, :other => :string do + attr_accessible :other + end + @model = Example.new + end + + should "reject being mass-assignable" do + assert_rejects allow_mass_assignment_of(:attr), @model + end + end + + context "an attribute that is whitelisted for mass-assignment" do + setup do + define_model :example, :attr => :string do + attr_accessible :attr + end + @model = Example.new + end + + should "accept being mass-assignable" do + assert_accepts allow_mass_assignment_of(:attr), @model + end + end + + context "an attribute not included in the mass-assignment blacklist" do + setup do + define_model :example, :attr => :string, :other => :string do + attr_protected :other + end + @model = Example.new + end + + should "accept being mass-assignable" do + assert_accepts allow_mass_assignment_of(:attr), @model + end + end + + context "an attribute on a class with no protected attributes" do + setup do + define_model :example, :attr => :string + @model = Example.new + end + + should "accept being mass-assignable" do + assert_accepts allow_mass_assignment_of(:attr), @model + end + end + +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/allow_value_matcher_test.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/allow_value_matcher_test.rb new file mode 100644 index 0000000..11fcc56 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/allow_value_matcher_test.rb @@ -0,0 +1,41 @@ +require File.join(File.dirname(__FILE__), '..', '..', 'test_helper') + +class AllowValueMatcherTest < Test::Unit::TestCase # :nodoc: + + context "an attribute with a format validation" do + setup do + define_model :example, :attr => :string do + validates_format_of :attr, :with => /abc/ + end + @model = Example.new + end + + should "allow a good value" do + assert_accepts allow_value("abcde").for(:attr), @model + end + + should "not allow a bad value" do + assert_rejects allow_value("xyz").for(:attr), @model + end + end + + context "an attribute with a format validation and a custom message" do + setup do + define_model :example, :attr => :string do + validates_format_of :attr, :with => /abc/, :message => 'bad value' + end + @model = Example.new + end + + should "allow a good value" do + assert_accepts allow_value('abcde').for(:attr).with_message(/bad/), + @model + end + + should "not allow a bad value" do + assert_rejects allow_value('xyz').for(:attr).with_message(/bad/), + @model + end + end + +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/association_matcher_test.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/association_matcher_test.rb new file mode 100644 index 0000000..703537e --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/association_matcher_test.rb @@ -0,0 +1,258 @@ +require File.join(File.dirname(__FILE__), '..', '..', 'test_helper') + +class AssociationMatcherTest < Test::Unit::TestCase # :nodoc: + + context "belong_to" do + setup do + @matcher = belong_to(:parent) + end + + should "accept a good association with the default foreign key" do + define_model :parent + define_model :child, :parent_id => :integer do + belongs_to :parent + end + assert_accepts @matcher, Child.new + end + + should "reject a nonexistent association" do + define_model :child + assert_rejects @matcher, Child.new + end + + should "reject an association of the wrong type" do + define_model :parent, :child_id => :integer + child_class = define_model :child do + has_one :parent + end + assert_rejects @matcher, Child.new + end + + should "reject an association that has a nonexistent foreign key" do + define_model :parent + define_model :child do + belongs_to :parent + end + assert_rejects @matcher, Child.new + end + + should "accept an association with an existing custom foreign key" do + define_model :parent + define_model :child, :guardian_id => :integer do + belongs_to :parent, :foreign_key => 'guardian_id' + end + assert_accepts @matcher, Child.new + end + + should "accept a polymorphic association" do + define_model :child, :parent_type => :string, + :parent_id => :integer do + belongs_to :parent, :polymorphic => true + end + assert_accepts @matcher, Child.new + end + + should "accept an association with a valid :dependent option" do + define_model :parent + define_model :child, :parent_id => :integer do + belongs_to :parent, :dependent => :destroy + end + assert_accepts @matcher.dependent(:destroy), Child.new + end + + should "reject an association with a bad :dependent option" do + define_model :parent + define_model :child, :parent_id => :integer do + belongs_to :parent + end + assert_rejects @matcher.dependent(:destroy), Child.new + end + end + + context "have_many" do + setup do + @matcher = have_many(:children) + end + + should "accept a valid association without any options" do + define_model :child, :parent_id => :integer + define_model :parent do + has_many :children + end + assert_accepts @matcher, Parent.new + end + + should "accept a valid association with a :through option" do + define_model :child + define_model :conception, :child_id => :integer, + :parent_id => :integer do + belongs_to :child + end + define_model :parent do + has_many :conceptions + has_many :children, :through => :conceptions + end + assert_accepts @matcher, Parent.new + end + + should "accept a valid association with an :as option" do + define_model :child, :guardian_type => :string, + :guardian_id => :integer + define_model :parent do + has_many :children, :as => :guardian + end + assert_accepts @matcher, Parent.new + end + + should "reject an association that has a nonexistent foreign key" do + define_model :child + define_model :parent do + has_many :children + end + assert_rejects @matcher, Parent.new + end + + should "reject an association with a bad :as option" do + define_model :child, :caretaker_type => :string, + :caretaker_id => :integer + define_model :parent do + has_many :children, :as => :guardian + end + assert_rejects @matcher, Parent.new + end + + should "reject an association that has a bad :through option" do + define_model :child, :parent_id => :integer + define_model :parent do + has_many :children + end + assert_rejects @matcher.through(:conceptions), Parent.new + end + + should "reject an association that has the wrong :through option" do + define_model :child + define_model :conception, :child_id => :integer, + :parent_id => :integer do + belongs_to :child + end + define_model :parent do + has_many :conceptions + has_many :children, :through => :conceptions + end + assert_rejects @matcher.through(:relationships), Parent.new + end + + should "accept an association with a valid :dependent option" do + define_model :child, :parent_id => :integer + define_model :parent do + has_many :children, :dependent => :destroy + end + assert_accepts @matcher.dependent(:destroy), Parent.new + end + + should "reject an association with a bad :dependent option" do + define_model :child, :parent_id => :integer + define_model :parent do + has_many :children + end + assert_rejects @matcher.dependent(:destroy), Parent.new + end + end + + context "have_one" do + setup do + @matcher = have_one(:profile) + end + + should "accept a valid association without any options" do + define_model :profile, :person_id => :integer + define_model :person do + has_one :profile + end + assert_accepts @matcher, Person.new + end + + should "accept a valid association with an :as option" do + define_model :profile, :profilable_id => :integer, + :profilable_type => :string + define_model :person do + has_one :profile, :as => :profilable + end + assert_accepts @matcher, Person.new + end + + should "reject an association that has a nonexistent foreign key" do + define_model :profile + define_model :person do + has_one :profile + end + assert_rejects @matcher, Person.new + end + + should "reject an association with a bad :as option" do + define_model :profile, :profilable_id => :integer, + :profilable_type => :string + define_model :person do + has_one :profile, :as => :describable + end + assert_rejects @matcher, Person.new + end + + should "accept an association with a valid :dependent option" do + define_model :profile, :person_id => :integer + define_model :person do + has_one :profile, :dependent => :destroy + end + assert_accepts @matcher.dependent(:destroy), Person.new + end + + should "reject an association with a bad :dependent option" do + define_model :profile, :person_id => :integer + define_model :person do + has_one :profile + end + assert_rejects @matcher.dependent(:destroy), Person.new + end + end + + context "have_and_belong_to_many" do + setup do + @matcher = have_and_belong_to_many(:relatives) + end + + should "accept a valid association" do + define_model :relatives + define_model :person do + has_and_belongs_to_many :relatives + end + define_model :people_relative, :person_id => :integer, + :relative_id => :integer + assert_accepts @matcher, Person.new + end + + should "reject a nonexistent association" do + define_model :relatives + define_model :person + define_model :people_relative, :person_id => :integer, + :relative_id => :integer + assert_rejects @matcher, Person.new + end + + should "reject an association with a nonexistent join table" do + define_model :relatives + define_model :person do + has_and_belongs_to_many :relatives + end + assert_rejects @matcher, Person.new + end + + should "reject an association of the wrong type" do + define_model :relatives, :person_id => :integer + define_model :person do + has_many :relatives + end + assert_rejects @matcher, Person.new + end + end + +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/ensure_inclusion_of_matcher_test.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/ensure_inclusion_of_matcher_test.rb new file mode 100644 index 0000000..bb0b45f --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/ensure_inclusion_of_matcher_test.rb @@ -0,0 +1,80 @@ +require File.join(File.dirname(__FILE__), '..', '..', 'test_helper') + +class EnsureInclusionOfMatcherTest < Test::Unit::TestCase # :nodoc: + + context "an attribute which must be included in a range" do + setup do + @model = define_model(:example, :attr => :integer) do + validates_inclusion_of :attr, :in => 2..5 + end.new + end + + should "accept ensuring the correct range" do + assert_accepts ensure_inclusion_of(:attr).in_range(2..5), @model + end + + should "reject ensuring a lower minimum value" do + assert_rejects ensure_inclusion_of(:attr).in_range(1..5), @model + end + + should "reject ensuring a higher minimum value" do + assert_rejects ensure_inclusion_of(:attr).in_range(3..5), @model + end + + should "reject ensuring a lower maximum value" do + assert_rejects ensure_inclusion_of(:attr).in_range(2..4), @model + end + + should "reject ensuring a higher maximum value" do + assert_rejects ensure_inclusion_of(:attr).in_range(2..6), @model + end + + should "not override the default message with a blank" do + assert_accepts ensure_inclusion_of(:attr). + in_range(2..5). + with_message(nil), + @model + end + end + + context "an attribute with a custom ranged value validation" do + setup do + @model = define_model(:example, :attr => :string) do + validates_inclusion_of :attr, :in => 2..4, :message => 'not good' + + end.new + end + + should "accept ensuring the correct range" do + assert_accepts ensure_inclusion_of(:attr). + in_range(2..4). + with_message(/not good/), + @model + end + end + + context "an attribute with custom range validations" do + setup do + define_model :example, :attr => :integer do + def validate + if attr < 2 + errors.add(:attr, 'too low') + elsif attr > 5 + errors.add(:attr, 'too high') + end + end + end + @model = Example.new + end + + should "accept ensuring the correct range and messages" do + assert_accepts ensure_inclusion_of(:attr). + in_range(2..5). + with_low_message(/low/). + with_high_message(/high/), + @model + end + + end + +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/ensure_length_of_matcher_test.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/ensure_length_of_matcher_test.rb new file mode 100644 index 0000000..a41d5f0 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/ensure_length_of_matcher_test.rb @@ -0,0 +1,158 @@ +require File.join(File.dirname(__FILE__), '..', '..', 'test_helper') + +class EnsureLengthOfMatcher < Test::Unit::TestCase # :nodoc: + + context "an attribute with a non-zero minimum length validation" do + setup do + @model = define_model(:example, :attr => :string) do + validates_length_of :attr, :minimum => 4 + end.new + end + + should "accept ensuring the correct minimum length" do + assert_accepts ensure_length_of(:attr).is_at_least(4), @model + end + + should "reject ensuring a lower minimum length with any message" do + assert_rejects ensure_length_of(:attr). + is_at_least(3). + with_short_message(/.*/), + @model + end + + should "reject ensuring a higher minimum length with any message" do + assert_rejects ensure_length_of(:attr). + is_at_least(5). + with_short_message(/.*/), + @model + end + + should "not override the default message with a blank" do + assert_accepts ensure_length_of(:attr). + is_at_least(4). + with_short_message(nil), + @model + end + end + + context "an attribute with a minimum length validation of 0" do + setup do + @model = define_model(:example, :attr => :string) do + validates_length_of :attr, :minimum => 0 + end.new + end + + should "accept ensuring the correct minimum length" do + assert_accepts ensure_length_of(:attr).is_at_least(0), @model + end + end + + context "an attribute with a maximum length" do + setup do + @model = define_model(:example, :attr => :string) do + validates_length_of :attr, :maximum => 4 + end.new + end + + should "accept ensuring the correct maximum length" do + assert_accepts ensure_length_of(:attr).is_at_most(4), @model + end + + should "reject ensuring a lower maximum length with any message" do + assert_rejects ensure_length_of(:attr). + is_at_most(3). + with_long_message(/.*/), + @model + end + + should "reject ensuring a higher maximum length with any message" do + assert_rejects ensure_length_of(:attr). + is_at_most(5). + with_long_message(/.*/), + @model + end + + should "not override the default message with a blank" do + assert_accepts ensure_length_of(:attr). + is_at_most(4). + with_long_message(nil), + @model + end + end + + context "an attribute with a required exact length" do + setup do + @model = define_model(:example, :attr => :string) do + validates_length_of :attr, :is => 4 + end.new + end + + should "accept ensuring the correct length" do + assert_accepts ensure_length_of(:attr).is_equal_to(4), @model + end + + should "reject ensuring a lower maximum length with any message" do + assert_rejects ensure_length_of(:attr). + is_equal_to(3). + with_message(/.*/), + @model + end + + should "reject ensuring a higher maximum length with any message" do + assert_rejects ensure_length_of(:attr). + is_equal_to(5). + with_message(/.*/), + @model + end + + should "not override the default message with a blank" do + assert_accepts ensure_length_of(:attr). + is_equal_to(4). + with_message(nil), + @model + end + end + + context "an attribute with a custom minimum length validation" do + setup do + @model = define_model(:example, :attr => :string) do + validates_length_of :attr, :minimum => 4, :too_short => 'short' + end.new + end + + should "accept ensuring the correct minimum length" do + assert_accepts ensure_length_of(:attr). + is_at_least(4). + with_short_message(/short/), + @model + end + + end + + context "an attribute with a custom maximum length validation" do + setup do + @model = define_model(:example, :attr => :string) do + validates_length_of :attr, :maximum => 4, :too_long => 'long' + end.new + end + + should "accept ensuring the correct minimum length" do + assert_accepts ensure_length_of(:attr). + is_at_most(4). + with_long_message(/long/), + @model + end + + end + + context "an attribute without a length validation" do + setup do + @model = define_model(:example, :attr => :string).new + end + + should "reject ensuring a minimum length" do + assert_rejects ensure_length_of(:attr).is_at_least(1), @model + end + end + +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/have_db_column_matcher_test.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/have_db_column_matcher_test.rb new file mode 100644 index 0000000..5afeeec --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/have_db_column_matcher_test.rb @@ -0,0 +1,169 @@ +require File.join(File.dirname(__FILE__), '..', '..', 'test_helper') + +class HaveDbColumnMatcherTest < Test::Unit::TestCase # :nodoc: + + context "have_db_column" do + setup do + @matcher = have_db_column(:nickname) + end + + should "accept an existing database column" do + create_table 'superheros' do |table| + table.string :nickname + end + define_model_class 'Superhero' + assert_accepts @matcher, Superhero.new + end + + should "reject a nonexistent database column" do + define_model :superhero + assert_rejects @matcher, Superhero.new + end + end + + context "have_db_column of type string" do + setup do + @matcher = have_db_column(:nickname).of_type(:string) + end + + should "accept a column of correct type" do + create_table 'superheros' do |table| + table.string :nickname + end + define_model_class 'Superhero' + assert_accepts @matcher, Superhero.new + end + + should "reject a nonexistent database column" do + define_model :superhero + assert_rejects @matcher, Superhero.new + end + + should "reject a column of wrong type" do + create_table 'superheros' do |table| + table.integer :nickname + end + define_model_class 'Superhero' + assert_rejects @matcher, Superhero.new + end + end + + context "have_db_column with precision option" do + setup do + @matcher = have_db_column(:salary).with_options(:precision => 5) + end + + should "accept a column of correct precision" do + create_table 'superheros' do |table| + table.decimal :salary, :precision => 5 + end + define_model_class 'Superhero' + assert_accepts @matcher, Superhero.new + end + + should "reject a column of wrong precision" do + create_table 'superheros' do |table| + table.decimal :salary, :precision => 15 + end + define_model_class 'Superhero' + assert_rejects @matcher, Superhero.new + end + end + + context "have_db_column with limit option" do + setup do + @matcher = have_db_column(:email). + of_type(:string). + with_options(:limit => 255) + end + + should "accept a column of correct limit" do + create_table 'superheros' do |table| + table.string :email, :limit => 255 + end + define_model_class 'Superhero' + assert_accepts @matcher, Superhero.new + end + + should "reject a column of wrong limit" do + create_table 'superheros' do |table| + table.string :email, :limit => 500 + end + define_model_class 'Superhero' + assert_rejects @matcher, Superhero.new + end + end + + context "have_db_column with default option" do + setup do + @matcher = have_db_column(:admin). + of_type(:boolean). + with_options(:default => false) + end + + should "accept a column of correct default" do + create_table 'superheros' do |table| + table.boolean :admin, :default => false + end + define_model_class 'Superhero' + assert_accepts @matcher, Superhero.new + end + + should "reject a column of wrong default" do + create_table 'superheros' do |table| + table.boolean :admin, :default => true + end + define_model_class 'Superhero' + assert_rejects @matcher, Superhero.new + end + end + + context "have_db_column with null option" do + setup do + @matcher = have_db_column(:admin). + of_type(:boolean). + with_options(:null => false) + end + + should "accept a column of correct null" do + create_table 'superheros' do |table| + table.boolean :admin, :null => false + end + define_model_class 'Superhero' + assert_accepts @matcher, Superhero.new + end + + should "reject a column of wrong null" do + create_table 'superheros' do |table| + table.boolean :admin, :null => true + end + define_model_class 'Superhero' + assert_rejects @matcher, Superhero.new + end + end + + context "have_db_column with scale option" do + setup do + @matcher = have_db_column(:salary). + of_type(:decimal). + with_options(:scale => 2) + end + + should "accept a column of correct scale" do + create_table 'superheros' do |table| + table.decimal :salary, :precision => 10, :scale => 2 + end + define_model_class 'Superhero' + assert_accepts @matcher, Superhero.new + end + + should "reject a column of wrong scale" do + create_table 'superheros' do |table| + table.decimal :salary, :precision => 10, :scale => 4 + end + define_model_class 'Superhero' + assert_rejects @matcher, Superhero.new + end + end + +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/have_index_matcher_test.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/have_index_matcher_test.rb new file mode 100644 index 0000000..a7cea9f --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/have_index_matcher_test.rb @@ -0,0 +1,74 @@ +require File.join(File.dirname(__FILE__), '..', '..', 'test_helper') + +class HaveIndexMatcherTest < Test::Unit::TestCase # :nodoc: + + context "have_index" do + setup do + @matcher = have_index(:age) + end + + should "accept an existing index" do + db_connection = create_table 'superheros' do |table| + table.integer :age + end + db_connection.add_index :superheros, :age + define_model_class 'Superhero' + assert_accepts @matcher, Superhero.new + end + + should "reject a nonexistent index" do + define_model :superhero + assert_rejects @matcher, Superhero.new + end + end + + context "have_index with unique option" do + setup do + @matcher = have_index(:ssn).unique(true) + end + + should "accept an index of correct unique" do + db_connection = create_table 'superheros' do |table| + table.integer :ssn + end + db_connection.add_index :superheros, :ssn, :unique => true + define_model_class 'Superhero' + assert_accepts @matcher, Superhero.new + end + + should "reject an index of wrong unique" do + db_connection = create_table 'superheros' do |table| + table.integer :ssn + end + db_connection.add_index :superheros, :ssn, :unique => false + define_model_class 'Superhero' + assert_rejects @matcher, Superhero.new + end + end + + context "have_index on multiple columns" do + setup do + @matcher = have_index([:geocodable_type, :geocodable_id]) + end + + should "accept an existing index" do + db_connection = create_table 'geocodings' do |table| + table.integer :geocodable_id + table.string :geocodable_type + end + db_connection.add_index :geocodings, [:geocodable_type, :geocodable_id] + define_model_class 'Geocoding' + assert_accepts @matcher, Geocoding.new + end + + should "reject a nonexistant index" do + db_connection = create_table 'geocodings' do |table| + table.integer :geocodable_id + table.string :geocodable_type + end + define_model_class 'Geocoding' + assert_rejects @matcher, Geocoding.new + end + end + +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/have_named_scope_matcher_test.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/have_named_scope_matcher_test.rb new file mode 100644 index 0000000..2e9ecb5 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/have_named_scope_matcher_test.rb @@ -0,0 +1,65 @@ +require File.join(File.dirname(__FILE__), '..', '..', 'test_helper') + +class HaveNamedScopeMatcherTest < Test::Unit::TestCase # :nodoc: + + context "an attribute with a named scope" do + setup do + define_model :example, :attr => :string do + named_scope :xyz, lambda {|n| + { :order => :attr } + } + end + @model = Example.new + end + + should "accept having a scope with the correct signature" do + assert_accepts have_named_scope("xyz(1)"), @model + end + + should "accept having a scope with the correct signature and find options" do + assert_accepts have_named_scope("xyz(1)").finding(:order => :attr), @model + end + + should "reject having a scope with incorrect find options" do + assert_rejects have_named_scope("xyz(1)"). + finding(:order => 'attr DESC'), + @model + end + + should "reject having a scope with another name" do + assert_rejects have_named_scope("abc(1)"), @model + end + + end + + should "evaluate the scope in the correct context" do + define_model :example, :attr => :string do + named_scope :xyz, lambda {|n| + { :order => n } + } + end + model = Example.new + @order = :attr + assert_accepts have_named_scope("xyz(@order)"). + finding(:order => @order). + in_context(self), + model + end + + context "a method that does not return a scope" do + setup do + klass = Class.new + klass.class_eval do + def self.xyz + 'xyz' + end + end + @model = klass.new + end + + should "reject having a named scope with that name" do + assert_rejects have_named_scope(:xyz), @model + end + end + +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/have_readonly_attributes_matcher_test.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/have_readonly_attributes_matcher_test.rb new file mode 100644 index 0000000..81a47c8 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/have_readonly_attributes_matcher_test.rb @@ -0,0 +1,29 @@ +require File.join(File.dirname(__FILE__), '..', '..', 'test_helper') + +class HaveReadonlyAttributesMatcherTest < Test::Unit::TestCase # :nodoc: + + context "an attribute that cannot be set after being saved" do + setup do + define_model :example, :attr => :string do + attr_readonly :attr + end + @model = Example.new + end + + should "accept being read-only" do + assert_accepts have_readonly_attribute(:attr), @model + end + end + + context "an attribute that can be set after being saved" do + setup do + define_model :example, :attr => :string + @model = Example.new + end + + should "accept being read-only" do + assert_rejects have_readonly_attribute(:attr), @model + end + end + +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/validate_acceptance_of_matcher_test.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/validate_acceptance_of_matcher_test.rb new file mode 100644 index 0000000..d19d5ff --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/validate_acceptance_of_matcher_test.rb @@ -0,0 +1,44 @@ +require File.join(File.dirname(__FILE__), '..', '..', 'test_helper') + +class ValidateAcceptanceOfMatcherTest < Test::Unit::TestCase # :nodoc: + + context "an attribute which must be accepted" do + setup do + @model = define_model(:example) do + validates_acceptance_of :attr + end.new + end + + should "require that attribute to be accepted" do + assert_accepts validate_acceptance_of(:attr), @model + end + + should "not overwrite the default message with nil" do + assert_accepts validate_acceptance_of(:attr).with_message(nil), @model + end + end + + context "an attribute that does not need to be accepted" do + setup do + @model = define_model(:example, :attr => :string).new + end + + should "not require that attribute to be accepted" do + assert_rejects validate_acceptance_of(:attr), @model + end + end + + context "an attribute which must be accepted with a custom message" do + setup do + @model = define_model(:example) do + validates_acceptance_of :attr, :message => 'custom' + end.new + end + + should "require that attribute to be accepted with that message" do + assert_accepts validate_acceptance_of(:attr).with_message(/custom/), + @model + end + end + +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/validate_numericality_of_matcher_test.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/validate_numericality_of_matcher_test.rb new file mode 100644 index 0000000..f9ab3a1 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/validate_numericality_of_matcher_test.rb @@ -0,0 +1,52 @@ +require File.join(File.dirname(__FILE__), '..', '..', 'test_helper') + +class ValidateNumericalityOfMatcherTest < Test::Unit::TestCase # :nodoc: + + context "a numeric attribute" do + setup do + define_model :example, :attr => :string do + validates_numericality_of :attr + end + @model = Example.new + end + + should "only allow numeric values for that attribute" do + assert_accepts validate_numericality_of(:attr), @model + end + + should "not override the default message with a blank" do + assert_accepts validate_numericality_of(:attr).with_message(nil), + @model + end + end + + context "a numeric attribute with a custom validation message" do + setup do + define_model :example, :attr => :string do + validates_numericality_of :attr, :message => 'custom' + end + @model = Example.new + end + + should "only allow numeric values for that attribute with that message" do + assert_accepts validate_numericality_of(:attr). + with_message(/custom/), + @model + end + + should "not allow numeric values for that attribute with another message" do + assert_rejects validate_numericality_of(:attr), @model + end + end + + context "a non-numeric attribute" do + setup do + @model = define_model(:example, :attr => :string).new + end + + should "not only allow numeric values for that attribute" do + assert_rejects validate_numericality_of(:attr), @model + end + end + +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/validate_presence_of_matcher_test.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/validate_presence_of_matcher_test.rb new file mode 100644 index 0000000..f59440a --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/validate_presence_of_matcher_test.rb @@ -0,0 +1,86 @@ +require File.join(File.dirname(__FILE__), '..', '..', 'test_helper') + +class ValidatePresenceOfMatcherTest < Test::Unit::TestCase # :nodoc: + + context "a required attribute" do + setup do + define_model :example, :attr => :string do + validates_presence_of :attr + end + @model = Example.new + end + + should "require a value" do + assert_accepts validate_presence_of(:attr), @model + end + + should "not override the default message with a blank" do + assert_accepts validate_presence_of(:attr).with_message(nil), @model + end + end + + context "an optional attribute" do + setup do + @model = define_model(:example, :attr => :string).new + end + + should "not require a value" do + assert_rejects validate_presence_of(:attr), @model + end + end + + context "a required has_many association" do + setup do + define_model :child + @model = define_model :parent do + has_many :children + validates_presence_of :children + end.new + end + + should "require the attribute to be set" do + assert_accepts validate_presence_of(:children), @model + end + end + + context "an optional has_many association" do + setup do + define_model :child + @model = define_model :parent do + has_many :children + end.new + end + + should "not require the attribute to be set" do + assert_rejects validate_presence_of(:children), @model + end + end + + context "a required has_and_belongs_to_many association" do + setup do + define_model :child + @model = define_model :parent do + has_and_belongs_to_many :children + validates_presence_of :children + end.new + end + + should "require the attribute to be set" do + assert_accepts validate_presence_of(:children), @model + end + end + + context "an optional has_and_belongs_to_many association" do + setup do + define_model :child + @model = define_model :parent do + has_and_belongs_to_many :children + end.new + end + + should "not require the attribute to be set" do + assert_rejects validate_presence_of(:children), @model + end + end + +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/validate_uniqueness_of_matcher_test.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/validate_uniqueness_of_matcher_test.rb new file mode 100644 index 0000000..cf7c0f9 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/active_record/validate_uniqueness_of_matcher_test.rb @@ -0,0 +1,147 @@ +require File.join(File.dirname(__FILE__), '..', '..', 'test_helper') + +class ValidateUniquenessOfMatcherTest < Test::Unit::TestCase # :nodoc: + + context "a unique attribute" do + setup do + @model = define_model(:example, :attr => :string, + :other => :integer) do + validates_uniqueness_of :attr + end.new + end + + context "with an existing value" do + setup do + @existing = Example.create!(:attr => 'value', :other => 1) + end + + should "require a unique value for that attribute" do + assert_accepts validate_uniqueness_of(:attr), @model + end + + should "pass when the subject is an existing record" do + assert_accepts validate_uniqueness_of(:attr), @existing + end + + should "fail when a scope is specified" do + assert_rejects validate_uniqueness_of(:attr).scoped_to(:other), @model + end + end + + context "without an existing value" do + setup do + assert_nil Example.find(:first) + @matcher = validate_uniqueness_of(:attr) + end + + should "fail to require a unique value" do + assert_rejects @matcher, @model + end + + should "alert the tester that an existing value is not present" do + @matcher.matches?(@model) + assert @matcher.negative_failure_message =~ /^Can't find first .*/ + end + end + end + + context "a unique attribute with a custom error and an existing value" do + setup do + @model = define_model(:example, :attr => :string) do + validates_uniqueness_of :attr, :message => 'Bad value' + end.new + Example.create! + end + + should "fail when checking the default message" do + assert_rejects validate_uniqueness_of(:attr), @model + end + + should "fail when checking a message that doesn't match" do + assert_rejects validate_uniqueness_of(:attr).with_message(/abc/i), @model + end + + should "pass when checking a message that matches" do + assert_accepts validate_uniqueness_of(:attr).with_message(/bad/i), @model + end + end + + context "a scoped unique attribute with an existing value" do + setup do + @model = define_model(:example, :attr => :string, + :scope1 => :integer, + :scope2 => :integer) do + validates_uniqueness_of :attr, :scope => [:scope1, :scope2] + end.new + @existing = Example.create!(:attr => 'value', :scope1 => 1, :scope2 => 2) + end + + should "pass when the correct scope is specified" do + assert_accepts validate_uniqueness_of(:attr).scoped_to(:scope1, :scope2), + @model + end + + should "pass when the subject is an existing record" do + assert_accepts validate_uniqueness_of(:attr).scoped_to(:scope1, :scope2), + @existing + end + + should "fail when a different scope is specified" do + assert_rejects validate_uniqueness_of(:attr).scoped_to(:scope1), @model + end + + should "fail when no scope is specified" do + assert_rejects validate_uniqueness_of(:attr), @model + end + + should "fail when a non-existent attribute is specified as a scope" do + assert_rejects validate_uniqueness_of(:attr).scoped_to(:fake), @model + end + end + + context "a non-unique attribute with an existing value" do + setup do + @model = define_model(:example, :attr => :string).new + Example.create!(:attr => 'value') + end + + should "not require a unique value for that attribute" do + assert_rejects validate_uniqueness_of(:attr), @model + end + end + + context "a case sensitive unique attribute with an existing value" do + setup do + @model = define_model(:example, :attr => :string) do + validates_uniqueness_of :attr, :case_sensitive => true + end.new + Example.create!(:attr => 'value') + end + + should "not require a unique, case-insensitive value for that attribute" do + assert_rejects validate_uniqueness_of(:attr).case_insensitive, @model + end + + should "require a unique, case-sensitive value for that attribute" do + assert_accepts validate_uniqueness_of(:attr), @model + end + end + + context "a case sensitive unique integer attribute with an existing value" do + setup do + @model = define_model(:example, :attr => :integer) do + validates_uniqueness_of :attr, :case_sensitive => true + end.new + Example.create!(:attr => 'value') + end + + should "require a unique, case-insensitive value for that attribute" do + assert_accepts validate_uniqueness_of(:attr).case_insensitive, @model + end + + should "require a unique, case-sensitive value for that attribute" do + assert_accepts validate_uniqueness_of(:attr), @model + end + end + +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/controller/assign_to_matcher_test.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/controller/assign_to_matcher_test.rb new file mode 100644 index 0000000..4b32724 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/controller/assign_to_matcher_test.rb @@ -0,0 +1,35 @@ +require File.join(File.dirname(__FILE__), '..', '..', 'test_helper') + +class AssignToMatcherTest < Test::Unit::TestCase # :nodoc: + + context "a controller that assigns to an instance variable" do + setup do + @controller = build_response { @var = 'value' } + end + + should "accept assigning to that variable" do + assert_accepts assign_to(:var), @controller + end + + should "accept assigning to that variable with the correct class" do + assert_accepts assign_to(:var).with_kind_of(String), @controller + end + + should "reject assigning to that variable with another class" do + assert_rejects assign_to(:var).with_kind_of(Fixnum), @controller + end + + should "accept assigning the correct value to that variable" do + assert_accepts assign_to(:var).with('value'), @controller + end + + should "reject assigning another value to that variable" do + assert_rejects assign_to(:var).with('other'), @controller + end + + should "reject assigning to another variable" do + assert_rejects assign_to(:other), @controller + end + end + +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/controller/filter_param_matcher_test.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/controller/filter_param_matcher_test.rb new file mode 100644 index 0000000..e8437af --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/controller/filter_param_matcher_test.rb @@ -0,0 +1,32 @@ +require File.join(File.dirname(__FILE__), '..', '..', 'test_helper') + +class FilterParamMatcherTest < Test::Unit::TestCase # :nodoc: + + context "a controller that filters no parameters" do + setup do + @controller = define_controller(:examples).new + end + + should "reject filtering any parameter" do + assert_rejects filter_param(:any), @controller + end + end + + context "a controller that filters a parameter" do + setup do + @controller = define_controller :examples do + filter_parameter_logging :password + end.new + end + + should "accept filtering that parameter" do + assert_accepts filter_param(:password), @controller + end + + should "reject filtering another parameter" do + assert_rejects filter_param(:other), @controller + end + end + +end + diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/controller/render_with_layout_matcher_test.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/controller/render_with_layout_matcher_test.rb new file mode 100644 index 0000000..e7f7e2b --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/controller/render_with_layout_matcher_test.rb @@ -0,0 +1,33 @@ +require File.join(File.dirname(__FILE__), '..', '..', 'test_helper') + +class RenderWithLayoutMatcherTest < Test::Unit::TestCase # :nodoc: + + context "a controller that renders with a layout" do + setup do + @controller = build_response { render :layout => 'wide' } + end + + should "accept rendering with any layout" do + assert_accepts render_with_layout, @controller + end + + should "accept rendering with that layout" do + assert_accepts render_with_layout(:wide), @controller + end + + should "reject rendering with another layout" do + assert_rejects render_with_layout(:other), @controller + end + end + + context "a controller that renders without a layout" do + setup do + @controller = build_response { render :layout => false } + end + + should "reject rendering with a layout" do + assert_rejects render_with_layout, @controller + end + end + +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/controller/respond_with_content_type_matcher_test.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/controller/respond_with_content_type_matcher_test.rb new file mode 100644 index 0000000..6719ff3 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/controller/respond_with_content_type_matcher_test.rb @@ -0,0 +1,27 @@ +require File.join(File.dirname(__FILE__), '..', '..', 'test_helper') + +class RespondWithContentTypeMatcherTest < Test::Unit::TestCase # :nodoc: + + context "a controller responding with content type :xml" do + setup do + @controller = build_response { render :xml => { :user => "thoughtbot" }.to_xml } + end + + should "accept responding with content type :xml" do + assert_accepts respond_with_content_type(:xml), @controller + end + + should "accept responding with content type 'application/xml'" do + assert_accepts respond_with_content_type('application/xml'), @controller + end + + should "accept responding with content type /xml/" do + assert_accepts respond_with_content_type(/xml/), @controller + end + + should "reject responding with another content type" do + assert_rejects respond_with_content_type(:json), @controller + end + end + +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/controller/respond_with_matcher_test.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/controller/respond_with_matcher_test.rb new file mode 100644 index 0000000..759ae16 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/controller/respond_with_matcher_test.rb @@ -0,0 +1,106 @@ +require File.join(File.dirname(__FILE__), '..', '..', 'test_helper') + +class RespondWithMatcherTest < Test::Unit::TestCase # :nodoc: + + context "a controller responding with success" do + setup do + @controller = build_response { render :text => "text", :status => 200 } + end + + should "accept responding with 200" do + assert_accepts respond_with(200), @controller + end + + should "accept responding with :success" do + assert_accepts respond_with(:success), @controller + end + + should "reject responding with another status" do + assert_rejects respond_with(:error), @controller + end + end + + context "a controller responding with redirect" do + setup do + @controller = build_response { render :text => "text", :status => 301 } + end + + should "accept responding with 301" do + assert_accepts respond_with(301), @controller + end + + should "accept responding with :redirect" do + assert_accepts respond_with(:redirect), @controller + end + + should "reject responding with another status" do + assert_rejects respond_with(:error), @controller + end + end + + context "a controller responding with missing" do + setup do + @controller = build_response { render :text => "text", :status => 404 } + end + + should "accept responding with 404" do + assert_accepts respond_with(404), @controller + end + + should "accept responding with :missing" do + assert_accepts respond_with(:missing), @controller + end + + should "reject responding with another status" do + assert_rejects respond_with(:success), @controller + end + end + + context "a controller responding with error" do + setup do + @controller = build_response { render :text => "text", :status => 500 } + end + + should "accept responding with 500" do + assert_accepts respond_with(500), @controller + end + + should "accept responding with :error" do + assert_accepts respond_with(:error), @controller + end + + should "reject responding with another status" do + assert_rejects respond_with(:success), @controller + end + end + + context "a controller responding with not implemented" do + setup do + @controller = build_response { render :text => "text", :status => 501 } + end + + should "accept responding with 501" do + assert_accepts respond_with(501), @controller + end + + should "accept responding with :not_implemented" do + assert_accepts respond_with(:not_implemented), @controller + end + + should "reject responding with another status" do + assert_rejects respond_with(:success), @controller + end + end + + context "a controller raising an error" do + setup do + @controller = build_response { raise RailsError } + end + + should "reject responding with any status" do + assert_rejects respond_with(:success), @controller + end + end + +end + diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/controller/route_matcher_test.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/controller/route_matcher_test.rb new file mode 100644 index 0000000..ede9b4d --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/controller/route_matcher_test.rb @@ -0,0 +1,58 @@ +require File.join(File.dirname(__FILE__), '..', '..', 'test_helper') + +class RouteToMatcherTest < Test::Unit::TestCase # :nodoc: + + context "given a controller with a defined route" do + setup do + @controller = define_controller('Examples').new + define_routes do |map| + map.connect 'examples/:id', :controller => 'examples', + :action => 'example' + end + end + + should "accept routing the correct path to the correct parameters" do + assert_accepts route(:get, '/examples/1'). + to(:action => 'example', :id => '1'), + @controller + end + + should "accept a symbol controller" do + assert_accepts route(:get, '/examples/1'). + to(:controller => :examples, + :action => 'example', + :id => '1'), + self + end + + should "accept a symbol action" do + assert_accepts route(:get, '/examples/1'). + to(:action => :example, :id => '1'), + @controller + end + + should "accept a non-string parameter" do + assert_accepts route(:get, '/examples/1'). + to(:action => 'example', :id => 1), + @controller + end + + should "reject an undefined route" do + assert_rejects route(:get, '/bad_route').to(:var => 'value'), @controller + end + + should "reject a route for another controller" do + @other = define_controller('Other').new + assert_rejects route(:get, '/examples/1'). + to(:action => 'example', :id => '1'), + @other + end + + should "reject a route for different parameters" do + assert_rejects route(:get, '/examples/1'). + to(:action => 'other', :id => '1'), + @controller + end + end + +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/controller/set_session_matcher_test.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/controller/set_session_matcher_test.rb new file mode 100644 index 0000000..771bce3 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/controller/set_session_matcher_test.rb @@ -0,0 +1,31 @@ +require File.join(File.dirname(__FILE__), '..', '..', 'test_helper') + +class SetSessionMatcherTest < Test::Unit::TestCase # :nodoc: + + context "a controller that sets a session variable" do + setup do + @controller = build_response { session[:var] = 'value' } + end + + should "accept assigning to that variable" do + assert_accepts set_session(:var), @controller + end + + should "accept assigning the correct value to that variable" do + assert_accepts set_session(:var).to('value'), @controller + end + + should "reject assigning another value to that variable" do + assert_rejects set_session(:var).to('other'), @controller + end + + should "reject assigning to another variable" do + assert_rejects set_session(:other), @controller + end + + should "accept assigning nil to another variable" do + assert_accepts set_session(:other).to(nil), @controller + end + end + +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/controller/set_the_flash_matcher.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/controller/set_the_flash_matcher.rb new file mode 100644 index 0000000..4d0a17d --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/matchers/controller/set_the_flash_matcher.rb @@ -0,0 +1,41 @@ +require File.join(File.dirname(__FILE__), '..', '..', 'test_helper') + +class SetTheFlashMatcherTest < Test::Unit::TestCase # :nodoc: + + context "a controller that sets a flash message" do + setup do + @controller = build_response { flash[:notice] = 'value' } + end + + should "accept setting any flash message" do + assert_accepts set_the_flash, @controller + end + + should "accept setting the exact flash message" do + assert_accepts set_the_flash.to('value'), @controller + end + + should "accept setting a matched flash message" do + assert_accepts set_the_flash.to(/value/), @controller + end + + should "reject setting a different flash message" do + assert_rejects set_the_flash.to('other'), @controller + end + + should "reject setting a different pattern" do + assert_rejects set_the_flash.to(/other/), @controller + end + end + + context "a controller that doesn't set a flash message" do + setup do + @controller = build_response + end + + should "reject setting any flash message" do + assert_rejects set_the_flash, @controller + end + end + +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/model_builder.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/model_builder.rb new file mode 100644 index 0000000..084f1a7 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/model_builder.rb @@ -0,0 +1,106 @@ +class Test::Unit::TestCase + def create_table(table_name, &block) + connection = ActiveRecord::Base.connection + + begin + connection.execute("DROP TABLE IF EXISTS #{table_name}") + connection.create_table(table_name, &block) + @created_tables ||= [] + @created_tables << table_name + connection + rescue Exception => e + connection.execute("DROP TABLE IF EXISTS #{table_name}") + raise e + end + end + + def define_constant(class_name, base, &block) + class_name = class_name.to_s.camelize + + klass = Class.new(base) + Object.const_set(class_name, klass) + + klass.class_eval(&block) if block_given? + + @defined_constants ||= [] + @defined_constants << class_name + + klass + end + + def define_model_class(class_name, &block) + define_constant(class_name, ActiveRecord::Base, &block) + end + + def define_model(name, columns = {}, &block) + class_name = name.to_s.pluralize.classify + table_name = class_name.tableize + + create_table(table_name) do |table| + columns.each do |name, type| + table.column name, type + end + end + + define_model_class(class_name, &block) + end + + def define_controller(class_name, &block) + class_name = class_name.to_s + class_name << 'Controller' unless class_name =~ /Controller$/ + define_constant(class_name, ActionController::Base, &block) + end + + def define_routes(&block) + @replaced_routes = ActionController::Routing::Routes + new_routes = ActionController::Routing::RouteSet.new + silence_warnings do + ActionController::Routing.const_set('Routes', new_routes) + end + new_routes.draw(&block) + end + + def build_response(&block) + klass = define_controller('Examples') + block ||= lambda { render :nothing => true } + klass.class_eval { define_method(:example, &block) } + define_routes do |map| + map.connect 'examples', :controller => 'examples', :action => 'example' + end + + @controller = klass.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + get :example + + @controller + end + + def teardown_with_models + if @defined_constants + @defined_constants.each do |class_name| + Object.send(:remove_const, class_name) + end + end + + if @created_tables + @created_tables.each do |table_name| + ActiveRecord::Base. + connection. + execute("DROP TABLE IF EXISTS #{table_name}") + end + end + + if @replaced_routes + ActionController::Routing::Routes.clear! + silence_warnings do + ActionController::Routing.const_set('Routes', @replaced_routes) + end + @replaced_routes.reload! + end + + teardown_without_models + end + alias_method :teardown_without_models, :teardown + alias_method :teardown, :teardown_with_models +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/other/autoload_macro_test.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/other/autoload_macro_test.rb new file mode 100644 index 0000000..ecfa356 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/other/autoload_macro_test.rb @@ -0,0 +1,18 @@ +require File.join(File.dirname(__FILE__), '..', 'test_helper') + +class AutoloadMacroTest < Test::Unit::TestCase # :nodoc: + context "The macro auto-loader" do + should "load macros from the plugins" do + assert self.class.respond_to?('plugin_macro') + end + + should "load macros from the gems" do + assert self.class.respond_to?('gem_macro') + end + + should "load custom macros from ROOT/test/shoulda_macros" do + assert self.class.respond_to?('custom_macro') + end + end +end + diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/other/context_test.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/other/context_test.rb new file mode 100644 index 0000000..352ea14 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/other/context_test.rb @@ -0,0 +1,145 @@ +require File.join(File.dirname(__FILE__), '..', 'test_helper') + +class ContextTest < Test::Unit::TestCase # :nodoc: + + def self.context_macro(&blk) + context "with a subcontext made by a macro" do + setup { @context_macro = :foo } + + merge_block &blk + end + end + + # def self.context_macro(&blk) + # context "with a subcontext made by a macro" do + # setup { @context_macro = :foo } + # yield # <- this doesn't work. + # end + # end + + context "context with setup block" do + setup do + @blah = "blah" + end + + should "run the setup block" do + assert_equal "blah", @blah + end + + should "have name set right" do + assert_match(/^test: context with setup block/, self.to_s) + end + + context "and a subcontext" do + setup do + @blah = "#{@blah} twice" + end + + should "be named correctly" do + assert_match(/^test: context with setup block and a subcontext should be named correctly/, self.to_s) + end + + should "run the setup blocks in order" do + assert_equal @blah, "blah twice" + end + end + + context_macro do + should "have name set right" do + assert_match(/^test: context with setup block with a subcontext made by a macro should have name set right/, self.to_s) + end + + should "run the setup block of that context macro" do + assert_equal :foo, @context_macro + end + + should "run the setup block of the main context" do + assert_equal "blah", @blah + end + end + + end + + context "another context with setup block" do + setup do + @blah = "foo" + end + + should "have @blah == 'foo'" do + assert_equal "foo", @blah + end + + should "have name set right" do + assert_match(/^test: another context with setup block/, self.to_s) + end + end + + context "context with method definition" do + setup do + def hello; "hi"; end + end + + should "be able to read that method" do + assert_equal "hi", hello + end + + should "have name set right" do + assert_match(/^test: context with method definition/, self.to_s) + end + end + + context "another context" do + should "not define @blah" do + assert_nil @blah + end + end + + context "context with multiple setups and/or teardowns" do + + cleanup_count = 0 + + 2.times do |i| + setup { cleanup_count += 1 } + teardown { cleanup_count -= 1 } + end + + 2.times do |i| + should "call all setups and all teardowns (check ##{i + 1})" do + assert_equal 2, cleanup_count + end + end + + context "subcontexts" do + + 2.times do |i| + setup { cleanup_count += 1 } + teardown { cleanup_count -= 1 } + end + + 2.times do |i| + should "also call all setups and all teardowns in parent and subcontext (check ##{i + 1})" do + assert_equal 4, cleanup_count + end + end + + end + + end + + should_eventually "pass, since it's unimplemented" do + flunk "what?" + end + + should_eventually "not require a block when using should_eventually" + should "pass without a block, as that causes it to piggyback to should_eventually" + + context "context for testing should piggybacking" do + should "call should_eventually as we are not passing a block" + end + + context "context" do + context "with nested subcontexts" do + should_eventually "only print this statement once for a should_eventually" + end + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/other/convert_to_should_syntax_test.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/other/convert_to_should_syntax_test.rb new file mode 100644 index 0000000..8b0594f --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/other/convert_to_should_syntax_test.rb @@ -0,0 +1,63 @@ +require 'test/unit' + +class ConvertToShouldSyntaxTest < Test::Unit::TestCase # :nodoc: + + BEFORE_FIXTURE = <<-EOS + class DummyTest < Test::Unit::TestCase + + should "Not change this_word_with_underscores" do + end + + def test_should_be_working + assert true + end + + def test_some_cool_stuff + assert true + end + + def non_test_method + end + + end + EOS + + AFTER_FIXTURE = <<-EOS + class DummyTest < Test::Unit::TestCase + + should "Not change this_word_with_underscores" do + end + + should "be working" do + assert true + end + + should "RENAME ME: test some cool stuff" do + assert true + end + + def non_test_method + end + + end + EOS + + FIXTURE_PATH = "./convert_to_should_syntax_fixture.dat" + + RUBY = ENV['RUBY'] || 'ruby' + + def test_convert_to_should_syntax + File.open(FIXTURE_PATH, "w") {|f| f.write(BEFORE_FIXTURE)} + cmd = "#{RUBY} #{File.join(File.dirname(__FILE__), '../../bin/convert_to_should_syntax')} #{FIXTURE_PATH}" + output = `#{cmd}` + File.unlink($1) if output.match(/has been stored in '([^']+)/) + assert_match(/has been converted/, output) + result = IO.read(FIXTURE_PATH) + assert_equal result, AFTER_FIXTURE + end + + def teardown + File.unlink(FIXTURE_PATH) + end + +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/other/helpers_test.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/other/helpers_test.rb new file mode 100644 index 0000000..0c581b9 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/other/helpers_test.rb @@ -0,0 +1,241 @@ +require File.join(File.dirname(__FILE__), '..', 'test_helper') +require 'action_mailer' +require 'mocha' + +class HelpersTest < Test::Unit::TestCase # :nodoc: + + context "given delivered emails" do + setup do + email1 = stub(:subject => "one", :to => ["none1@email.com"]) + email2 = stub(:subject => "two", :to => ["none2@email.com"]) + ActionMailer::Base.stubs(:deliveries).returns([email1, email2]) + end + + should "have sent an email" do + assert_sent_email + + assert_raises(Test::Unit::AssertionFailedError) do + assert_did_not_send_email + end + end + + should "find email one" do + assert_sent_email do |e| + e.subject =~ /one/ + end + end + + should "not find an email that doesn't exist" do + assert_raises(Test::Unit::AssertionFailedError) do + assert_sent_email do |e| + e.subject =~ /whatever/ + end + end + end + end + + context "when there are no emails" do + setup do + ActionMailer::Base.stubs(:deliveries).returns([]) + end + + should "not have sent an email" do + assert_did_not_send_email + + assert_raises(Test::Unit::AssertionFailedError) do + assert_sent_email + end + end + end + + context "an array of values" do + setup do + @a = ['abc', 'def', 3] + end + + [/b/, 'abc', 3].each do |x| + should "contain #{x.inspect}" do + assert_raises(Test::Unit::AssertionFailedError) do + assert_does_not_contain @a, x + end + assert_contains @a, x + end + end + + should "not contain 'wtf'" do + assert_raises(Test::Unit::AssertionFailedError) {assert_contains @a, 'wtf'} + assert_does_not_contain @a, 'wtf' + end + + should "be the same as another array, ordered differently" do + assert_same_elements(@a, [3, "def", "abc"]) + assert_raises(Test::Unit::AssertionFailedError) do + assert_same_elements(@a, [3, 3, "def", "abc"]) + end + assert_raises(Test::Unit::AssertionFailedError) do + assert_same_elements([@a, "abc"].flatten, [3, 3, "def", "abc"]) + end + end + end + + context "an array of values" do + setup do + @a = [1, 2, "(3)"] + end + + context "after adding another value" do + setup do + @a.push(4) + end + + should_change "@a.length", :by => 1 + should_change "@a.length", :from => 3 + should_change "@a.length", :to => 4 + should_change "@a[0]", :by => 0 + should_not_change "@a[0]" + end + + context "after replacing it with an array of strings" do + setup do + @a = %w(a b c d e f) + end + + should_change "@a.length", :by => 3 + should_change "@a.length", :from => 3, :to => 6, :by => 3 + should_change "@a[0]" + should_change "@a[1]", :from => 2, :to => "b" + should_change "@a[2]", :from => /\d/, :to => /\w/ + should_change "@a[3]", :to => String + end + end + + context "assert_good_value" do + should "validate a good email address" do + assert_good_value User.new, :email, "good@example.com" + end + + should "validate a good SSN with a custom message" do + assert_good_value User.new, :ssn, "xxxxxxxxx", /length/ + end + + should "fail to validate a bad email address" do + assert_raises Test::Unit::AssertionFailedError do + assert_good_value User.new, :email, "bad" + end + end + + should "fail to validate a bad SSN that is too short" do + assert_raises Test::Unit::AssertionFailedError do + assert_good_value User.new, :ssn, "x", /length/ + end + end + + should "accept a class as the first argument" do + assert_good_value User, :email, "good@example.com" + end + + context "with an instance variable" do + setup do + @product = Product.new(:tangible => true) + end + + should "use that instance variable" do + assert_good_value Product, :price, "9999", /included/ + end + end + end + + context "assert_bad_value" do + should "invalidate a bad email address" do + assert_bad_value User.new, :email, "bad" + end + + should "invalidate a bad SSN with a custom message" do + assert_bad_value User.new, :ssn, "x", /length/ + end + + should "fail to invalidate a good email address" do + assert_raises Test::Unit::AssertionFailedError do + assert_bad_value User.new, :email, "good@example.com" + end + end + + should "fail to invalidate a good SSN" do + assert_raises Test::Unit::AssertionFailedError do + assert_bad_value User.new, :ssn, "xxxxxxxxx", /length/ + end + end + + should "accept a class as the first argument" do + assert_bad_value User, :email, "bad" + end + + context "with an instance variable" do + setup do + @product = Product.new(:tangible => true) + end + + should "use that instance variable" do + assert_bad_value Product, :price, "0", /included/ + end + end + end + + context "a matching matcher" do + setup do + @matcher = stub('matcher', :matches? => true, + :failure_message => 'bad failure message', + :negative_failure_message => 'big time failure') + end + + should "pass when given to assert_accepts" do + assert_accepts @matcher, 'target' + end + + context "when given to assert_rejects" do + setup do + begin + assert_rejects @matcher, 'target' + rescue Test::Unit::AssertionFailedError => @error + end + end + + should "fail" do + assert_not_nil @error + end + + should "use the error message from the matcher" do + assert_equal 'big time failure', @error.message + end + end + end + + context "a non-matching matcher" do + setup do + @matcher = stub('matcher', :matches? => false, + :failure_message => 'big time failure', + :negative_failure_message => 'bad failure message') + end + + should "pass when given to assert_rejects" do + assert_rejects @matcher, 'target' + end + + context "when given to assert_accepts" do + setup do + begin + assert_accepts @matcher, 'target' + rescue Test::Unit::AssertionFailedError => @error + end + end + + should "fail" do + assert_not_nil @error + end + + should "use the error message from the matcher" do + assert_equal 'big time failure', @error.message + end + end + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/other/private_helpers_test.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/other/private_helpers_test.rb new file mode 100644 index 0000000..7b2564a --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/other/private_helpers_test.rb @@ -0,0 +1,34 @@ +require File.join(File.dirname(__FILE__), '..', 'test_helper') + +class PrivateHelpersTest < Test::Unit::TestCase # :nodoc: + include Shoulda::Private + context "get_options!" do + should "remove opts from args" do + args = [:a, :b, {}] + get_options!(args) + assert_equal [:a, :b], args + end + + should "return wanted opts in order" do + args = [{:one => 1, :two => 2}] + one, two = get_options!(args, :one, :two) + assert_equal 1, one + assert_equal 2, two + end + + should "raise ArgumentError if given unwanted option" do + args = [{:one => 1, :two => 2}] + assert_raises ArgumentError do + get_options!(args, :one) + end + end + end + + class ::SomeModel; end + context "model_class" do + should "sniff the class constant from the test class" do + self.expects(:name).returns("SomeModelTest") + assert_equal SomeModel, model_class + end + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/other/should_test.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/other/should_test.rb new file mode 100644 index 0000000..f32e8f1 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/other/should_test.rb @@ -0,0 +1,266 @@ +require File.join(File.dirname(__FILE__), '..', 'test_helper') + +class ShouldTest < Test::Unit::TestCase # :nodoc: + should "be able to define a should statement outside of a context" do + assert true + end + + should "see the name of my class as ShouldTest" do + assert_equal "ShouldTest", self.class.name + end + + def self.should_see_class_methods + should "be able to see class methods" do + assert true + end + end + + def self.should_see_a_context_block_like_a_Test_Unit_class + should "see a context block as a Test::Unit class" do + assert_equal "ShouldTest", self.class.name + end + end + + def self.should_see_blah + should "see @blah through a macro" do + assert @blah + end + end + + def self.should_not_see_blah + should "not see @blah through a macro" do + assert_nil @blah + end + end + + def self.should_be_able_to_make_context_macros(prefix = nil) + context "a macro" do + should "have the tests named correctly" do + assert_match(/^test: #{prefix}a macro should have the tests named correctly/, self.to_s) + end + end + end + + context "Context" do + + should_see_class_methods + should_see_a_context_block_like_a_Test_Unit_class + should_be_able_to_make_context_macros("Context ") + + should "not define @blah" do + assert ! self.instance_variables.include?("@blah") + end + + should_not_see_blah + + should "be able to define a should statement" do + assert true + end + + should "see the name of my class as ShouldTest" do + assert_equal "ShouldTest", self.class.name + end + + context "with a subcontext" do + should_be_able_to_make_context_macros("Context with a subcontext ") + end + end + + context "Context with setup block" do + setup do + @blah = "blah" + end + + should "have @blah == 'blah'" do + assert_equal "blah", @blah + end + should_see_blah + + should "have name set right" do + assert_match(/^test: Context with setup block/, self.to_s) + end + + context "and a subcontext" do + setup do + @blah = "#{@blah} twice" + end + + should "be named correctly" do + assert_match(/^test: Context with setup block and a subcontext should be named correctly/, self.to_s) + end + + should "run the setup methods in order" do + assert_equal @blah, "blah twice" + end + should_see_blah + end + end + + context "Another context with setup block" do + setup do + @blah = "foo" + end + + should "have @blah == 'foo'" do + assert_equal "foo", @blah + end + + should "have name set right" do + assert_match(/^test: Another context with setup block/, self.to_s) + end + should_see_blah + end + + should_eventually "pass, since it's a should_eventually" do + flunk "what?" + end + + # Context creation and naming + + def test_should_create_a_new_context + assert_nothing_raised do + Shoulda::Context.new("context name", self) do; end + end + end + + def test_should_create_a_nested_context + assert_nothing_raised do + parent = Shoulda::Context.new("Parent", self) do; end + child = Shoulda::Context.new("Child", parent) do; end + end + end + + def test_should_name_a_contexts_correctly + parent = Shoulda::Context.new("Parent", self) do; end + child = Shoulda::Context.new("Child", parent) do; end + grandchild = Shoulda::Context.new("GrandChild", child) do; end + + assert_equal "Parent", parent.full_name + assert_equal "Parent Child", child.full_name + assert_equal "Parent Child GrandChild", grandchild.full_name + end + + # Should statements + + def test_should_have_should_hashes_when_given_should_statements + context = Shoulda::Context.new("name", self) do + should "be good" do; end + should "another" do; end + end + + names = context.shoulds.map {|s| s[:name]} + assert_equal ["another", "be good"], names.sort + end + + # setup and teardown + + def test_should_capture_setup_and_teardown_blocks + context = Shoulda::Context.new("name", self) do + setup do; "setup"; end + teardown do; "teardown"; end + end + + assert_equal "setup", context.setup_blocks.first.call + assert_equal "teardown", context.teardown_blocks.first.call + end + + # building + + def test_should_create_shoulda_test_for_each_should_on_build + context = Shoulda::Context.new("name", self) do + should "one" do; end + should "two" do; end + end + context.expects(:create_test_from_should_hash).with(has_entry(:name => "one")) + context.expects(:create_test_from_should_hash).with(has_entry(:name => "two")) + context.build + end + + def test_should_create_test_methods_on_build + tu_class = Test::Unit::TestCase + context = Shoulda::Context.new("A Context", tu_class) do + should "define the test" do; end + end + + tu_class.expects(:define_method).with(:"test: A Context should define the test. ") + context.build + end + + def test_should_create_test_methods_on_build_when_subcontext + tu_class = Test::Unit::TestCase + context = Shoulda::Context.new("A Context", tu_class) do + context "with a child" do + should "define the test" do; end + end + end + + tu_class.expects(:define_method).with(:"test: A Context with a child should define the test. ") + context.build + end + + # Test::Unit integration + + def test_should_create_a_new_context_and_build_it_on_Test_Unit_context + c = mock("context") + c.expects(:build) + Shoulda::Context.expects(:new).with("foo", kind_of(Class)).returns(c) + self.class.context "foo" do; end + end + + def test_should_create_a_one_off_context_and_build_it_on_Test_Unit_should + s = mock("test") + Shoulda::Context.any_instance.expects(:should).with("rock", {}).returns(s) + Shoulda::Context.any_instance.expects(:build) + self.class.should "rock" do; end + end + + def test_should_create_a_one_off_context_and_build_it_on_Test_Unit_should_eventually + s = mock("test") + Shoulda::Context.any_instance.expects(:should_eventually).with("rock").returns(s) + Shoulda::Context.any_instance.expects(:build) + self.class.should_eventually "rock" do; end + end + + should "run a :before proc", :before => lambda { @value = "before" } do + assert_equal "before", @value + end + + context "A :before proc" do + setup do + assert_equal "before", @value + @value = "setup" + end + + should "run before the current setup", :before => lambda { @value = "before" } do + assert_equal "setup", @value + end + end + + context "a before statement" do + setup do + assert_equal "before", @value + @value = "setup" + end + + before_should "run before the current setup" do + @value = "before" + end + end + + context "A context" do + setup do + @value = "outer" + end + + context "with a subcontext and a :before proc" do + before = lambda do + assert "outer", @value + @value = "before" + end + should "run after the parent setup", :before => before do + assert_equal "before", @value + end + end + end + +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/controllers/application.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/controllers/application.rb new file mode 100644 index 0000000..10fa987 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/controllers/application.rb @@ -0,0 +1,25 @@ +# Filters added to this controller apply to all controllers in the application. +# Likewise, all the methods added will be available for all controllers. + +class ApplicationController < ActionController::Base + # Pick a unique cookie name to distinguish our session data from others' + session :session_key => '_rails_root_session_id' + + def ensure_logged_in + unless session[:logged_in] + respond_to do |accepts| + accepts.html do + flash[:error] = 'What do you think you\'re doing?' + redirect_to '/' + end + accepts.xml do + headers["Status"] = "Unauthorized" + headers["WWW-Authenticate"] = %(Basic realm="Web Password") + render :text => "Couldn't authenticate you", :status => '401 Unauthorized' + end + end + return false + end + return true + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/controllers/posts_controller.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/controllers/posts_controller.rb new file mode 100644 index 0000000..46c9212 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/controllers/posts_controller.rb @@ -0,0 +1,86 @@ +class PostsController < ApplicationController + before_filter :ensure_logged_in + before_filter :load_user + + def index + @posts = @user.posts + + respond_to do |format| + format.html # index.rhtml + format.xml { render :xml => @posts.to_xml } + format.rss do + headers['Content-Type'] = 'application/rss+xml' + session[:special] = '$2 off your next purchase' + session[:special_user_id] = @user.id + head :ok + end + end + end + + def show + @post = @user.posts.find(params[:id]) + @false_flag = false + + respond_to do |format| + format.html { render :layout => 'wide' } + format.xml { render :xml => @post.to_xml } + end + end + + def new + @post = @user.posts.build + render :layout => false + end + + def edit + @post = @user.posts.find(params[:id]) + end + + def create + @post = @user.posts.build(params[:post]) + + respond_to do |format| + if @post.save + flash[:notice] = 'Post was successfully created.' + format.html { redirect_to user_post_url(@post.user, @post) } + format.xml { head :created, :location => user_post_url(@post.user, @post) } + else + format.html { render :action => "new" } + format.xml { render :xml => @post.errors.to_xml } + end + end + end + + def update + @post = @user.posts.find(params[:id]) + + respond_to do |format| + if @post.update_attributes(params[:post]) + flash[:notice] = 'Post was successfully updated.' + format.html { redirect_to user_post_url(@post.user, @post) } + format.xml { head :ok } + else + format.html { render :action => "edit" } + format.xml { render :xml => @post.errors.to_xml } + end + end + end + + def destroy + @post = @user.posts.find(params[:id]) + @post.destroy + + flash[:notice] = "Post was removed" + + respond_to do |format| + format.html { redirect_to user_posts_url(@post.user) } + format.xml { head :ok } + end + end + + private + + def load_user + @user = User.find(params[:user_id]) + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/controllers/users_controller.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/controllers/users_controller.rb new file mode 100644 index 0000000..7a54a30 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/controllers/users_controller.rb @@ -0,0 +1,84 @@ +class UsersController < ApplicationController + + filter_parameter_logging :ssn + + # GET /users + # GET /users.xml + def index + @users = User.find(:all) + + respond_to do |format| + format.html # index.rhtml + format.xml { render :xml => @users.to_xml } + end + end + + # GET /users/1 + # GET /users/1.xml + def show + @user = User.find(params[:id]) + + respond_to do |format| + format.html # show.rhtml + format.xml { render :xml => @user.to_xml } + end + end + + # GET /users/new + def new + @user = User.new + end + + # GET /users/1;edit + def edit + @user = User.find(params[:id]) + end + + # POST /users + # POST /users.xml + def create + @user = User.new(params[:user]) + + respond_to do |format| + if @user.save + flash[:notice] = 'User was successfully created.' + format.html { redirect_to user_url(@user) } + format.xml { head :created, :location => user_url(@user) } + else + format.html { render :action => "new" } + format.xml { render :xml => @user.errors.to_xml } + end + end + end + + # PUT /users/1 + # PUT /users/1.xml + def update + @user = User.find(params[:id]) + + respond_to do |format| + if @user.update_attributes(params[:user]) + flash[:notice] = 'User was successfully updated.' + format.html { redirect_to user_url(@user) } + format.xml { head :ok } + else + format.html { render :action => "edit" } + format.xml { render :xml => @user.errors.to_xml } + end + end + end + + # DELETE /users/1 + # DELETE /users/1.xml + def destroy + @user = User.find(params[:id]) + @user.destroy + + flash[:notice] = "User was removed" + + respond_to do |format| + format.html { redirect_to users_url } + format.xml { head :ok } + end + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/helpers/application_helper.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/helpers/application_helper.rb new file mode 100644 index 0000000..22a7940 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/helpers/application_helper.rb @@ -0,0 +1,3 @@ +# Methods added to this helper will be available to all templates in the application. +module ApplicationHelper +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/helpers/posts_helper.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/helpers/posts_helper.rb new file mode 100644 index 0000000..a7b8cec --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/helpers/posts_helper.rb @@ -0,0 +1,2 @@ +module PostsHelper +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/helpers/users_helper.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/helpers/users_helper.rb new file mode 100644 index 0000000..2310a24 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/helpers/users_helper.rb @@ -0,0 +1,2 @@ +module UsersHelper +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/models/address.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/models/address.rb new file mode 100644 index 0000000..225903e --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/models/address.rb @@ -0,0 +1,7 @@ +class Address < ActiveRecord::Base + belongs_to :addressable, :polymorphic => true + validates_uniqueness_of :title, :scope => [:addressable_type, :addressable_id] + + validates_length_of :zip, :minimum => 5 + validates_numericality_of :zip +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/models/flea.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/models/flea.rb new file mode 100644 index 0000000..0ad2beb --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/models/flea.rb @@ -0,0 +1,3 @@ +class Flea < ActiveRecord::Base + has_and_belongs_to_many :dogs +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/models/friendship.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/models/friendship.rb new file mode 100644 index 0000000..3844c77 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/models/friendship.rb @@ -0,0 +1,4 @@ +class Friendship < ActiveRecord::Base + belongs_to :user + belongs_to :friend, :class_name => "User" +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/models/pets/dog.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/models/pets/dog.rb new file mode 100644 index 0000000..c1810c0 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/models/pets/dog.rb @@ -0,0 +1,10 @@ +module Pets + class Dog < ActiveRecord::Base + belongs_to :user, :foreign_key => :owner_id + belongs_to :address, :dependent => :destroy + has_many :treats + has_and_belongs_to_many :fleas, :join_table => :fleas + validates_presence_of :treats, :fleas + validates_presence_of :owner_id + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/models/post.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/models/post.rb new file mode 100644 index 0000000..7d13e19 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/models/post.rb @@ -0,0 +1,12 @@ +class Post < ActiveRecord::Base + belongs_to :user + belongs_to :owner, :foreign_key => :user_id, :class_name => 'User' + has_many :taggings + has_many :tags, :through => :taggings + has_many :through_tags, :through => :taggings, :source => :tag + + validates_uniqueness_of :title + validates_presence_of :title + validates_presence_of :body, :message => 'Seriously... wtf' + validates_numericality_of :user_id +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/models/product.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/models/product.rb new file mode 100644 index 0000000..6222bec --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/models/product.rb @@ -0,0 +1,12 @@ +class Product < ActiveRecord::Base + validates_presence_of :title + + validates_inclusion_of :price, :in => 0..99, :unless => :tangible + validates_format_of :size, :with => /^\d+\D+$/, :unless => :tangible + + validates_presence_of :price, :if => :tangible + validates_inclusion_of :price, :in => 1..9999, :if => :tangible + validates_inclusion_of :weight, :in => 1..100, :if => :tangible + validates_format_of :size, :with => /.+x.+x.+/, :if => :tangible + validates_length_of :size, :in => 5..20, :if => :tangible +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/models/tag.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/models/tag.rb new file mode 100644 index 0000000..83692df --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/models/tag.rb @@ -0,0 +1,8 @@ +class Tag < ActiveRecord::Base + has_many :taggings, :dependent => :destroy + has_many :posts, :through => :taggings + + validates_length_of :name, :minimum => 2 + + attr_accessible :name +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/models/tagging.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/models/tagging.rb new file mode 100644 index 0000000..9b8fb6b --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/models/tagging.rb @@ -0,0 +1,4 @@ +class Tagging < ActiveRecord::Base + belongs_to :post + belongs_to :tag +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/models/treat.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/models/treat.rb new file mode 100644 index 0000000..a80a7e0 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/models/treat.rb @@ -0,0 +1,3 @@ +class Treat < ActiveRecord::Base + +end \ No newline at end of file diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/models/user.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/models/user.rb new file mode 100644 index 0000000..c99857c --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/models/user.rb @@ -0,0 +1,29 @@ +class User < ActiveRecord::Base + has_many :posts + has_many :dogs, :foreign_key => :owner_id, :class_name => "Pets::Dog" + + has_many :friendships + has_many :friends, :through => :friendships + + has_one :address, :as => :addressable, :dependent => :destroy + + named_scope :old, :conditions => "age > 50" + named_scope :eighteen, :conditions => { :age => 18 } + named_scope :recent, lambda {|count| { :limit => count } } + + def self.recent_via_method(count) + scoped(:limit => count) + end + + attr_protected :password + attr_readonly :name + + validates_format_of :email, :with => /\w*@\w*.com/ + validates_length_of :email, :in => 1..100 + validates_numericality_of :age, :greater_than_or_equal_to => 1, + :less_than_or_equal_to => 100 + validates_acceptance_of :eula + validates_uniqueness_of :email, :scope => :name, :case_sensitive => false + validates_length_of :ssn, :is => 9, :message => "Social Security Number is not the right length" + validates_numericality_of :ssn +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/views/layouts/posts.rhtml b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/views/layouts/posts.rhtml new file mode 100644 index 0000000..3b15ce3 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/views/layouts/posts.rhtml @@ -0,0 +1,19 @@ + + + + + + + + Posts: <%= controller.action_name %> + <%= stylesheet_link_tag 'scaffold' %> + + + +

<%= flash[:notice] %>

+ +<%= yield %> + + + diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/views/layouts/users.rhtml b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/views/layouts/users.rhtml new file mode 100644 index 0000000..23757aa --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/views/layouts/users.rhtml @@ -0,0 +1,17 @@ + + + + + + Users: <%= controller.action_name %> + <%= stylesheet_link_tag 'scaffold' %> + + + +

<%= flash[:notice] %>

+ +<%= yield %> + + + diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/views/layouts/wide.html.erb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/views/layouts/wide.html.erb new file mode 100644 index 0000000..668d3b7 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/views/layouts/wide.html.erb @@ -0,0 +1 @@ +<%= yield %> \ No newline at end of file diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/views/posts/edit.rhtml b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/views/posts/edit.rhtml new file mode 100644 index 0000000..65bd4fe --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/views/posts/edit.rhtml @@ -0,0 +1,27 @@ +

Editing post

+ +<%= error_messages_for :post %> + +<% form_for(:post, :url => user_post_path(@post.user, @post), :html => { :method => :put }) do |f| %> +

+ User
+ <%= f.text_field :user_id %> +

+ +

+ Title
+ <%= f.text_field :title %> +

+ +

+ Body
+ <%= f.text_area :body %> +

+ +

+ <%= submit_tag "Update" %> +

+<% end %> + +<%= link_to 'Show', user_post_path(@post.user, @post) %> | +<%= link_to 'Back', user_posts_path(@post.user) %> diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/views/posts/index.rhtml b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/views/posts/index.rhtml new file mode 100644 index 0000000..f6bb3bd --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/views/posts/index.rhtml @@ -0,0 +1,25 @@ +

Listing posts

+ + + + + + + + +<% for post in @posts %> + + + + + + + + +<% end %> +
UserTitleBody
<%=h post.user_id %><%=h post.title %><%=h post.body %><%= link_to 'Show', user_post_path(post.user, post) %><%= link_to 'Edit', edit_user_post_path(post.user, post) %><%= link_to 'Destroy', user_post_path(post.user, post), :confirm => 'Are you sure?', + :method => :delete %>
+ +
+ +<%= link_to 'New post', new_user_post_path(post.user) %> diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/views/posts/new.rhtml b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/views/posts/new.rhtml new file mode 100644 index 0000000..216f1e0 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/views/posts/new.rhtml @@ -0,0 +1,26 @@ +

New post

+ +<%= error_messages_for :post %> + +<% form_for(:post, :url => user_posts_path(@user)) do |f| %> +

+ User
+ <%= f.text_field :user_id %> +

+ +

+ Title
+ <%= f.text_field :title %> +

+ +

+ Body
+ <%= f.text_area :body %> +

+ +

+ <%= submit_tag "Create" %> +

+<% end %> + +<%= link_to 'Back', user_posts_path(@user) %> diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/views/posts/show.rhtml b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/views/posts/show.rhtml new file mode 100644 index 0000000..b9d3791 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/views/posts/show.rhtml @@ -0,0 +1,18 @@ +

+ User: + <%=h @post.user_id %> +

+ +

+ Title: + <%=h @post.title %> +

+ +

+ Body: + <%=h @post.body %> +

+ + +<%= link_to 'Edit', edit_user_post_path(@post.user, @post) %> | +<%= link_to 'Back', user_posts_path(@post.user) %> diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/views/users/edit.rhtml b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/views/users/edit.rhtml new file mode 100644 index 0000000..9c47ad5 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/views/users/edit.rhtml @@ -0,0 +1,22 @@ +

Editing user

+ +<%= error_messages_for :user %> + +<% form_for(:user, :url => user_path(@user), :html => { :method => :put }) do |f| %> +

+ Email
+ <%= f.text_field :email %> +

+ +

+ Age
+ <%= f.text_field :age %> +

+ +

+ <%= submit_tag "Update" %> +

+<% end %> + +<%= link_to 'Show', user_path(@user) %> | +<%= link_to 'Back', users_path %> \ No newline at end of file diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/views/users/index.rhtml b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/views/users/index.rhtml new file mode 100644 index 0000000..83f2e91 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/views/users/index.rhtml @@ -0,0 +1,22 @@ +

Listing users

+ + + + + + + +<% for user in @users %> + + + + + + + +<% end %> +
EmailAge
<%=h user.email %><%=h user.age %><%= link_to 'Show', user_path(user) %><%= link_to 'Edit', edit_user_path(user) %><%= link_to 'Destroy', user_path(user), :confirm => 'Are you sure?', :method => :delete %>
+ +
+ +<%= link_to 'New user', new_user_path %> \ No newline at end of file diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/views/users/new.rhtml b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/views/users/new.rhtml new file mode 100644 index 0000000..6f2c3a4 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/views/users/new.rhtml @@ -0,0 +1,21 @@ +

New user

+ +<%= error_messages_for :user %> + +<% form_for(:user, :url => users_path) do |f| %> +

+ Email
+ <%= f.text_field :email %> +

+ +

+ Age
+ <%= f.text_field :age %> +

+ +

+ <%= submit_tag "Create" %> +

+<% end %> + +<%= link_to 'Back', users_path %> \ No newline at end of file diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/views/users/show.rhtml b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/views/users/show.rhtml new file mode 100644 index 0000000..bdcad8a --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/app/views/users/show.rhtml @@ -0,0 +1,13 @@ +

+ Email: + <%=h @user.email %> +

+ +

+ Age: + <%=h @user.age %> +

+ + +<%= link_to 'Edit', edit_user_path(@user) %> | +<%= link_to 'Back', users_path %> \ No newline at end of file diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/config/boot.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/config/boot.rb new file mode 100644 index 0000000..cd21fb9 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/config/boot.rb @@ -0,0 +1,109 @@ +# Don't change this file! +# Configure your app in config/environment.rb and config/environments/*.rb + +RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT) + +module Rails + class << self + def boot! + unless booted? + preinitialize + pick_boot.run + end + end + + def booted? + defined? Rails::Initializer + end + + def pick_boot + (vendor_rails? ? VendorBoot : GemBoot).new + end + + def vendor_rails? + File.exist?("#{RAILS_ROOT}/vendor/rails") + end + + def preinitialize + load(preinitializer_path) if File.exist?(preinitializer_path) + end + + def preinitializer_path + "#{RAILS_ROOT}/config/preinitializer.rb" + end + end + + class Boot + def run + load_initializer + Rails::Initializer.run(:set_load_path) + end + end + + class VendorBoot < Boot + def load_initializer + require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer" + Rails::Initializer.run(:install_gem_spec_stubs) + end + end + + class GemBoot < Boot + def load_initializer + self.class.load_rubygems + load_rails_gem + require 'initializer' + end + + def load_rails_gem + if version = self.class.gem_version + gem 'rails', version + else + gem 'rails' + end + rescue Gem::LoadError => load_error + $stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.) + exit 1 + end + + class << self + def rubygems_version + Gem::RubyGemsVersion if defined? Gem::RubyGemsVersion + end + + def gem_version + if defined? RAILS_GEM_VERSION + RAILS_GEM_VERSION + elsif ENV.include?('RAILS_GEM_VERSION') + ENV['RAILS_GEM_VERSION'] + else + parse_gem_version(read_environment_rb) + end + end + + def load_rubygems + require 'rubygems' + + unless rubygems_version >= '0.9.4' + $stderr.puts %(Rails requires RubyGems >= 0.9.4 (you have #{rubygems_version}). Please `gem update --system` and try again.) + exit 1 + end + + rescue LoadError + $stderr.puts %(Rails requires RubyGems >= 0.9.4. Please install RubyGems and try again: http://rubygems.rubyforge.org) + exit 1 + end + + def parse_gem_version(text) + $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/ + end + + private + def read_environment_rb + File.read("#{RAILS_ROOT}/config/environment.rb") + end + end + end +end + +# All that for this: +Rails.boot! diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/config/database.yml b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/config/database.yml new file mode 100644 index 0000000..bd1e25e --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/config/database.yml @@ -0,0 +1,4 @@ +test: + :adapter: sqlite3 + # :dbfile: db/sqlite3.db + :dbfile: ":memory:" diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/config/environment.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/config/environment.rb new file mode 100644 index 0000000..a3b00b8 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/config/environment.rb @@ -0,0 +1,14 @@ +# Specifies gem version of Rails to use when vendor/rails is not present +old_verbose, $VERBOSE = $VERBOSE, nil +RAILS_GEM_VERSION = '= 2.2.2' unless defined? RAILS_GEM_VERSION +$VERBOSE = old_verbose + +require File.join(File.dirname(__FILE__), 'boot') + +Rails::Initializer.run do |config| + config.log_level = :debug + config.cache_classes = false + config.whiny_nils = true +end + +# Dependencies.log_activity = true diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/config/environments/test.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/config/environments/test.rb new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/config/environments/test.rb diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/config/initializers/new_rails_defaults.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/config/initializers/new_rails_defaults.rb new file mode 100644 index 0000000..5e60c0a --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/config/initializers/new_rails_defaults.rb @@ -0,0 +1,15 @@ +# These settings change the behavior of Rails 2 apps and will be defaults +# for Rails 3. You can remove this initializer when Rails 3 is released. + +# Include Active Record class name as root for JSON serialized output. +ActiveRecord::Base.include_root_in_json = true + +# Store the full class name (including module namespace) in STI type column. +ActiveRecord::Base.store_full_sti_class = true + +# Use ISO 8601 format for JSON serialized times and dates. +ActiveSupport.use_standard_json_time_format = true + +# Don't escape HTML entities in JSON, leave that for the #json_escape helper. +# if you're including raw json in an HTML page. +ActiveSupport.escape_html_entities_in_json = false \ No newline at end of file diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/config/initializers/shoulda.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/config/initializers/shoulda.rb new file mode 100644 index 0000000..d132470 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/config/initializers/shoulda.rb @@ -0,0 +1,8 @@ +# This simulates loading the shoulda plugin, but without relying on +# vendor/plugins + +shoulda_path = File.join(File.dirname(__FILE__), *%w(.. .. .. ..)) +shoulda_lib_path = File.join(shoulda_path, "lib") + +$LOAD_PATH.unshift(shoulda_lib_path) +load File.join(shoulda_path, "init.rb") diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/config/routes.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/config/routes.rb new file mode 100644 index 0000000..ae2bddd --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/config/routes.rb @@ -0,0 +1,6 @@ +ActionController::Routing::Routes.draw do |map| + + map.resources :posts + map.resources :users, :has_many => :posts + +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/db/migrate/001_create_users.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/db/migrate/001_create_users.rb new file mode 100644 index 0000000..13abb7b --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/db/migrate/001_create_users.rb @@ -0,0 +1,19 @@ +class CreateUsers < ActiveRecord::Migration + def self.up + create_table :users do |t| + t.column :name, :string + t.column :email, :string + t.column :age, :integer + t.column :ssn, :string + t.column :phone, :string + end + add_index :users, :email, :unique => true + add_index :users, :name + add_index :users, :age + add_index :users, [:email, :name], :unique => true + end + + def self.down + drop_table :users + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/db/migrate/002_create_posts.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/db/migrate/002_create_posts.rb new file mode 100644 index 0000000..9ed4deb --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/db/migrate/002_create_posts.rb @@ -0,0 +1,13 @@ +class CreatePosts < ActiveRecord::Migration + def self.up + create_table :posts do |t| + t.column :user_id, :integer + t.column :title, :string + t.column :body, :text + end + end + + def self.down + drop_table :posts + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/db/migrate/003_create_taggings.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/db/migrate/003_create_taggings.rb new file mode 100644 index 0000000..e163a0a --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/db/migrate/003_create_taggings.rb @@ -0,0 +1,12 @@ +class CreateTaggings < ActiveRecord::Migration + def self.up + create_table :taggings do |t| + t.column :post_id, :integer + t.column :tag_id, :integer + end + end + + def self.down + drop_table :taggings + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/db/migrate/004_create_tags.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/db/migrate/004_create_tags.rb new file mode 100644 index 0000000..dc58c4f --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/db/migrate/004_create_tags.rb @@ -0,0 +1,11 @@ +class CreateTags < ActiveRecord::Migration + def self.up + create_table :tags do |t| + t.column :name, :string + end + end + + def self.down + drop_table :tags + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/db/migrate/005_create_dogs.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/db/migrate/005_create_dogs.rb new file mode 100644 index 0000000..d1ada90 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/db/migrate/005_create_dogs.rb @@ -0,0 +1,12 @@ +class CreateDogs < ActiveRecord::Migration + def self.up + create_table :dogs do |t| + t.column :owner_id, :integer + t.column :address_id, :integer + end + end + + def self.down + drop_table :dogs + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/db/migrate/006_create_addresses.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/db/migrate/006_create_addresses.rb new file mode 100644 index 0000000..151cf45 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/db/migrate/006_create_addresses.rb @@ -0,0 +1,14 @@ +class CreateAddresses < ActiveRecord::Migration + def self.up + create_table :addresses do |t| + t.column :title, :string + t.column :addressable_id, :integer + t.column :addressable_type, :string + t.column :zip, :string + end + end + + def self.down + drop_table :addresses + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/db/migrate/007_create_fleas.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/db/migrate/007_create_fleas.rb new file mode 100644 index 0000000..81ac051 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/db/migrate/007_create_fleas.rb @@ -0,0 +1,11 @@ +class CreateFleas < ActiveRecord::Migration + def self.up + create_table :fleas do |t| + t.string :name + end + end + + def self.down + drop_table :fleas + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/db/migrate/008_create_dogs_fleas.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/db/migrate/008_create_dogs_fleas.rb new file mode 100644 index 0000000..98555ae --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/db/migrate/008_create_dogs_fleas.rb @@ -0,0 +1,12 @@ +class CreateDogsFleas < ActiveRecord::Migration + def self.up + create_table :dogs_fleas do |t| + t.integer :dog_id + t.integer :flea_id + end + end + + def self.down + drop_table :dogs_fleas + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/db/migrate/009_create_products.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/db/migrate/009_create_products.rb new file mode 100644 index 0000000..173f948 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/db/migrate/009_create_products.rb @@ -0,0 +1,17 @@ +class CreateProducts < ActiveRecord::Migration + def self.up + create_table :products do |t| + t.string :title + t.integer :price + t.integer :weight + t.string :size + t.boolean :tangible + + t.timestamps + end + end + + def self.down + drop_table :products + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/db/migrate/010_create_friendships.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/db/migrate/010_create_friendships.rb new file mode 100644 index 0000000..99d0f6c --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/db/migrate/010_create_friendships.rb @@ -0,0 +1,14 @@ +class CreateFriendships < ActiveRecord::Migration + def self.up + create_table :friendships do |t| + t.integer :user_id + t.integer :friend_id + + t.timestamps + end + end + + def self.down + drop_table :friendships + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/db/migrate/011_create_treats.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/db/migrate/011_create_treats.rb new file mode 100644 index 0000000..1b1a002 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/db/migrate/011_create_treats.rb @@ -0,0 +1,12 @@ +class CreateTreats < ActiveRecord::Migration + def self.up + create_table :treats do |t| + t.integer :dog_id + t.timestamps + end + end + + def self.down + drop_table :treats + end +end \ No newline at end of file diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/db/schema.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/db/schema.rb new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/db/schema.rb diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/public/404.html b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/public/404.html new file mode 100644 index 0000000..eff660b --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/public/404.html @@ -0,0 +1,30 @@ + + + + + + + The page you were looking for doesn't exist (404) + + + + + +
+

The page you were looking for doesn't exist.

+

You may have mistyped the address or the page may have moved.

+
+ + \ No newline at end of file diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/public/422.html b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/public/422.html new file mode 100644 index 0000000..b54e4a3 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/public/422.html @@ -0,0 +1,30 @@ + + + + + + + The change you wanted was rejected (422) + + + + + +
+

The change you wanted was rejected.

+

Maybe you tried to change something you didn't have access to.

+
+ + \ No newline at end of file diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/public/500.html b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/public/500.html new file mode 100644 index 0000000..0e9c14f --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/public/500.html @@ -0,0 +1,30 @@ + + + + + + + We're sorry, but something went wrong (500) + + + + + +
+

We're sorry, but something went wrong.

+

We've been notified about this issue and we'll take a look at it shortly.

+
+ + \ No newline at end of file diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/script/console b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/script/console new file mode 100755 index 0000000..498077a --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/script/console @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +require File.dirname(__FILE__) + '/../config/boot' +require 'commands/console' diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/script/generate b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/script/generate new file mode 100755 index 0000000..173a9f1 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/script/generate @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +require File.dirname(__FILE__) + '/../config/boot' +require 'commands/generate' diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/test/shoulda_macros/custom_macro.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/test/shoulda_macros/custom_macro.rb new file mode 100644 index 0000000..ffae9e8 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/test/shoulda_macros/custom_macro.rb @@ -0,0 +1,6 @@ +module CustomMacro + def custom_macro + end +end +Test::Unit::TestCase.extend(CustomMacro) + diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/vendor/gems/gem_with_macro-0.0.1/shoulda_macros/gem_macro.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/vendor/gems/gem_with_macro-0.0.1/shoulda_macros/gem_macro.rb new file mode 100644 index 0000000..6c47076 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/vendor/gems/gem_with_macro-0.0.1/shoulda_macros/gem_macro.rb @@ -0,0 +1,6 @@ +module GemMacro + def gem_macro + end +end +Test::Unit::TestCase.extend(GemMacro) + diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/vendor/plugins/plugin_with_macro/shoulda_macros/plugin_macro.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/vendor/plugins/plugin_with_macro/shoulda_macros/plugin_macro.rb new file mode 100644 index 0000000..4c3ba16 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rails_root/vendor/plugins/plugin_with_macro/shoulda_macros/plugin_macro.rb @@ -0,0 +1,6 @@ +module PluginMacro + def plugin_macro + end +end +Test::Unit::TestCase.extend(PluginMacro) + diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/rspec_test.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rspec_test.rb new file mode 100644 index 0000000..dfbc0e9 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/rspec_test.rb @@ -0,0 +1,207 @@ +require 'test_helper' + +begin + gem 'rspec' + gem 'rspec-rails' +rescue LoadError => exception + puts exception.message + puts "RSpec integration was not tested because RSpec is not available" +else + + class RspecTest < Test::Unit::TestCase + + SHOULDA_ROOT = + File.expand_path(File.join(File.dirname(__FILE__), '..')).freeze + + def setup + build_gemspec + end + + def teardown + FileUtils.rm_rf(project_dir) + FileUtils.rm_rf("#{shoulda_root}/pkg") + end + + should "integrate correctly when using config.gem in test.rb" do + create_project + insert(rspec_dependencies, "config/environments/test.rb") + vendor_gems('test') + configure_spec_rails + assert_configured + end + + should "integrate correctly when using config.gem in environment.rb" do + create_project + insert(rspec_dependencies, + "config/environment.rb", + /Rails::Initializer\.run/) + vendor_gems('development') + configure_spec_rails + assert_configured + end + + should "integrate correctly when using require in spec_helper" do + create_project + configure_spec_rails + insert(%{gem 'shoulda'; require 'shoulda'}, + "spec/spec_helper.rb", + %{require 'spec/rails'}) + assert_configured + end + + should "integrate correctly when unpacked and required in spec_helper" do + create_project + configure_spec_rails + insert(%{require 'shoulda'}, + "spec/spec_helper.rb", + %{require 'spec/rails'}) + unpack_gems + assert_configured + end + + def create_project + command "rails #{project_dir}" + end + + def vendor_gems(env) + project_command "rake gems:unpack RAILS_ENV=#{env}" + end + + def unpack_gems + FileUtils.mkdir_p "#{project_dir}/vendor/gems" + FileUtils.cd "#{project_dir}/vendor/gems" do + %w(rspec rspec-rails shoulda).each do |gem| + command "gem unpack #{gem}" + end + end + + insert('config.load_paths += Dir["#{RAILS_ROOT}/vendor/gems/*/lib"]', + "config/environment.rb", + /Rails::Initializer\.run/) + end + + def command(command) + output = `GEM_PATH=#{shoulda_root}/pkg #{command} 2>&1` + unless $? == 0 + flunk("Command failed with status #{$?}\n#{command}\n#{output}") + end + @command_output ||= '' + @command_output << output + output + end + + def project_command(command) + result = nil + FileUtils.cd project_dir do + result = command(command) + end + result + end + + def shoulda_command(command) + FileUtils.cd shoulda_root do + command(command) + end + end + + def project_name + 'example_rails_project' + end + + def project_dir + File.expand_path(File.join(File.dirname(__FILE__), project_name)) + end + + def insert(content, path, after = nil) + path = File.join(project_dir, path) + contents = IO.read(path) + if after + contents.gsub!(/^(.*#{after}.*)$/, "\\1\n#{content}") + else + contents << "\n" << content + end + File.open(path, 'w') {|file| file.write(contents) } + end + + def rspec_dependencies + return <<-EOS + config.gem 'rspec', :lib => 'spec' + config.gem 'rspec-rails', :lib => false + config.gem 'shoulda', :lib => 'shoulda' + EOS + end + + def configure_spec_rails + project_command "script/generate rspec" + end + + def assert_configured + create_model + migrate + create_controller + assert_spec_passes + end + + def create_model + project_command "script/generate rspec_model person name:string" + insert "validates_presence_of :name", + "app/models/person.rb", + /class Person/ + insert "it { should validate_presence_of(:name) }", + "spec/models/person_spec.rb", + /describe Person do/ + end + + def create_controller + project_command "script/generate rspec_controller people" + insert "def index; render :text => 'Hello'; end", + "app/controllers/people_controller.rb", + /class PeopleController/ + shoulda_controller_example = <<-EOS + describe PeopleController, "on GET index" do + integrate_views + subject { controller } + before(:each) { get :index } + it { should respond_with(:success) } + end + EOS + insert shoulda_controller_example, + "spec/controllers/people_controller_spec.rb" + end + + def migrate + project_command "rake db:migrate" + end + + def assert_spec_passes + result = project_command("rake spec SPEC_OPTS=-fs") + assert_match /should require name to be set/, result + assert_match /should respond with 200/, result + end + + def shoulda_root + SHOULDA_ROOT + end + + def build_gemspec + backup_gemspec do + shoulda_command "rake gemspec" + shoulda_command "rake gem" + shoulda_command "gem install --no-ri --no-rdoc -i pkg pkg/shoulda*.gem" + end + end + + def backup_gemspec + actual = "#{shoulda_root}/shoulda.gemspec" + backup = "#{shoulda_root}/backup.gemspec" + FileUtils.mv(actual, backup) + begin + yield + ensure + FileUtils.mv(backup, actual) + end + end + + end + +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/test_helper.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/test_helper.rb new file mode 100644 index 0000000..29b1910 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/test_helper.rb @@ -0,0 +1,35 @@ +require 'fileutils' + +# Load the environment +ENV['RAILS_ENV'] = 'test' + +rails_root = File.dirname(__FILE__) + '/rails_root' + +require "#{rails_root}/config/environment.rb" + +# Load the testing framework +require 'test_help' +silence_warnings { RAILS_ENV = ENV['RAILS_ENV'] } + +# Run the migrations +ActiveRecord::Migration.verbose = false +ActiveRecord::Migrator.migrate("#{RAILS_ROOT}/db/migrate") + +# Setup the fixtures path +Test::Unit::TestCase.fixture_path = File.join(File.dirname(__FILE__), "fixtures") + +class Test::Unit::TestCase #:nodoc: + def create_fixtures(*table_names) + if block_given? + Fixtures.create_fixtures(Test::Unit::TestCase.fixture_path, table_names) { yield } + else + Fixtures.create_fixtures(Test::Unit::TestCase.fixture_path, table_names) + end + end + + self.use_transactional_fixtures = false + self.use_instantiated_fixtures = false +end + +require 'test/fail_macros' +require 'test/model_builder' diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/unit/address_test.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/unit/address_test.rb new file mode 100644 index 0000000..bce0005 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/unit/address_test.rb @@ -0,0 +1,10 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class AddressTest < Test::Unit::TestCase + fixtures :all + + should_belong_to :addressable + should_validate_uniqueness_of :title, :scoped_to => [:addressable_id, :addressable_type] + should_ensure_length_at_least :zip, 5 + should_only_allow_numeric_values_for :zip +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/unit/dog_test.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/unit/dog_test.rb new file mode 100644 index 0000000..f927117 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/unit/dog_test.rb @@ -0,0 +1,10 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class Pets::DogTest < Test::Unit::TestCase + should_belong_to :user + should_belong_to :address, :dependent => :destroy + should_have_many :treats + should_have_and_belong_to_many :fleas + should_require_attributes :treats, :fleas + should_validate_presence_of :owner_id +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/unit/flea_test.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/unit/flea_test.rb new file mode 100644 index 0000000..37f4b64 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/unit/flea_test.rb @@ -0,0 +1,6 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class FleaTest < Test::Unit::TestCase + should_have_and_belong_to_many :dogs +end + diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/unit/friendship_test.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/unit/friendship_test.rb new file mode 100644 index 0000000..2407d44 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/unit/friendship_test.rb @@ -0,0 +1,6 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class FriendshipTest < ActiveSupport::TestCase + should_belong_to :user + should_belong_to :friend +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/unit/post_test.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/unit/post_test.rb new file mode 100644 index 0000000..2dd5dd5 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/unit/post_test.rb @@ -0,0 +1,19 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class PostTest < Test::Unit::TestCase + fixtures :all + + should_belong_to :user + should_belong_to :owner + should_have_many :tags, :through => :taggings + should_have_many :through_tags, :through => :taggings + + should_require_unique_attributes :title + should_validate_presence_of :body, :message => /wtf/ + should_validate_presence_of :title + should_validate_numericality_of :user_id + + should_fail do + should_validate_uniqueness_of :title, :case_sensitive => false + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/unit/product_test.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/unit/product_test.rb new file mode 100644 index 0000000..1c47f79 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/unit/product_test.rb @@ -0,0 +1,27 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class ProductTest < ActiveSupport::TestCase + context "An intangible product" do + setup do + @product = Product.new(:tangible => false) + end + + should_validate_presence_of :title + should_not_allow_values_for :size, "22" + should_allow_values_for :size, "22kb" + should_ensure_value_in_range :price, 0..99 + end + + context "A tangible product" do + setup do + @product = Product.new(:tangible => true) + end + + should_validate_presence_of :price + should_ensure_value_in_range :price, 1..9999 + should_ensure_value_in_range :weight, 1..100 + should_not_allow_values_for :size, "22", "10x15" + should_allow_values_for :size, "12x12x1" + should_ensure_length_in_range :size, 5..20 + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/unit/tag_test.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/unit/tag_test.rb new file mode 100644 index 0000000..fc2e1d1 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/unit/tag_test.rb @@ -0,0 +1,15 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class TagTest < Test::Unit::TestCase + should_have_many :taggings, :dependent => :destroy + should_have_many :posts + + should_ensure_length_at_least :name, 2 + + should_protect_attributes :secret + should_allow_mass_assignment_of :name + + should_fail do + should_not_allow_mass_assignment_of :name + end +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/unit/tagging_test.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/unit/tagging_test.rb new file mode 100644 index 0000000..3f8c35c --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/unit/tagging_test.rb @@ -0,0 +1,6 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class TaggingTest < Test::Unit::TestCase + should_belong_to :post + should_belong_to :tag +end diff --git a/vendor/gems/thoughtbot-shoulda-2.10.1/test/unit/user_test.rb b/vendor/gems/thoughtbot-shoulda-2.10.1/test/unit/user_test.rb new file mode 100644 index 0000000..d47f421 --- /dev/null +++ b/vendor/gems/thoughtbot-shoulda-2.10.1/test/unit/user_test.rb @@ -0,0 +1,70 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class UserTest < Test::Unit::TestCase + fixtures :all + + should_have_many :posts + should_have_many :dogs + + should_have_many :friendships + should_have_many :friends + + should_have_one :address + should_have_one :address, :dependent => :destroy + + should_have_indices :email, :name + should_have_index :age + should_have_index [:email, :name], :unique => true + should_have_index :age, :unique => false + + should_fail do + should_have_index :phone + should_have_index :email, :unique => false + should_have_index :age, :unique => true + end + + should_have_named_scope :old, :conditions => "age > 50" + should_have_named_scope :eighteen, :conditions => { :age => 18 } + + should_have_named_scope 'recent(5)', :limit => 5 + should_have_named_scope 'recent(1)', :limit => 1 + should_have_named_scope 'recent_via_method(7)', :limit => 7 + + context "when given an instance variable" do + setup { @count = 2 } + should_have_named_scope 'recent(@count)', :limit => 2 + end + + should_not_allow_values_for :email, "blah", "b lah" + should_allow_values_for :email, "a@b.com", "asdf@asdf.com" + should_ensure_length_in_range :email, 1..100 + should_ensure_value_in_range :age, 1..100, :low_message => /greater/, + :high_message => /less/ + should_fail do + should_ensure_value_in_range :age, 1..100, :low_message => /more/, + :high_message => /less/ + end + should_fail do + should_ensure_value_in_range :age, 1..100, :low_message => /greater/, + :high_message => /fewer/ + end + should_not_allow_mass_assignment_of :password + should_have_class_methods :find, :destroy + should_have_instance_methods :email, :age, :email=, :valid? + should_have_db_columns :name, :email, :age + should_have_db_column :id, :type => "integer" + should_have_db_column :email, :type => "string", :default => nil, :precision => nil, :limit => 255, + :null => true, :scale => nil + should_validate_acceptance_of :eula + should_require_acceptance_of :eula + should_validate_uniqueness_of :email, :scoped_to => :name, :case_sensitive => false + + should_ensure_length_is :ssn, 9, :message => "Social Security Number is not the right length" + should_validate_numericality_of :ssn + + should_have_readonly_attributes :name + + should_fail do + should_not_allow_mass_assignment_of :name, :age + end +end -- libgit2 0.21.2