diff --git a/Rakefile b/Rakefile index c56347e5..583436b9 100644 --- a/Rakefile +++ b/Rakefile @@ -8,9 +8,9 @@ require_relative 'lib/shoulda/matchers/version' CURRENT_VERSION = Shoulda::Matchers::VERSION -RSpec::Core::RakeTask.new do |t| +RSpec::Core::RakeTask.new('spec:unit') do |t| t.ruby_opts = '-w -r ./spec/report_warnings' - t.pattern = "spec/**/*_spec.rb" + t.pattern = "spec/unit/**/*_spec.rb" t.rspec_opts = '--color --format progress' t.verbose = false end @@ -30,7 +30,7 @@ end task :default do if ENV['BUNDLE_GEMFILE'] =~ /gemfiles/ - Rake::Task['spec'].invoke + sh 'rake spec:unit' Rake::Task['cucumber'].invoke else Rake::Task['appraise'].invoke diff --git a/spec/support/unit/helpers/active_model_helpers.rb b/spec/support/unit/helpers/active_model_helpers.rb index 29b2a95e..f2f95e26 100644 --- a/spec/support/unit/helpers/active_model_helpers.rb +++ b/spec/support/unit/helpers/active_model_helpers.rb @@ -1,23 +1,25 @@ -module ActiveModelHelpers - def custom_validation(options = {}, &block) - attribute_name = options.fetch(:attribute_name, :attr) - attribute_type = options.fetch(:attribute_type, :integer) +module UnitTests + module ActiveModelHelpers + def self.configure_example_group(example_group) + example_group.include(self) + end - define_model(:example, attribute_name => attribute_type) do - validate :custom_validation + def custom_validation(options = {}, &block) + attribute_name = options.fetch(:attribute_name, :attr) + attribute_type = options.fetch(:attribute_type, :integer) - define_method(:custom_validation, &block) - end.new - end - alias record_with_custom_validation custom_validation + define_model(:example, attribute_name => attribute_type) do + validate :custom_validation - def validating_format(options) - define_model :example, attr: :string do - validates_format_of :attr, options - end.new + define_method(:custom_validation, &block) + end.new + end + alias record_with_custom_validation custom_validation + + def validating_format(options) + define_model :example, attr: :string do + validates_format_of :attr, options + end.new + end end end - -RSpec.configure do |c| - c.include ActiveModelHelpers -end diff --git a/spec/support/unit/helpers/active_model_versions.rb b/spec/support/unit/helpers/active_model_versions.rb index 0b9a31d9..8bc5686a 100644 --- a/spec/support/unit/helpers/active_model_versions.rb +++ b/spec/support/unit/helpers/active_model_versions.rb @@ -1,13 +1,20 @@ -RSpec.configure do |c| - def active_model_3_1? - (::ActiveModel::VERSION::MAJOR == 3 && ::ActiveModel::VERSION::MINOR >= 1) || active_model_4_0? - end +module UnitTests + module ActiveModelVersions + def self.configure_example_group(example_group) + example_group.include(self) + example_group.extend(self) + end - def active_model_3_2? - (::ActiveModel::VERSION::MAJOR == 3 && ::ActiveModel::VERSION::MINOR >= 2) || active_model_4_0? - end + def active_model_3_1? + (::ActiveModel::VERSION::MAJOR == 3 && ::ActiveModel::VERSION::MINOR >= 1) || active_model_4_0? + end - def active_model_4_0? - ::ActiveModel::VERSION::MAJOR == 4 + def active_model_3_2? + (::ActiveModel::VERSION::MAJOR == 3 && ::ActiveModel::VERSION::MINOR >= 2) || active_model_4_0? + end + + def active_model_4_0? + ::ActiveModel::VERSION::MAJOR == 4 + end end end diff --git a/spec/support/unit/helpers/active_resource_builder.rb b/spec/support/unit/helpers/active_resource_builder.rb index c844b4f7..b3b490d3 100644 --- a/spec/support/unit/helpers/active_resource_builder.rb +++ b/spec/support/unit/helpers/active_resource_builder.rb @@ -1,29 +1,27 @@ require 'active_resource' -module ActiveResourceBuilder - def self.included(example_group) - example_group.class_eval do - after do +module UnitTests + module ActiveResourceBuilder + def self.configure_example_group(example_group) + example_group.include ActiveResourceBuilder + + example_group.after do ActiveSupport::Dependencies.clear end end - end - def define_active_resource_class(class_name, attributes = {}, &block) - define_class(class_name, ActiveResource::Base) do - schema do - attributes.each do |attr, type| - attribute attr, type + def define_active_resource_class(class_name, attributes = {}, &block) + define_class(class_name, ActiveResource::Base) do + schema do + attributes.each do |attr, type| + attribute attr, type + end end - end - if block_given? - class_eval(&block) + if block_given? + class_eval(&block) + end end end end end - -RSpec.configure do |config| - config.include ActiveResourceBuilder -end diff --git a/spec/support/unit/helpers/allow_value_matcher_helpers.rb b/spec/support/unit/helpers/allow_value_matcher_helpers.rb index 9e9b7308..c4143989 100644 --- a/spec/support/unit/helpers/allow_value_matcher_helpers.rb +++ b/spec/support/unit/helpers/allow_value_matcher_helpers.rb @@ -1,6 +1,7 @@ -require_relative '../model_builder' +require_relative '../record_with_different_error_attribute_builder' +require_relative '../record_builder_with_i18n_validation_message' -module Helpers +module UnitTests module AllowValueMatcherHelpers def builder_for_record_with_different_error_attribute(options = {}) RecordWithDifferentErrorAttributeBuilder.new(options) @@ -10,94 +11,5 @@ module Helpers builder = builder_for_record_with_different_error_attribute(options) RecordBuilderWithI18nValidationMessage.new(builder) end - - class RecordWithDifferentErrorAttributeBuilder - include ModelBuilder - - def initialize(options) - @options = options.reverse_merge(default_options) - end - - def attribute_that_receives_error - options[:attribute_that_receives_error] - end - - def attribute_to_validate - options[:attribute_to_validate] - end - - def message - options[:message] - end - - def message=(message) - options[:message] = message - end - - def model - @_model ||= create_model - end - - def model_name - 'Example' - end - - def record - model.new - end - - def valid_value - 'some value' - end - - protected - - attr_reader :options - - private - - def context - { - validation_method_name: validation_method_name, - valid_value: valid_value, - attribute_to_validate: attribute_to_validate, - attribute_that_receives_error: attribute_that_receives_error, - message: message - } - end - - def create_model - _context = context - - define_model model_name, model_columns do - validate _context[:validation_method_name] - - define_method(_context[:validation_method_name]) do - if self[_context[:attribute_to_validate]] != _context[:valid_value] - self.errors.add(_context[:attribute_that_receives_error], _context[:message]) - end - end - end - end - - def validation_method_name - :custom_validation - end - - def model_columns - { - attribute_to_validate => :string, - attribute_that_receives_error => :string - } - end - - def default_options - { - attribute_that_receives_error: :attribute_that_receives_error, - attribute_to_validate: :attribute_to_validate, - message: 'some message' - } - end - end end end diff --git a/spec/support/unit/helpers/class_builder.rb b/spec/support/unit/helpers/class_builder.rb index 23a23186..fff1290c 100644 --- a/spec/support/unit/helpers/class_builder.rb +++ b/spec/support/unit/helpers/class_builder.rb @@ -1,69 +1,80 @@ -module ClassBuilder - def self.parse_constant_name(name) - namespace = Shoulda::Matchers::Util.deconstantize(name) - qualified_namespace = (namespace.presence || 'Object').constantize - name_without_namespace = name.to_s.demodulize - [qualified_namespace, name_without_namespace] - end - - def self.teardown_defined_constants - ActiveSupport::Dependencies.clear - end - - def define_module(module_name, &block) - module_name = module_name.to_s.camelize - - namespace, name_without_namespace = - ClassBuilder.parse_constant_name(module_name) - - if namespace.const_defined?(name_without_namespace, false) - namespace.__send__(:remove_const, name_without_namespace) +module UnitTests + module ClassBuilder + def self.parse_constant_name(name) + namespace = Shoulda::Matchers::Util.deconstantize(name) + qualified_namespace = (namespace.presence || 'Object').constantize + name_without_namespace = name.to_s.demodulize + [qualified_namespace, name_without_namespace] end - eval <<-RUBY - module #{namespace}::#{name_without_namespace} - end - RUBY + def self.configure_example_group(example_group) + example_group.include(self) - namespace.const_get(name_without_namespace).tap do |constant| - constant.unloadable - - if block - constant.module_eval(&block) + example_group.after do + teardown_defined_constants end end - end - def define_class(class_name, parent_class = Object, &block) - class_name = class_name.to_s.camelize + def define_module(module_name, &block) + module_name = module_name.to_s.camelize - namespace, name_without_namespace = - ClassBuilder.parse_constant_name(class_name) + namespace, name_without_namespace = + ClassBuilder.parse_constant_name(module_name) - if namespace.const_defined?(name_without_namespace, false) - namespace.__send__(:remove_const, name_without_namespace) + if namespace.const_defined?(name_without_namespace, false) + namespace.__send__(:remove_const, name_without_namespace) + end + + eval <<-RUBY + module #{namespace}::#{name_without_namespace} + end + RUBY + + namespace.const_get(name_without_namespace).tap do |constant| + constant.unloadable + + if block + constant.module_eval(&block) + end + end end - eval <<-RUBY - class #{namespace}::#{name_without_namespace} < #{parent_class} - end - RUBY + def define_class(class_name, parent_class = Object, &block) + class_name = class_name.to_s.camelize - namespace.const_get(name_without_namespace).tap do |constant| - constant.unloadable + namespace, name_without_namespace = + ClassBuilder.parse_constant_name(class_name) - if block_given? - constant.class_eval(&block) + if namespace.const_defined?(name_without_namespace, false) + namespace.__send__(:remove_const, name_without_namespace) end - if constant.respond_to?(:reset_column_information) - constant.reset_column_information + eval <<-RUBY + class #{namespace}::#{name_without_namespace} < #{parent_class} + end + RUBY + + namespace.const_get(name_without_namespace).tap do |constant| + constant.unloadable + + if block_given? + constant.class_eval(&block) + end + + if constant.respond_to?(:reset_column_information) + constant.reset_column_information + end end end + + private + + def teardown_defined_constants + ActiveSupport::Dependencies.clear + end + + def teardown_defined_constants + ActiveSupport::Dependencies.clear + end end end - -RSpec.configure do |config| - config.include ClassBuilder - config.after { ClassBuilder.teardown_defined_constants } -end diff --git a/spec/support/unit/helpers/confirmation_matcher_helpers.rb b/spec/support/unit/helpers/confirmation_matcher_helpers.rb index 0e0e3bcf..70933203 100644 --- a/spec/support/unit/helpers/confirmation_matcher_helpers.rb +++ b/spec/support/unit/helpers/confirmation_matcher_helpers.rb @@ -1,6 +1,7 @@ -require_relative '../model_builder' +require_relative '../record_validating_confirmation_builder' +require_relative '../record_builder_with_i18n_validation_message' -module Helpers +module UnitTests module ConfirmationMatcherHelpers def builder_for_record_validating_confirmation(options = {}) RecordValidatingConfirmationBuilder.new(options) @@ -12,58 +13,5 @@ module Helpers validation_message_key: :confirmation ) end - - class RecordValidatingConfirmationBuilder - include ModelBuilder - - def initialize(options) - @options = options - end - - def model - @_model ||= create_model - end - - def model_name - 'Example' - end - - def record - model.new - end - - def message=(message) - options[:message] = message - end - - def attribute_to_confirm - :attribute_to_confirm - end - alias_method :attribute, :attribute_to_confirm - - def confirmation_attribute - :"#{attribute_to_confirm}_confirmation" - end - - def attribute_that_receives_error - Shoulda::Matchers::RailsShim. - validates_confirmation_of_error_attribute(self) - end - - protected - - attr_reader :options - - private - - def create_model - _attribute = attribute_to_confirm - _options = options - - define_model(model_name, _attribute => :string) do - validates_confirmation_of(_attribute, _options) - end - end - end end end diff --git a/spec/support/unit/helpers/controller_builder.rb b/spec/support/unit/helpers/controller_builder.rb index 11207c65..1bd62a23 100644 --- a/spec/support/unit/helpers/controller_builder.rb +++ b/spec/support/unit/helpers/controller_builder.rb @@ -1,102 +1,98 @@ -module ControllerBuilder - def self.included(example_group) - example_group.class_eval do - after do +module UnitTests + module ControllerBuilder + def self.configure_example_group(example_group) + example_group.include(self) + + example_group.after do delete_temporary_views restore_original_routes end end - end - def define_controller(class_name, &block) - class_name = class_name.to_s - class_name << 'Controller' unless class_name =~ /Controller$/ - define_class(class_name, ActionController::Base, &block) - end - - def define_routes(&block) - @routes = $test_app.draw_routes(&block) - class << self - include ActionDispatch::Assertions - end - end - - def build_fake_response(opts = {}, &block) - action = opts[:action] || 'example' - partial = opts[:partial] || '_partial' - block ||= lambda { render nothing: true } - controller_class = define_controller('Examples') do - layout false - define_method(action, &block) - end - controller_class.view_paths = [ $test_app.temp_views_dir_path ] - - define_routes do - get 'examples', to: "examples##{action}" + def define_controller(class_name, &block) + class_name = class_name.to_s + class_name << 'Controller' unless class_name =~ /Controller$/ + define_class(class_name, ActionController::Base, &block) end - create_view("examples/#{action}.html.erb", 'action') - create_view("examples/#{partial}.html.erb", 'partial') - - setup_rails_controller_test(controller_class) - get action - - @controller - end - - def setup_rails_controller_test(controller_class) - @controller = controller_class.new - @request = ::ActionController::TestRequest.new - @response = ::ActionController::TestResponse.new - - class << self - include ActionController::TestCase::Behavior - end - end - - def create_view(path, contents) - $test_app.create_temp_view(path, contents) - end - - def controller_for_resource_with_strong_parameters(options = {}, &action_body) - model_name = options.fetch(:model_name, 'User') - controller_name = options.fetch(:controller_name, 'UsersController') - collection_name = controller_name. - to_s.sub(/Controller$/, '').underscore. - to_sym - action_name = options.fetch(:action, :some_action) - routes ||= options.fetch(:routes, -> { resources collection_name }) - - define_model(model_name) - - controller_class = define_controller(controller_name) do - define_method action_name do - if action_body - instance_eval(&action_body) - end - - render nothing: true + def define_routes(&block) + @routes = $test_app.draw_routes(&block) + class << self + include ActionDispatch::Assertions end end - setup_rails_controller_test(controller_class) + def build_fake_response(opts = {}, &block) + action = opts[:action] || 'example' + partial = opts[:partial] || '_partial' + block ||= lambda { render nothing: true } + controller_class = define_controller('Examples') do + layout false + define_method(action, &block) + end + controller_class.view_paths = [ $test_app.temp_views_directory.to_s ] - define_routes(&routes) + define_routes do + get 'examples', to: "examples##{action}" + end - controller_class - end + create_view("examples/#{action}.html.erb", 'action') + create_view("examples/#{partial}.html.erb", 'partial') - private + setup_rails_controller_test(controller_class) + get action - def delete_temporary_views - $test_app.delete_temp_views - end + @controller + end - def restore_original_routes - Rails.application.reload_routes! + def setup_rails_controller_test(controller_class) + @controller = controller_class.new + @request = ::ActionController::TestRequest.new + @response = ::ActionController::TestResponse.new + + class << self + include ActionController::TestCase::Behavior + end + end + + def create_view(path, contents) + $test_app.create_temp_view(path, contents) + end + + def controller_for_resource_with_strong_parameters(options = {}, &action_body) + model_name = options.fetch(:model_name, 'User') + controller_name = options.fetch(:controller_name, 'UsersController') + collection_name = controller_name. + to_s.sub(/Controller$/, '').underscore. + to_sym + action_name = options.fetch(:action, :some_action) + routes ||= options.fetch(:routes, -> { resources collection_name }) + + define_model(model_name) + + controller_class = define_controller(controller_name) do + define_method action_name do + if action_body + instance_eval(&action_body) + end + + render nothing: true + end + end + + setup_rails_controller_test(controller_class) + + define_routes(&routes) + + controller_class + end + + def delete_temporary_views + $test_app.delete_temp_views + end + + def restore_original_routes + Rails.application.reload_routes! + end end end - -RSpec.configure do |config| - config.include ControllerBuilder -end diff --git a/spec/support/unit/helpers/i18n_faker.rb b/spec/support/unit/helpers/i18n_faker.rb index 1497fbdb..aa46b97a 100644 --- a/spec/support/unit/helpers/i18n_faker.rb +++ b/spec/support/unit/helpers/i18n_faker.rb @@ -1,13 +1,15 @@ -module I18nFaker - extend self +module UnitTests + module I18nFaker + extend self - def stub_translation(key_or_keys, message) - keys = [key_or_keys].flatten.join('.').split('.') - tree = keys.reverse.inject(message) { |data, key| { key => data } } - I18n.backend.store_translations(:en, tree) + def self.configure_example_group(example_group) + example_group.include(self) + end + + def stub_translation(key_or_keys, message) + keys = [key_or_keys].flatten.join('.').split('.') + tree = keys.reverse.inject(message) { |data, key| { key => data } } + I18n.backend.store_translations(:en, tree) + end end end - -RSpec.configure do |config| - config.include I18nFaker -end diff --git a/spec/support/unit/helpers/mailer_builder.rb b/spec/support/unit/helpers/mailer_builder.rb index 764aaed2..9e284f03 100644 --- a/spec/support/unit/helpers/mailer_builder.rb +++ b/spec/support/unit/helpers/mailer_builder.rb @@ -1,10 +1,12 @@ -module MailerBuilder - def define_mailer(name, paths, &block) - class_name = name.to_s.pluralize.classify - define_class(class_name, ActionMailer::Base, &block) +module UnitTests + module MailerBuilder + def self.configure_example_group(example_group) + example_group.include(self) + end + + def define_mailer(name, paths, &block) + class_name = name.to_s.pluralize.classify + define_class(class_name, ActionMailer::Base, &block) + end end end - -RSpec.configure do |config| - config.include MailerBuilder -end diff --git a/spec/support/unit/helpers/model_builder.rb b/spec/support/unit/helpers/model_builder.rb index 43a339a3..5397842c 100644 --- a/spec/support/unit/helpers/model_builder.rb +++ b/spec/support/unit/helpers/model_builder.rb @@ -1,91 +1,91 @@ require_relative 'class_builder' -module ModelBuilder - include ClassBuilder +module UnitTests + module ModelBuilder + include ClassBuilder - def self.drop_created_tables - connection = ActiveRecord::Base.connection + def self.configure_example_group(example_group) + example_group.include(self) - created_tables.each do |table_name| - connection.execute("DROP TABLE IF EXISTS #{table_name}") - end - end - - def self.created_tables - @_created_tables ||= [] - end - - def create_table(table_name, options = {}, &block) - connection = ActiveRecord::Base.connection - - begin - connection.execute("DROP TABLE IF EXISTS #{table_name}") - connection.create_table(table_name, options, &block) - ModelBuilder.created_tables << table_name - connection - rescue Exception => e - connection.execute("DROP TABLE IF EXISTS #{table_name}") - raise e - end - end - - def define_model_class(class_name, &block) - define_class(class_name, ActiveRecord::Base, &block) - end - - def define_active_model_class(class_name, options = {}, &block) - define_class(class_name) do - include ActiveModel::Validations - - options[:accessors].each do |column| - attr_accessor column.to_sym - end - - if block_given? - class_eval(&block) + example_group.after do + drop_created_tables end end - end - def define_model(name, columns = {}, &block) - class_name = name.to_s.pluralize.classify - table_name = class_name.tableize.gsub('/', '_') + def create_table(table_name, options = {}, &block) + connection = ActiveRecord::Base.connection - table_block = lambda do |table| - columns.each do |name, specification| - if specification.is_a?(Hash) - table.column name, specification[:type], specification[:options] - else - table.column name, specification + begin + connection.execute("DROP TABLE IF EXISTS #{table_name}") + connection.create_table(table_name, options, &block) + created_tables << table_name + connection + rescue Exception => e + connection.execute("DROP TABLE IF EXISTS #{table_name}") + raise e + end + end + + def define_model_class(class_name, &block) + define_class(class_name, ActiveRecord::Base, &block) + end + + def define_active_model_class(class_name, options = {}, &block) + define_class(class_name) do + include ActiveModel::Validations + + options[:accessors].each do |column| + attr_accessor column.to_sym + end + + if block_given? + class_eval(&block) end end end - if columns.key?(:id) && columns[:id] == false - columns.delete(:id) - create_table(table_name, id: false, &table_block) - else - create_table(table_name, &table_block) - end + def define_model(name, columns = {}, &block) + class_name = name.to_s.pluralize.classify + table_name = class_name.tableize.gsub('/', '_') - define_model_class(class_name).tap do |model| - if block - model.class_eval(&block) + table_block = lambda do |table| + columns.each do |name, specification| + if specification.is_a?(Hash) + table.column name, specification[:type], specification[:options] + else + table.column name, specification + end + end end - model.table_name = table_name + if columns.key?(:id) && columns[:id] == false + columns.delete(:id) + create_table(table_name, id: false, &table_block) + else + create_table(table_name, &table_block) + end + + define_model_class(class_name).tap do |model| + if block + model.class_eval(&block) + end + + model.table_name = table_name + end + end + + private + + def drop_created_tables + connection = ActiveRecord::Base.connection + + created_tables.each do |table_name| + connection.execute("DROP TABLE IF EXISTS #{table_name}") + end + end + + def created_tables + @_created_tables ||= [] end end end - -RSpec.configure do |config| - config.include ModelBuilder - - config.before do - ModelBuilder.created_tables.clear - end - - config.after do - ModelBuilder.drop_created_tables - end -end diff --git a/spec/support/unit/helpers/rails_versions.rb b/spec/support/unit/helpers/rails_versions.rb index e2795066..b93767b9 100644 --- a/spec/support/unit/helpers/rails_versions.rb +++ b/spec/support/unit/helpers/rails_versions.rb @@ -1,26 +1,28 @@ -module RailsVersions - def rails_version - Gem::Version.new(Rails::VERSION::STRING) - end +module UnitTests + module RailsVersions + def self.configure_example_group(example_group) + example_group.include(self) + example_group.extend(self) + end - def rails_3_x? - Gem::Requirement.new('~> 3.0').satisfied_by?(rails_version) - end + def rails_version + Gem::Version.new(Rails::VERSION::STRING) + end - def rails_4_x? - Gem::Requirement.new('~> 4.0').satisfied_by?(rails_version) - end + def rails_3_x? + Gem::Requirement.new('~> 3.0').satisfied_by?(rails_version) + end - def rails_gte_4_1? - Gem::Requirement.new('>= 4.1').satisfied_by?(rails_version) - end + def rails_4_x? + Gem::Requirement.new('~> 4.0').satisfied_by?(rails_version) + end - def active_record_supports_enum? - defined?(::ActiveRecord::Enum) + def rails_gte_4_1? + Gem::Requirement.new('>= 4.1').satisfied_by?(rails_version) + end + + def active_record_supports_enum? + defined?(::ActiveRecord::Enum) + end end end - -RSpec.configure do |config| - config.include(RailsVersions) - config.extend(RailsVersions) -end diff --git a/spec/support/unit/matchers/fail_with_message_including_matcher.rb b/spec/support/unit/matchers/fail_with_message_including_matcher.rb index 76f1c345..6acfeeb0 100644 --- a/spec/support/unit/matchers/fail_with_message_including_matcher.rb +++ b/spec/support/unit/matchers/fail_with_message_including_matcher.rb @@ -1,44 +1,50 @@ -RSpec::Matchers.define :fail_with_message_including do |expected| - def supports_block_expectations? - true - end +module UnitTests + module Matchers + extend RSpec::Matchers::DSL - match do |block| - @actual = nil + matcher :fail_with_message_including do |expected| + def supports_block_expectations? + true + end - begin - block.call - rescue RSpec::Expectations::ExpectationNotMetError => ex - @actual = ex.message + match do |block| + @actual = nil + + begin + block.call + rescue RSpec::Expectations::ExpectationNotMetError => ex + @actual = ex.message + end + + @actual && @actual.include?(expected) + end + + def failure_message + msg = "Expectation should have failed with message including '#{expected}'" + + if @actual + msg << ", actually failed with '#{@actual}'" + else + msg << ", but did not fail." + end + + msg + end + + def failure_message_for_should + failure_message + end + + def failure_message_when_negated + msg = "Expectation should not have failed with message including '#{expected}'" + msg << ", but did." + + msg + end + + def failure_message_for_should_not + failure_message_when_negated + end end - - @actual && @actual.include?(expected) - end - - def failure_message - msg = "Expectation should have failed with message including '#{expected}'" - - if @actual - msg << ", actually failed with '#{@actual}'" - else - msg << ", but did not fail." - end - - msg - end - - def failure_message_for_should - failure_message - end - - def failure_message_when_negated - msg = "Expectation should not have failed with message including '#{expected}'" - msg << ", but did." - - msg - end - - def failure_message_for_should_not - failure_message_when_negated end end diff --git a/spec/support/unit/matchers/fail_with_message_matcher.rb b/spec/support/unit/matchers/fail_with_message_matcher.rb index 31e2d2b1..a7a752ff 100644 --- a/spec/support/unit/matchers/fail_with_message_matcher.rb +++ b/spec/support/unit/matchers/fail_with_message_matcher.rb @@ -1,44 +1,50 @@ -RSpec::Matchers.define :fail_with_message do |expected| - def supports_block_expectations? - true - end +module UnitTests + module Matchers + extend RSpec::Matchers::DSL - match do |block| - @actual = nil + matcher :fail_with_message do |expected| + def supports_block_expectations? + true + end - begin - block.call - rescue RSpec::Expectations::ExpectationNotMetError => ex - @actual = ex.message + match do |block| + @actual = nil + + begin + block.call + rescue RSpec::Expectations::ExpectationNotMetError => ex + @actual = ex.message + end + + @actual && @actual == expected + end + + def failure_message + msg = "Expectation should have failed with message '#{expected}'" + + if @actual + msg << ", actually failed with '#{@actual}'" + else + msg << ", but did not fail." + end + + msg + end + + def failure_message_for_should + failure_message + end + + def failure_message_when_negated + msg = "Expectation should not have failed with message '#{expected}'" + msg << ", but did." + + msg + end + + def failure_message_for_should_not + failure_message_when_negated + end end - - @actual && @actual == expected - end - - def failure_message - msg = "Expectation should have failed with message '#{expected}'" - - if @actual - msg << ", actually failed with '#{@actual}'" - else - msg << ", but did not fail." - end - - msg - end - - def failure_message_for_should - failure_message - end - - def failure_message_when_negated - msg = "Expectation should not have failed with message '#{expected}'" - msg << ", but did." - - msg - end - - def failure_message_for_should_not - failure_message_when_negated end end diff --git a/spec/support/unit/rails_application.rb b/spec/support/unit/rails_application.rb index f152bec2..2e970b19 100644 --- a/spec/support/unit/rails_application.rb +++ b/spec/support/unit/rails_application.rb @@ -1,118 +1,120 @@ require 'fileutils' -class TestApplication - ROOT_DIR = File.expand_path('../../../tmp/aruba/testapp', __FILE__) +module UnitTests + class TestApplication + ROOT_DIR = File.expand_path('../../../tmp/aruba/testapp', __FILE__) - def create - clean - generate - within_app { install_gems } - end + def create + clean + generate + within_app { install_gems } + end - def load - load_environment - run_migrations - end + def load + load_environment + run_migrations + end - def gemfile_path - File.join(ROOT_DIR, 'Gemfile') - end + def gemfile_path + File.join(ROOT_DIR, 'Gemfile') + end - def environment_file_path - File.join(ROOT_DIR, 'config/environment') - end + def environment_file_path + File.join(ROOT_DIR, 'config/environment') + end - def temp_views_dir_path - File.join(ROOT_DIR, 'tmp/views') - end + def temp_views_dir_path + File.join(ROOT_DIR, 'tmp/views') + end - def create_temp_view(path, contents) - full_path = temp_view_path_for(path) - FileUtils.mkdir_p(File.dirname(full_path)) - File.open(full_path, 'w') { |file| file.write(contents) } - end + def create_temp_view(path, contents) + full_path = temp_view_path_for(path) + FileUtils.mkdir_p(File.dirname(full_path)) + File.open(full_path, 'w') { |file| file.write(contents) } + end - def delete_temp_views - FileUtils.rm_rf(temp_views_dir_path) - end + def delete_temp_views + FileUtils.rm_rf(temp_views_dir_path) + end - def draw_routes(&block) - Rails.application.routes.draw(&block) - Rails.application.routes - end + def draw_routes(&block) + Rails.application.routes.draw(&block) + Rails.application.routes + end - private + private - def migrations_dir_path - File.join(ROOT_DIR, 'db/migrate') - end + def migrations_dir_path + File.join(ROOT_DIR, 'db/migrate') + end - def temp_view_path_for(path) - File.join(temp_views_dir_path, path) - end + def temp_view_path_for(path) + File.join(temp_views_dir_path, path) + end - def clean - FileUtils.rm_rf(ROOT_DIR) - end + def clean + FileUtils.rm_rf(ROOT_DIR) + end - def generate - rails_new - fix_available_locales_warning - end + def generate + rails_new + fix_available_locales_warning + end - def rails_new - `rails new #{ROOT_DIR} --skip-bundle` - end + def rails_new + `rails new #{ROOT_DIR} --skip-bundle` + end - def fix_available_locales_warning - # See here for more on this: - # http://stackoverflow.com/questions/20361428/rails-i18n-validation-deprecation-warning + def fix_available_locales_warning + # See here for more on this: + # http://stackoverflow.com/questions/20361428/rails-i18n-validation-deprecation-warning - filename = File.join(ROOT_DIR, 'config/application.rb') + filename = File.join(ROOT_DIR, 'config/application.rb') - lines = File.read(filename).split("\n") - lines.insert(-3, < { `#{command}` } + def install_gems + retrying('bundle install --local') do |command| + Bundler.with_clean_env { `#{command}` } + end + end - retry_count = 0 - loop do - output = runner.call("#{command} 2>&1") - if $? == 0 - break - else - retry_count += 1 - if retry_count == 3 - raise "Command '#{command}' failed:\n#{output}" + def within_app(&block) + Dir.chdir(ROOT_DIR, &block) + end + + def retrying(command, &runner) + runner ||= -> { `#{command}` } + + retry_count = 0 + loop do + output = runner.call("#{command} 2>&1") + if $? == 0 + break + else + retry_count += 1 + if retry_count == 3 + raise "Command '#{command}' failed:\n#{output}" + end end end end diff --git a/spec/support/unit/record_builder_with_i18n_validation_message.rb b/spec/support/unit/record_builder_with_i18n_validation_message.rb index aa1d3a93..1cc1d2ab 100644 --- a/spec/support/unit/record_builder_with_i18n_validation_message.rb +++ b/spec/support/unit/record_builder_with_i18n_validation_message.rb @@ -1,6 +1,6 @@ require 'delegate' -module Helpers +module UnitTests class RecordBuilderWithI18nValidationMessage < SimpleDelegator def initialize(builder, options = {}) super(builder) diff --git a/spec/support/unit/record_validating_confirmation_builder.rb b/spec/support/unit/record_validating_confirmation_builder.rb new file mode 100644 index 00000000..b1b9de78 --- /dev/null +++ b/spec/support/unit/record_validating_confirmation_builder.rb @@ -0,0 +1,56 @@ +require_relative 'helpers/model_builder' + +module UnitTests + class RecordValidatingConfirmationBuilder + include ModelBuilder + + def initialize(options) + @options = options + end + + def model + @_model ||= create_model + end + + def model_name + 'Example' + end + + def record + model.new + end + + def message=(message) + options[:message] = message + end + + def attribute_to_confirm + :attribute_to_confirm + end + alias_method :attribute, :attribute_to_confirm + + def confirmation_attribute + :"#{attribute_to_confirm}_confirmation" + end + + def attribute_that_receives_error + Shoulda::Matchers::RailsShim. + validates_confirmation_of_error_attribute(self) + end + + protected + + attr_reader :options + + private + + def create_model + _attribute = attribute_to_confirm + _options = options + + define_model(model_name, _attribute => :string) do + validates_confirmation_of(_attribute, _options) + end + end + end +end diff --git a/spec/support/unit/record_with_different_error_attribute_builder.rb b/spec/support/unit/record_with_different_error_attribute_builder.rb new file mode 100644 index 00000000..4e667511 --- /dev/null +++ b/spec/support/unit/record_with_different_error_attribute_builder.rb @@ -0,0 +1,92 @@ +require_relative 'helpers/model_builder' + +module UnitTests + class RecordWithDifferentErrorAttributeBuilder + include ModelBuilder + + def initialize(options) + @options = options.reverse_merge(default_options) + end + + def attribute_that_receives_error + options[:attribute_that_receives_error] + end + + def attribute_to_validate + options[:attribute_to_validate] + end + + def message + options[:message] + end + + def message=(message) + options[:message] = message + end + + def model + @_model ||= create_model + end + + def model_name + 'Example' + end + + def record + model.new + end + + def valid_value + 'some value' + end + + protected + + attr_reader :options + + private + + def context + { + validation_method_name: validation_method_name, + valid_value: valid_value, + attribute_to_validate: attribute_to_validate, + attribute_that_receives_error: attribute_that_receives_error, + message: message + } + end + + def create_model + _context = context + + define_model model_name, model_columns do + validate _context[:validation_method_name] + + define_method(_context[:validation_method_name]) do + if self[_context[:attribute_to_validate]] != _context[:valid_value] + self.errors.add(_context[:attribute_that_receives_error], _context[:message]) + end + end + end + end + + def validation_method_name + :custom_validation + end + + def model_columns + { + attribute_to_validate => :string, + attribute_that_receives_error => :string + } + end + + def default_options + { + attribute_that_receives_error: :attribute_that_receives_error, + attribute_to_validate: :attribute_to_validate, + message: 'some message' + } + end + end + end diff --git a/spec/unit/shoulda/matchers/action_controller/callback_matcher_spec.rb b/spec/unit/shoulda/matchers/action_controller/callback_matcher_spec.rb index cb5ace6d..c93ad202 100644 --- a/spec/unit/shoulda/matchers/action_controller/callback_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/action_controller/callback_matcher_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'unit_spec_helper' describe Shoulda::Matchers::ActionController::CallbackMatcher do shared_examples 'CallbackMatcher' do |kind, callback_type| diff --git a/spec/unit/shoulda/matchers/action_controller/filter_param_matcher_spec.rb b/spec/unit/shoulda/matchers/action_controller/filter_param_matcher_spec.rb index 4d30146d..833c9106 100644 --- a/spec/unit/shoulda/matchers/action_controller/filter_param_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/action_controller/filter_param_matcher_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'unit_spec_helper' describe Shoulda::Matchers::ActionController::FilterParamMatcher do it 'accepts filtering a filtered parameter' do diff --git a/spec/unit/shoulda/matchers/action_controller/redirect_to_matcher_spec.rb b/spec/unit/shoulda/matchers/action_controller/redirect_to_matcher_spec.rb index 83d5d7e5..a4b0ae9c 100644 --- a/spec/unit/shoulda/matchers/action_controller/redirect_to_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/action_controller/redirect_to_matcher_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'unit_spec_helper' describe Shoulda::Matchers::ActionController::RedirectToMatcher do context 'a controller that redirects' do diff --git a/spec/unit/shoulda/matchers/action_controller/render_template_matcher_spec.rb b/spec/unit/shoulda/matchers/action_controller/render_template_matcher_spec.rb index 1114736b..b4754d20 100644 --- a/spec/unit/shoulda/matchers/action_controller/render_template_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/action_controller/render_template_matcher_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'unit_spec_helper' describe Shoulda::Matchers::ActionController::RenderTemplateMatcher do include ActionController::TemplateAssertions diff --git a/spec/unit/shoulda/matchers/action_controller/render_with_layout_matcher_spec.rb b/spec/unit/shoulda/matchers/action_controller/render_with_layout_matcher_spec.rb index e7e896f4..f4a87325 100644 --- a/spec/unit/shoulda/matchers/action_controller/render_with_layout_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/action_controller/render_with_layout_matcher_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'unit_spec_helper' describe Shoulda::Matchers::ActionController::RenderWithLayoutMatcher do include ActionController::TemplateAssertions diff --git a/spec/unit/shoulda/matchers/action_controller/rescue_from_matcher_spec.rb b/spec/unit/shoulda/matchers/action_controller/rescue_from_matcher_spec.rb index cbe347d0..6328f495 100644 --- a/spec/unit/shoulda/matchers/action_controller/rescue_from_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/action_controller/rescue_from_matcher_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'unit_spec_helper' describe Shoulda::Matchers::ActionController::RescueFromMatcher do context 'a controller that rescues from RuntimeError' do diff --git a/spec/unit/shoulda/matchers/action_controller/respond_with_matcher_spec.rb b/spec/unit/shoulda/matchers/action_controller/respond_with_matcher_spec.rb index 7af2b5cd..8d5397b5 100644 --- a/spec/unit/shoulda/matchers/action_controller/respond_with_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/action_controller/respond_with_matcher_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'unit_spec_helper' describe Shoulda::Matchers::ActionController::RespondWithMatcher do statuses = { success: 200, redirect: 301, missing: 404, error: 500, diff --git a/spec/unit/shoulda/matchers/action_controller/route_matcher_spec.rb b/spec/unit/shoulda/matchers/action_controller/route_matcher_spec.rb index de26a170..20d971ca 100644 --- a/spec/unit/shoulda/matchers/action_controller/route_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/action_controller/route_matcher_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'unit_spec_helper' describe 'Shoulda::Matchers::ActionController::RouteMatcher', type: :controller do context 'given a controller with a defined glob url' do diff --git a/spec/unit/shoulda/matchers/action_controller/route_params_spec.rb b/spec/unit/shoulda/matchers/action_controller/route_params_spec.rb index 20001124..5b7d7b42 100644 --- a/spec/unit/shoulda/matchers/action_controller/route_params_spec.rb +++ b/spec/unit/shoulda/matchers/action_controller/route_params_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'unit_spec_helper' describe Shoulda::Matchers::ActionController::RouteParams do describe "#normalize" do diff --git a/spec/unit/shoulda/matchers/action_controller/set_session_matcher_spec.rb b/spec/unit/shoulda/matchers/action_controller/set_session_matcher_spec.rb index 9c1c46f5..00ac86f7 100644 --- a/spec/unit/shoulda/matchers/action_controller/set_session_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/action_controller/set_session_matcher_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'unit_spec_helper' describe Shoulda::Matchers::ActionController::SetSessionMatcher do context 'a controller that sets a session variable' do diff --git a/spec/unit/shoulda/matchers/action_controller/set_the_flash_matcher_spec.rb b/spec/unit/shoulda/matchers/action_controller/set_the_flash_matcher_spec.rb index bde5d305..552b5e7b 100644 --- a/spec/unit/shoulda/matchers/action_controller/set_the_flash_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/action_controller/set_the_flash_matcher_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'unit_spec_helper' describe Shoulda::Matchers::ActionController::SetTheFlashMatcher do it 'fails with unmatchable #to' do diff --git a/spec/unit/shoulda/matchers/action_controller/strong_parameters_matcher_spec.rb b/spec/unit/shoulda/matchers/action_controller/strong_parameters_matcher_spec.rb index 4f26e8c8..17e4f420 100644 --- a/spec/unit/shoulda/matchers/action_controller/strong_parameters_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/action_controller/strong_parameters_matcher_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'unit_spec_helper' describe Shoulda::Matchers::ActionController do describe '#permit' do diff --git a/spec/unit/shoulda/matchers/active_model/allow_mass_assignment_of_matcher_spec.rb b/spec/unit/shoulda/matchers/active_model/allow_mass_assignment_of_matcher_spec.rb index 454e1798..4fb5bbc1 100644 --- a/spec/unit/shoulda/matchers/active_model/allow_mass_assignment_of_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/active_model/allow_mass_assignment_of_matcher_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'unit_spec_helper' describe Shoulda::Matchers::ActiveModel::AllowMassAssignmentOfMatcher do context '#description' do diff --git a/spec/unit/shoulda/matchers/active_model/allow_value_matcher_spec.rb b/spec/unit/shoulda/matchers/active_model/allow_value_matcher_spec.rb index 05960b76..be8ea82c 100644 --- a/spec/unit/shoulda/matchers/active_model/allow_value_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/active_model/allow_value_matcher_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'unit_spec_helper' describe Shoulda::Matchers::ActiveModel::AllowValueMatcher do context "#description" do @@ -89,7 +89,7 @@ describe Shoulda::Matchers::ActiveModel::AllowValueMatcher do end context 'when the attribute being validated is different than the attribute that receives the validation error' do - include Helpers::AllowValueMatcherHelpers + include UnitTests::AllowValueMatcherHelpers context 'when the validation error message was provided directly' do it 'passes given a valid value' do diff --git a/spec/unit/shoulda/matchers/active_model/disallow_value_matcher_spec.rb b/spec/unit/shoulda/matchers/active_model/disallow_value_matcher_spec.rb index 4a7f2fa2..7725ac14 100644 --- a/spec/unit/shoulda/matchers/active_model/disallow_value_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/active_model/disallow_value_matcher_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'unit_spec_helper' describe Shoulda::Matchers::ActiveModel::DisallowValueMatcher do context 'an attribute with a format validation' do diff --git a/spec/unit/shoulda/matchers/active_model/ensure_length_of_matcher_spec.rb b/spec/unit/shoulda/matchers/active_model/ensure_length_of_matcher_spec.rb index b05e7714..e61d038b 100644 --- a/spec/unit/shoulda/matchers/active_model/ensure_length_of_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/active_model/ensure_length_of_matcher_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'unit_spec_helper' describe Shoulda::Matchers::ActiveModel::EnsureLengthOfMatcher do context 'an attribute with a non-zero minimum length validation' do diff --git a/spec/unit/shoulda/matchers/active_model/exception_message_finder_spec.rb b/spec/unit/shoulda/matchers/active_model/exception_message_finder_spec.rb index 6210c395..3efa53e3 100644 --- a/spec/unit/shoulda/matchers/active_model/exception_message_finder_spec.rb +++ b/spec/unit/shoulda/matchers/active_model/exception_message_finder_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'unit_spec_helper' describe Shoulda::Matchers::ActiveModel::ExceptionMessageFinder do if active_model_3_2? diff --git a/spec/unit/shoulda/matchers/active_model/have_secure_password_matcher_spec.rb b/spec/unit/shoulda/matchers/active_model/have_secure_password_matcher_spec.rb index d9d187db..ac0e76bb 100644 --- a/spec/unit/shoulda/matchers/active_model/have_secure_password_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/active_model/have_secure_password_matcher_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'unit_spec_helper' describe Shoulda::Matchers::ActiveModel::HaveSecurePasswordMatcher do if active_model_3_1? diff --git a/spec/unit/shoulda/matchers/active_model/helpers_spec.rb b/spec/unit/shoulda/matchers/active_model/helpers_spec.rb index eeb2ca49..ab9e174a 100644 --- a/spec/unit/shoulda/matchers/active_model/helpers_spec.rb +++ b/spec/unit/shoulda/matchers/active_model/helpers_spec.rb @@ -1,5 +1,5 @@ # encoding: UTF-8 -require 'spec_helper' +require 'unit_spec_helper' describe Shoulda::Matchers::ActiveModel::Helpers do include Shoulda::Matchers::ActiveModel diff --git a/spec/unit/shoulda/matchers/active_model/numericality_matchers/comparison_matcher_spec.rb b/spec/unit/shoulda/matchers/active_model/numericality_matchers/comparison_matcher_spec.rb index 4ea3016e..122f7a05 100644 --- a/spec/unit/shoulda/matchers/active_model/numericality_matchers/comparison_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/active_model/numericality_matchers/comparison_matcher_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'unit_spec_helper' describe Shoulda::Matchers::ActiveModel::NumericalityMatchers::ComparisonMatcher do subject { described_class.new(matcher, 0, :>) } diff --git a/spec/unit/shoulda/matchers/active_model/numericality_matchers/even_number_matcher_spec.rb b/spec/unit/shoulda/matchers/active_model/numericality_matchers/even_number_matcher_spec.rb index 199e09dc..c7bd572e 100644 --- a/spec/unit/shoulda/matchers/active_model/numericality_matchers/even_number_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/active_model/numericality_matchers/even_number_matcher_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'unit_spec_helper' describe Shoulda::Matchers::ActiveModel::NumericalityMatchers::EvenNumberMatcher do subject { described_class.new(:attr) } diff --git a/spec/unit/shoulda/matchers/active_model/numericality_matchers/odd_number_matcher_spec.rb b/spec/unit/shoulda/matchers/active_model/numericality_matchers/odd_number_matcher_spec.rb index b4aebd5d..ef79972c 100644 --- a/spec/unit/shoulda/matchers/active_model/numericality_matchers/odd_number_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/active_model/numericality_matchers/odd_number_matcher_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'unit_spec_helper' describe Shoulda::Matchers::ActiveModel::NumericalityMatchers::OddNumberMatcher do subject { described_class.new(:attr) } diff --git a/spec/unit/shoulda/matchers/active_model/numericality_matchers/only_integer_matcher_spec.rb b/spec/unit/shoulda/matchers/active_model/numericality_matchers/only_integer_matcher_spec.rb index 35378bf4..7eeec92f 100644 --- a/spec/unit/shoulda/matchers/active_model/numericality_matchers/only_integer_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/active_model/numericality_matchers/only_integer_matcher_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'unit_spec_helper' describe Shoulda::Matchers::ActiveModel::NumericalityMatchers::OnlyIntegerMatcher do subject { described_class.new(:attr) } diff --git a/spec/unit/shoulda/matchers/active_model/validate_absence_of_matcher_spec.rb b/spec/unit/shoulda/matchers/active_model/validate_absence_of_matcher_spec.rb index 47a9d6da..74f46682 100644 --- a/spec/unit/shoulda/matchers/active_model/validate_absence_of_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/active_model/validate_absence_of_matcher_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'unit_spec_helper' describe Shoulda::Matchers::ActiveModel::ValidateAbsenceOfMatcher do if active_model_4_0? diff --git a/spec/unit/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb b/spec/unit/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb index d0ed25f4..b2349211 100644 --- a/spec/unit/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'unit_spec_helper' describe Shoulda::Matchers::ActiveModel::ValidateAcceptanceOfMatcher do context 'a model with an acceptance validation' do diff --git a/spec/unit/shoulda/matchers/active_model/validate_confirmation_of_matcher_spec.rb b/spec/unit/shoulda/matchers/active_model/validate_confirmation_of_matcher_spec.rb index 25496452..bcc1f006 100644 --- a/spec/unit/shoulda/matchers/active_model/validate_confirmation_of_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/active_model/validate_confirmation_of_matcher_spec.rb @@ -1,7 +1,7 @@ -require 'spec_helper' +require 'unit_spec_helper' describe Shoulda::Matchers::ActiveModel::ValidateConfirmationOfMatcher do - include Helpers::ConfirmationMatcherHelpers + include UnitTests::ConfirmationMatcherHelpers context '#description' do it 'states that the confirmation must match its base attribute' do diff --git a/spec/unit/shoulda/matchers/active_model/validate_exclusion_of_matcher_spec.rb b/spec/unit/shoulda/matchers/active_model/validate_exclusion_of_matcher_spec.rb index a8e02081..914e01fe 100644 --- a/spec/unit/shoulda/matchers/active_model/validate_exclusion_of_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/active_model/validate_exclusion_of_matcher_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'unit_spec_helper' describe Shoulda::Matchers::ActiveModel do describe '#ensure_exclusion_of' do diff --git a/spec/unit/shoulda/matchers/active_model/validate_inclusion_of_matcher_spec.rb b/spec/unit/shoulda/matchers/active_model/validate_inclusion_of_matcher_spec.rb index 2303479b..8ca36d22 100644 --- a/spec/unit/shoulda/matchers/active_model/validate_inclusion_of_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/active_model/validate_inclusion_of_matcher_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'unit_spec_helper' describe Shoulda::Matchers::ActiveModel do describe '#ensure_inclusion_of' do diff --git a/spec/unit/shoulda/matchers/active_model/validate_numericality_of_matcher_spec.rb b/spec/unit/shoulda/matchers/active_model/validate_numericality_of_matcher_spec.rb index b0093ace..78ec6203 100644 --- a/spec/unit/shoulda/matchers/active_model/validate_numericality_of_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/active_model/validate_numericality_of_matcher_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'unit_spec_helper' describe Shoulda::Matchers::ActiveModel::ValidateNumericalityOfMatcher do diff --git a/spec/unit/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb b/spec/unit/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb index 301d046a..740941f6 100644 --- a/spec/unit/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'unit_spec_helper' describe Shoulda::Matchers::ActiveModel::ValidatePresenceOfMatcher do context 'a model with a presence validation' do diff --git a/spec/unit/shoulda/matchers/active_model/validate_uniqueness_of_matcher_spec.rb b/spec/unit/shoulda/matchers/active_model/validate_uniqueness_of_matcher_spec.rb index 22f5d87e..b0dac4d8 100644 --- a/spec/unit/shoulda/matchers/active_model/validate_uniqueness_of_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/active_model/validate_uniqueness_of_matcher_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'unit_spec_helper' describe Shoulda::Matchers::ActiveModel::ValidateUniquenessOfMatcher do context 'a model without a a uniqueness validation' do diff --git a/spec/unit/shoulda/matchers/active_model/validation_message_finder_spec.rb b/spec/unit/shoulda/matchers/active_model/validation_message_finder_spec.rb index 5b209dda..82ebdfa5 100644 --- a/spec/unit/shoulda/matchers/active_model/validation_message_finder_spec.rb +++ b/spec/unit/shoulda/matchers/active_model/validation_message_finder_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'unit_spec_helper' describe Shoulda::Matchers::ActiveModel::ValidationMessageFinder do context '#allow_description' do diff --git a/spec/unit/shoulda/matchers/active_record/accept_nested_attributes_for_matcher_spec.rb b/spec/unit/shoulda/matchers/active_record/accept_nested_attributes_for_matcher_spec.rb index 15cc7d16..87f028f0 100644 --- a/spec/unit/shoulda/matchers/active_record/accept_nested_attributes_for_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/active_record/accept_nested_attributes_for_matcher_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'unit_spec_helper' describe Shoulda::Matchers::ActiveRecord::AcceptNestedAttributesForMatcher do it 'accepts an existing declaration' do diff --git a/spec/unit/shoulda/matchers/active_record/association_matcher_spec.rb b/spec/unit/shoulda/matchers/active_record/association_matcher_spec.rb index 07a9401b..5c4ab36d 100644 --- a/spec/unit/shoulda/matchers/active_record/association_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/active_record/association_matcher_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'unit_spec_helper' describe Shoulda::Matchers::ActiveRecord::AssociationMatcher do context 'belong_to' do diff --git a/spec/unit/shoulda/matchers/active_record/association_matchers/model_reflection_spec.rb b/spec/unit/shoulda/matchers/active_record/association_matchers/model_reflection_spec.rb index 709b220c..2f158dda 100644 --- a/spec/unit/shoulda/matchers/active_record/association_matchers/model_reflection_spec.rb +++ b/spec/unit/shoulda/matchers/active_record/association_matchers/model_reflection_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'unit_spec_helper' describe Shoulda::Matchers::ActiveRecord::AssociationMatchers::ModelReflection do it 'delegates other methods to the given Reflection object' do diff --git a/spec/unit/shoulda/matchers/active_record/define_enum_for_matcher_spec.rb b/spec/unit/shoulda/matchers/active_record/define_enum_for_matcher_spec.rb index 0afa71df..f0905014 100644 --- a/spec/unit/shoulda/matchers/active_record/define_enum_for_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/active_record/define_enum_for_matcher_spec.rb @@ -1,4 +1,4 @@ -require "spec_helper" +require "unit_spec_helper" describe Shoulda::Matchers::ActiveRecord::DefineEnumForMatcher do if active_record_supports_enum? diff --git a/spec/unit/shoulda/matchers/active_record/have_db_column_matcher_spec.rb b/spec/unit/shoulda/matchers/active_record/have_db_column_matcher_spec.rb index 65771eea..b9ded0b7 100644 --- a/spec/unit/shoulda/matchers/active_record/have_db_column_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/active_record/have_db_column_matcher_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'unit_spec_helper' describe Shoulda::Matchers::ActiveRecord::HaveDbColumnMatcher do it 'accepts an existing database column' do diff --git a/spec/unit/shoulda/matchers/active_record/have_db_index_matcher_spec.rb b/spec/unit/shoulda/matchers/active_record/have_db_index_matcher_spec.rb index 2ea98575..7aa1560e 100644 --- a/spec/unit/shoulda/matchers/active_record/have_db_index_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/active_record/have_db_index_matcher_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'unit_spec_helper' describe Shoulda::Matchers::ActiveRecord::HaveDbIndexMatcher do context 'have_db_index' do diff --git a/spec/unit/shoulda/matchers/active_record/have_readonly_attributes_matcher_spec.rb b/spec/unit/shoulda/matchers/active_record/have_readonly_attributes_matcher_spec.rb index b3f78fb6..64694249 100644 --- a/spec/unit/shoulda/matchers/active_record/have_readonly_attributes_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/active_record/have_readonly_attributes_matcher_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'unit_spec_helper' describe Shoulda::Matchers::ActiveRecord::HaveReadonlyAttributeMatcher do context 'a read-only attribute' do diff --git a/spec/unit/shoulda/matchers/active_record/serialize_matcher_spec.rb b/spec/unit/shoulda/matchers/active_record/serialize_matcher_spec.rb index 48538489..2ca523f3 100644 --- a/spec/unit/shoulda/matchers/active_record/serialize_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/active_record/serialize_matcher_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'unit_spec_helper' describe Shoulda::Matchers::ActiveRecord::SerializeMatcher do it 'accepts when the attribute is serialized' do diff --git a/spec/unit/shoulda/matchers/doublespeak/double_collection_spec.rb b/spec/unit/shoulda/matchers/doublespeak/double_collection_spec.rb index 48f65472..43628d42 100644 --- a/spec/unit/shoulda/matchers/doublespeak/double_collection_spec.rb +++ b/spec/unit/shoulda/matchers/doublespeak/double_collection_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'unit_spec_helper' module Shoulda::Matchers::Doublespeak describe DoubleCollection do diff --git a/spec/unit/shoulda/matchers/doublespeak/double_implementation_registry_spec.rb b/spec/unit/shoulda/matchers/doublespeak/double_implementation_registry_spec.rb index 4bbe2d15..36f1c7ce 100644 --- a/spec/unit/shoulda/matchers/doublespeak/double_implementation_registry_spec.rb +++ b/spec/unit/shoulda/matchers/doublespeak/double_implementation_registry_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'unit_spec_helper' module Shoulda::Matchers::Doublespeak describe DoubleImplementationRegistry do diff --git a/spec/unit/shoulda/matchers/doublespeak/double_spec.rb b/spec/unit/shoulda/matchers/doublespeak/double_spec.rb index fac71de9..2cde3a6e 100644 --- a/spec/unit/shoulda/matchers/doublespeak/double_spec.rb +++ b/spec/unit/shoulda/matchers/doublespeak/double_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'unit_spec_helper' module Shoulda::Matchers::Doublespeak describe Double do diff --git a/spec/unit/shoulda/matchers/doublespeak/object_double_spec.rb b/spec/unit/shoulda/matchers/doublespeak/object_double_spec.rb index f5550993..b28bf5b4 100644 --- a/spec/unit/shoulda/matchers/doublespeak/object_double_spec.rb +++ b/spec/unit/shoulda/matchers/doublespeak/object_double_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'unit_spec_helper' module Shoulda::Matchers::Doublespeak describe ObjectDouble do diff --git a/spec/unit/shoulda/matchers/doublespeak/proxy_implementation_spec.rb b/spec/unit/shoulda/matchers/doublespeak/proxy_implementation_spec.rb index 814b5649..8ff99ca1 100644 --- a/spec/unit/shoulda/matchers/doublespeak/proxy_implementation_spec.rb +++ b/spec/unit/shoulda/matchers/doublespeak/proxy_implementation_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'unit_spec_helper' module Shoulda::Matchers::Doublespeak describe ProxyImplementation do diff --git a/spec/unit/shoulda/matchers/doublespeak/stub_implementation_spec.rb b/spec/unit/shoulda/matchers/doublespeak/stub_implementation_spec.rb index fd6d3ad5..6112fc10 100644 --- a/spec/unit/shoulda/matchers/doublespeak/stub_implementation_spec.rb +++ b/spec/unit/shoulda/matchers/doublespeak/stub_implementation_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'unit_spec_helper' module Shoulda::Matchers::Doublespeak describe StubImplementation do diff --git a/spec/unit/shoulda/matchers/doublespeak/world_spec.rb b/spec/unit/shoulda/matchers/doublespeak/world_spec.rb index d1ca6934..0db255a7 100644 --- a/spec/unit/shoulda/matchers/doublespeak/world_spec.rb +++ b/spec/unit/shoulda/matchers/doublespeak/world_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'unit_spec_helper' module Shoulda::Matchers::Doublespeak describe World do diff --git a/spec/unit/shoulda/matchers/doublespeak_spec.rb b/spec/unit/shoulda/matchers/doublespeak_spec.rb index 0d256818..6a0abe69 100644 --- a/spec/unit/shoulda/matchers/doublespeak_spec.rb +++ b/spec/unit/shoulda/matchers/doublespeak_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'unit_spec_helper' module Shoulda::Matchers describe Doublespeak do diff --git a/spec/unit/shoulda/matchers/independent/delegate_method_matcher/stubbed_target_spec.rb b/spec/unit/shoulda/matchers/independent/delegate_method_matcher/stubbed_target_spec.rb index e132ed00..f44dcbf5 100644 --- a/spec/unit/shoulda/matchers/independent/delegate_method_matcher/stubbed_target_spec.rb +++ b/spec/unit/shoulda/matchers/independent/delegate_method_matcher/stubbed_target_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'unit_spec_helper' describe Shoulda::Matchers::Independent::DelegateMethodMatcher::StubbedTarget do subject(:target) { described_class.new(:stubbed_method) } diff --git a/spec/unit/shoulda/matchers/independent/delegate_method_matcher_spec.rb b/spec/unit/shoulda/matchers/independent/delegate_method_matcher_spec.rb index 53d6f8ee..989e611c 100644 --- a/spec/unit/shoulda/matchers/independent/delegate_method_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/independent/delegate_method_matcher_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'unit_spec_helper' describe Shoulda::Matchers::Independent::DelegateMethodMatcher do describe '#description' do diff --git a/spec/unit_spec_helper.rb b/spec/unit_spec_helper.rb index 51e06472..b93fce83 100644 --- a/spec/unit_spec_helper.rb +++ b/spec/unit_spec_helper.rb @@ -1,4 +1,4 @@ -require File.expand_path('../support/test_application', __FILE__) +require File.expand_path('../support/unit/rails_application', __FILE__) def monkey_patch_minitest_to_do_nothing # Rails 3.1's test_help file requires Turn, which loads Minitest in autorun @@ -13,7 +13,7 @@ def monkey_patch_minitest_to_do_nothing end end -$test_app = TestApplication.new +$test_app = UnitTests::RailsApplication.new $test_app.create $test_app.load @@ -29,18 +29,33 @@ require 'rspec/rails' PROJECT_ROOT = File.expand_path('../..', __FILE__) $LOAD_PATH << File.join(PROJECT_ROOT, 'lib') -Dir[ File.join(PROJECT_ROOT, 'spec/support/**/*.rb') ].each { |file| require file } +Dir[ File.join(File.expand_path('../support/unit/**/*.rb', __FILE__)) ].each do |file| + require file +end + RSpec.configure do |config| config.expect_with :rspec do |c| c.syntax = :expect end - config.mock_with :mocha - config.include Shoulda::Matchers::ActionController, type: :controller - if config.respond_to?(:infer_spec_type_from_file_location!) config.infer_spec_type_from_file_location! end + + config.mock_with :mocha + config.include Shoulda::Matchers::ActionController, type: :controller + + UnitTests::ActiveModelHelpers.configure_example_group(config) + UnitTests::ActiveModelVersions.configure_example_group(config) + UnitTests::ActiveResourceBuilder.configure_example_group(config) + UnitTests::ClassBuilder.configure_example_group(config) + UnitTests::ControllerBuilder.configure_example_group(config) + UnitTests::I18nFaker.configure_example_group(config) + UnitTests::MailerBuilder.configure_example_group(config) + UnitTests::ModelBuilder.configure_example_group(config) + UnitTests::RailsVersions.configure_example_group(config) + + config.include UnitTests::Matchers end $VERBOSE = true