From 6aca71765a3cac6f02468217a5a0a2eb5f1fb87c Mon Sep 17 00:00:00 2001 From: Joe Ferris Date: Mon, 13 Dec 2010 17:28:59 -0500 Subject: [PATCH] Extracted the context framework, switched to rspec --- .bundle/config | 2 + Gemfile | 9 + Gemfile.lock | 115 +++++ Rakefile | 34 +- bin/convert_to_should_syntax | 42 -- features/step_definitions/rails3_steps.rb | 2 +- init.rb | 1 - lib/shoulda.rb | 1 + lib/shoulda/action_controller.rb | 50 +- .../{matchers => }/assign_to_matcher.rb | 0 .../action_controller/filter_param_matcher.rb | 50 ++ lib/shoulda/action_controller/matchers.rb | 39 -- .../matchers/filter_param_matcher.rb | 74 --- .../{matchers => }/redirect_to_matcher.rb | 0 .../{matchers => }/render_template_matcher.rb | 0 .../render_with_layout_matcher.rb | 4 +- .../respond_with_content_type_matcher.rb | 0 .../{matchers => }/respond_with_matcher.rb | 0 .../{matchers => }/route_matcher.rb | 0 .../{matchers => }/set_session_matcher.rb | 0 .../{matchers => }/set_the_flash_matcher.rb | 12 +- lib/shoulda/action_mailer.rb | 25 +- .../{matchers => }/have_sent_email.rb | 0 lib/shoulda/action_mailer/matchers.rb | 22 - lib/shoulda/active_record.rb | 44 +- .../allow_mass_assignment_of_matcher.rb | 0 .../{matchers => }/allow_value_matcher.rb | 0 .../{matchers => }/association_matcher.rb | 0 .../ensure_inclusion_of_matcher.rb | 0 .../ensure_length_of_matcher.rb | 0 .../{matchers => }/have_db_column_matcher.rb | 0 .../{matchers => }/have_db_index_matcher.rb | 0 .../have_readonly_attribute_matcher.rb | 0 lib/shoulda/active_record/matchers.rb | 42 -- .../validate_acceptance_of_matcher.rb | 0 .../validate_format_of_matcher.rb | 0 .../validate_numericality_of_matcher.rb | 0 .../validate_presence_of_matcher.rb | 0 .../validate_uniqueness_of_matcher.rb | 0 .../{matchers => }/validation_matcher.rb | 0 lib/shoulda/assertions.rb | 79 ---- lib/shoulda/autoload_macros.rb | 46 -- lib/shoulda/context.rb | 441 ------------------ lib/shoulda/integrations/rspec.rb | 33 +- lib/shoulda/integrations/test_unit.rb | 47 +- lib/shoulda/proc_extensions.rb | 14 - lib/shoulda/rails.rb | 8 - lib/shoulda/tasks.rb | 3 - lib/shoulda/tasks/list_tests.rake | 29 -- lib/shoulda/tasks/yaml_to_shoulda.rake | 28 -- rails/init.rb | 8 - {test => spec}/fixtures/addresses.yml | 0 {test => spec}/fixtures/friendships.yml | 0 {test => spec}/fixtures/posts.yml | 0 {test => spec}/fixtures/products.yml | 0 {test => spec}/fixtures/taggings.yml | 0 {test => spec}/fixtures/tags.yml | 0 {test => spec}/fixtures/users.yml | 0 {test => spec}/rails3_root/.gitignore | 0 spec/rails3_root/Gemfile | 7 + {test => spec}/rails3_root/Gemfile.lock | 18 + {test => spec}/rails3_root/README | 0 {test => spec}/rails3_root/Rakefile | 0 .../app/controllers/application_controller.rb | 0 .../app/controllers/posts_controller.rb | 0 .../app/controllers/users_controller.rb | 0 .../app/helpers/application_helper.rb | 0 .../rails3_root/app/models/address.rb | 0 {test => spec}/rails3_root/app/models/flea.rb | 0 .../rails3_root/app/models/friendship.rb | 0 .../rails3_root/app/models/notifier.rb | 0 .../rails3_root/app/models/pets/cat.rb | 0 .../rails3_root/app/models/pets/dog.rb | 0 {test => spec}/rails3_root/app/models/post.rb | 0 .../rails3_root/app/models/product.rb | 0 .../rails3_root/app/models/profile.rb | 0 .../rails3_root/app/models/registration.rb | 0 {test => spec}/rails3_root/app/models/tag.rb | 0 .../rails3_root/app/models/tagging.rb | 0 .../rails3_root/app/models/treat.rb | 0 {test => spec}/rails3_root/app/models/user.rb | 0 .../app/views/layouts/application.html.erb | 0 .../rails3_root/app/views/layouts/posts.rhtml | 0 .../rails3_root/app/views/layouts/users.rhtml | 0 .../app/views/layouts/wide.html.erb | 0 .../app/views/notifier/the_email.html.erb | 0 .../rails3_root/app/views/posts/edit.rhtml | 0 .../rails3_root/app/views/posts/index.rhtml | 0 .../rails3_root/app/views/posts/new.rhtml | 0 .../rails3_root/app/views/posts/show.rhtml | 0 .../rails3_root/app/views/users/edit.rhtml | 0 .../rails3_root/app/views/users/index.rhtml | 0 .../rails3_root/app/views/users/new.rhtml | 0 .../rails3_root/app/views/users/show.rhtml | 0 {test => spec}/rails3_root/config.ru | 0 .../rails3_root/config/application.rb | 0 {test => spec}/rails3_root/config/boot.rb | 0 .../rails3_root/config/database.yml | 0 .../rails3_root/config/environment.rb | 0 .../config/environments/development.rb | 0 .../config/environments/production.rb | 0 .../rails3_root/config/environments/test.rb | 0 .../initializers/backtrace_silencers.rb | 0 .../config/initializers/inflections.rb | 0 .../config/initializers/mime_types.rb | 0 .../config/initializers/secret_token.rb | 0 .../config/initializers/session_store.rb | 0 .../rails3_root/config/locales/en.yml | 0 {test => spec}/rails3_root/config/routes.rb | 0 .../db/migrate/001_create_users.rb | 0 .../db/migrate/002_create_posts.rb | 0 .../db/migrate/003_create_taggings.rb | 0 .../rails3_root/db/migrate/004_create_tags.rb | 0 .../rails3_root/db/migrate/005_create_dogs.rb | 0 .../db/migrate/006_create_addresses.rb | 0 .../db/migrate/007_create_fleas.rb | 0 .../db/migrate/008_create_dogs_fleas.rb | 0 .../db/migrate/009_create_products.rb | 0 .../db/migrate/010_create_friendships.rb | 0 .../db/migrate/011_create_treats.rb | 0 .../migrate/20090506203502_create_profiles.rb | 0 .../20090506203536_create_registrations.rb | 0 .../db/migrate/20090513104502_create_cats.rb | 0 {test => spec}/rails3_root/db/seeds.rb | 0 {test => spec}/rails3_root/lib/tasks/.gitkeep | 0 {test => spec}/rails3_root/public/404.html | 0 {test => spec}/rails3_root/public/422.html | 0 {test => spec}/rails3_root/public/500.html | 0 {test => spec}/rails3_root/public/favicon.ico | 0 .../rails3_root/public/images/rails.png | Bin {test => spec}/rails3_root/public/index.html | 0 .../public/javascripts/application.js | 0 .../public/javascripts/controls.js | 0 .../public/javascripts/dragdrop.js | 0 .../rails3_root/public/javascripts/effects.js | 0 .../public/javascripts/prototype.js | 0 .../rails3_root/public/javascripts/rails.js | 0 {test => spec}/rails3_root/public/robots.txt | 0 .../rails3_root/public/stylesheets/.gitkeep | 0 {test => spec}/rails3_root/script/rails | 0 .../test/performance/browsing_test.rb | 0 .../test/shoulda_macros/custom_macro.rb | 0 .../rails3_root/test/test_helper.rb | 0 .../shoulda_macros/gem_macro.rb | 0 .../rails3_root/vendor/plugins/.gitkeep | 0 .../rails3_root/vendor/plugins/.keep | 0 .../shoulda_macros/plugin_macro.rb | 0 .../assign_to_matcher_spec.rb | 55 +++ .../filter_param_matcher_spec.rb | 23 + .../redirect_to_matcher_spec.rb | 37 ++ .../render_template_matcher_spec.rb | 38 ++ .../render_with_layout_matcher_spec.rb | 48 ++ .../respond_with_content_type_matcher_spec.rb | 32 ++ .../respond_with_matcher_spec.rb | 96 ++++ .../action_controller/route_matcher_spec.rb | 68 +++ .../set_session_matcher_spec.rb | 48 ++ .../set_the_flash_matcher_spec.rb | 95 ++++ .../action_mailer/have_sent_email_spec.rb | 71 +++ .../allow_mass_assignment_of_matcher_spec.rb | 38 +- .../active_record/allow_value_matcher_spec.rb | 42 +- .../active_record/association_matcher_spec.rb | 144 +++--- .../ensure_inclusion_of_matcher_spec.rb | 71 +++ .../ensure_length_of_matcher_spec.rb | 125 +++++ .../have_db_column_matcher_spec.rb | 108 ++--- .../have_db_index_matcher_spec.rb | 65 ++- .../have_readonly_attributes_matcher_spec.rb | 16 +- .../validate_acceptance_of_matcher_spec.rb | 43 ++ .../validate_format_of_matcher_spec.rb | 35 ++ .../validate_numericality_of_matcher_spec.rb | 49 ++ .../validate_presence_of_matcher_spec.rb | 44 +- .../validate_uniqueness_of_matcher_spec.rb | 145 ++++++ spec/spec_helper.rb | 32 ++ .../support/model_builder.rb | 54 ++- tasks/shoulda.rake | 1 - test/README | 36 -- .../action_mailer/have_sent_email_test.rb | 76 --- .../ensure_inclusion_of_matcher_test.rb | 81 ---- .../ensure_length_of_matcher_test.rb | 158 ------- .../validate_acceptance_of_matcher_test.rb | 44 -- .../validate_format_of_matcher_test.rb | 39 -- .../validate_numericality_of_matcher_test.rb | 52 --- .../validate_uniqueness_of_matcher_test.rb | 147 ------ .../controller/assign_to_matcher_test.rb | 55 --- .../controller/filter_param_matcher_test.rb | 40 -- .../controller/redirect_to_matcher_test.rb | 37 -- .../render_template_matcher_test.rb | 37 -- .../render_with_layout_matcher_test.rb | 47 -- .../respond_with_content_type_matcher_test.rb | 32 -- .../controller/respond_with_matcher_test.rb | 96 ---- .../matchers/controller/route_matcher_test.rb | 75 --- .../controller/set_session_matcher_test.rb | 48 -- .../controller/set_the_flash_matcher.rb | 95 ---- test/other/autoload_macro_test.rb | 18 - test/other/context_test.rb | 372 --------------- test/other/convert_to_should_syntax_test.rb | 63 --- test/other/helpers_test.rb | 126 ----- test/other/should_test.rb | 271 ----------- test/rails3_root/Gemfile | 28 -- test/rspec_test.rb | 207 -------- test/test_helper.rb | 34 -- 200 files changed, 1735 insertions(+), 3531 deletions(-) create mode 100644 .bundle/config create mode 100644 Gemfile create mode 100644 Gemfile.lock delete mode 100755 bin/convert_to_should_syntax delete mode 100644 init.rb rename lib/shoulda/action_controller/{matchers => }/assign_to_matcher.rb (100%) create mode 100644 lib/shoulda/action_controller/filter_param_matcher.rb delete mode 100644 lib/shoulda/action_controller/matchers.rb delete mode 100644 lib/shoulda/action_controller/matchers/filter_param_matcher.rb rename lib/shoulda/action_controller/{matchers => }/redirect_to_matcher.rb (100%) rename lib/shoulda/action_controller/{matchers => }/render_template_matcher.rb (100%) rename lib/shoulda/action_controller/{matchers => }/render_with_layout_matcher.rb (95%) rename lib/shoulda/action_controller/{matchers => }/respond_with_content_type_matcher.rb (100%) rename lib/shoulda/action_controller/{matchers => }/respond_with_matcher.rb (100%) rename lib/shoulda/action_controller/{matchers => }/route_matcher.rb (100%) rename lib/shoulda/action_controller/{matchers => }/set_session_matcher.rb (100%) rename lib/shoulda/action_controller/{matchers => }/set_the_flash_matcher.rb (87%) rename lib/shoulda/action_mailer/{matchers => }/have_sent_email.rb (100%) delete mode 100644 lib/shoulda/action_mailer/matchers.rb rename lib/shoulda/active_record/{matchers => }/allow_mass_assignment_of_matcher.rb (100%) rename lib/shoulda/active_record/{matchers => }/allow_value_matcher.rb (100%) rename lib/shoulda/active_record/{matchers => }/association_matcher.rb (100%) rename lib/shoulda/active_record/{matchers => }/ensure_inclusion_of_matcher.rb (100%) rename lib/shoulda/active_record/{matchers => }/ensure_length_of_matcher.rb (100%) rename lib/shoulda/active_record/{matchers => }/have_db_column_matcher.rb (100%) rename lib/shoulda/active_record/{matchers => }/have_db_index_matcher.rb (100%) rename lib/shoulda/active_record/{matchers => }/have_readonly_attribute_matcher.rb (100%) delete mode 100644 lib/shoulda/active_record/matchers.rb rename lib/shoulda/active_record/{matchers => }/validate_acceptance_of_matcher.rb (100%) rename lib/shoulda/active_record/{matchers => }/validate_format_of_matcher.rb (100%) rename lib/shoulda/active_record/{matchers => }/validate_numericality_of_matcher.rb (100%) rename lib/shoulda/active_record/{matchers => }/validate_presence_of_matcher.rb (100%) rename lib/shoulda/active_record/{matchers => }/validate_uniqueness_of_matcher.rb (100%) rename lib/shoulda/active_record/{matchers => }/validation_matcher.rb (100%) delete mode 100644 lib/shoulda/assertions.rb delete mode 100644 lib/shoulda/autoload_macros.rb delete mode 100644 lib/shoulda/context.rb delete mode 100644 lib/shoulda/proc_extensions.rb delete mode 100644 lib/shoulda/rails.rb delete mode 100644 lib/shoulda/tasks.rb delete mode 100644 lib/shoulda/tasks/list_tests.rake delete mode 100644 lib/shoulda/tasks/yaml_to_shoulda.rake delete mode 100644 rails/init.rb rename {test => spec}/fixtures/addresses.yml (100%) rename {test => spec}/fixtures/friendships.yml (100%) rename {test => spec}/fixtures/posts.yml (100%) rename {test => spec}/fixtures/products.yml (100%) rename {test => spec}/fixtures/taggings.yml (100%) rename {test => spec}/fixtures/tags.yml (100%) rename {test => spec}/fixtures/users.yml (100%) rename {test => spec}/rails3_root/.gitignore (100%) create mode 100644 spec/rails3_root/Gemfile rename {test => spec}/rails3_root/Gemfile.lock (78%) rename {test => spec}/rails3_root/README (100%) rename {test => spec}/rails3_root/Rakefile (100%) rename {test => spec}/rails3_root/app/controllers/application_controller.rb (100%) rename {test => spec}/rails3_root/app/controllers/posts_controller.rb (100%) rename {test => spec}/rails3_root/app/controllers/users_controller.rb (100%) rename {test => spec}/rails3_root/app/helpers/application_helper.rb (100%) rename {test => spec}/rails3_root/app/models/address.rb (100%) rename {test => spec}/rails3_root/app/models/flea.rb (100%) rename {test => spec}/rails3_root/app/models/friendship.rb (100%) rename {test => spec}/rails3_root/app/models/notifier.rb (100%) rename {test => spec}/rails3_root/app/models/pets/cat.rb (100%) rename {test => spec}/rails3_root/app/models/pets/dog.rb (100%) rename {test => spec}/rails3_root/app/models/post.rb (100%) rename {test => spec}/rails3_root/app/models/product.rb (100%) rename {test => spec}/rails3_root/app/models/profile.rb (100%) rename {test => spec}/rails3_root/app/models/registration.rb (100%) rename {test => spec}/rails3_root/app/models/tag.rb (100%) rename {test => spec}/rails3_root/app/models/tagging.rb (100%) rename {test => spec}/rails3_root/app/models/treat.rb (100%) rename {test => spec}/rails3_root/app/models/user.rb (100%) rename {test => spec}/rails3_root/app/views/layouts/application.html.erb (100%) rename {test => spec}/rails3_root/app/views/layouts/posts.rhtml (100%) rename {test => spec}/rails3_root/app/views/layouts/users.rhtml (100%) rename {test => spec}/rails3_root/app/views/layouts/wide.html.erb (100%) rename {test => spec}/rails3_root/app/views/notifier/the_email.html.erb (100%) rename {test => spec}/rails3_root/app/views/posts/edit.rhtml (100%) rename {test => spec}/rails3_root/app/views/posts/index.rhtml (100%) rename {test => spec}/rails3_root/app/views/posts/new.rhtml (100%) rename {test => spec}/rails3_root/app/views/posts/show.rhtml (100%) rename {test => spec}/rails3_root/app/views/users/edit.rhtml (100%) rename {test => spec}/rails3_root/app/views/users/index.rhtml (100%) rename {test => spec}/rails3_root/app/views/users/new.rhtml (100%) rename {test => spec}/rails3_root/app/views/users/show.rhtml (100%) rename {test => spec}/rails3_root/config.ru (100%) rename {test => spec}/rails3_root/config/application.rb (100%) rename {test => spec}/rails3_root/config/boot.rb (100%) rename {test => spec}/rails3_root/config/database.yml (100%) rename {test => spec}/rails3_root/config/environment.rb (100%) rename {test => spec}/rails3_root/config/environments/development.rb (100%) rename {test => spec}/rails3_root/config/environments/production.rb (100%) rename {test => spec}/rails3_root/config/environments/test.rb (100%) rename {test => spec}/rails3_root/config/initializers/backtrace_silencers.rb (100%) rename {test => spec}/rails3_root/config/initializers/inflections.rb (100%) rename {test => spec}/rails3_root/config/initializers/mime_types.rb (100%) rename {test => spec}/rails3_root/config/initializers/secret_token.rb (100%) rename {test => spec}/rails3_root/config/initializers/session_store.rb (100%) rename {test => spec}/rails3_root/config/locales/en.yml (100%) rename {test => spec}/rails3_root/config/routes.rb (100%) rename {test => spec}/rails3_root/db/migrate/001_create_users.rb (100%) rename {test => spec}/rails3_root/db/migrate/002_create_posts.rb (100%) rename {test => spec}/rails3_root/db/migrate/003_create_taggings.rb (100%) rename {test => spec}/rails3_root/db/migrate/004_create_tags.rb (100%) rename {test => spec}/rails3_root/db/migrate/005_create_dogs.rb (100%) rename {test => spec}/rails3_root/db/migrate/006_create_addresses.rb (100%) rename {test => spec}/rails3_root/db/migrate/007_create_fleas.rb (100%) rename {test => spec}/rails3_root/db/migrate/008_create_dogs_fleas.rb (100%) rename {test => spec}/rails3_root/db/migrate/009_create_products.rb (100%) rename {test => spec}/rails3_root/db/migrate/010_create_friendships.rb (100%) rename {test => spec}/rails3_root/db/migrate/011_create_treats.rb (100%) rename {test => spec}/rails3_root/db/migrate/20090506203502_create_profiles.rb (100%) rename {test => spec}/rails3_root/db/migrate/20090506203536_create_registrations.rb (100%) rename {test => spec}/rails3_root/db/migrate/20090513104502_create_cats.rb (100%) rename {test => spec}/rails3_root/db/seeds.rb (100%) rename {test => spec}/rails3_root/lib/tasks/.gitkeep (100%) rename {test => spec}/rails3_root/public/404.html (100%) rename {test => spec}/rails3_root/public/422.html (100%) rename {test => spec}/rails3_root/public/500.html (100%) rename {test => spec}/rails3_root/public/favicon.ico (100%) rename {test => spec}/rails3_root/public/images/rails.png (100%) rename {test => spec}/rails3_root/public/index.html (100%) rename {test => spec}/rails3_root/public/javascripts/application.js (100%) rename {test => spec}/rails3_root/public/javascripts/controls.js (100%) rename {test => spec}/rails3_root/public/javascripts/dragdrop.js (100%) rename {test => spec}/rails3_root/public/javascripts/effects.js (100%) rename {test => spec}/rails3_root/public/javascripts/prototype.js (100%) rename {test => spec}/rails3_root/public/javascripts/rails.js (100%) rename {test => spec}/rails3_root/public/robots.txt (100%) rename {test => spec}/rails3_root/public/stylesheets/.gitkeep (100%) rename {test => spec}/rails3_root/script/rails (100%) rename {test => spec}/rails3_root/test/performance/browsing_test.rb (100%) rename {test => spec}/rails3_root/test/shoulda_macros/custom_macro.rb (100%) rename {test => spec}/rails3_root/test/test_helper.rb (100%) rename {test => spec}/rails3_root/vendor/gems/gem_with_macro-0.0.1/shoulda_macros/gem_macro.rb (100%) rename {test => spec}/rails3_root/vendor/plugins/.gitkeep (100%) rename {test => spec}/rails3_root/vendor/plugins/.keep (100%) rename {test => spec}/rails3_root/vendor/plugins/plugin_with_macro/shoulda_macros/plugin_macro.rb (100%) create mode 100644 spec/shoulda/action_controller/assign_to_matcher_spec.rb create mode 100644 spec/shoulda/action_controller/filter_param_matcher_spec.rb create mode 100644 spec/shoulda/action_controller/redirect_to_matcher_spec.rb create mode 100644 spec/shoulda/action_controller/render_template_matcher_spec.rb create mode 100644 spec/shoulda/action_controller/render_with_layout_matcher_spec.rb create mode 100644 spec/shoulda/action_controller/respond_with_content_type_matcher_spec.rb create mode 100644 spec/shoulda/action_controller/respond_with_matcher_spec.rb create mode 100644 spec/shoulda/action_controller/route_matcher_spec.rb create mode 100644 spec/shoulda/action_controller/set_session_matcher_spec.rb create mode 100644 spec/shoulda/action_controller/set_the_flash_matcher_spec.rb create mode 100644 spec/shoulda/action_mailer/have_sent_email_spec.rb rename test/matchers/active_record/allow_mass_assignment_of_matcher_test.rb => spec/shoulda/active_record/allow_mass_assignment_of_matcher_spec.rb (58%) rename test/matchers/active_record/allow_value_matcher_test.rb => spec/shoulda/active_record/allow_value_matcher_spec.rb (55%) rename test/matchers/active_record/association_matcher_test.rb => spec/shoulda/active_record/association_matcher_spec.rb (51%) create mode 100644 spec/shoulda/active_record/ensure_inclusion_of_matcher_spec.rb create mode 100644 spec/shoulda/active_record/ensure_length_of_matcher_spec.rb rename test/matchers/active_record/have_db_column_matcher_test.rb => spec/shoulda/active_record/have_db_column_matcher_spec.rb (64%) rename test/matchers/active_record/have_db_index_matcher_test.rb => spec/shoulda/active_record/have_db_index_matcher_spec.rb (53%) rename test/matchers/active_record/have_readonly_attributes_matcher_test.rb => spec/shoulda/active_record/have_readonly_attributes_matcher_spec.rb (53%) create mode 100644 spec/shoulda/active_record/validate_acceptance_of_matcher_spec.rb create mode 100644 spec/shoulda/active_record/validate_format_of_matcher_spec.rb create mode 100644 spec/shoulda/active_record/validate_numericality_of_matcher_spec.rb rename test/matchers/active_record/validate_presence_of_matcher_test.rb => spec/shoulda/active_record/validate_presence_of_matcher_spec.rb (55%) create mode 100644 spec/shoulda/active_record/validate_uniqueness_of_matcher_spec.rb create mode 100644 spec/spec_helper.rb rename test/rails3_model_builder.rb => spec/support/model_builder.rb (76%) delete mode 100644 tasks/shoulda.rake delete mode 100644 test/README delete mode 100644 test/matchers/action_mailer/have_sent_email_test.rb delete mode 100644 test/matchers/active_record/ensure_inclusion_of_matcher_test.rb delete mode 100644 test/matchers/active_record/ensure_length_of_matcher_test.rb delete mode 100644 test/matchers/active_record/validate_acceptance_of_matcher_test.rb delete mode 100644 test/matchers/active_record/validate_format_of_matcher_test.rb delete mode 100644 test/matchers/active_record/validate_numericality_of_matcher_test.rb delete mode 100644 test/matchers/active_record/validate_uniqueness_of_matcher_test.rb delete mode 100644 test/matchers/controller/assign_to_matcher_test.rb delete mode 100644 test/matchers/controller/filter_param_matcher_test.rb delete mode 100644 test/matchers/controller/redirect_to_matcher_test.rb delete mode 100644 test/matchers/controller/render_template_matcher_test.rb delete mode 100644 test/matchers/controller/render_with_layout_matcher_test.rb delete mode 100644 test/matchers/controller/respond_with_content_type_matcher_test.rb delete mode 100644 test/matchers/controller/respond_with_matcher_test.rb delete mode 100644 test/matchers/controller/route_matcher_test.rb delete mode 100644 test/matchers/controller/set_session_matcher_test.rb delete mode 100644 test/matchers/controller/set_the_flash_matcher.rb delete mode 100644 test/other/autoload_macro_test.rb delete mode 100644 test/other/context_test.rb delete mode 100644 test/other/convert_to_should_syntax_test.rb delete mode 100644 test/other/helpers_test.rb delete mode 100644 test/other/should_test.rb delete mode 100644 test/rails3_root/Gemfile delete mode 100644 test/rspec_test.rb delete mode 100644 test/test_helper.rb diff --git a/.bundle/config b/.bundle/config new file mode 100644 index 00000000..8ebbe30e --- /dev/null +++ b/.bundle/config @@ -0,0 +1,2 @@ +--- +BUNDLE_DISABLE_SHARED_GEMS: "1" diff --git a/Gemfile b/Gemfile new file mode 100644 index 00000000..ac16ec88 --- /dev/null +++ b/Gemfile @@ -0,0 +1,9 @@ +source 'http://rubygems.org' + +gem 'rails', '3.0.0.beta4' +gem 'sqlite3-ruby', :require => 'sqlite3' +gem 'mocha' +gem 'rspec-rails', '2.0.0.beta.12' +gem 'ruby-debug' +gem 'cucumber' + diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 00000000..44231ea8 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,115 @@ +GEM + remote: http://rubygems.org/ + specs: + abstract (1.0.0) + actionmailer (3.0.0.beta4) + actionpack (= 3.0.0.beta4) + mail (~> 2.2.3) + actionpack (3.0.0.beta4) + activemodel (= 3.0.0.beta4) + activesupport (= 3.0.0.beta4) + builder (~> 2.1.2) + erubis (~> 2.6.5) + i18n (~> 0.4.1) + rack (~> 1.1.0) + rack-mount (~> 0.6.3) + rack-test (~> 0.5.4) + tzinfo (~> 0.3.16) + activemodel (3.0.0.beta4) + activesupport (= 3.0.0.beta4) + builder (~> 2.1.2) + i18n (~> 0.4.1) + activerecord (3.0.0.beta4) + activemodel (= 3.0.0.beta4) + activesupport (= 3.0.0.beta4) + arel (~> 0.4.0) + tzinfo (~> 0.3.16) + activeresource (3.0.0.beta4) + activemodel (= 3.0.0.beta4) + activesupport (= 3.0.0.beta4) + activesupport (3.0.0.beta4) + arel (0.4.0) + activesupport (>= 3.0.0.beta) + builder (2.1.2) + columnize (0.3.1) + cucumber (0.9.4) + builder (~> 2.1.2) + diff-lcs (~> 1.1.2) + gherkin (~> 2.2.9) + json (~> 1.4.6) + term-ansicolor (~> 1.0.5) + diff-lcs (1.1.2) + erubis (2.6.6) + abstract (>= 1.0.0) + gherkin (2.2.9) + json (~> 1.4.6) + term-ansicolor (~> 1.0.5) + i18n (0.4.1) + json (1.4.6) + linecache (0.43) + mail (2.2.12) + activesupport (>= 2.3.6) + i18n (>= 0.4.0) + mime-types (~> 1.16) + treetop (~> 1.4.8) + mime-types (1.16) + mocha (0.9.10) + rake + nokogiri (1.4.4) + polyglot (0.3.1) + rack (1.1.0) + rack-mount (0.6.13) + rack (>= 1.0.0) + rack-test (0.5.6) + rack (>= 1.0) + rails (3.0.0.beta4) + actionmailer (= 3.0.0.beta4) + actionpack (= 3.0.0.beta4) + activerecord (= 3.0.0.beta4) + activeresource (= 3.0.0.beta4) + activesupport (= 3.0.0.beta4) + bundler (>= 0.9.26) + railties (= 3.0.0.beta4) + railties (3.0.0.beta4) + actionpack (= 3.0.0.beta4) + activesupport (= 3.0.0.beta4) + rake (>= 0.8.3) + thor (~> 0.13.6) + rake (0.8.7) + rspec (2.0.0.beta.12) + rspec-core (= 2.0.0.beta.12) + rspec-expectations (= 2.0.0.beta.12) + rspec-mocks (= 2.0.0.beta.12) + rspec-core (2.0.0.beta.12) + rspec-expectations (2.0.0.beta.12) + diff-lcs (>= 1.1.2) + rspec-mocks (2.0.0.beta.12) + rspec-rails (2.0.0.beta.12) + rspec (= 2.0.0.beta.12) + webrat (>= 0.7.0) + ruby-debug (0.10.3) + columnize (>= 0.1) + ruby-debug-base (~> 0.10.3.0) + ruby-debug-base (0.10.3) + linecache (>= 0.3) + sqlite3-ruby (1.3.2) + term-ansicolor (1.0.5) + thor (0.13.8) + treetop (1.4.9) + polyglot (>= 0.3.1) + tzinfo (0.3.23) + webrat (0.7.2) + nokogiri (>= 1.2.0) + rack (>= 1.0) + rack-test (>= 0.5.3) + +PLATFORMS + ruby + +DEPENDENCIES + cucumber + mocha + rails (= 3.0.0.beta4) + rspec-rails (= 2.0.0.beta.12) + ruby-debug + sqlite3-ruby diff --git a/Rakefile b/Rakefile index efe4442c..930caf6a 100644 --- a/Rakefile +++ b/Rakefile @@ -1,25 +1,13 @@ require 'rubygems' +require 'bundler/setup' require 'rake' -require 'rake/testtask' require 'rake/rdoctask' require 'rake/gempackagetask' -begin - require 'cucumber/rake/task' -rescue LoadError - warn "couldn't load cucumber, skipping" -end +require 'rspec/core/rake_task' +require 'cucumber/rake/task' $LOAD_PATH.unshift("lib") require 'shoulda/version' -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' << 'test' - t.pattern = test_files_pattern - t.verbose = false -end Rake::RDocTask.new { |rdoc| rdoc.rdoc_dir = 'doc' @@ -29,11 +17,15 @@ Rake::RDocTask.new { |rdoc| rdoc.rdoc_files.include('README.rdoc', 'CONTRIBUTION_GUIDELINES.rdoc', 'lib/**/*.rb') } +RSpec::Core::RakeTask.new do |t| + t.pattern = "spec/**/*_spec.rb" +end + 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(' ')}" +RSpec::Core::RakeTask.new(:coverage) do |t| + t.rcov = true + t.rcov_opts = %{--exclude osx\/objc,spec,gems\/ --failure-threshold 100} + t.pattern = "spec/**/*_spec.rb" end eval("$specification = begin; #{IO.read('shoulda.gemspec')}; end") @@ -51,6 +43,6 @@ Cucumber::Rake::Task.new do |t| t.profile = 'default' end -desc 'Default: run test and cucumber features for support versions' -task :default => [:test, :cucumber] +desc 'Default: run specs and cucumber features' +task :default => [:spec, :cucumber] diff --git a/bin/convert_to_should_syntax b/bin/convert_to_should_syntax deleted file mode 100755 index d1264d07..00000000 --- a/bin/convert_to_should_syntax +++ /dev/null @@ -1,42 +0,0 @@ -#!/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/features/step_definitions/rails3_steps.rb b/features/step_definitions/rails3_steps.rb index 55d09b09..f16ac310 100644 --- a/features/step_definitions/rails3_steps.rb +++ b/features/step_definitions/rails3_steps.rb @@ -29,7 +29,7 @@ When /^I run the rspec generator$/ do end When /^I configure the application to use rspec\-rails$/ do - append_to_gemfile "gem 'rspec-rails', '>= 2.0.0.beta.12'" + append_to_gemfile "gem 'rspec-rails', '= 2.0.0.beta.12'" steps %{And I run "bundle install"} end diff --git a/init.rb b/init.rb deleted file mode 100644 index 6dbfa4cb..00000000 --- a/init.rb +++ /dev/null @@ -1 +0,0 @@ -require File.join(File.dirname(__FILE__), 'rails', 'init') diff --git a/lib/shoulda.rb b/lib/shoulda.rb index 45c2e2a9..208e64d5 100644 --- a/lib/shoulda.rb +++ b/lib/shoulda.rb @@ -5,3 +5,4 @@ if defined?(RSpec) else require 'shoulda/integrations/test_unit' end + diff --git a/lib/shoulda/action_controller.rb b/lib/shoulda/action_controller.rb index 2e05ad3b..ec1cb21b 100644 --- a/lib/shoulda/action_controller.rb +++ b/lib/shoulda/action_controller.rb @@ -1,19 +1,39 @@ -require 'shoulda' -require 'shoulda/action_controller/matchers' +require 'shoulda/action_controller/assign_to_matcher' +require 'shoulda/action_controller/filter_param_matcher' +require 'shoulda/action_controller/set_the_flash_matcher' +require 'shoulda/action_controller/render_with_layout_matcher' +require 'shoulda/action_controller/respond_with_matcher' +require 'shoulda/action_controller/respond_with_content_type_matcher' +require 'shoulda/action_controller/set_session_matcher' +require 'shoulda/action_controller/route_matcher' +require 'shoulda/action_controller/redirect_to_matcher' +require 'shoulda/action_controller/render_template_matcher' -module Test # :nodoc: all - module Unit - class TestCase - include Shoulda::ActionController::Matchers - extend Shoulda::ActionController::Matchers - end - end -end - -if defined?(ActionController::TestCase) - class ActionController::TestCase - def subject - @controller +module Shoulda # :nodoc: + module ActionController # :nodoc: + + # By using the matchers 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/lib/shoulda/action_controller/matchers/assign_to_matcher.rb b/lib/shoulda/action_controller/assign_to_matcher.rb similarity index 100% rename from lib/shoulda/action_controller/matchers/assign_to_matcher.rb rename to lib/shoulda/action_controller/assign_to_matcher.rb diff --git a/lib/shoulda/action_controller/filter_param_matcher.rb b/lib/shoulda/action_controller/filter_param_matcher.rb new file mode 100644 index 00000000..e31965af --- /dev/null +++ b/lib/shoulda/action_controller/filter_param_matcher.rb @@ -0,0 +1,50 @@ +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_key? + end + + def failure_message + "Expected #{@key} to be filtered; filtered keys: #{filtered_keys.join(', ')}" + end + + def negative_failure_message + "Did not expect #{@key} to be filtered" + end + + def description + "filter #{@key}" + end + + private + + def filters_key? + filtered_keys.include?(@key) + end + + def filtered_keys + Rails.application.config.filter_parameters.map { |filter| filter.to_s } + end + end + + end + end +end diff --git a/lib/shoulda/action_controller/matchers.rb b/lib/shoulda/action_controller/matchers.rb deleted file mode 100644 index 15cc5617..00000000 --- a/lib/shoulda/action_controller/matchers.rb +++ /dev/null @@ -1,39 +0,0 @@ -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' -require 'shoulda/action_controller/matchers/redirect_to_matcher' -require 'shoulda/action_controller/matchers/render_template_matcher' - -module Shoulda # :nodoc: - module ActionController # :nodoc: - - # By using the matchers 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/lib/shoulda/action_controller/matchers/filter_param_matcher.rb b/lib/shoulda/action_controller/matchers/filter_param_matcher.rb deleted file mode 100644 index d10b4026..00000000 --- a/lib/shoulda/action_controller/matchers/filter_param_matcher.rb +++ /dev/null @@ -1,74 +0,0 @@ -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) || - request.respond_to?(:filtered_parameters) - end - - def filters_key? - filtered_value == '[FILTERED]' - end - - def filtered_value - if request.respond_to?(:filtered_parameters) - filtered_request_value - else - filtered_controller_value - end - end - - def filtered_controller_value - filtered = @controller.send(:filter_parameters, - @key.to_s => @key.to_s) - filtered[@key.to_s] - end - - def filtered_request_value - request.env['action_dispatch.request.parameters'] = { @key.to_s => 'value' } - request.filtered_parameters[@key.to_s] - end - - def request - @request ||= ::ActionController::TestRequest.new - end - end - - end - end -end diff --git a/lib/shoulda/action_controller/matchers/redirect_to_matcher.rb b/lib/shoulda/action_controller/redirect_to_matcher.rb similarity index 100% rename from lib/shoulda/action_controller/matchers/redirect_to_matcher.rb rename to lib/shoulda/action_controller/redirect_to_matcher.rb diff --git a/lib/shoulda/action_controller/matchers/render_template_matcher.rb b/lib/shoulda/action_controller/render_template_matcher.rb similarity index 100% rename from lib/shoulda/action_controller/matchers/render_template_matcher.rb rename to lib/shoulda/action_controller/render_template_matcher.rb diff --git a/lib/shoulda/action_controller/matchers/render_with_layout_matcher.rb b/lib/shoulda/action_controller/render_with_layout_matcher.rb similarity index 95% rename from lib/shoulda/action_controller/matchers/render_with_layout_matcher.rb rename to lib/shoulda/action_controller/render_with_layout_matcher.rb index 1e6208ba..e28cabdc 100644 --- a/lib/shoulda/action_controller/matchers/render_with_layout_matcher.rb +++ b/lib/shoulda/action_controller/render_with_layout_matcher.rb @@ -10,10 +10,10 @@ module Shoulda # :nodoc: # it { should render_with_layout(:special) } # it { should_not render_with_layout } def render_with_layout(expected_layout = nil) - RenderWithLayout.new(expected_layout) + RenderWithLayoutMatcher.new(expected_layout).in_context(self) end - class RenderWithLayout # :nodoc: + class RenderWithLayoutMatcher # :nodoc: def initialize(expected_layout) @expected_layout = expected_layout.to_s unless expected_layout.nil? diff --git a/lib/shoulda/action_controller/matchers/respond_with_content_type_matcher.rb b/lib/shoulda/action_controller/respond_with_content_type_matcher.rb similarity index 100% rename from lib/shoulda/action_controller/matchers/respond_with_content_type_matcher.rb rename to lib/shoulda/action_controller/respond_with_content_type_matcher.rb diff --git a/lib/shoulda/action_controller/matchers/respond_with_matcher.rb b/lib/shoulda/action_controller/respond_with_matcher.rb similarity index 100% rename from lib/shoulda/action_controller/matchers/respond_with_matcher.rb rename to lib/shoulda/action_controller/respond_with_matcher.rb diff --git a/lib/shoulda/action_controller/matchers/route_matcher.rb b/lib/shoulda/action_controller/route_matcher.rb similarity index 100% rename from lib/shoulda/action_controller/matchers/route_matcher.rb rename to lib/shoulda/action_controller/route_matcher.rb diff --git a/lib/shoulda/action_controller/matchers/set_session_matcher.rb b/lib/shoulda/action_controller/set_session_matcher.rb similarity index 100% rename from lib/shoulda/action_controller/matchers/set_session_matcher.rb rename to lib/shoulda/action_controller/set_session_matcher.rb diff --git a/lib/shoulda/action_controller/matchers/set_the_flash_matcher.rb b/lib/shoulda/action_controller/set_the_flash_matcher.rb similarity index 87% rename from lib/shoulda/action_controller/matchers/set_the_flash_matcher.rb rename to lib/shoulda/action_controller/set_the_flash_matcher.rb index 13a36cae..4fd6bf93 100644 --- a/lib/shoulda/action_controller/matchers/set_the_flash_matcher.rb +++ b/lib/shoulda/action_controller/set_the_flash_matcher.rb @@ -67,15 +67,9 @@ module Shoulda # :nodoc: def flash return @flash if @flash - flash_and_now = @controller.request.session["flash"].dup if @controller.request.session["flash"] - flash = @controller.send(:flash) - - @flash = if @now - flash.keys.each {|key| flash_and_now.delete(key) } - flash_and_now - else - flash - end + @flash = @controller.flash.dup + @flash.sweep unless @now + @flash end def expectation diff --git a/lib/shoulda/action_mailer.rb b/lib/shoulda/action_mailer.rb index 4d57855e..2ec1a05e 100644 --- a/lib/shoulda/action_mailer.rb +++ b/lib/shoulda/action_mailer.rb @@ -1,11 +1,22 @@ -require 'shoulda' -require 'shoulda/action_mailer/matchers' +require 'shoulda/action_mailer/have_sent_email' -module Test # :nodoc: all - module Unit - class TestCase - include Shoulda::ActionMailer::Matchers - extend Shoulda::ActionMailer::Matchers +module Shoulda # :nodoc: + module ActionMailer # :nodoc: + # = Matchers for your mailers + # + # This matcher will test that email is sent properly + # + # describe User do + # it { should have_sent_email.with_subject(/is spam$/) } + # it { should have_sent_email.from('do-not-reply@example.com') } + # it { should have_sent_email.with_body(/is spam\./) } + # it { should have_sent_email.to('myself@me.com') } + # it { should have_sent_email.with_subject(/spam/). + # from('do-not-reply@example.com'). + # with_body(/spam/). + # to('myself@me.com') } + # end + module Matchers end end end diff --git a/lib/shoulda/action_mailer/matchers/have_sent_email.rb b/lib/shoulda/action_mailer/have_sent_email.rb similarity index 100% rename from lib/shoulda/action_mailer/matchers/have_sent_email.rb rename to lib/shoulda/action_mailer/have_sent_email.rb diff --git a/lib/shoulda/action_mailer/matchers.rb b/lib/shoulda/action_mailer/matchers.rb deleted file mode 100644 index 8ffb32e8..00000000 --- a/lib/shoulda/action_mailer/matchers.rb +++ /dev/null @@ -1,22 +0,0 @@ -require 'shoulda/action_mailer/matchers/have_sent_email' - -module Shoulda # :nodoc: - module ActionMailer # :nodoc: - # = Matchers for your mailers - # - # This matcher will test that email is sent properly - # - # describe User do - # it { should have_sent_email.with_subject(/is spam$/) } - # it { should have_sent_email.from('do-not-reply@example.com') } - # it { should have_sent_email.with_body(/is spam\./) } - # it { should have_sent_email.to('myself@me.com') } - # it { should have_sent_email.with_subject(/spam/). - # from('do-not-reply@example.com'). - # with_body(/spam/). - # to('myself@me.com') } - # end - module Matchers - end - end -end diff --git a/lib/shoulda/active_record.rb b/lib/shoulda/active_record.rb index 7365e5f0..0949d4bc 100644 --- a/lib/shoulda/active_record.rb +++ b/lib/shoulda/active_record.rb @@ -1,12 +1,42 @@ -require 'shoulda' require 'shoulda/active_record/helpers' -require 'shoulda/active_record/matchers' +require 'shoulda/active_record/validation_matcher' +require 'shoulda/active_record/allow_value_matcher' +require 'shoulda/active_record/ensure_length_of_matcher' +require 'shoulda/active_record/ensure_inclusion_of_matcher' +require 'shoulda/active_record/validate_presence_of_matcher' +require 'shoulda/active_record/validate_format_of_matcher' +require 'shoulda/active_record/validate_uniqueness_of_matcher' +require 'shoulda/active_record/validate_acceptance_of_matcher' +require 'shoulda/active_record/validate_numericality_of_matcher' +require 'shoulda/active_record/association_matcher' +require 'shoulda/active_record/have_db_column_matcher' +require 'shoulda/active_record/have_db_index_matcher' +require 'shoulda/active_record/have_readonly_attribute_matcher' +require 'shoulda/active_record/allow_mass_assignment_of_matcher' -module Test # :nodoc: all - module Unit - class TestCase - include Shoulda::ActiveRecord::Matchers - extend Shoulda::ActiveRecord::Matchers + +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/lib/shoulda/active_record/matchers/allow_mass_assignment_of_matcher.rb b/lib/shoulda/active_record/allow_mass_assignment_of_matcher.rb similarity index 100% rename from lib/shoulda/active_record/matchers/allow_mass_assignment_of_matcher.rb rename to lib/shoulda/active_record/allow_mass_assignment_of_matcher.rb diff --git a/lib/shoulda/active_record/matchers/allow_value_matcher.rb b/lib/shoulda/active_record/allow_value_matcher.rb similarity index 100% rename from lib/shoulda/active_record/matchers/allow_value_matcher.rb rename to lib/shoulda/active_record/allow_value_matcher.rb diff --git a/lib/shoulda/active_record/matchers/association_matcher.rb b/lib/shoulda/active_record/association_matcher.rb similarity index 100% rename from lib/shoulda/active_record/matchers/association_matcher.rb rename to lib/shoulda/active_record/association_matcher.rb diff --git a/lib/shoulda/active_record/matchers/ensure_inclusion_of_matcher.rb b/lib/shoulda/active_record/ensure_inclusion_of_matcher.rb similarity index 100% rename from lib/shoulda/active_record/matchers/ensure_inclusion_of_matcher.rb rename to lib/shoulda/active_record/ensure_inclusion_of_matcher.rb diff --git a/lib/shoulda/active_record/matchers/ensure_length_of_matcher.rb b/lib/shoulda/active_record/ensure_length_of_matcher.rb similarity index 100% rename from lib/shoulda/active_record/matchers/ensure_length_of_matcher.rb rename to lib/shoulda/active_record/ensure_length_of_matcher.rb diff --git a/lib/shoulda/active_record/matchers/have_db_column_matcher.rb b/lib/shoulda/active_record/have_db_column_matcher.rb similarity index 100% rename from lib/shoulda/active_record/matchers/have_db_column_matcher.rb rename to lib/shoulda/active_record/have_db_column_matcher.rb diff --git a/lib/shoulda/active_record/matchers/have_db_index_matcher.rb b/lib/shoulda/active_record/have_db_index_matcher.rb similarity index 100% rename from lib/shoulda/active_record/matchers/have_db_index_matcher.rb rename to lib/shoulda/active_record/have_db_index_matcher.rb diff --git a/lib/shoulda/active_record/matchers/have_readonly_attribute_matcher.rb b/lib/shoulda/active_record/have_readonly_attribute_matcher.rb similarity index 100% rename from lib/shoulda/active_record/matchers/have_readonly_attribute_matcher.rb rename to lib/shoulda/active_record/have_readonly_attribute_matcher.rb diff --git a/lib/shoulda/active_record/matchers.rb b/lib/shoulda/active_record/matchers.rb deleted file mode 100644 index 7e0ae4a4..00000000 --- a/lib/shoulda/active_record/matchers.rb +++ /dev/null @@ -1,42 +0,0 @@ -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_format_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_db_index_matcher' -require 'shoulda/active_record/matchers/have_readonly_attribute_matcher' -require 'shoulda/active_record/matchers/allow_mass_assignment_of_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/lib/shoulda/active_record/matchers/validate_acceptance_of_matcher.rb b/lib/shoulda/active_record/validate_acceptance_of_matcher.rb similarity index 100% rename from lib/shoulda/active_record/matchers/validate_acceptance_of_matcher.rb rename to lib/shoulda/active_record/validate_acceptance_of_matcher.rb diff --git a/lib/shoulda/active_record/matchers/validate_format_of_matcher.rb b/lib/shoulda/active_record/validate_format_of_matcher.rb similarity index 100% rename from lib/shoulda/active_record/matchers/validate_format_of_matcher.rb rename to lib/shoulda/active_record/validate_format_of_matcher.rb diff --git a/lib/shoulda/active_record/matchers/validate_numericality_of_matcher.rb b/lib/shoulda/active_record/validate_numericality_of_matcher.rb similarity index 100% rename from lib/shoulda/active_record/matchers/validate_numericality_of_matcher.rb rename to lib/shoulda/active_record/validate_numericality_of_matcher.rb diff --git a/lib/shoulda/active_record/matchers/validate_presence_of_matcher.rb b/lib/shoulda/active_record/validate_presence_of_matcher.rb similarity index 100% rename from lib/shoulda/active_record/matchers/validate_presence_of_matcher.rb rename to lib/shoulda/active_record/validate_presence_of_matcher.rb diff --git a/lib/shoulda/active_record/matchers/validate_uniqueness_of_matcher.rb b/lib/shoulda/active_record/validate_uniqueness_of_matcher.rb similarity index 100% rename from lib/shoulda/active_record/matchers/validate_uniqueness_of_matcher.rb rename to lib/shoulda/active_record/validate_uniqueness_of_matcher.rb diff --git a/lib/shoulda/active_record/matchers/validation_matcher.rb b/lib/shoulda/active_record/validation_matcher.rb similarity index 100% rename from lib/shoulda/active_record/matchers/validation_matcher.rb rename to lib/shoulda/active_record/validation_matcher.rb diff --git a/lib/shoulda/assertions.rb b/lib/shoulda/assertions.rb deleted file mode 100644 index 463d825d..00000000 --- a/lib/shoulda/assertions.rb +++ /dev/null @@ -1,79 +0,0 @@ -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, options = {}) - if matcher.respond_to?(:in_context) - matcher.in_context(self) - end - - if matcher.matches?(target) - assert_block { true } - if options[:message] - assert_match options[:message], matcher.negative_failure_message - end - else - assert_block(matcher.failure_message) { false } - end - end - - # Asserts that the given matcher returns false when +target+ is passed to #matches? - def assert_rejects(matcher, target, options = {}) - if matcher.respond_to?(:in_context) - matcher.in_context(self) - end - - unless matcher.matches?(target) - assert_block { true } - if options[:message] - assert_match options[:message], matcher.failure_message - end - else - assert_block(matcher.negative_failure_message) { false } - end - end - end -end diff --git a/lib/shoulda/autoload_macros.rb b/lib/shoulda/autoload_macros.rb deleted file mode 100644 index 8945db2f..00000000 --- a/lib/shoulda/autoload_macros.rb +++ /dev/null @@ -1,46 +0,0 @@ -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/lib/shoulda/context.rb b/lib/shoulda/context.rb deleted file mode 100644 index 6e11af08..00000000 --- a/lib/shoulda/context.rb +++ /dev/null @@ -1,441 +0,0 @@ -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 - # - # Should statements can also wrap matchers, making virtually any matcher - # usable in a macro style. The matcher's description is used to generate a - # test name and failure message, and the test will pass if the matcher - # matches the subject. - # - # === Example: - # - # should validate_presence_of(:first_name).with_message(/gotta be there/) - # - - def should(name_or_matcher, options = {}, &blk) - if Shoulda.current_context - Shoulda.current_context.should(name_or_matcher, options, &blk) - else - context_name = self.name.gsub(/Test/, "") - context = Shoulda::Context.new(context_name, self) do - should(name_or_matcher, options, &blk) - end - context.build - end - end - - # Allows negative tests using matchers. The matcher's description is used - # to generate a test name and negative failure message, and the test will - # pass unless the matcher matches the subject. - # - # === Example: - # - # should_not set_the_flash - def should_not(matcher) - if Shoulda.current_context - Shoulda.current_context.should_not(matcher) - else - context_name = self.name.gsub(/Test/, "") - context = Shoulda::Context.new(context_name, self) do - should_not(matcher) - 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 - - # Returns the class being tested, as determined by the test class name. - # - # class UserTest; described_type; end - # # => User - def described_type - self.name.gsub(/Test$/, '').constantize - end - - # Sets the return value of the subject instance method: - # - # class UserTest < Test::Unit::TestCase - # subject { User.first } - # - # # uses the existing user - # should validate_uniqueness_of(:email) - # end - def subject(&block) - @subject_block = block - end - - def subject_block # :nodoc: - @subject_block - end - end - - module InstanceMethods - # Returns an instance of the class under test. - # - # class UserTest - # should "be a user" do - # assert_kind_of User, subject # passes - # end - # end - # - # The subject can be explicitly set using the subject class method: - # - # class UserTest - # subject { User.first } - # should "be an existing user" do - # assert !subject.new_record? # uses the first user - # end - # end - # - # The subject is used by all macros that require an instance of the class - # being tested. - def subject - @shoulda_subject ||= construct_subject - end - - def subject_block # :nodoc: - (@shoulda_context && @shoulda_context.subject_block) || self.class.subject_block - end - - def get_instance_of(object_or_klass) # :nodoc: - if object_or_klass.is_a?(Class) - object_or_klass.new - else - object_or_klass - end - end - - def instance_variable_name_for(klass) # :nodoc: - klass.to_s.split('::').last.underscore - end - - private - - def construct_subject - if subject_block - instance_eval(&subject_block) - else - get_instance_of(self.class.described_type) - 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 - attr_accessor :subject_block - - 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_or_matcher, options = {}, &blk) - if name_or_matcher.respond_to?(:description) && name_or_matcher.respond_to?(:matches?) - name = name_or_matcher.description - blk = lambda { assert_accepts name_or_matcher, subject } - else - name = name_or_matcher - end - - if blk - self.shoulds << { :name => name, :before => options[:before], :block => blk } - else - self.should_eventuallys << { :name => name } - end - end - - def should_not(matcher) - name = matcher.description - blk = lambda { assert_rejects matcher, subject } - self.shoulds << { :name => "not #{name}", :block => blk } - end - - def should_eventually(name, &blk) - self.should_eventuallys << { :name => name, :block => blk } - end - - def subject(&block) - self.subject_block = block - end - - def subject_block - return @subject_block if @subject_block - parent.subject_block - 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 test_methods - @test_methods ||= Hash.new { |h,k| - h[k] = Hash[k.instance_methods.map { |n| [n, true] }] - } - end - - def create_test_from_should_hash(should) - test_name = ["test:", full_name, "should", "#{should[:name]}. "].flatten.join(' ').to_sym - - if test_methods[test_unit_class][test_name.to_s] then - warn " * WARNING: '#{test_name}' is already defined" - end - - test_methods[test_unit_class][test_name.to_s] = true - - context = self - test_unit_class.send(:define_method, test_name) do - @shoulda_context = context - 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/lib/shoulda/integrations/rspec.rb b/lib/shoulda/integrations/rspec.rb index 15876fb5..6e4f0360 100644 --- a/lib/shoulda/integrations/rspec.rb +++ b/lib/shoulda/integrations/rspec.rb @@ -1,22 +1,23 @@ -require 'shoulda/active_record/matchers' -require 'shoulda/action_controller/matchers' -require 'shoulda/action_mailer/matchers' - # :enddoc: -module RSpec - module Matchers +if defined?(::ActiveRecord) + require 'shoulda/active_record' + module RSpec::Matchers include Shoulda::ActiveRecord::Matchers end - - module Rails - module ControllerExampleGroup - include Shoulda::ActionController::Matchers - end - - module MailerExampleGroup - include Shoulda::ActionMailer::Matchers - end - end +end + +if defined?(::ActionController) + require 'shoulda/action_controller' + module Rails::ControllerExampleGroup + include Shoulda::ActionController::Matchers + end +end + +if defined?(::ActionMailer) + require 'shoulda/action_mailer' + module Rails::MailerExampleGroup + include Shoulda::ActionMailer::Matchers + end end diff --git a/lib/shoulda/integrations/test_unit.rb b/lib/shoulda/integrations/test_unit.rb index 39b98d59..97363e8f 100644 --- a/lib/shoulda/integrations/test_unit.rb +++ b/lib/shoulda/integrations/test_unit.rb @@ -1,17 +1,40 @@ -require 'test/unit' +# :enddoc: -require 'shoulda/context' -require 'shoulda/proc_extensions' -require 'shoulda/assertions' -require 'shoulda/autoload_macros' -require 'shoulda/rails' if defined? RAILS_ROOT +if defined?(ActionController) + require 'shoulda/action_controller' -module Test # :nodoc: all - module Unit - class TestCase - include Shoulda::InstanceMethods - extend Shoulda::ClassMethods - include Shoulda::Assertions + class ActionController::TestCase + include Shoulda::ActionController::Matchers + extend Shoulda::ActionController::Matchers + + def subject + @controller + end + end +end + +if defined?(ActionMailer) + require 'shoulda/action_mailer' + + module Test + module Unit + class TestCase + include Shoulda::ActionMailer::Matchers + extend Shoulda::ActionMailer::Matchers + end + end + end +end + +if defined?(ActiveRecord) + require 'shoulda/active_record' + + module Test + module Unit + class TestCase + include Shoulda::ActiveRecord::Matchers + extend Shoulda::ActiveRecord::Matchers + end end end end diff --git a/lib/shoulda/proc_extensions.rb b/lib/shoulda/proc_extensions.rb deleted file mode 100644 index 0d577df9..00000000 --- a/lib/shoulda/proc_extensions.rb +++ /dev/null @@ -1,14 +0,0 @@ -# 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/lib/shoulda/rails.rb b/lib/shoulda/rails.rb deleted file mode 100644 index 96b6f488..00000000 --- a/lib/shoulda/rails.rb +++ /dev/null @@ -1,8 +0,0 @@ -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_mailer' if defined? ActionMailer::Base - diff --git a/lib/shoulda/tasks.rb b/lib/shoulda/tasks.rb deleted file mode 100644 index b59c89ee..00000000 --- a/lib/shoulda/tasks.rb +++ /dev/null @@ -1,3 +0,0 @@ -Dir[File.join(File.dirname(__FILE__), 'tasks', '*.rake')].each do |f| - load f -end diff --git a/lib/shoulda/tasks/list_tests.rake b/lib/shoulda/tasks/list_tests.rake deleted file mode 100644 index 521daf20..00000000 --- a/lib/shoulda/tasks/list_tests.rake +++ /dev/null @@ -1,29 +0,0 @@ -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/lib/shoulda/tasks/yaml_to_shoulda.rake b/lib/shoulda/tasks/yaml_to_shoulda.rake deleted file mode 100644 index ca9e7939..00000000 --- a/lib/shoulda/tasks/yaml_to_shoulda.rake +++ /dev/null @@ -1,28 +0,0 @@ -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 diff --git a/rails/init.rb b/rails/init.rb deleted file mode 100644 index db181196..00000000 --- a/rails/init.rb +++ /dev/null @@ -1,8 +0,0 @@ -if RAILS_ENV == 'test' - if defined? Spec - require 'shoulda/integrations/rspec' - else - require 'shoulda/integrations/test_unit' - Shoulda.autoload_macros RAILS_ROOT, File.join("vendor", "{plugins,gems}", "*") - end -end diff --git a/test/fixtures/addresses.yml b/spec/fixtures/addresses.yml similarity index 100% rename from test/fixtures/addresses.yml rename to spec/fixtures/addresses.yml diff --git a/test/fixtures/friendships.yml b/spec/fixtures/friendships.yml similarity index 100% rename from test/fixtures/friendships.yml rename to spec/fixtures/friendships.yml diff --git a/test/fixtures/posts.yml b/spec/fixtures/posts.yml similarity index 100% rename from test/fixtures/posts.yml rename to spec/fixtures/posts.yml diff --git a/test/fixtures/products.yml b/spec/fixtures/products.yml similarity index 100% rename from test/fixtures/products.yml rename to spec/fixtures/products.yml diff --git a/test/fixtures/taggings.yml b/spec/fixtures/taggings.yml similarity index 100% rename from test/fixtures/taggings.yml rename to spec/fixtures/taggings.yml diff --git a/test/fixtures/tags.yml b/spec/fixtures/tags.yml similarity index 100% rename from test/fixtures/tags.yml rename to spec/fixtures/tags.yml diff --git a/test/fixtures/users.yml b/spec/fixtures/users.yml similarity index 100% rename from test/fixtures/users.yml rename to spec/fixtures/users.yml diff --git a/test/rails3_root/.gitignore b/spec/rails3_root/.gitignore similarity index 100% rename from test/rails3_root/.gitignore rename to spec/rails3_root/.gitignore diff --git a/spec/rails3_root/Gemfile b/spec/rails3_root/Gemfile new file mode 100644 index 00000000..c0ec536a --- /dev/null +++ b/spec/rails3_root/Gemfile @@ -0,0 +1,7 @@ +source 'http://rubygems.org' + +gem 'rails', '3.0.0.beta4' +gem 'sqlite3-ruby', :require => 'sqlite3' +gem 'mocha' +gem 'rspec-rails', '2.0.0.beta.12' + diff --git a/test/rails3_root/Gemfile.lock b/spec/rails3_root/Gemfile.lock similarity index 78% rename from test/rails3_root/Gemfile.lock rename to spec/rails3_root/Gemfile.lock index 3536ea6e..135679f0 100644 --- a/test/rails3_root/Gemfile.lock +++ b/spec/rails3_root/Gemfile.lock @@ -31,6 +31,7 @@ GEM arel (0.4.0) activesupport (>= 3.0.0.beta) builder (2.1.2) + diff-lcs (1.1.2) erubis (2.6.6) abstract (>= 1.0.0) i18n (0.4.1) @@ -42,6 +43,7 @@ GEM mime-types (1.16) mocha (0.9.10) rake + nokogiri (1.4.4) polyglot (0.3.1) rack (1.1.0) rack-mount (0.6.13) @@ -62,11 +64,26 @@ GEM rake (>= 0.8.3) thor (~> 0.13.6) rake (0.8.7) + rspec (2.0.0.beta.12) + rspec-core (= 2.0.0.beta.12) + rspec-expectations (= 2.0.0.beta.12) + rspec-mocks (= 2.0.0.beta.12) + rspec-core (2.0.0.beta.12) + rspec-expectations (2.0.0.beta.12) + diff-lcs (>= 1.1.2) + rspec-mocks (2.0.0.beta.12) + rspec-rails (2.0.0.beta.12) + rspec (= 2.0.0.beta.12) + webrat (>= 0.7.0) sqlite3-ruby (1.3.2) thor (0.13.8) treetop (1.4.9) polyglot (>= 0.3.1) tzinfo (0.3.23) + webrat (0.7.2) + nokogiri (>= 1.2.0) + rack (>= 1.0) + rack-test (>= 0.5.3) PLATFORMS ruby @@ -74,4 +91,5 @@ PLATFORMS DEPENDENCIES mocha rails (= 3.0.0.beta4) + rspec-rails (= 2.0.0.beta.12) sqlite3-ruby diff --git a/test/rails3_root/README b/spec/rails3_root/README similarity index 100% rename from test/rails3_root/README rename to spec/rails3_root/README diff --git a/test/rails3_root/Rakefile b/spec/rails3_root/Rakefile similarity index 100% rename from test/rails3_root/Rakefile rename to spec/rails3_root/Rakefile diff --git a/test/rails3_root/app/controllers/application_controller.rb b/spec/rails3_root/app/controllers/application_controller.rb similarity index 100% rename from test/rails3_root/app/controllers/application_controller.rb rename to spec/rails3_root/app/controllers/application_controller.rb diff --git a/test/rails3_root/app/controllers/posts_controller.rb b/spec/rails3_root/app/controllers/posts_controller.rb similarity index 100% rename from test/rails3_root/app/controllers/posts_controller.rb rename to spec/rails3_root/app/controllers/posts_controller.rb diff --git a/test/rails3_root/app/controllers/users_controller.rb b/spec/rails3_root/app/controllers/users_controller.rb similarity index 100% rename from test/rails3_root/app/controllers/users_controller.rb rename to spec/rails3_root/app/controllers/users_controller.rb diff --git a/test/rails3_root/app/helpers/application_helper.rb b/spec/rails3_root/app/helpers/application_helper.rb similarity index 100% rename from test/rails3_root/app/helpers/application_helper.rb rename to spec/rails3_root/app/helpers/application_helper.rb diff --git a/test/rails3_root/app/models/address.rb b/spec/rails3_root/app/models/address.rb similarity index 100% rename from test/rails3_root/app/models/address.rb rename to spec/rails3_root/app/models/address.rb diff --git a/test/rails3_root/app/models/flea.rb b/spec/rails3_root/app/models/flea.rb similarity index 100% rename from test/rails3_root/app/models/flea.rb rename to spec/rails3_root/app/models/flea.rb diff --git a/test/rails3_root/app/models/friendship.rb b/spec/rails3_root/app/models/friendship.rb similarity index 100% rename from test/rails3_root/app/models/friendship.rb rename to spec/rails3_root/app/models/friendship.rb diff --git a/test/rails3_root/app/models/notifier.rb b/spec/rails3_root/app/models/notifier.rb similarity index 100% rename from test/rails3_root/app/models/notifier.rb rename to spec/rails3_root/app/models/notifier.rb diff --git a/test/rails3_root/app/models/pets/cat.rb b/spec/rails3_root/app/models/pets/cat.rb similarity index 100% rename from test/rails3_root/app/models/pets/cat.rb rename to spec/rails3_root/app/models/pets/cat.rb diff --git a/test/rails3_root/app/models/pets/dog.rb b/spec/rails3_root/app/models/pets/dog.rb similarity index 100% rename from test/rails3_root/app/models/pets/dog.rb rename to spec/rails3_root/app/models/pets/dog.rb diff --git a/test/rails3_root/app/models/post.rb b/spec/rails3_root/app/models/post.rb similarity index 100% rename from test/rails3_root/app/models/post.rb rename to spec/rails3_root/app/models/post.rb diff --git a/test/rails3_root/app/models/product.rb b/spec/rails3_root/app/models/product.rb similarity index 100% rename from test/rails3_root/app/models/product.rb rename to spec/rails3_root/app/models/product.rb diff --git a/test/rails3_root/app/models/profile.rb b/spec/rails3_root/app/models/profile.rb similarity index 100% rename from test/rails3_root/app/models/profile.rb rename to spec/rails3_root/app/models/profile.rb diff --git a/test/rails3_root/app/models/registration.rb b/spec/rails3_root/app/models/registration.rb similarity index 100% rename from test/rails3_root/app/models/registration.rb rename to spec/rails3_root/app/models/registration.rb diff --git a/test/rails3_root/app/models/tag.rb b/spec/rails3_root/app/models/tag.rb similarity index 100% rename from test/rails3_root/app/models/tag.rb rename to spec/rails3_root/app/models/tag.rb diff --git a/test/rails3_root/app/models/tagging.rb b/spec/rails3_root/app/models/tagging.rb similarity index 100% rename from test/rails3_root/app/models/tagging.rb rename to spec/rails3_root/app/models/tagging.rb diff --git a/test/rails3_root/app/models/treat.rb b/spec/rails3_root/app/models/treat.rb similarity index 100% rename from test/rails3_root/app/models/treat.rb rename to spec/rails3_root/app/models/treat.rb diff --git a/test/rails3_root/app/models/user.rb b/spec/rails3_root/app/models/user.rb similarity index 100% rename from test/rails3_root/app/models/user.rb rename to spec/rails3_root/app/models/user.rb diff --git a/test/rails3_root/app/views/layouts/application.html.erb b/spec/rails3_root/app/views/layouts/application.html.erb similarity index 100% rename from test/rails3_root/app/views/layouts/application.html.erb rename to spec/rails3_root/app/views/layouts/application.html.erb diff --git a/test/rails3_root/app/views/layouts/posts.rhtml b/spec/rails3_root/app/views/layouts/posts.rhtml similarity index 100% rename from test/rails3_root/app/views/layouts/posts.rhtml rename to spec/rails3_root/app/views/layouts/posts.rhtml diff --git a/test/rails3_root/app/views/layouts/users.rhtml b/spec/rails3_root/app/views/layouts/users.rhtml similarity index 100% rename from test/rails3_root/app/views/layouts/users.rhtml rename to spec/rails3_root/app/views/layouts/users.rhtml diff --git a/test/rails3_root/app/views/layouts/wide.html.erb b/spec/rails3_root/app/views/layouts/wide.html.erb similarity index 100% rename from test/rails3_root/app/views/layouts/wide.html.erb rename to spec/rails3_root/app/views/layouts/wide.html.erb diff --git a/test/rails3_root/app/views/notifier/the_email.html.erb b/spec/rails3_root/app/views/notifier/the_email.html.erb similarity index 100% rename from test/rails3_root/app/views/notifier/the_email.html.erb rename to spec/rails3_root/app/views/notifier/the_email.html.erb diff --git a/test/rails3_root/app/views/posts/edit.rhtml b/spec/rails3_root/app/views/posts/edit.rhtml similarity index 100% rename from test/rails3_root/app/views/posts/edit.rhtml rename to spec/rails3_root/app/views/posts/edit.rhtml diff --git a/test/rails3_root/app/views/posts/index.rhtml b/spec/rails3_root/app/views/posts/index.rhtml similarity index 100% rename from test/rails3_root/app/views/posts/index.rhtml rename to spec/rails3_root/app/views/posts/index.rhtml diff --git a/test/rails3_root/app/views/posts/new.rhtml b/spec/rails3_root/app/views/posts/new.rhtml similarity index 100% rename from test/rails3_root/app/views/posts/new.rhtml rename to spec/rails3_root/app/views/posts/new.rhtml diff --git a/test/rails3_root/app/views/posts/show.rhtml b/spec/rails3_root/app/views/posts/show.rhtml similarity index 100% rename from test/rails3_root/app/views/posts/show.rhtml rename to spec/rails3_root/app/views/posts/show.rhtml diff --git a/test/rails3_root/app/views/users/edit.rhtml b/spec/rails3_root/app/views/users/edit.rhtml similarity index 100% rename from test/rails3_root/app/views/users/edit.rhtml rename to spec/rails3_root/app/views/users/edit.rhtml diff --git a/test/rails3_root/app/views/users/index.rhtml b/spec/rails3_root/app/views/users/index.rhtml similarity index 100% rename from test/rails3_root/app/views/users/index.rhtml rename to spec/rails3_root/app/views/users/index.rhtml diff --git a/test/rails3_root/app/views/users/new.rhtml b/spec/rails3_root/app/views/users/new.rhtml similarity index 100% rename from test/rails3_root/app/views/users/new.rhtml rename to spec/rails3_root/app/views/users/new.rhtml diff --git a/test/rails3_root/app/views/users/show.rhtml b/spec/rails3_root/app/views/users/show.rhtml similarity index 100% rename from test/rails3_root/app/views/users/show.rhtml rename to spec/rails3_root/app/views/users/show.rhtml diff --git a/test/rails3_root/config.ru b/spec/rails3_root/config.ru similarity index 100% rename from test/rails3_root/config.ru rename to spec/rails3_root/config.ru diff --git a/test/rails3_root/config/application.rb b/spec/rails3_root/config/application.rb similarity index 100% rename from test/rails3_root/config/application.rb rename to spec/rails3_root/config/application.rb diff --git a/test/rails3_root/config/boot.rb b/spec/rails3_root/config/boot.rb similarity index 100% rename from test/rails3_root/config/boot.rb rename to spec/rails3_root/config/boot.rb diff --git a/test/rails3_root/config/database.yml b/spec/rails3_root/config/database.yml similarity index 100% rename from test/rails3_root/config/database.yml rename to spec/rails3_root/config/database.yml diff --git a/test/rails3_root/config/environment.rb b/spec/rails3_root/config/environment.rb similarity index 100% rename from test/rails3_root/config/environment.rb rename to spec/rails3_root/config/environment.rb diff --git a/test/rails3_root/config/environments/development.rb b/spec/rails3_root/config/environments/development.rb similarity index 100% rename from test/rails3_root/config/environments/development.rb rename to spec/rails3_root/config/environments/development.rb diff --git a/test/rails3_root/config/environments/production.rb b/spec/rails3_root/config/environments/production.rb similarity index 100% rename from test/rails3_root/config/environments/production.rb rename to spec/rails3_root/config/environments/production.rb diff --git a/test/rails3_root/config/environments/test.rb b/spec/rails3_root/config/environments/test.rb similarity index 100% rename from test/rails3_root/config/environments/test.rb rename to spec/rails3_root/config/environments/test.rb diff --git a/test/rails3_root/config/initializers/backtrace_silencers.rb b/spec/rails3_root/config/initializers/backtrace_silencers.rb similarity index 100% rename from test/rails3_root/config/initializers/backtrace_silencers.rb rename to spec/rails3_root/config/initializers/backtrace_silencers.rb diff --git a/test/rails3_root/config/initializers/inflections.rb b/spec/rails3_root/config/initializers/inflections.rb similarity index 100% rename from test/rails3_root/config/initializers/inflections.rb rename to spec/rails3_root/config/initializers/inflections.rb diff --git a/test/rails3_root/config/initializers/mime_types.rb b/spec/rails3_root/config/initializers/mime_types.rb similarity index 100% rename from test/rails3_root/config/initializers/mime_types.rb rename to spec/rails3_root/config/initializers/mime_types.rb diff --git a/test/rails3_root/config/initializers/secret_token.rb b/spec/rails3_root/config/initializers/secret_token.rb similarity index 100% rename from test/rails3_root/config/initializers/secret_token.rb rename to spec/rails3_root/config/initializers/secret_token.rb diff --git a/test/rails3_root/config/initializers/session_store.rb b/spec/rails3_root/config/initializers/session_store.rb similarity index 100% rename from test/rails3_root/config/initializers/session_store.rb rename to spec/rails3_root/config/initializers/session_store.rb diff --git a/test/rails3_root/config/locales/en.yml b/spec/rails3_root/config/locales/en.yml similarity index 100% rename from test/rails3_root/config/locales/en.yml rename to spec/rails3_root/config/locales/en.yml diff --git a/test/rails3_root/config/routes.rb b/spec/rails3_root/config/routes.rb similarity index 100% rename from test/rails3_root/config/routes.rb rename to spec/rails3_root/config/routes.rb diff --git a/test/rails3_root/db/migrate/001_create_users.rb b/spec/rails3_root/db/migrate/001_create_users.rb similarity index 100% rename from test/rails3_root/db/migrate/001_create_users.rb rename to spec/rails3_root/db/migrate/001_create_users.rb diff --git a/test/rails3_root/db/migrate/002_create_posts.rb b/spec/rails3_root/db/migrate/002_create_posts.rb similarity index 100% rename from test/rails3_root/db/migrate/002_create_posts.rb rename to spec/rails3_root/db/migrate/002_create_posts.rb diff --git a/test/rails3_root/db/migrate/003_create_taggings.rb b/spec/rails3_root/db/migrate/003_create_taggings.rb similarity index 100% rename from test/rails3_root/db/migrate/003_create_taggings.rb rename to spec/rails3_root/db/migrate/003_create_taggings.rb diff --git a/test/rails3_root/db/migrate/004_create_tags.rb b/spec/rails3_root/db/migrate/004_create_tags.rb similarity index 100% rename from test/rails3_root/db/migrate/004_create_tags.rb rename to spec/rails3_root/db/migrate/004_create_tags.rb diff --git a/test/rails3_root/db/migrate/005_create_dogs.rb b/spec/rails3_root/db/migrate/005_create_dogs.rb similarity index 100% rename from test/rails3_root/db/migrate/005_create_dogs.rb rename to spec/rails3_root/db/migrate/005_create_dogs.rb diff --git a/test/rails3_root/db/migrate/006_create_addresses.rb b/spec/rails3_root/db/migrate/006_create_addresses.rb similarity index 100% rename from test/rails3_root/db/migrate/006_create_addresses.rb rename to spec/rails3_root/db/migrate/006_create_addresses.rb diff --git a/test/rails3_root/db/migrate/007_create_fleas.rb b/spec/rails3_root/db/migrate/007_create_fleas.rb similarity index 100% rename from test/rails3_root/db/migrate/007_create_fleas.rb rename to spec/rails3_root/db/migrate/007_create_fleas.rb diff --git a/test/rails3_root/db/migrate/008_create_dogs_fleas.rb b/spec/rails3_root/db/migrate/008_create_dogs_fleas.rb similarity index 100% rename from test/rails3_root/db/migrate/008_create_dogs_fleas.rb rename to spec/rails3_root/db/migrate/008_create_dogs_fleas.rb diff --git a/test/rails3_root/db/migrate/009_create_products.rb b/spec/rails3_root/db/migrate/009_create_products.rb similarity index 100% rename from test/rails3_root/db/migrate/009_create_products.rb rename to spec/rails3_root/db/migrate/009_create_products.rb diff --git a/test/rails3_root/db/migrate/010_create_friendships.rb b/spec/rails3_root/db/migrate/010_create_friendships.rb similarity index 100% rename from test/rails3_root/db/migrate/010_create_friendships.rb rename to spec/rails3_root/db/migrate/010_create_friendships.rb diff --git a/test/rails3_root/db/migrate/011_create_treats.rb b/spec/rails3_root/db/migrate/011_create_treats.rb similarity index 100% rename from test/rails3_root/db/migrate/011_create_treats.rb rename to spec/rails3_root/db/migrate/011_create_treats.rb diff --git a/test/rails3_root/db/migrate/20090506203502_create_profiles.rb b/spec/rails3_root/db/migrate/20090506203502_create_profiles.rb similarity index 100% rename from test/rails3_root/db/migrate/20090506203502_create_profiles.rb rename to spec/rails3_root/db/migrate/20090506203502_create_profiles.rb diff --git a/test/rails3_root/db/migrate/20090506203536_create_registrations.rb b/spec/rails3_root/db/migrate/20090506203536_create_registrations.rb similarity index 100% rename from test/rails3_root/db/migrate/20090506203536_create_registrations.rb rename to spec/rails3_root/db/migrate/20090506203536_create_registrations.rb diff --git a/test/rails3_root/db/migrate/20090513104502_create_cats.rb b/spec/rails3_root/db/migrate/20090513104502_create_cats.rb similarity index 100% rename from test/rails3_root/db/migrate/20090513104502_create_cats.rb rename to spec/rails3_root/db/migrate/20090513104502_create_cats.rb diff --git a/test/rails3_root/db/seeds.rb b/spec/rails3_root/db/seeds.rb similarity index 100% rename from test/rails3_root/db/seeds.rb rename to spec/rails3_root/db/seeds.rb diff --git a/test/rails3_root/lib/tasks/.gitkeep b/spec/rails3_root/lib/tasks/.gitkeep similarity index 100% rename from test/rails3_root/lib/tasks/.gitkeep rename to spec/rails3_root/lib/tasks/.gitkeep diff --git a/test/rails3_root/public/404.html b/spec/rails3_root/public/404.html similarity index 100% rename from test/rails3_root/public/404.html rename to spec/rails3_root/public/404.html diff --git a/test/rails3_root/public/422.html b/spec/rails3_root/public/422.html similarity index 100% rename from test/rails3_root/public/422.html rename to spec/rails3_root/public/422.html diff --git a/test/rails3_root/public/500.html b/spec/rails3_root/public/500.html similarity index 100% rename from test/rails3_root/public/500.html rename to spec/rails3_root/public/500.html diff --git a/test/rails3_root/public/favicon.ico b/spec/rails3_root/public/favicon.ico similarity index 100% rename from test/rails3_root/public/favicon.ico rename to spec/rails3_root/public/favicon.ico diff --git a/test/rails3_root/public/images/rails.png b/spec/rails3_root/public/images/rails.png similarity index 100% rename from test/rails3_root/public/images/rails.png rename to spec/rails3_root/public/images/rails.png diff --git a/test/rails3_root/public/index.html b/spec/rails3_root/public/index.html similarity index 100% rename from test/rails3_root/public/index.html rename to spec/rails3_root/public/index.html diff --git a/test/rails3_root/public/javascripts/application.js b/spec/rails3_root/public/javascripts/application.js similarity index 100% rename from test/rails3_root/public/javascripts/application.js rename to spec/rails3_root/public/javascripts/application.js diff --git a/test/rails3_root/public/javascripts/controls.js b/spec/rails3_root/public/javascripts/controls.js similarity index 100% rename from test/rails3_root/public/javascripts/controls.js rename to spec/rails3_root/public/javascripts/controls.js diff --git a/test/rails3_root/public/javascripts/dragdrop.js b/spec/rails3_root/public/javascripts/dragdrop.js similarity index 100% rename from test/rails3_root/public/javascripts/dragdrop.js rename to spec/rails3_root/public/javascripts/dragdrop.js diff --git a/test/rails3_root/public/javascripts/effects.js b/spec/rails3_root/public/javascripts/effects.js similarity index 100% rename from test/rails3_root/public/javascripts/effects.js rename to spec/rails3_root/public/javascripts/effects.js diff --git a/test/rails3_root/public/javascripts/prototype.js b/spec/rails3_root/public/javascripts/prototype.js similarity index 100% rename from test/rails3_root/public/javascripts/prototype.js rename to spec/rails3_root/public/javascripts/prototype.js diff --git a/test/rails3_root/public/javascripts/rails.js b/spec/rails3_root/public/javascripts/rails.js similarity index 100% rename from test/rails3_root/public/javascripts/rails.js rename to spec/rails3_root/public/javascripts/rails.js diff --git a/test/rails3_root/public/robots.txt b/spec/rails3_root/public/robots.txt similarity index 100% rename from test/rails3_root/public/robots.txt rename to spec/rails3_root/public/robots.txt diff --git a/test/rails3_root/public/stylesheets/.gitkeep b/spec/rails3_root/public/stylesheets/.gitkeep similarity index 100% rename from test/rails3_root/public/stylesheets/.gitkeep rename to spec/rails3_root/public/stylesheets/.gitkeep diff --git a/test/rails3_root/script/rails b/spec/rails3_root/script/rails similarity index 100% rename from test/rails3_root/script/rails rename to spec/rails3_root/script/rails diff --git a/test/rails3_root/test/performance/browsing_test.rb b/spec/rails3_root/test/performance/browsing_test.rb similarity index 100% rename from test/rails3_root/test/performance/browsing_test.rb rename to spec/rails3_root/test/performance/browsing_test.rb diff --git a/test/rails3_root/test/shoulda_macros/custom_macro.rb b/spec/rails3_root/test/shoulda_macros/custom_macro.rb similarity index 100% rename from test/rails3_root/test/shoulda_macros/custom_macro.rb rename to spec/rails3_root/test/shoulda_macros/custom_macro.rb diff --git a/test/rails3_root/test/test_helper.rb b/spec/rails3_root/test/test_helper.rb similarity index 100% rename from test/rails3_root/test/test_helper.rb rename to spec/rails3_root/test/test_helper.rb diff --git a/test/rails3_root/vendor/gems/gem_with_macro-0.0.1/shoulda_macros/gem_macro.rb b/spec/rails3_root/vendor/gems/gem_with_macro-0.0.1/shoulda_macros/gem_macro.rb similarity index 100% rename from test/rails3_root/vendor/gems/gem_with_macro-0.0.1/shoulda_macros/gem_macro.rb rename to spec/rails3_root/vendor/gems/gem_with_macro-0.0.1/shoulda_macros/gem_macro.rb diff --git a/test/rails3_root/vendor/plugins/.gitkeep b/spec/rails3_root/vendor/plugins/.gitkeep similarity index 100% rename from test/rails3_root/vendor/plugins/.gitkeep rename to spec/rails3_root/vendor/plugins/.gitkeep diff --git a/test/rails3_root/vendor/plugins/.keep b/spec/rails3_root/vendor/plugins/.keep similarity index 100% rename from test/rails3_root/vendor/plugins/.keep rename to spec/rails3_root/vendor/plugins/.keep diff --git a/test/rails3_root/vendor/plugins/plugin_with_macro/shoulda_macros/plugin_macro.rb b/spec/rails3_root/vendor/plugins/plugin_with_macro/shoulda_macros/plugin_macro.rb similarity index 100% rename from test/rails3_root/vendor/plugins/plugin_with_macro/shoulda_macros/plugin_macro.rb rename to spec/rails3_root/vendor/plugins/plugin_with_macro/shoulda_macros/plugin_macro.rb diff --git a/spec/shoulda/action_controller/assign_to_matcher_spec.rb b/spec/shoulda/action_controller/assign_to_matcher_spec.rb new file mode 100644 index 00000000..516bb7e9 --- /dev/null +++ b/spec/shoulda/action_controller/assign_to_matcher_spec.rb @@ -0,0 +1,55 @@ +require 'spec_helper' + +describe Shoulda::ActionController::Matchers::AssignToMatcher do + + context "a controller that assigns to an instance variable" do + before do + @controller = build_response { @var = 'value' } + end + + it "should accept assigning to that variable" do + @controller.should assign_to(:var) + end + + it "should accept assigning to that variable with the correct class" do + @controller.should assign_to(:var).with_kind_of(String) + end + + it "should reject assigning to that variable with another class" do + @controller.should_not assign_to(:var).with_kind_of(Fixnum) + end + + it "should accept assigning the correct value to that variable" do + @controller.should assign_to(:var).with('value') + end + + it "should reject assigning another value to that variable" do + @controller.should_not assign_to(:var).with('other') + end + + it "should reject assigning to another variable" do + @controller.should_not assign_to(:other) + end + + it "should accept assigning to the same value in the test context" do + @expected = 'value' + @controller.should assign_to(:var).in_context(self).with { @expected } + end + + it "should reject assigning to the another value in the test context" do + @expected = 'other' + @controller.should_not assign_to(:var).in_context(self).with { @expected } + end + end + + context "a controller that assigns a nil value to an instance variable" do + before do + @controller = build_response { @var = nil } + end + + it "should accept assigning to that variable" do + @controller.should assign_to(:var) + end + end + +end diff --git a/spec/shoulda/action_controller/filter_param_matcher_spec.rb b/spec/shoulda/action_controller/filter_param_matcher_spec.rb new file mode 100644 index 00000000..d39165a4 --- /dev/null +++ b/spec/shoulda/action_controller/filter_param_matcher_spec.rb @@ -0,0 +1,23 @@ +require 'spec_helper' + +describe Shoulda::ActionController::Matchers::FilterParamMatcher do + + context "given parameter filters" do + before do + Rails.application.config.filter_parameters = [:secret] + end + + it "should accept filtering that parameter" do + nil.should filter_param(:secret) + end + + it "should reject filtering another parameter" do + matcher = filter_param(:other) + matcher.matches?(nil).should be_false + matcher.failure_message.should include("Expected other to be filtered") + matcher.failure_message.should =~ /secret/ + end + end + +end + diff --git a/spec/shoulda/action_controller/redirect_to_matcher_spec.rb b/spec/shoulda/action_controller/redirect_to_matcher_spec.rb new file mode 100644 index 00000000..5465609e --- /dev/null +++ b/spec/shoulda/action_controller/redirect_to_matcher_spec.rb @@ -0,0 +1,37 @@ +require 'spec_helper' + +describe Shoulda::ActionController::Matchers::RedirectToMatcher do + + context "a controller that redirects" do + before do + @controller = build_response { redirect_to '/some/url' } + end + + it "should accept redirecting to that url" do + @controller.should redirect_to('/some/url') + end + + it "should reject redirecting to a different url" do + @controller.should_not redirect_to('/some/other/url') + end + + it "should accept redirecting to that url in a block" do + @controller.should redirect_to('somewhere') { '/some/url' } + end + + it "should reject redirecting to a different url in a block" do + @controller.should_not redirect_to('somewhere else') { '/some/other/url' } + end + end + + context "a controller that doesn't redirect" do + before do + @controller = build_response { render :text => 'hello' } + end + + it "should reject redirecting to a url" do + @controller.should_not redirect_to('/some/url') + end + end + +end diff --git a/spec/shoulda/action_controller/render_template_matcher_spec.rb b/spec/shoulda/action_controller/render_template_matcher_spec.rb new file mode 100644 index 00000000..75d4a70b --- /dev/null +++ b/spec/shoulda/action_controller/render_template_matcher_spec.rb @@ -0,0 +1,38 @@ +require 'spec_helper' + +describe Shoulda::ActionController::Matchers::RenderTemplateMatcher do + include ActionController::TemplateAssertions + + context "a controller that renders a template" do + before do + @controller = build_response(:action => 'show') { render } + end + + it "should accept rendering that template" do + @controller.should render_template(:show) + end + + it "should reject rendering a different template" do + @controller.should_not render_template(:index) + end + + it "should accept rendering that template in the given context" do + @controller.should render_template(:show).in_context(self) + end + + it "should reject rendering a different template in the given context" do + @controller.should_not render_template(:index).in_context(self) + end + end + + context "a controller that doesn't render a template" do + before do + @controller = build_response { render :nothing => true } + end + + it "should reject rendering a template" do + @controller.should_not render_template(:show) + end + end + +end diff --git a/spec/shoulda/action_controller/render_with_layout_matcher_spec.rb b/spec/shoulda/action_controller/render_with_layout_matcher_spec.rb new file mode 100644 index 00000000..521811e7 --- /dev/null +++ b/spec/shoulda/action_controller/render_with_layout_matcher_spec.rb @@ -0,0 +1,48 @@ +require 'spec_helper' + +describe Shoulda::ActionController::Matchers::RenderWithLayoutMatcher do + include ActionController::TemplateAssertions + + context "a controller that renders with a layout" do + before do + create_view('layouts/wide.html.erb', 'some content, <%= yield %>') + @controller = build_response { render :layout => 'wide' } + end + + it "should accept rendering with any layout" do + @controller.should render_with_layout + end + + it "should accept rendering with that layout" do + @controller.should render_with_layout(:wide) + end + + it "should reject rendering with another layout" do + @controller.should_not render_with_layout(:other) + end + end + + context "a controller that renders without a layout" do + before do + @controller = build_response { render :layout => false } + end + + it "should reject rendering with a layout" do + @controller.should_not render_with_layout + end + end + + context "given a context with layouts" do + before do + @layout = 'happy' + @controller = build_response { render :layout => false } + @layouts = Hash.new(0) + @layouts[@layout] = 1 + end + + it "should accept that layout in that context" do + @controller.should render_with_layout(@layout).in_context(self) + end + end + +end diff --git a/spec/shoulda/action_controller/respond_with_content_type_matcher_spec.rb b/spec/shoulda/action_controller/respond_with_content_type_matcher_spec.rb new file mode 100644 index 00000000..3eaff19f --- /dev/null +++ b/spec/shoulda/action_controller/respond_with_content_type_matcher_spec.rb @@ -0,0 +1,32 @@ +require 'spec_helper' + +describe Shoulda::ActionController::Matchers::RespondWithContentTypeMatcher do + + context "a controller responding with content type :xml" do + before do + @controller = build_response { render :xml => { :user => "thoughtbot" }.to_xml } + end + + it "should accept responding with content type :xml" do + @controller.should respond_with_content_type(:xml) + end + + it "should accept responding with content type 'application/xml'" do + @controller.should respond_with_content_type('application/xml') + end + + it "should accept responding with content type /xml/" do + @controller.should respond_with_content_type(/xml/) + end + + it "should reject responding with another content type" do + @controller.should_not respond_with_content_type(:json) + end + end + + it "should generate the correct test name" do + respond_with_content_type(:xml).description. + should == "respond with content type of application/xml" + end + +end diff --git a/spec/shoulda/action_controller/respond_with_matcher_spec.rb b/spec/shoulda/action_controller/respond_with_matcher_spec.rb new file mode 100644 index 00000000..1b77ef1b --- /dev/null +++ b/spec/shoulda/action_controller/respond_with_matcher_spec.rb @@ -0,0 +1,96 @@ +require 'spec_helper' + +describe Shoulda::ActionController::Matchers::RespondWithMatcher do + + context "a controller responding with success" do + before do + @controller = build_response { render :text => "text", :status => 200 } + end + + it "should accept responding with 200" do + @controller.should respond_with(200) + end + + it "should accept responding with :success" do + @controller.should respond_with(:success) + end + + it "should reject responding with another status" do + @controller.should_not respond_with(:error) + end + end + + context "a controller responding with redirect" do + before do + @controller = build_response { render :text => "text", :status => 301 } + end + + it "should accept responding with 301" do + @controller.should respond_with(301) + end + + it "should accept responding with :redirect" do + @controller.should respond_with(:redirect) + end + + it "should reject responding with another status" do + @controller.should_not respond_with(:error) + end + end + + context "a controller responding with missing" do + before do + @controller = build_response { render :text => "text", :status => 404 } + end + + it "should accept responding with 404" do + @controller.should respond_with(404) + end + + it "should accept responding with :missing" do + @controller.should respond_with(:missing) + end + + it "should reject responding with another status" do + @controller.should_not respond_with(:success) + end + end + + context "a controller responding with error" do + before do + @controller = build_response { render :text => "text", :status => 500 } + end + + it "should accept responding with 500" do + @controller.should respond_with(500) + end + + it "should accept responding with :error" do + @controller.should respond_with(:error) + end + + it "should reject responding with another status" do + @controller.should_not respond_with(:success) + end + end + + context "a controller responding with not implemented" do + before do + @controller = build_response { render :text => "text", :status => 501 } + end + + it "should accept responding with 501" do + @controller.should respond_with(501) + end + + it "should accept responding with :not_implemented" do + @controller.should respond_with(:not_implemented) + end + + it "should reject responding with another status" do + @controller.should_not respond_with(:success) + end + end + +end + diff --git a/spec/shoulda/action_controller/route_matcher_spec.rb b/spec/shoulda/action_controller/route_matcher_spec.rb new file mode 100644 index 00000000..4d31b868 --- /dev/null +++ b/spec/shoulda/action_controller/route_matcher_spec.rb @@ -0,0 +1,68 @@ +require 'spec_helper' + +describe Shoulda::ActionController::Matchers::RouteMatcher do + + context "given a controller with a defined glob url" do + before do + @controller = define_controller('Examples').new + define_routes do |map| + map.connect 'examples/*id', :controller => 'examples', + :action => 'example' + end + end + + it "should accept glob route" do + @controller.should route(:get, '/examples/foo/bar'). + to(:action => 'example', :id => ['foo', 'bar']) + end + + end + + context "given a controller with a defined route" do + before do + @controller = define_controller('Examples').new + define_routes do |map| + map.connect 'examples/:id', :controller => 'examples', + :action => 'example' + end + end + + it "should accept routing the correct path to the correct parameters" do + @controller.should route(:get, '/examples/1'). + to(:action => 'example', :id => '1') + end + + it "should accept a symbol controller" do + Object.new.should route(:get, '/examples/1'). + to(:controller => :examples, + :action => 'example', + :id => '1') + end + + it "should accept a symbol action" do + @controller.should route(:get, '/examples/1'). + to(:action => :example, :id => '1') + end + + it "should accept a non-string parameter" do + @controller.should route(:get, '/examples/1'). + to(:action => 'example', :id => 1) + end + + it "should reject an undefined route" do + @controller.should_not route(:get, '/bad_route').to(:var => 'value') + end + + it "should reject a route for another controller" do + @other = define_controller('Other').new + @other.should_not route(:get, '/examples/1'). + to(:action => 'example', :id => '1') + end + + it "should reject a route for different parameters" do + @controller.should_not route(:get, '/examples/1'). + to(:action => 'other', :id => '1') + end + end + +end diff --git a/spec/shoulda/action_controller/set_session_matcher_spec.rb b/spec/shoulda/action_controller/set_session_matcher_spec.rb new file mode 100644 index 00000000..9ce3d85f --- /dev/null +++ b/spec/shoulda/action_controller/set_session_matcher_spec.rb @@ -0,0 +1,48 @@ +require 'spec_helper' + +describe Shoulda::ActionController::Matchers::SetSessionMatcher do + + context "a controller that sets a session variable" do + before do + @controller = build_response do + session[:var] = 'value' + session[:false_var] = false + end + end + + it "should accept assigning to that variable" do + @controller.should set_session(:var) + end + + it "should accept assigning the correct value to that variable" do + @controller.should set_session(:var).to('value') + end + + it "should reject assigning another value to that variable" do + @controller.should_not set_session(:var).to('other') + end + + it "should reject assigning to another variable" do + @controller.should_not set_session(:other) + end + + it "should accept assigning nil to another variable" do + @controller.should set_session(:other).to(nil) + end + + it "should accept assigning false to that variable" do + @controller.should set_session(:false_var).to(false) + end + + it "should accept assigning to the same value in the test context" do + @expected = 'value' + @controller.should set_session(:var).in_context(self).to { @expected } + end + + it "should reject assigning to the another value in the test context" do + @expected = 'other' + @controller.should_not set_session(:var).in_context(self).to { @expected } + end + end + +end diff --git a/spec/shoulda/action_controller/set_the_flash_matcher_spec.rb b/spec/shoulda/action_controller/set_the_flash_matcher_spec.rb new file mode 100644 index 00000000..43e71ef1 --- /dev/null +++ b/spec/shoulda/action_controller/set_the_flash_matcher_spec.rb @@ -0,0 +1,95 @@ +require 'spec_helper' + +describe Shoulda::ActionController::Matchers::SetTheFlashMatcher do + + context "a controller that sets a flash message" do + before do + @controller = build_response { flash[:notice] = 'value' } + end + + it "should accept setting any flash message" do + @controller.should set_the_flash + end + + it "should accept setting the exact flash message" do + @controller.should set_the_flash.to('value') + end + + it "should accept setting a matched flash message" do + @controller.should set_the_flash.to(/value/) + end + + it "should reject setting a different flash message" do + @controller.should_not set_the_flash.to('other') + end + + it "should reject setting a different pattern" do + @controller.should_not set_the_flash.to(/other/) + end + end + + context "a controller that sets a flash.now message" do + before do + @controller = build_response { flash.now[:notice] = 'value' } + end + + it "should reject setting any flash message" do + @controller.should_not set_the_flash + end + + it "should accept setting any flash.now message" do + @controller.should set_the_flash.now + end + + it "should accept setting the exact flash.now message" do + @controller.should set_the_flash.to('value').now + end + + it "should accept setting a matched flash.now message" do + @controller.should set_the_flash.to(/value/).now + end + + it "should reject setting a different flash.now message" do + @controller.should_not set_the_flash.to('other').now + end + + it "should reject setting a different flash.now pattern" do + @controller.should_not set_the_flash.to(/other/).now + end + end + + context "a controller that sets multiple flash messages" do + before do + @controller = build_response { + flash.now[:notice] = 'value' + flash[:success] = 'great job' + } + end + + it "should accept setting any flash.now message" do + @controller.should set_the_flash.now + @controller.should set_the_flash + end + + it "should accept setting a matched flash.now message" do + @controller.should set_the_flash.to(/value/).now + @controller.should set_the_flash.to(/great/) + end + + it "should reject setting a different flash.now message" do + @controller.should_not set_the_flash.to('other').now + @controller.should_not set_the_flash.to('other') + end + end + + context "a controller that doesn't set a flash message" do + before do + @controller = build_response + end + + it "should reject setting any flash message" do + @controller.should_not set_the_flash + end + end + +end diff --git a/spec/shoulda/action_mailer/have_sent_email_spec.rb b/spec/shoulda/action_mailer/have_sent_email_spec.rb new file mode 100644 index 00000000..6248165a --- /dev/null +++ b/spec/shoulda/action_mailer/have_sent_email_spec.rb @@ -0,0 +1,71 @@ +require 'spec_helper' + +describe Shoulda::ActionMailer::Matchers::HaveSentEmailMatcher do + def add_mail_to_deliveries + ::ActionMailer::Base.deliveries << Mailer.the_email + end + + context "an email" do + before do + define_mailer :mailer, [:the_email] do + def the_email + mail :from => "do-not-reply@example.com", + :to => "myself@me.com", + :subject => "This is spam", + :body => "Every email is spam." + end + end + add_mail_to_deliveries + end + + after { ::ActionMailer::Base.deliveries.clear } + + it "should accept based on the subject" do + should have_sent_email.with_subject(/is spam$/) + matcher = have_sent_email.with_subject(/totally safe/) + matcher.matches?(nil) + matcher.failure_message.should =~ /Expected sent email with subject/ + end + + it "should accept based on a string sender" do + should have_sent_email.from('do-not-reply@example.com') + matcher = have_sent_email.from('you@example.com') + matcher.matches?(nil) + matcher.failure_message.should =~ /Expected sent email from/ + end + + it "should accept based on a regexp sender" do + should have_sent_email.from(/@example\.com/) + matcher = have_sent_email.from(/you@/) + matcher.matches?(nil) + matcher.failure_message.should =~ /Expected sent email from/ + end + + it "should accept based on the body" do + should have_sent_email.with_body(/is spam\./) + matcher = have_sent_email.with_body(/totally safe/) + matcher.matches?(nil) + matcher.failure_message.should =~ /Expected sent email with body/ + end + + it "should accept based on the recipient" do + should have_sent_email.to('myself@me.com') + matcher = have_sent_email.to('you@example.com') + matcher.matches?(nil) + matcher.failure_message.should =~ /Expected sent email to/ + end + + it "should list all deliveries within failure message" do + add_mail_to_deliveries + + matcher = have_sent_email.to('you@example.com') + matcher.matches?(nil) + matcher.failure_message.should =~ /Deliveries:\n"This is spam" to \["myself@me\.com"\]\n"This is spam" to \["myself@me\.com"\]/ + end + + it "should chain" do + should have_sent_email.with_subject(/spam/).from('do-not-reply@example.com').with_body(/spam/).to('myself@me.com') + should_not have_sent_email.with_subject(/ham/).from('you@example.com').with_body(/ham/).to('them@example.com') + end + end +end diff --git a/test/matchers/active_record/allow_mass_assignment_of_matcher_test.rb b/spec/shoulda/active_record/allow_mass_assignment_of_matcher_spec.rb similarity index 58% rename from test/matchers/active_record/allow_mass_assignment_of_matcher_test.rb rename to spec/shoulda/active_record/allow_mass_assignment_of_matcher_spec.rb index 2aca698c..c258ad6e 100644 --- a/test/matchers/active_record/allow_mass_assignment_of_matcher_test.rb +++ b/spec/shoulda/active_record/allow_mass_assignment_of_matcher_spec.rb @@ -1,73 +1,73 @@ -require 'test_helper' +require 'spec_helper' -class AllowMassAssignmentOfMatcherTest < ActiveSupport::TestCase # :nodoc: +describe Shoulda::ActiveRecord::Matchers::AllowMassAssignmentOfMatcher do context "an attribute that is blacklisted from mass-assignment" do - setup do + before 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 + it "should reject being mass-assignable" do + @model.should_not allow_mass_assignment_of(:attr) end end context "an attribute that is not whitelisted for mass-assignment" do - setup do + before 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 + it "should reject being mass-assignable" do + @model.should_not allow_mass_assignment_of(:attr) end end context "an attribute that is whitelisted for mass-assignment" do - setup do + before 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 + it "should accept being mass-assignable" do + @model.should allow_mass_assignment_of(:attr) end end context "an attribute not included in the mass-assignment blacklist" do - setup do + before 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 + it "should accept being mass-assignable" do + @model.should allow_mass_assignment_of(:attr) end end context "an attribute on a class with no protected attributes" do - setup do + before do define_model :example, :attr => :string @model = Example.new end - should "accept being mass-assignable" do - assert_accepts allow_mass_assignment_of(:attr), @model + it "should accept being mass-assignable" do + @model.should allow_mass_assignment_of(:attr) end - should "assign a negative failure message" do + it "should assign a negative failure message" do matcher = allow_mass_assignment_of(:attr) matcher.matches?(@model) - assert_not_nil matcher.negative_failure_message + matcher.negative_failure_message.should_not be_nil end end diff --git a/test/matchers/active_record/allow_value_matcher_test.rb b/spec/shoulda/active_record/allow_value_matcher_spec.rb similarity index 55% rename from test/matchers/active_record/allow_value_matcher_test.rb rename to spec/shoulda/active_record/allow_value_matcher_spec.rb index beeb4019..e891d1a3 100644 --- a/test/matchers/active_record/allow_value_matcher_test.rb +++ b/spec/shoulda/active_record/allow_value_matcher_spec.rb @@ -1,45 +1,43 @@ -require 'test_helper' +require 'spec_helper' -class AllowValueMatcherTest < ActiveSupport::TestCase # :nodoc: +describe Shoulda::ActiveRecord::Matchers::AllowValueMatcher do context "an attribute with a format validation" do - setup do + before 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 + it "should allow a good value" do + @model.should allow_value("abcde").for(:attr) end - - should "not allow a bad value" do - assert_rejects allow_value("xyz").for(:attr), @model + + it "should not allow a bad value" do + @model.should_not allow_value("xyz").for(:attr) end end context "an attribute with a format validation and a custom message" do - setup do + before 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 + it "should allow a good value" do + @model.should allow_value('abcde').for(:attr).with_message(/bad/) end - - should "not allow a bad value" do - assert_rejects allow_value('xyz').for(:attr).with_message(/bad/), - @model + + it "should not allow a bad value" do + @model.should_not allow_value('xyz').for(:attr).with_message(/bad/) end end context "an attribute with several validations" do - setup do + before do define_model :example, :attr => :string do validates_presence_of :attr validates_length_of :attr, :within => 1..5 @@ -49,14 +47,14 @@ class AllowValueMatcherTest < ActiveSupport::TestCase # :nodoc: @model = Example.new end - should "allow a good value" do - assert_accepts allow_value("12345").for(:attr), @model + it "should allow a good value" do + @model.should allow_value("12345").for(:attr) end - + bad_values = [nil, "", "abc", "0", "50001", "123456"] bad_values.each do |value| - should "not allow a bad value (#{value.inspect})" do - assert_rejects allow_value(value).for(:attr), @model + it "should not allow a bad value (#{value.inspect})" do + @model.should_not allow_value(value).for(:attr) end end end diff --git a/test/matchers/active_record/association_matcher_test.rb b/spec/shoulda/active_record/association_matcher_spec.rb similarity index 51% rename from test/matchers/active_record/association_matcher_test.rb rename to spec/shoulda/active_record/association_matcher_spec.rb index 61b9c179..5a1d1fa4 100644 --- a/test/matchers/active_record/association_matcher_test.rb +++ b/spec/shoulda/active_record/association_matcher_spec.rb @@ -1,140 +1,139 @@ -require 'test_helper' +require 'spec_helper' -class AssociationMatcherTest < ActiveSupport::TestCase # :nodoc: +describe Shoulda::ActiveRecord::Matchers::AssociationMatcher do context "belong_to" do - setup do + before do @matcher = belong_to(:parent) end - should "accept a good association with the default foreign key" do + it "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 + Child.new.should @matcher end - should "reject a nonexistent association" do + it "should reject a nonexistent association" do define_model :child - assert_rejects @matcher, Child.new + Child.new.should_not @matcher end - should "reject an association of the wrong type" do + it "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 + Child.new.should_not @matcher end - should "reject an association that has a nonexistent foreign key" do + it "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 + Child.new.should_not @matcher end - should "accept an association with an existing custom foreign key" do + it "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 + Child.new.should @matcher end - should "accept a polymorphic association" do + it "should accept a polymorphic association" do define_model :child, :parent_type => :string, - :parent_id => :integer do + :parent_id => :integer do belongs_to :parent, :polymorphic => true end - assert_accepts @matcher, Child.new + Child.new.should @matcher end - should "accept an association with a valid :dependent option" do + it "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 + Child.new.should @matcher.dependent(:destroy) end - should "reject an association with a bad :dependent option" do + it "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 + Child.new.should_not @matcher.dependent(:destroy) end end context "have_many" do - setup do + before do @matcher = have_many(:children) end - should "accept a valid association without any options" do + it "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 + Parent.new.should @matcher end - should "accept a valid association with a :through option" do + it "should accept a valid association with a :through option" do define_model :child define_model :conception, :child_id => :integer, - :parent_id => :integer do + :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 + Parent.new.should @matcher end - should "accept a valid association with an :as option" do + it "should accept a valid association with an :as option" do define_model :child, :guardian_type => :string, - :guardian_id => :integer + :guardian_id => :integer define_model :parent do has_many :children, :as => :guardian end - assert_accepts @matcher, Parent.new + Parent.new.should @matcher end - should "reject an association that has a nonexistent foreign key" do + it "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 + Parent.new.should_not @matcher end - should "reject an association with a bad :as option" do + it "should reject an association with a bad :as option" do define_model :child, :caretaker_type => :string, - :caretaker_id => :integer + :caretaker_id => :integer define_model :parent do has_many :children, :as => :guardian end - assert_rejects @matcher, Parent.new + Parent.new.should_not @matcher end - should "reject an association that has a bad :through option" do + it "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, - :message => /does not have any relationship to conceptions/ + @matcher.through(:conceptions).matches?(Parent.new).should be_false + @matcher.failure_message.should =~ /does not have any relationship to conceptions/ end - should "reject an association that has the wrong :through option" do + it "should reject an association that has the wrong :through option" do define_model :child define_model :conception, :child_id => :integer, - :parent_id => :integer do + :parent_id => :integer do belongs_to :child end define_model :parent do @@ -142,121 +141,120 @@ class AssociationMatcherTest < ActiveSupport::TestCase # :nodoc: has_many :relationships has_many :children, :through => :conceptions end - assert_rejects @matcher.through(:relationships), - Parent.new, - :message => /through relationships, but got it through conceptions/ + @matcher.through(:relationships).matches?(Parent.new).should be_false + @matcher.failure_message.should =~ /through relationships, but got it through conceptions/ end - should "accept an association with a valid :dependent option" do + it "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 + Parent.new.should @matcher.dependent(:destroy) end - should "reject an association with a bad :dependent option" do + it "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 + Parent.new.should_not @matcher.dependent(:destroy) end end context "have_one" do - setup do + before do @matcher = have_one(:detail) end - should "accept a valid association without any options" do + it "should accept a valid association without any options" do define_model :detail, :person_id => :integer define_model :person do has_one :detail end - assert_accepts @matcher, Person.new + Person.new.should @matcher end - should "accept a valid association with an :as option" do + it "should accept a valid association with an :as option" do define_model :detail, :detailable_id => :integer, - :detailable_type => :string + :detailable_type => :string define_model :person do has_one :detail, :as => :detailable end - assert_accepts @matcher, Person.new + Person.new.should @matcher end - should "reject an association that has a nonexistent foreign key" do + it "should reject an association that has a nonexistent foreign key" do define_model :detail define_model :person do has_one :detail end - assert_rejects @matcher, Person.new + Person.new.should_not @matcher end - should "reject an association with a bad :as option" do + it "should reject an association with a bad :as option" do define_model :detail, :detailable_id => :integer, - :detailable_type => :string + :detailable_type => :string define_model :person do has_one :detail, :as => :describable end - assert_rejects @matcher, Person.new + Person.new.should_not @matcher end - should "accept an association with a valid :dependent option" do + it "should accept an association with a valid :dependent option" do define_model :detail, :person_id => :integer define_model :person do has_one :detail, :dependent => :destroy end - assert_accepts @matcher.dependent(:destroy), Person.new + Person.new.should @matcher.dependent(:destroy) end - should "reject an association with a bad :dependent option" do + it "should reject an association with a bad :dependent option" do define_model :detail, :person_id => :integer define_model :person do has_one :detail end - assert_rejects @matcher.dependent(:destroy), Person.new + Person.new.should_not @matcher.dependent(:destroy) end end context "have_and_belong_to_many" do - setup do + before do @matcher = have_and_belong_to_many(:relatives) end - should "accept a valid association" do + it "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 + :relative_id => :integer + Person.new.should @matcher end - should "reject a nonexistent association" do + it "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 + :relative_id => :integer + Person.new.should_not @matcher end - should "reject an association with a nonexistent join table" do + it "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 + Person.new.should_not @matcher end - should "reject an association of the wrong type" do + it "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 + Person.new.should_not @matcher end end diff --git a/spec/shoulda/active_record/ensure_inclusion_of_matcher_spec.rb b/spec/shoulda/active_record/ensure_inclusion_of_matcher_spec.rb new file mode 100644 index 00000000..7b19cbe0 --- /dev/null +++ b/spec/shoulda/active_record/ensure_inclusion_of_matcher_spec.rb @@ -0,0 +1,71 @@ +require 'spec_helper' + +describe Shoulda::ActiveRecord::Matchers::EnsureInclusionOfMatcher do + + context "an attribute which must be included in a range" do + before do + @model = define_model(:example, :attr => :integer) do + validates_inclusion_of :attr, :in => 2..5 + end.new + end + + it "should accept ensuring the correct range" do + @model.should ensure_inclusion_of(:attr).in_range(2..5) + end + + it "should reject ensuring a lower minimum value" do + @model.should_not ensure_inclusion_of(:attr).in_range(1..5) + end + + it "should reject ensuring a higher minimum value" do + @model.should_not ensure_inclusion_of(:attr).in_range(3..5) + end + + it "should reject ensuring a lower maximum value" do + @model.should_not ensure_inclusion_of(:attr).in_range(2..4) + end + + it "should reject ensuring a higher maximum value" do + @model.should_not ensure_inclusion_of(:attr).in_range(2..6) + end + + it "should not override the default message with a blank" do + @model.should ensure_inclusion_of(:attr).in_range(2..5).with_message(nil) + end + end + + context "an attribute with a custom ranged value validation" do + before do + @model = define_model(:example, :attr => :string) do + validates_inclusion_of :attr, :in => 2..4, :message => 'not good' + + end.new + end + + it "should accept ensuring the correct range" do + @model.should ensure_inclusion_of(:attr).in_range(2..4).with_message(/not good/) + end + end + + context "an attribute with custom range validations" do + before do + define_model :example, :attr => :integer do + validate :custom_validation + def custom_validation + if attr < 2 + errors.add(:attr, 'too low') + elsif attr > 5 + errors.add(:attr, 'too high') + end + end + end + @model = Example.new + end + + it "should accept ensuring the correct range and messages" do + @model.should ensure_inclusion_of(:attr).in_range(2..5).with_low_message(/low/).with_high_message(/high/) + end + + end + +end diff --git a/spec/shoulda/active_record/ensure_length_of_matcher_spec.rb b/spec/shoulda/active_record/ensure_length_of_matcher_spec.rb new file mode 100644 index 00000000..0b07de73 --- /dev/null +++ b/spec/shoulda/active_record/ensure_length_of_matcher_spec.rb @@ -0,0 +1,125 @@ +require 'spec_helper' + +describe Shoulda::ActiveRecord::Matchers::EnsureLengthOfMatcher do + + context "an attribute with a non-zero minimum length validation" do + before do + @model = define_model(:example, :attr => :string) do + validates_length_of :attr, :minimum => 4 + end.new + end + + it "should accept ensuring the correct minimum length" do + @model.should ensure_length_of(:attr).is_at_least(4) + end + + it "should reject ensuring a lower minimum length with any message" do + @model.should_not ensure_length_of(:attr).is_at_least(3).with_short_message(/.*/) + end + + it "should reject ensuring a higher minimum length with any message" do + @model.should_not ensure_length_of(:attr).is_at_least(5).with_short_message(/.*/) + end + + it "should not override the default message with a blank" do + @model.should ensure_length_of(:attr).is_at_least(4).with_short_message(nil) + end + end + + context "an attribute with a minimum length validation of 0" do + before do + @model = define_model(:example, :attr => :string) do + validates_length_of :attr, :minimum => 0 + end.new + end + + it "should accept ensuring the correct minimum length" do + @model.should ensure_length_of(:attr).is_at_least(0) + end + end + + context "an attribute with a maximum length" do + before do + @model = define_model(:example, :attr => :string) do + validates_length_of :attr, :maximum => 4 + end.new + end + + it "should accept ensuring the correct maximum length" do + @model.should ensure_length_of(:attr).is_at_most(4) + end + + it "should reject ensuring a lower maximum length with any message" do + @model.should_not ensure_length_of(:attr).is_at_most(3).with_long_message(/.*/) + end + + it "should reject ensuring a higher maximum length with any message" do + @model.should_not ensure_length_of(:attr).is_at_most(5).with_long_message(/.*/) + end + + it "should not override the default message with a blank" do + @model.should ensure_length_of(:attr).is_at_most(4).with_long_message(nil) + end + end + + context "an attribute with a required exact length" do + before do + @model = define_model(:example, :attr => :string) do + validates_length_of :attr, :is => 4 + end.new + end + + it "should accept ensuring the correct length" do + @model.should ensure_length_of(:attr).is_equal_to(4) + end + + it "should reject ensuring a lower maximum length with any message" do + @model.should_not ensure_length_of(:attr).is_equal_to(3).with_message(/.*/) + end + + it "should reject ensuring a higher maximum length with any message" do + @model.should_not ensure_length_of(:attr).is_equal_to(5).with_message(/.*/) + end + + it "should not override the default message with a blank" do + @model.should ensure_length_of(:attr).is_equal_to(4).with_message(nil) + end + end + + context "an attribute with a custom minimum length validation" do + before do + @model = define_model(:example, :attr => :string) do + validates_length_of :attr, :minimum => 4, :too_short => 'short' + end.new + end + + it "should accept ensuring the correct minimum length" do + @model.should ensure_length_of(:attr).is_at_least(4).with_short_message(/short/) + end + + end + + context "an attribute with a custom maximum length validation" do + before do + @model = define_model(:example, :attr => :string) do + validates_length_of :attr, :maximum => 4, :too_long => 'long' + end.new + end + + it "should accept ensuring the correct minimum length" do + @model.should ensure_length_of(:attr).is_at_most(4).with_long_message(/long/) + end + + end + + context "an attribute without a length validation" do + before do + @model = define_model(:example, :attr => :string).new + end + + it "should reject ensuring a minimum length" do + @model.should_not ensure_length_of(:attr).is_at_least(1) + end + end + +end diff --git a/test/matchers/active_record/have_db_column_matcher_test.rb b/spec/shoulda/active_record/have_db_column_matcher_spec.rb similarity index 64% rename from test/matchers/active_record/have_db_column_matcher_test.rb rename to spec/shoulda/active_record/have_db_column_matcher_spec.rb index 92003c84..bfd1f7cd 100644 --- a/test/matchers/active_record/have_db_column_matcher_test.rb +++ b/spec/shoulda/active_record/have_db_column_matcher_spec.rb @@ -1,169 +1,169 @@ -require 'test_helper' +require 'spec_helper' -class HaveDbColumnMatcherTest < ActiveSupport::TestCase # :nodoc: +describe Shoulda::ActiveRecord::Matchers::HaveDbColumnMatcher do context "have_db_column" do - setup do + before do @matcher = have_db_column(:nickname) end - should "accept an existing database column" do + it "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 + Superhero.new.should @matcher end - - should "reject a nonexistent database column" do + + it "should reject a nonexistent database column" do define_model :superhero - assert_rejects @matcher, Superhero.new + Superhero.new.should_not @matcher end end - + context "have_db_column of type string" do - setup do + before do @matcher = have_db_column(:nickname).of_type(:string) end - should "accept a column of correct type" do + it "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 + Superhero.new.should @matcher end - - should "reject a nonexistent database column" do + + it "should reject a nonexistent database column" do define_model :superhero - assert_rejects @matcher, Superhero.new + Superhero.new.should_not @matcher end - - should "reject a column of wrong type" do + + it "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 + Superhero.new.should_not @matcher end end - + context "have_db_column with precision option" do - setup do + before do @matcher = have_db_column(:salary).with_options(:precision => 5) end - - should "accept a column of correct precision" do + + it "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 + Superhero.new.should @matcher end - should "reject a column of wrong precision" do + it "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 + Superhero.new.should_not @matcher end end - + context "have_db_column with limit option" do - setup do + before do @matcher = have_db_column(:email). of_type(:string). with_options(:limit => 255) end - - should "accept a column of correct limit" do + + it "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 + Superhero.new.should @matcher end - should "reject a column of wrong limit" do + it "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 + Superhero.new.should_not @matcher end end - + context "have_db_column with default option" do - setup do + before do @matcher = have_db_column(:admin). of_type(:boolean). with_options(:default => false) end - - should "accept a column of correct default" do + + it "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 + Superhero.new.should @matcher end - should "reject a column of wrong default" do + it "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 + Superhero.new.should_not @matcher end end - + context "have_db_column with null option" do - setup do + before do @matcher = have_db_column(:admin). of_type(:boolean). with_options(:null => false) end - - should "accept a column of correct null" do + + it "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 + Superhero.new.should @matcher end - should "reject a column of wrong null" do + it "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 + Superhero.new.should_not @matcher end end - + context "have_db_column with scale option" do - setup do + before do @matcher = have_db_column(:salary). of_type(:decimal). with_options(:scale => 2) end - - should "accept a column of correct scale" do + + it "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 + Superhero.new.should @matcher end - should "reject a column of wrong scale" do + it "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 + Superhero.new.should_not @matcher end end - + end diff --git a/test/matchers/active_record/have_db_index_matcher_test.rb b/spec/shoulda/active_record/have_db_index_matcher_spec.rb similarity index 53% rename from test/matchers/active_record/have_db_index_matcher_test.rb rename to spec/shoulda/active_record/have_db_index_matcher_spec.rb index 0e80eff7..d1573aff 100644 --- a/test/matchers/active_record/have_db_index_matcher_test.rb +++ b/spec/shoulda/active_record/have_db_index_matcher_spec.rb @@ -1,91 +1,90 @@ -require 'test_helper' +require 'spec_helper' + +describe Shoulda::ActiveRecord::Matchers::HaveDbIndexMatcher do -class HaveDbIndexMatcherTest < ActiveSupport::TestCase # :nodoc: - context "have_db_index" do - setup do + before do @matcher = have_db_index(:age) end - should "accept an existing index" do + it "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 + Superhero.new.should @matcher end - - should "reject a nonexistent index" do + + it "should reject a nonexistent index" do define_model :superhero - assert_rejects @matcher, Superhero.new + Superhero.new.should_not @matcher end end - + context "have_db_index with unique option" do - setup do + before do @matcher = have_db_index(:ssn).unique(true) end - should "accept an index of correct unique" do + it "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 + Superhero.new.should @matcher end - - should "reject an index of wrong unique" do + + it "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 + Superhero.new.should_not @matcher end end - + context "have_db_index on multiple columns" do - setup do + before do @matcher = have_db_index([:geocodable_type, :geocodable_id]) end - should "accept an existing index" do + it "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 + Geocoding.new.should @matcher end - - should "reject a nonexistant index" do + + it "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 + Geocoding.new.should_not @matcher end end - should "join columns with and describing multiple columns" do - assert_match /on columns user_id and post_id/, - have_db_index([:user_id, :post_id]).description + it "should join columns with and describing multiple columns" do + have_db_index([:user_id, :post_id]).description.should =~ /on columns user_id and post_id/ end - should "describe a unique index as unique" do - assert_match /a unique index/, have_db_index(:user_id).unique(true).description + it "should context a unique index as unique" do + have_db_index(:user_id).unique(true).description.should =~ /a unique index/ end - should "describe a non-unique index as non-unique" do - assert_match /a non-unique index/, have_db_index(:user_id).unique(false).description + it "should context a non-unique index as non-unique" do + have_db_index(:user_id).unique(false).description.should =~ /a non-unique index/ end - should "not describe an index's uniqueness when it isn't important" do - assert_no_match /unique/, have_db_index(:user_id).description + it "should not context an index's uniqueness when it isn't important" do + have_db_index(:user_id).description.should_not =~ /unique/ end - + end diff --git a/test/matchers/active_record/have_readonly_attributes_matcher_test.rb b/spec/shoulda/active_record/have_readonly_attributes_matcher_spec.rb similarity index 53% rename from test/matchers/active_record/have_readonly_attributes_matcher_test.rb rename to spec/shoulda/active_record/have_readonly_attributes_matcher_spec.rb index 526fa454..2abc9d40 100644 --- a/test/matchers/active_record/have_readonly_attributes_matcher_test.rb +++ b/spec/shoulda/active_record/have_readonly_attributes_matcher_spec.rb @@ -1,28 +1,28 @@ -require 'test_helper' +require 'spec_helper' -class HaveReadonlyAttributesMatcherTest < ActiveSupport::TestCase # :nodoc: +describe Shoulda::ActiveRecord::Matchers::HaveReadonlyAttributeMatcher do context "an attribute that cannot be set after being saved" do - setup do + before 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 + it "should accept being read-only" do + @model.should have_readonly_attribute(:attr) end end context "an attribute that can be set after being saved" do - setup do + before do define_model :example, :attr => :string @model = Example.new end - should "accept being read-only" do - assert_rejects have_readonly_attribute(:attr), @model + it "should accept being read-only" do + @model.should_not have_readonly_attribute(:attr) end end diff --git a/spec/shoulda/active_record/validate_acceptance_of_matcher_spec.rb b/spec/shoulda/active_record/validate_acceptance_of_matcher_spec.rb new file mode 100644 index 00000000..3a52100e --- /dev/null +++ b/spec/shoulda/active_record/validate_acceptance_of_matcher_spec.rb @@ -0,0 +1,43 @@ +require 'spec_helper' + +describe Shoulda::ActiveRecord::Matchers::ValidateAcceptanceOfMatcher do + + context "an attribute which must be accepted" do + before do + @model = define_model(:example) do + validates_acceptance_of :attr + end.new + end + + it "should require that attribute to be accepted" do + @model.should validate_acceptance_of(:attr) + end + + it "should not overwrite the default message with nil" do + @model.should validate_acceptance_of(:attr).with_message(nil) + end + end + + context "an attribute that does not need to be accepted" do + before do + @model = define_model(:example, :attr => :string).new + end + + it "should not require that attribute to be accepted" do + @model.should_not validate_acceptance_of(:attr) + end + end + + context "an attribute which must be accepted with a custom message" do + before do + @model = define_model(:example) do + validates_acceptance_of :attr, :message => 'custom' + end.new + end + + it "should require that attribute to be accepted with that message" do + @model.should validate_acceptance_of(:attr).with_message(/custom/) + end + end + +end diff --git a/spec/shoulda/active_record/validate_format_of_matcher_spec.rb b/spec/shoulda/active_record/validate_format_of_matcher_spec.rb new file mode 100644 index 00000000..22cb2c08 --- /dev/null +++ b/spec/shoulda/active_record/validate_format_of_matcher_spec.rb @@ -0,0 +1,35 @@ +require 'spec_helper' + +describe Shoulda::ActiveRecord::Matchers::ValidateFormatOfMatcher do + + context "a postal code" do + before do + define_model :example, :attr => :string do + validates_format_of :attr, :with => /^\d{5}$/ + end + @model = Example.new + end + + it "should be valid" do + @model.should validate_format_of(:attr).with('12345') + end + + it "should not be valid with alpha in zip" do + @model.should_not validate_format_of(:attr).not_with('1234a') + end + + it "should not be valid with to few digits" do + @model.should_not validate_format_of(:attr).not_with('1234') + end + + it "should not be valid with to many digits" do + @model.should_not validate_format_of(:attr).not_with('123456') + end + + it "should raise error if you try to call both with and not_with" do + expect { validate_format_of(:attr).not_with('123456').with('12345') }. + to raise_error(RuntimeError) + end + end + +end diff --git a/spec/shoulda/active_record/validate_numericality_of_matcher_spec.rb b/spec/shoulda/active_record/validate_numericality_of_matcher_spec.rb new file mode 100644 index 00000000..11ae87e2 --- /dev/null +++ b/spec/shoulda/active_record/validate_numericality_of_matcher_spec.rb @@ -0,0 +1,49 @@ +require 'spec_helper' + +describe Shoulda::ActiveRecord::Matchers::ValidateNumericalityOfMatcher do + + context "a numeric attribute" do + before do + define_model :example, :attr => :string do + validates_numericality_of :attr + end + @model = Example.new + end + + it "should only allow numeric values for that attribute" do + @model.should validate_numericality_of(:attr) + end + + it "should not override the default message with a blank" do + @model.should validate_numericality_of(:attr).with_message(nil) + end + end + + context "a numeric attribute with a custom validation message" do + before do + define_model :example, :attr => :string do + validates_numericality_of :attr, :message => 'custom' + end + @model = Example.new + end + + it "should only allow numeric values for that attribute with that message" do + @model.should validate_numericality_of(:attr).with_message(/custom/) + end + + it "should not allow numeric values for that attribute with another message" do + @model.should_not validate_numericality_of(:attr) + end + end + + context "a non-numeric attribute" do + before do + @model = define_model(:example, :attr => :string).new + end + + it "should not only allow numeric values for that attribute" do + @model.should_not validate_numericality_of(:attr) + end + end + +end diff --git a/test/matchers/active_record/validate_presence_of_matcher_test.rb b/spec/shoulda/active_record/validate_presence_of_matcher_spec.rb similarity index 55% rename from test/matchers/active_record/validate_presence_of_matcher_test.rb rename to spec/shoulda/active_record/validate_presence_of_matcher_spec.rb index de915e23..7fc9b631 100644 --- a/test/matchers/active_record/validate_presence_of_matcher_test.rb +++ b/spec/shoulda/active_record/validate_presence_of_matcher_spec.rb @@ -1,36 +1,36 @@ -require 'test_helper' +require 'spec_helper' -class ValidatePresenceOfMatcherTest < ActiveSupport::TestCase # :nodoc: +describe Shoulda::ActiveRecord::Matchers::ValidatePresenceOfMatcher do context "a required attribute" do - setup do + before 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 + it "should require a value" do + @model.should validate_presence_of(:attr) end - should "not override the default message with a blank" do - assert_accepts validate_presence_of(:attr).with_message(nil), @model + it "should not override the default message with a blank" do + @model.should validate_presence_of(:attr).with_message(nil) end end context "an optional attribute" do - setup do + before do @model = define_model(:example, :attr => :string).new end - should "not require a value" do - assert_rejects validate_presence_of(:attr), @model + it "should not require a value" do + @model.should_not validate_presence_of(:attr) end end context "a required has_many association" do - setup do + before do define_model :child @model = define_model :parent do has_many :children @@ -38,26 +38,26 @@ class ValidatePresenceOfMatcherTest < ActiveSupport::TestCase # :nodoc: end.new end - should "require the attribute to be set" do - assert_accepts validate_presence_of(:children), @model + it "should require the attribute to be set" do + @model.should validate_presence_of(:children) end end context "an optional has_many association" do - setup do + before 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 + it "should not require the attribute to be set" do + @model.should_not validate_presence_of(:children) end end context "a required has_and_belongs_to_many association" do - setup do + before do define_model :child @model = define_model :parent do has_and_belongs_to_many :children @@ -65,21 +65,21 @@ class ValidatePresenceOfMatcherTest < ActiveSupport::TestCase # :nodoc: end.new end - should "require the attribute to be set" do - assert_accepts validate_presence_of(:children), @model + it "should require the attribute to be set" do + @model.should validate_presence_of(:children) end end context "an optional has_and_belongs_to_many association" do - setup do + before 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 + it "should not require the attribute to be set" do + @model.should_not validate_presence_of(:children) end end diff --git a/spec/shoulda/active_record/validate_uniqueness_of_matcher_spec.rb b/spec/shoulda/active_record/validate_uniqueness_of_matcher_spec.rb new file mode 100644 index 00000000..5b04c0db --- /dev/null +++ b/spec/shoulda/active_record/validate_uniqueness_of_matcher_spec.rb @@ -0,0 +1,145 @@ +require 'spec_helper' + +describe Shoulda::ActiveRecord::Matchers::ValidateUniquenessOfMatcher do + + context "a unique attribute" do + before do + @model = define_model(:example, :attr => :string, + :other => :integer) do + validates_uniqueness_of :attr + end.new + end + + context "with an existing value" do + before do + @existing = Example.create!(:attr => 'value', :other => 1) + end + + it "should require a unique value for that attribute" do + @model.should validate_uniqueness_of(:attr) + end + + it "should pass when the subject is an existing record" do + @existing.should validate_uniqueness_of(:attr) + end + + it "should fail when a scope is specified" do + @model.should_not validate_uniqueness_of(:attr).scoped_to(:other) + end + end + + context "without an existing value" do + before do + Example.find(:first).should be_nil + @matcher = validate_uniqueness_of(:attr) + end + + it "should fail to require a unique value" do + @model.should_not @matcher + end + + it "should alert the tester that an existing value is not present" do + @matcher.matches?(@model) + @matcher.negative_failure_message.should =~ /^Can't find first .*/ + end + end + end + + context "a unique attribute with a custom error and an existing value" do + before do + @model = define_model(:example, :attr => :string) do + validates_uniqueness_of :attr, :message => 'Bad value' + end.new + Example.create! + end + + it "should fail when checking the default message" do + @model.should_not validate_uniqueness_of(:attr) + end + + it "should fail when checking a message that doesn't match" do + @model.should_not validate_uniqueness_of(:attr).with_message(/abc/i) + end + + it "should pass when checking a message that matches" do + @model.should validate_uniqueness_of(:attr).with_message(/bad/i) + end + end + + context "a scoped unique attribute with an existing value" do + before 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 + + it "should pass when the correct scope is specified" do + @model.should validate_uniqueness_of(:attr).scoped_to(:scope1, :scope2) + end + + it "should pass when the subject is an existing record" do + @existing.should validate_uniqueness_of(:attr).scoped_to(:scope1, :scope2) + end + + it "should fail when a different scope is specified" do + @model.should_not validate_uniqueness_of(:attr).scoped_to(:scope1) + end + + it "should fail when no scope is specified" do + @model.should_not validate_uniqueness_of(:attr) + end + + it "should fail when a non-existent attribute is specified as a scope" do + @model.should_not validate_uniqueness_of(:attr).scoped_to(:fake) + end + end + + context "a non-unique attribute with an existing value" do + before do + @model = define_model(:example, :attr => :string).new + Example.create!(:attr => 'value') + end + + it "should not require a unique value for that attribute" do + @model.should_not validate_uniqueness_of(:attr) + end + end + + context "a case sensitive unique attribute with an existing value" do + before do + @model = define_model(:example, :attr => :string) do + validates_uniqueness_of :attr, :case_sensitive => true + end.new + Example.create!(:attr => 'value') + end + + it "should not require a unique, case-insensitive value for that attribute" do + @model.should_not validate_uniqueness_of(:attr).case_insensitive + end + + it "should require a unique, case-sensitive value for that attribute" do + @model.should validate_uniqueness_of(:attr) + end + end + + context "a case sensitive unique integer attribute with an existing value" do + before do + @model = define_model(:example, :attr => :integer) do + validates_uniqueness_of :attr, :case_sensitive => true + end.new + Example.create!(:attr => 'value') + end + + it "should require a unique, case-insensitive value for that attribute" do + @model.should validate_uniqueness_of(:attr).case_insensitive + end + + it "should require a unique, case-sensitive value for that attribute" do + @model.should validate_uniqueness_of(:attr) + end + end + +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 00000000..91a6cb41 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,32 @@ +ENV['RAILS_ENV'] = 'test' +ENV['RAILS_VERSION'] ||= '3.0.0.beta4' +RAILS_GEM_VERSION = ENV['RAILS_VERSION'] + +rails_root = File.dirname(__FILE__) + '/rails3_root' +ENV['BUNDLE_GEMFILE'] = rails_root + '/Gemfile' + +require "#{rails_root}/config/environment" +require 'rspec' +require 'rspec/autorun' + +PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..')).freeze + +$LOAD_PATH << File.join(PROJECT_ROOT, 'lib') + +Dir[File.join(PROJECT_ROOT, 'spec', 'support', '**', '*.rb')].each { |file| require(file) } + +require 'shoulda' +require 'rspec/rails' + +# Run the migrations +ActiveRecord::Migration.verbose = false +ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate") + +RSpec.configure do |config| + config.mock_with :mocha + config.include Shoulda::ActionController::Matchers, + :example_group => { :file_path => /action_controller/ } + config.include Shoulda::ActionMailer::Matchers, + :example_group => { :file_path => /action_mailer/ } +end + diff --git a/test/rails3_model_builder.rb b/spec/support/model_builder.rb similarity index 76% rename from test/rails3_model_builder.rb rename to spec/support/model_builder.rb index 78128dbf..8f1fcacf 100644 --- a/test/rails3_model_builder.rb +++ b/spec/support/model_builder.rb @@ -1,15 +1,24 @@ -class ActiveSupport::TestCase - +module ModelBuilder TMP_VIEW_PATH = File.expand_path(File.join(File.dirname(__FILE__), 'rails3_root', 'tmp', 'views')).freeze + def self.included(example_group) + example_group.class_eval do + before do + @created_tables ||= [] + @defined_constants ||= [] + end + + after { teardown_defined_constants } + end + end + 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 @@ -26,7 +35,6 @@ class ActiveSupport::TestCase klass.class_eval(&block) if block_given? - @defined_constants ||= [] @defined_constants << class_name klass @@ -62,6 +70,10 @@ class ActiveSupport::TestCase def define_routes(&block) Rails.application.routes.draw(&block) + @routes = Rails.application.routes + class << self + include ActionDispatch::Assertions + end end def build_response(opts = {}, &block) @@ -81,6 +93,12 @@ class ActiveSupport::TestCase @response = ActionController::TestResponse.new @controller.send :assign_shortcuts, @request, @response @controller.send :initialize_template_class, @response + + class << self + include ActionController::TestCase::Behavior + end + @routes = Rails.application.routes + get action @controller @@ -92,27 +110,25 @@ class ActiveSupport::TestCase File.open(full_path, 'w') { |file| file.write(contents) } end - def teardown_with_models - if @defined_constants - @defined_constants.each do |class_name| - Object.send(:remove_const, class_name) - end + def teardown_defined_constants + @defined_constants.each do |class_name| + Object.send(:remove_const, class_name) end + @defined_constants = [] - if @created_tables - @created_tables.each do |table_name| - ActiveRecord::Base. - connection. - execute("DROP TABLE IF EXISTS #{table_name}") - end + @created_tables.each do |table_name| + ActiveRecord::Base. + connection. + execute("DROP TABLE IF EXISTS #{table_name}") end FileUtils.rm_rf(TMP_VIEW_PATH) Rails.application.routes_reloader.reload! - - teardown_without_models end - alias_method :teardown_without_models, :teardown - alias_method :teardown, :teardown_with_models end + +RSpec.configure do |config| + config.include ModelBuilder +end + diff --git a/tasks/shoulda.rake b/tasks/shoulda.rake deleted file mode 100644 index 720f27d7..00000000 --- a/tasks/shoulda.rake +++ /dev/null @@ -1 +0,0 @@ -load File.join(File.dirname(__FILE__), "..", "lib", "shoulda", "tasks.rb") diff --git a/test/README b/test/README deleted file mode 100644 index 12a996c7..00000000 --- a/test/README +++ /dev/null @@ -1,36 +0,0 @@ -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/test/matchers/action_mailer/have_sent_email_test.rb b/test/matchers/action_mailer/have_sent_email_test.rb deleted file mode 100644 index 8234d957..00000000 --- a/test/matchers/action_mailer/have_sent_email_test.rb +++ /dev/null @@ -1,76 +0,0 @@ -require 'test_helper' - -class HaveSentEmailTest < ActiveSupport::TestCase # :nodoc: - def add_mail_to_deliveries - if defined?(AbstractController::Rendering) - ::ActionMailer::Base.deliveries << Mailer.the_email - else - ::ActionMailer::Base.deliveries << Mailer.create_the_email - end - end - - context "an email" do - setup do - define_mailer :mailer, [:the_email] do - def the_email - if defined?(AbstractController::Rendering) - mail :from => "do-not-reply@example.com", - :to => "myself@me.com", - :subject => "This is spam", - :body => "Every email is spam." - else - from "do-not-reply@example.com" - recipients "myself@me.com" - subject "This is spam" - body "Every email is spam." - end - end - end - add_mail_to_deliveries - end - - teardown { ::ActionMailer::Base.deliveries.clear } - - should "accept based on the subject" do - assert_accepts have_sent_email.with_subject(/is spam$/), nil - assert_rejects have_sent_email.with_subject(/totally safe/), nil, - :message => /Expected sent email with subject/ - end - - should "accept based on a string sender" do - assert_accepts have_sent_email.from('do-not-reply@example.com'), nil - assert_rejects have_sent_email.from('you@example.com'), nil, - :message => /Expected sent email from/ - end - - should "accept based on a regexp sender" do - assert_accepts have_sent_email.from(/@example\.com/), nil - assert_rejects have_sent_email.from(/you@/), nil, - :message => /Expected sent email from/ - end - - should "accept based on the body" do - assert_accepts have_sent_email.with_body(/is spam\./), nil - assert_rejects have_sent_email.with_body(/totally safe/), nil, - :message => /Expected sent email with body/ - end - - should "accept based on the recipient" do - assert_accepts have_sent_email.to('myself@me.com'), nil - assert_rejects have_sent_email.to('you@example.com'), nil, - :message => /Expected sent email to/ - end - - should "list all deliveries within failure message" do - add_mail_to_deliveries - - assert_rejects have_sent_email.to('you@example.com'), nil, - :message => /Deliveries:\n"This is spam" to \["myself@me\.com"\]\n"This is spam" to \["myself@me\.com"\]/ - end - - should "chain" do - assert_accepts have_sent_email.with_subject(/spam/).from('do-not-reply@example.com').with_body(/spam/).to('myself@me.com'), nil - assert_rejects have_sent_email.with_subject(/ham/).from('you@example.com').with_body(/ham/).to('them@example.com'), nil - end - end -end diff --git a/test/matchers/active_record/ensure_inclusion_of_matcher_test.rb b/test/matchers/active_record/ensure_inclusion_of_matcher_test.rb deleted file mode 100644 index 49e1c43a..00000000 --- a/test/matchers/active_record/ensure_inclusion_of_matcher_test.rb +++ /dev/null @@ -1,81 +0,0 @@ -require 'test_helper' - -class EnsureInclusionOfMatcherTest < ActiveSupport::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 - validate :custom_validation - def custom_validation - 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/test/matchers/active_record/ensure_length_of_matcher_test.rb b/test/matchers/active_record/ensure_length_of_matcher_test.rb deleted file mode 100644 index f281fc55..00000000 --- a/test/matchers/active_record/ensure_length_of_matcher_test.rb +++ /dev/null @@ -1,158 +0,0 @@ -require 'test_helper' - -class EnsureLengthOfMatcher < ActiveSupport::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/test/matchers/active_record/validate_acceptance_of_matcher_test.rb b/test/matchers/active_record/validate_acceptance_of_matcher_test.rb deleted file mode 100644 index 3e389bbc..00000000 --- a/test/matchers/active_record/validate_acceptance_of_matcher_test.rb +++ /dev/null @@ -1,44 +0,0 @@ -require 'test_helper' - -class ValidateAcceptanceOfMatcherTest < ActiveSupport::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/test/matchers/active_record/validate_format_of_matcher_test.rb b/test/matchers/active_record/validate_format_of_matcher_test.rb deleted file mode 100644 index 564510da..00000000 --- a/test/matchers/active_record/validate_format_of_matcher_test.rb +++ /dev/null @@ -1,39 +0,0 @@ -require 'test_helper' - -class ValidateFormatOfMatcherTest < ActiveSupport::TestCase # :nodoc: - - - context "a postal code" do - setup do - define_model :example, :attr => :string do - validates_format_of :attr, :with => /^\d{5}$/ - end - @model = Example.new - end - - should "be valid" do - assert_accepts validate_format_of(:attr).with('12345'), @model - end - - should "not be valid with alpha in zip" do - assert_rejects validate_format_of(:attr).not_with('1234a'), @model, :message=>"is invalid" - end - - should "not be valid with to few digits" do - assert_rejects validate_format_of(:attr).not_with('1234'), @model, :message=>"is invalid" - end - - should "not be valid with to many digits" do - assert_rejects validate_format_of(:attr).not_with('123456'), @model, :message=>"is invalid" - end - - should "raise error if you try to call both with and not_with" do - assert_raise RuntimeError do - validate_format_of(:attr).not_with('123456').with('12345') - end - end - - end - - -end diff --git a/test/matchers/active_record/validate_numericality_of_matcher_test.rb b/test/matchers/active_record/validate_numericality_of_matcher_test.rb deleted file mode 100644 index 72c78a74..00000000 --- a/test/matchers/active_record/validate_numericality_of_matcher_test.rb +++ /dev/null @@ -1,52 +0,0 @@ -require 'test_helper' - -class ValidateNumericalityOfMatcherTest < ActiveSupport::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/test/matchers/active_record/validate_uniqueness_of_matcher_test.rb b/test/matchers/active_record/validate_uniqueness_of_matcher_test.rb deleted file mode 100644 index 8ae1b6cc..00000000 --- a/test/matchers/active_record/validate_uniqueness_of_matcher_test.rb +++ /dev/null @@ -1,147 +0,0 @@ -require 'test_helper' - -class ValidateUniquenessOfMatcherTest < ActiveSupport::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/test/matchers/controller/assign_to_matcher_test.rb b/test/matchers/controller/assign_to_matcher_test.rb deleted file mode 100644 index c064cfd8..00000000 --- a/test/matchers/controller/assign_to_matcher_test.rb +++ /dev/null @@ -1,55 +0,0 @@ -require 'test_helper' - -class AssignToMatcherTest < ActionController::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 - - should "accept assigning to the same value in the test context" do - @expected = 'value' - assert_accepts assign_to(:var).with { @expected }, @controller - end - - should "reject assigning to the another value in the test context" do - @expected = 'other' - assert_rejects assign_to(:var).with { @expected }, @controller - end - end - - context "a controller that assigns a nil value to an instance variable" do - setup do - @controller = build_response { @var = nil } - end - - should "accept assigning to that variable" do - assert_accepts assign_to(:var), @controller - end - end - -end diff --git a/test/matchers/controller/filter_param_matcher_test.rb b/test/matchers/controller/filter_param_matcher_test.rb deleted file mode 100644 index b96a7b91..00000000 --- a/test/matchers/controller/filter_param_matcher_test.rb +++ /dev/null @@ -1,40 +0,0 @@ -require 'test_helper' - -class FilterParamMatcherTest < ActionController::TestCase # :nodoc: - - context "a controller that filters no parameters" do - setup do - if Rails.respond_to?(:application) - Rails.application.config.filter_parameters = [] - end - @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 - if Rails.respond_to?(:application) - Rails.application.config.filter_parameters = [:password] - end - @controller = define_controller :examples do - unless Rails.respond_to?(:application) - filter_parameter_logging :password - end - 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/test/matchers/controller/redirect_to_matcher_test.rb b/test/matchers/controller/redirect_to_matcher_test.rb deleted file mode 100644 index 93439be0..00000000 --- a/test/matchers/controller/redirect_to_matcher_test.rb +++ /dev/null @@ -1,37 +0,0 @@ -require 'test_helper' - -class RedirectToMatcherTest < ActionController::TestCase # :nodoc: - - context "a controller that redirects" do - setup do - @controller = build_response { redirect_to '/some/url' } - end - - should "accept redirecting to that url" do - assert_accepts redirect_to('/some/url'), @controller - end - - should "reject redirecting to a different url" do - assert_rejects redirect_to('/some/other/url'), @controller - end - - should "accept redirecting to that url in a block" do - assert_accepts redirect_to('somewhere') { '/some/url' }, @controller - end - - should "reject redirecting to a different url in a block" do - assert_rejects redirect_to('somewhere else') { '/some/other/url' }, @controller - end - end - - context "a controller that doesn't redirect" do - setup do - @controller = build_response { render :text => 'hello' } - end - - should "reject redirecting to a url" do - assert_rejects redirect_to('/some/url'), @controller - end - end - -end diff --git a/test/matchers/controller/render_template_matcher_test.rb b/test/matchers/controller/render_template_matcher_test.rb deleted file mode 100644 index 4a3c617f..00000000 --- a/test/matchers/controller/render_template_matcher_test.rb +++ /dev/null @@ -1,37 +0,0 @@ -require 'test_helper' - -class RenderTemplateMatcherTest < ActionController::TestCase # :nodoc: - - context "a controller that renders a template" do - setup do - @controller = build_response(:action => 'show') { render } - end - - should "accept rendering that template" do - assert_accepts render_template(:show), @controller - end - - should "reject rendering a different template" do - assert_rejects render_template(:index), @controller - end - - should "accept rendering that template in the given context" do - assert_accepts self.class.render_template(:show).in_context(self), @controller - end - - should "reject rendering a different template in the given context" do - assert_rejects self.class.render_template(:index).in_context(self), @controller - end - end - - context "a controller that doesn't render a template" do - setup do - @controller = build_response { render :nothing => true } - end - - should "reject rendering a template" do - assert_rejects render_template(:show), @controller - end - end - -end diff --git a/test/matchers/controller/render_with_layout_matcher_test.rb b/test/matchers/controller/render_with_layout_matcher_test.rb deleted file mode 100644 index 91624396..00000000 --- a/test/matchers/controller/render_with_layout_matcher_test.rb +++ /dev/null @@ -1,47 +0,0 @@ -require 'test_helper' - -class RenderWithLayoutMatcherTest < ActionController::TestCase # :nodoc: - - context "a controller that renders with a layout" do - setup do - create_view('layouts/wide.html.erb', 'some content, <%= yield %>') - @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 - - context "given a context with layouts" do - setup do - @layout = 'happy' - @controller = build_response { render :layout => false } - @layouts = Hash.new(0) - @layouts[@layout] = 1 - end - - should "accept that layout in that context" do - assert_accepts render_with_layout(@layout).in_context(self), @controller - end - end - -end diff --git a/test/matchers/controller/respond_with_content_type_matcher_test.rb b/test/matchers/controller/respond_with_content_type_matcher_test.rb deleted file mode 100644 index cc9a9e4c..00000000 --- a/test/matchers/controller/respond_with_content_type_matcher_test.rb +++ /dev/null @@ -1,32 +0,0 @@ -require 'test_helper' - -class RespondWithContentTypeMatcherTest < ActionController::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 - - should "generate the correct test name" do - assert_equal "respond with content type of application/xml", - respond_with_content_type(:xml).description - end - -end diff --git a/test/matchers/controller/respond_with_matcher_test.rb b/test/matchers/controller/respond_with_matcher_test.rb deleted file mode 100644 index 51e4cd0c..00000000 --- a/test/matchers/controller/respond_with_matcher_test.rb +++ /dev/null @@ -1,96 +0,0 @@ -require 'test_helper' - -class RespondWithMatcherTest < ActionController::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 - -end - diff --git a/test/matchers/controller/route_matcher_test.rb b/test/matchers/controller/route_matcher_test.rb deleted file mode 100644 index 1f6096b3..00000000 --- a/test/matchers/controller/route_matcher_test.rb +++ /dev/null @@ -1,75 +0,0 @@ -require 'test_helper' - -class RouteToMatcherTest < ActionController::TestCase # :nodoc: - - context "given a controller with a defined glob url" do - setup do - @controller = define_controller('Examples').new - define_routes do |map| - map.connect 'examples/*id', :controller => 'examples', - :action => 'example' - end - end - - should "accept glob route" do - assert_accepts route(:get, '/examples/foo/bar'). - to(:action => 'example', :id => ['foo', 'bar']), - @controller - end - - end - - 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/test/matchers/controller/set_session_matcher_test.rb b/test/matchers/controller/set_session_matcher_test.rb deleted file mode 100644 index 293a2132..00000000 --- a/test/matchers/controller/set_session_matcher_test.rb +++ /dev/null @@ -1,48 +0,0 @@ -require 'test_helper' - -class SetSessionMatcherTest < ActionController::TestCase # :nodoc: - - context "a controller that sets a session variable" do - setup do - @controller = build_response do - session[:var] = 'value' - session[:false_var] = false - end - 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 - - should "accept assigning false to that variable" do - assert_accepts set_session(:false_var).to(false), @controller - end - - should "accept assigning to the same value in the test context" do - @expected = 'value' - assert_accepts set_session(:var).to { @expected }, @controller - end - - should "reject assigning to the another value in the test context" do - @expected = 'other' - assert_rejects set_session(:var).to { @expected }, @controller - end - end - -end diff --git a/test/matchers/controller/set_the_flash_matcher.rb b/test/matchers/controller/set_the_flash_matcher.rb deleted file mode 100644 index f1b6c976..00000000 --- a/test/matchers/controller/set_the_flash_matcher.rb +++ /dev/null @@ -1,95 +0,0 @@ -require 'test_helper' - -class SetTheFlashMatcherTest < ActionController::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 sets a flash.now message" do - setup do - @controller = build_response { flash.now[:notice] = 'value' } - end - - should "reject setting any flash message" do - assert_rejects set_the_flash, @controller - end - - should "accept setting any flash.now message" do - assert_accepts set_the_flash.now, @controller - end - - should "accept setting the exact flash.now message" do - assert_accepts set_the_flash.to('value').now, @controller - end - - should "accept setting a matched flash.now message" do - assert_accepts set_the_flash.to(/value/).now, @controller - end - - should "reject setting a different flash.now message" do - assert_rejects set_the_flash.to('other').now, @controller - end - - should "reject setting a different flash.now pattern" do - assert_rejects set_the_flash.to(/other/).now, @controller - end - end - - context "a controller that sets multiple flash messages" do - setup do - @controller = build_response { - flash.now[:notice] = 'value' - flash[:success] = 'great job' - } - end - - should "accept setting any flash.now message" do - assert_accepts set_the_flash.now, @controller - assert_accepts set_the_flash, @controller - end - - should "accept setting a matched flash.now message" do - assert_accepts set_the_flash.to(/value/).now, @controller - assert_accepts set_the_flash.to(/great/), @controller - end - - should "reject setting a different flash.now message" do - assert_rejects set_the_flash.to('other').now, @controller - 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/test/other/autoload_macro_test.rb b/test/other/autoload_macro_test.rb deleted file mode 100644 index e9599ea5..00000000 --- a/test/other/autoload_macro_test.rb +++ /dev/null @@ -1,18 +0,0 @@ -require 'test_helper' - -class AutoloadMacroTest < ActiveSupport::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/test/other/context_test.rb b/test/other/context_test.rb deleted file mode 100644 index a3cdd9d8..00000000 --- a/test/other/context_test.rb +++ /dev/null @@ -1,372 +0,0 @@ -require 'test_helper' - -class ContextTest < ActiveSupport::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 - - class ::SomeModel; end - - context "given a test named after a class" do - setup do - self.class.stubs(:name).returns("SomeModelTest") - end - - should "determine the described type" do - assert_equal SomeModel, self.class.described_type - end - - should "return a new instance of the described type as the subject if none exists" do - assert_kind_of SomeModel, subject - end - - context "with an explicit subject block" do - setup { @expected = SomeModel.new } - subject { @expected } - should "return the result of the block as the subject" do - assert_equal @expected, subject - end - - context "nested context block without a subject block" do - should "return the result of the parent context's subject block" do - assert_equal @expected, subject - end - end - end - end -end - -class ShouldMatcherTest < Test::Unit::TestCase - class FakeMatcher - attr_reader :subject - attr_accessor :fail - - def description - "do something" - end - - def matches?(subject) - @subject = subject - !@fail - end - - def failure_message - "a failure message" - end - - def negative_failure_message - "not a failure message" - end - end - - def run_test - @test_suite.run(@test_result) { |event, name |} - end - - def setup - @matcher = FakeMatcher.new - @test_result = Test::Unit::TestResult.new - class << @test_result - def failure_messages - @failures.map { |failure| failure.message } - end - end - end - - def create_test_suite(&definition) - test_class = Class.new(Test::Unit::TestCase, &definition) - test_class.suite - end - - def assert_failed_with(message, test_result) - assert_equal 1, test_result.failure_count - assert_equal [message], test_result.failure_messages - end - - def assert_passed(test_result) - assert_equal 0, test_result.failure_count - end - - def assert_test_named(expected_name, test_suite) - name = test_suite.tests.map { |test| test.method_name }.first - assert name.include?(expected_name), "Expected #{name} to include #{expected_name}" - end - - def self.should_use_positive_matcher - should "generate a test using the matcher's description" do - assert_test_named "should #{@matcher.description}", @test_suite - end - - should "pass with a passing matcher" do - @matcher.fail = false - run_test - assert_passed @test_result - end - - should "fail with a failing matcher" do - @matcher.fail = true - run_test - assert_failed_with @matcher.failure_message, @test_result - end - - should "provide the subject" do - @matcher.fail = false - run_test - assert_equal 'a subject', @matcher.subject - end - end - - def self.should_use_negative_matcher - should "generate a test using the matcher's description" do - assert_test_named "should not #{@matcher.description}", @test_suite - end - - should "pass with a failing matcher" do - @matcher.fail = true - run_test - assert_passed @test_result - end - - should "fail with a passing matcher" do - @matcher.fail = false - run_test - assert_failed_with @matcher.negative_failure_message, @test_result - end - - should "provide the subject" do - @matcher.fail = false - run_test - assert_equal 'a subject', @matcher.subject - end - end - - context "a should block with a matcher" do - setup do - matcher = @matcher - @test_suite = create_test_suite do - subject { 'a subject' } - should matcher - end - end - - should_use_positive_matcher - end - - context "a should block with a matcher within a context" do - setup do - matcher = @matcher - @test_suite = create_test_suite do - context "in context" do - subject { 'a subject' } - should matcher - end - end - end - - should_use_positive_matcher - end - - context "a should_not block with a matcher" do - setup do - matcher = @matcher - @test_suite = create_test_suite do - subject { 'a subject' } - should_not matcher - end - end - - should_use_negative_matcher - end - - context "a should_not block with a matcher within a context" do - setup do - matcher = @matcher - @test_suite = create_test_suite do - context "in context" do - subject { 'a subject' } - should_not matcher - end - end - end - - should_use_negative_matcher - end -end - -class Subject; end - -class SubjectTest < ActiveSupport::TestCase - - def setup - @expected = Subject.new - end - - subject { @expected } - - should "return a specified subject" do - assert_equal @expected, subject - end -end - -class SubjectLazinessTest < ActiveSupport::TestCase - subject { Subject.new } - - should "only build the subject once" do - assert_equal subject, subject - end -end - -class SomeController < ActionController::Base -end - -class ControllerSubjectTest < ActionController::TestCase - tests SomeController - - should "use the controller as the subject outside a context" do - assert_equal @controller, subject - end - - context "in a context" do - should "use the controller as the subject" do - assert_equal @controller, subject - end - end -end diff --git a/test/other/convert_to_should_syntax_test.rb b/test/other/convert_to_should_syntax_test.rb deleted file mode 100644 index 4aa3f7f0..00000000 --- a/test/other/convert_to_should_syntax_test.rb +++ /dev/null @@ -1,63 +0,0 @@ -require 'test/unit' - -class ConvertToShouldSyntaxTest < ActiveSupport::TestCase # :nodoc: - - BEFORE_FIXTURE = <<-EOS - class DummyTest < ActiveSupport::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 < ActiveSupport::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/test/other/helpers_test.rb b/test/other/helpers_test.rb deleted file mode 100644 index 631b52c9..00000000 --- a/test/other/helpers_test.rb +++ /dev/null @@ -1,126 +0,0 @@ -require 'test_helper' -require 'action_mailer' -require 'mocha' - -class HelpersTest < ActiveSupport::TestCase # :nodoc: - - 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 "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 with no message expectation" do - assert_accepts @matcher, 'target' - end - - should "pass when given to assert_accepts with a matching message" do - assert_accepts @matcher, 'target', :message => /big time/ - end - - should "fail when given to assert_accepts with non-matching message" do - assert_raise Test::Unit::AssertionFailedError do - assert_accepts @matcher, 'target', :message => /small time/ - end - 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 with no message expectation" do - assert_rejects @matcher, 'target' - end - - should "pass when given to assert_rejects with a matching message" do - assert_rejects @matcher, 'target', :message => /big time/ - end - - should "fail when given to assert_rejects with a non-matching message" do - assert_raise Test::Unit::AssertionFailedError do - assert_rejects @matcher, 'target', :message => /small time/ - end - 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 - - should "assign context to a support matching on assert_accepts" do - matcher = stub('matcher', :matches? => true) - matcher.expects(:in_context).with(self) - assert_accepts matcher, nil - end - - should "assign context to a support matching on assert_rejects" do - matcher = stub('matcher', :matches? => false) - matcher.expects(:in_context).with(self) - assert_rejects matcher, nil - end -end diff --git a/test/other/should_test.rb b/test/other/should_test.rb deleted file mode 100644 index 1767e8d2..00000000 --- a/test/other/should_test.rb +++ /dev/null @@ -1,271 +0,0 @@ -require 'test_helper' - -class ShouldTest < ActiveSupport::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_be_able_to_setup_a_should_eventually_in_a_class_method - should "be able to setup a should eventually in a class method" - 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_be_able_to_setup_a_should_eventually_in_a_class_method - - 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 = ActiveSupport::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 = ActiveSupport::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/test/rails3_root/Gemfile b/test/rails3_root/Gemfile deleted file mode 100644 index 6044dd42..00000000 --- a/test/rails3_root/Gemfile +++ /dev/null @@ -1,28 +0,0 @@ -source 'http://rubygems.org' - -gem 'rails', '3.0.0.beta4' - -# Bundle edge Rails instead: -# gem 'rails', :git => 'git://github.com/rails/rails.git' - -gem 'sqlite3-ruby', :require => 'sqlite3' - -gem 'mocha' - -# Use unicorn as the web server -# gem 'unicorn' - -# Deploy with Capistrano -# gem 'capistrano' - -# Bundle the extra gems: -# gem 'bj' -# gem 'nokogiri', '1.4.1' -# gem 'sqlite3-ruby', :require => 'sqlite3' -# gem 'aws-s3', :require => 'aws/s3' - -# Bundle gems for certain environments: -# gem 'rspec', :group => :test -# group :test do -# gem 'webrat' -# end diff --git a/test/rspec_test.rb b/test/rspec_test.rb deleted file mode 100644 index 77e918e0..00000000 --- a/test/rspec_test.rb +++ /dev/null @@ -1,207 +0,0 @@ -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 < ActiveSupport::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/test/test_helper.rb b/test/test_helper.rb deleted file mode 100644 index b070f68b..00000000 --- a/test/test_helper.rb +++ /dev/null @@ -1,34 +0,0 @@ -require 'fileutils' -require 'test/unit' - -ENV['RAILS_ENV'] = 'test' - -ENV['RAILS_VERSION'] ||= '3.0.0.beta4' -RAILS_GEM_VERSION = ENV['RAILS_VERSION'] - -rails_root = File.dirname(__FILE__) + '/rails3_root' -ENV['BUNDLE_GEMFILE'] = rails_root + '/Gemfile' -require "#{rails_root}/config/environment.rb" -require 'test/rails3_model_builder' -require 'rails/test_help' - -shoulda_path = File.join(File.dirname(__FILE__), '..', 'lib') -$LOAD_PATH << shoulda_path -require 'shoulda' - -# Run the migrations -ActiveRecord::Migration.verbose = false -ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate") - -# Setup the fixtures path -ActiveSupport::TestCase.fixture_path = - File.join(File.dirname(__FILE__), "fixtures") - -class ActiveSupport::TestCase #:nodoc: - self.use_transactional_fixtures = false - self.use_instantiated_fixtures = false -end - -Shoulda.autoload_macros File.join(File.dirname(__FILE__), 'rails3_root'), - File.join("vendor", "{plugins,gems}", "*") -