-
-
Notifications
You must be signed in to change notification settings - Fork 909
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove auto-detection of Rails / test framework
- Loading branch information
Showing
37 changed files
with
718 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,22 @@ | ||
require 'shoulda/matchers/assertion_error' | ||
require 'shoulda/matchers/configuration' | ||
require 'shoulda/matchers/doublespeak' | ||
require 'shoulda/matchers/error' | ||
require 'shoulda/matchers/independent' | ||
require 'shoulda/matchers/integrations' | ||
require 'shoulda/matchers/matcher_context' | ||
require 'shoulda/matchers/rails_shim' | ||
require 'shoulda/matchers/util' | ||
require 'shoulda/matchers/version' | ||
require 'shoulda/matchers/warn' | ||
|
||
require 'shoulda/matchers/independent' | ||
require 'shoulda/matchers/action_controller' | ||
require 'shoulda/matchers/active_model' | ||
require 'shoulda/matchers/active_record' | ||
|
||
if defined?(ActiveModel) | ||
require 'shoulda/matchers/active_model' | ||
module Shoulda | ||
module Matchers | ||
class << self | ||
attr_accessor :assertion_exception_class | ||
end | ||
end | ||
end | ||
|
||
if defined?(ActiveRecord) | ||
require 'shoulda/matchers/active_record' | ||
end | ||
|
||
if defined?(ActionController) | ||
require 'shoulda/matchers/action_controller' | ||
end | ||
|
||
if defined?(RSpec) | ||
require 'shoulda/matchers/integrations/rspec' | ||
end | ||
|
||
require 'shoulda/matchers/integrations/test_unit' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module Shoulda | ||
module Matchers | ||
# @private | ||
def self.configure | ||
yield configuration | ||
end | ||
|
||
# @private | ||
def self.configuration | ||
@_configuration ||= Configuration.new | ||
end | ||
|
||
# @private | ||
class Configuration | ||
def integrate(&block) | ||
Integrations::Configuration.apply(self, &block) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
module Shoulda | ||
module Matchers | ||
module Integrations | ||
class << self | ||
def register_library(klass, name) | ||
library_registry.register(klass, name) | ||
end | ||
|
||
def find_library!(name) | ||
library_registry.find!(name) | ||
end | ||
|
||
def register_test_framework(klass, name) | ||
test_framework_registry.register(klass, name) | ||
end | ||
|
||
def find_test_framework!(name) | ||
test_framework_registry.find!(name) | ||
end | ||
|
||
private | ||
|
||
def library_registry | ||
@_library_registry ||= Registry.new | ||
end | ||
|
||
def test_framework_registry | ||
@_test_framework_registry ||= Registry.new | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
require 'shoulda/matchers/integrations/configuration' | ||
require 'shoulda/matchers/integrations/configuration_error' | ||
require 'shoulda/matchers/integrations/inclusion' | ||
require 'shoulda/matchers/integrations/rails' | ||
require 'shoulda/matchers/integrations/registry' | ||
|
||
require 'shoulda/matchers/integrations/libraries' | ||
require 'shoulda/matchers/integrations/test_frameworks' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
require 'set' | ||
|
||
module Shoulda | ||
module Matchers | ||
module Integrations | ||
# @private | ||
class Configuration | ||
def self.apply(configuration, &block) | ||
new(configuration, &block).apply | ||
end | ||
|
||
def initialize(configuration, &block) | ||
@test_frameworks = Set.new | ||
|
||
test_framework :missing_test_framework | ||
library :missing_library | ||
|
||
block.call(self) | ||
end | ||
|
||
def test_framework(name) | ||
clear_default_test_framework | ||
@test_frameworks << Integrations.find_test_framework!(name) | ||
end | ||
|
||
def library(name) | ||
@library = Integrations.find_library!(name) | ||
end | ||
|
||
def apply | ||
if no_test_frameworks_added? && library_not_set? | ||
raise ConfigurationError, <<EOT | ||
shoulda-matchers is not configured correctly. You need to specify a test | ||
framework and/or library. For example: | ||
Shoulda::Matchers.configure do |config| | ||
config.integrate do |with| | ||
with.test_framework :rspec | ||
with.library :rails | ||
end | ||
end | ||
EOT | ||
end | ||
|
||
@test_frameworks.each do |test_framework| | ||
test_framework.include(Shoulda::Matchers::Independent) | ||
@library.integrate_with(test_framework) | ||
end | ||
end | ||
|
||
private | ||
|
||
def clear_default_test_framework | ||
@test_frameworks.select!(&:present?) | ||
end | ||
|
||
def no_test_frameworks_added? | ||
@test_frameworks.empty? || !@test_frameworks.any?(&:present?) | ||
end | ||
|
||
def library_not_set? | ||
@library.nil? | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module Shoulda | ||
module Matchers | ||
module Integrations | ||
class ConfigurationError < StandardError | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module Shoulda | ||
module Matchers | ||
module Integrations | ||
module Inclusion | ||
def include_into(mod, *other_mods, &block) | ||
mods_to_include = other_mods.dup | ||
mods_to_extend = other_mods.dup | ||
|
||
if block | ||
mods_to_include << Module.new(&block) | ||
end | ||
|
||
mod.__send__(:include, *mods_to_include) | ||
mod.extend(*mods_to_extend) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'shoulda/matchers/integrations/libraries/action_controller' | ||
require 'shoulda/matchers/integrations/libraries/active_model' | ||
require 'shoulda/matchers/integrations/libraries/active_record' | ||
require 'shoulda/matchers/integrations/libraries/missing_library' | ||
require 'shoulda/matchers/integrations/libraries/rails' |
30 changes: 30 additions & 0 deletions
30
lib/shoulda/matchers/integrations/libraries/action_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
module Shoulda | ||
module Matchers | ||
module Integrations | ||
module Libraries | ||
class ActionController | ||
Integrations.register_library(self, :action_controller) | ||
|
||
include Integrations::Inclusion | ||
include Integrations::Rails | ||
|
||
def integrate_with(test_framework) | ||
test_framework.include(matchers_module) | ||
|
||
include_into(::ActionController::TestCase, matchers_module) do | ||
def subject | ||
@controller | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def matchers_module | ||
Shoulda::Matchers::ActionController | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
25 changes: 25 additions & 0 deletions
25
lib/shoulda/matchers/integrations/libraries/active_model.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
module Shoulda | ||
module Matchers | ||
module Integrations | ||
module Libraries | ||
class ActiveModel | ||
Integrations.register_library(self, :active_model) | ||
|
||
include Integrations::Inclusion | ||
include Integrations::Rails | ||
|
||
def integrate_with(test_framework) | ||
test_framework.include(matchers_module) | ||
include_into(ActiveSupport::TestCase, matchers_module) | ||
end | ||
|
||
private | ||
|
||
def matchers_module | ||
Shoulda::Matchers::ActiveModel | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
25 changes: 25 additions & 0 deletions
25
lib/shoulda/matchers/integrations/libraries/active_record.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
module Shoulda | ||
module Matchers | ||
module Integrations | ||
module Libraries | ||
class ActiveRecord | ||
Integrations.register_library(self, :active_record) | ||
|
||
include Integrations::Inclusion | ||
include Integrations::Rails | ||
|
||
def integrate_with(test_framework) | ||
test_framework.include(matchers_module) | ||
include_into(ActiveSupport::TestCase, matchers_module) | ||
end | ||
|
||
private | ||
|
||
def matchers_module | ||
Shoulda::Matchers::ActiveRecord | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
18 changes: 18 additions & 0 deletions
18
lib/shoulda/matchers/integrations/libraries/missing_library.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module Shoulda | ||
module Matchers | ||
module Integrations | ||
module Libraries | ||
class MissingLibrary | ||
Integrations.register_library(self, :missing_library) | ||
|
||
def integrate_with(test_framework) | ||
end | ||
|
||
def rails? | ||
false | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
module Shoulda | ||
module Matchers | ||
module Integrations | ||
module Libraries | ||
class Rails | ||
Integrations.register_library(self, :rails) | ||
|
||
include Integrations::Rails | ||
|
||
SUB_LIBRARIES = [ | ||
:active_model, | ||
:active_record, | ||
:action_controller | ||
] | ||
|
||
def integrate_with(test_framework) | ||
Shoulda::Matchers.assertion_exception_class = | ||
ActiveSupport::TestCase::Assertion | ||
|
||
SUB_LIBRARIES.each do |name| | ||
library = Integrations.find_library!(name) | ||
library.integrate_with(test_framework) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.