From 721900b8fde6806053e9c7872130c496386b5b4a Mon Sep 17 00:00:00 2001 From: Lucas D'Avila Date: Thu, 7 May 2015 01:43:35 -0300 Subject: [PATCH] Allow the use of matchers from multiple libs, for non rails projects. * It changes shoulda-matchers to allow the integration with multiple libraries like active_model and active_record. For example, in a non Rails project isn't possible to use both validate_presence_of and validate_uniqueness_of matchers, because they are from different libraries (one from active_model and the other from active_record respectively). This change allow the integration with multiple libraries. fixes #710 --- NEWS.md | 6 +-- README.md | 4 +- .../matchers/integrations/configuration.rb | 15 +++--- .../active_model_integration_spec.rb | 2 +- .../multiple_libraries_integration_spec.rb | 52 +++++++++++++++++++ spec/acceptance/rails_integration_spec.rb | 10 ++-- .../adds_shoulda_matchers_to_project.rb | 27 +++++----- 7 files changed, 83 insertions(+), 33 deletions(-) create mode 100644 spec/acceptance/multiple_libraries_integration_spec.rb diff --git a/NEWS.md b/NEWS.md index 3a37d605..289288ba 100644 --- a/NEWS.md +++ b/NEWS.md @@ -19,7 +19,7 @@ include the gem as normal. * You'll need to add the following somewhere in your `rails_helper` (for RSpec) or `test_helper` (for Minitest / Test::Unit): - + ``` ruby Shoulda::Matchers.configure do |config| config.integrate do |with| @@ -29,11 +29,11 @@ with.test_framework :minitest_4 with.test_framework :test_unit - # Choose a library: + # Choose one or more libraries: with.library :active_record with.library :active_model with.library :action_controller - # Or, choose all of the above: + # Or, choose the following (which implies all of the above): with.library :rails end end diff --git a/README.md b/README.md index ba65c148..6af05905 100644 --- a/README.md +++ b/README.md @@ -165,11 +165,11 @@ Shoulda::Matchers.configure do |config| with.test_framework :minitest_4 with.test_framework :test_unit - # Choose a library: + # Choose one or more libraries: with.library :active_record with.library :active_model with.library :action_controller - # Or, choose all of the above: + # Or, choose the following (which implies all of the above): with.library :rails end end diff --git a/lib/shoulda/matchers/integrations/configuration.rb b/lib/shoulda/matchers/integrations/configuration.rb index dd504f8f..b7179bf3 100644 --- a/lib/shoulda/matchers/integrations/configuration.rb +++ b/lib/shoulda/matchers/integrations/configuration.rb @@ -11,6 +11,7 @@ module Shoulda def initialize(configuration, &block) @test_frameworks = Set.new + @libraries = Set.new test_framework :missing_test_framework library :missing_library @@ -24,14 +25,14 @@ module Shoulda end def library(name) - @library = Integrations.find_library!(name) + @libraries << Integrations.find_library!(name) end def apply - if no_test_frameworks_added? && library_not_set? + if no_test_frameworks_added? && no_libraries_added? raise ConfigurationError, <