Module: Test::Spec::Rails
- Defined in:
- lib/test/spec/rails.rb,
lib/test/spec/rails.rb,
lib/test/spec/rails/macros.rb,
lib/test/spec/rails/expectations.rb,
lib/test/spec/rails/macros/response.rb,
lib/test/spec/rails/request_helpers.rb,
lib/test/spec/rails/response_helpers.rb,
lib/test/spec/rails/controller_helpers.rb,
lib/test/spec/rails/macros/authorization.rb
Defined Under Namespace
Modules: ControllerHelpers, Helpers, Macros, RequestHelpers, ResponseHelpers, ShouldExpectations, ShouldNotExpectations Classes: Layout, SpecResponder, Status, Template
Class Method Summary collapse
-
.extract_test_case_args(args) ⇒ Object
Returns the test class for a definition line in a spec.
-
.test_case_for_class(klass) ⇒ Object
Returns the test class for a class.
Class Method Details
.extract_test_case_args(args) ⇒ Object
Returns the test class for a definition line in a spec.
extract_test_case_args(["A", User, "concerning validation"]) # => ActiveRecord::TestCase
35 36 37 38 39 40 41 42 43 |
# File 'lib/test/spec/rails.rb', line 35 def self.extract_test_case_args(args) class_to_test = args.find { |a| a.is_a?(Module) } superclass = test_case_for_class(class_to_test) args.delete(class_to_test) if superclass == class_to_test name = args.map { |a| a.to_s }.join(' ') [name, class_to_test, superclass] end |
.test_case_for_class(klass) ⇒ Object
Returns the test class for a class
extract_test_case_for_class(UsersController) # => ActionController::TestCase
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/test/spec/rails.rb', line 48 def self.test_case_for_class(klass) if klass if klass.ancestors.include?(ActiveRecord::Base) ActiveRecord::TestCase elsif klass.ancestors.include?(ActionController::Base) ActionController::TestCase elsif klass.ancestors.include?(ActiveSupport::TestCase) klass elsif !klass.is_a?(Class) && klass.to_s.ends_with?('Helper') ActionView::TestCase end end || ActiveSupport::TestCase end |